Skip to content

Commit

Permalink
Merge pull request #34 from redradist/feature/add-set-tls-certificate
Browse files Browse the repository at this point in the history
Add setTLSCertificate to WebUI
  • Loading branch information
hassandraga authored Nov 29, 2023
2 parents 5966f94 + acb9138 commit 235bcda
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ export function loadLib() {
parameters: ["usize", "buffer"],
result: "bool",
},
webui_set_tls_certificate: {
// bool webui_set_tls_certificate(const char* certificate_pem, const char* private_key_pem)
parameters: ["buffer", "buffer"],
result: "bool",
},
} as const,
);
}
33 changes: 33 additions & 0 deletions src/webui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,39 @@ export class WebUI {
}
}

/**
* Set certificate
* @param certificatePem Set certificate
* @param privateKeyPem Set private key
* @throws {WebUIError} - If lib return false status.
* @example
* ```ts
* const myWindow = new WebUI()
*
* // Show the current time
* myWindow.setRootFolder('some/root/folder')
*
* const certificatePem = await Deno.readTextFile("some/root/certificate.pem");
* const privateKeyPem = await Deno.readTextFile("some/root/private_key.pem");
* WebUI.setTLSCertificate(certificatePem, privateKeyPem);
*
* // Show a local file
* await myWindow.show('some/root/folder/index.html')
*
* // Await to ensure WebUI.script and WebUI.run can send datas to the client
* console.assert(myWindow.isShown, true)
* ```
*/
static setTLSCertificate(certificatePem: string, privateKeyPem: string) {
const status = _lib.symbols.webui_set_tls_certificate(
toCString(certificatePem),
toCString(privateKeyPem),
);
if (!status) {
throw new WebUIError(`unable to set certificate`);
}
}

/**
* Show the window or update the UI with the new content.
* @returns Promise that resolves when the client bridge is linked.
Expand Down

0 comments on commit 235bcda

Please sign in to comment.