Skip to content

Instantly share code, notes, and snippets.

@nothingismagick
Created June 29, 2021 19:05
Show Gist options
  • Save nothingismagick/4cef55c21151685945b257fb5737ef02 to your computer and use it in GitHub Desktop.
Save nothingismagick/4cef55c21151685945b257fb5737ef02 to your computer and use it in GitHub Desktop.
Minimal Tauri "read public key" translation from Electron Sample
<html>
<head>
<script type="module">
import { invoke } from './@tauri-apps/api/tauri.js'; // just copied from node_modules
function getPubkey() {
return invoke("show_pubkey").then((message) => message);
}
document.getElementById("clicky").addEventListener("click", async function () {
document.getElementById("key").innerHTML = await getPubkey();
})
</script>
<style>
body {
background: rebeccapurple;
color: darkgoldenrod;
}
code {
width: 90%;
margin: auto;
background: indigo;
word-wrap: break-word;
box-decoration-break: clone;
padding: .1rem .3rem .2rem;
border-radius: .2rem;
}
</style>
</head>
<body>
<button id="clicky">Retrieve Public Key</button>
<h1>Public Key:</h1>
<code id="key"></code>
</body>
</html>
use tauri::api::path::home_dir;
use std::fs;
#[tauri::command]
fn show_pubkey() -> String {
if let Some(home) = home_dir() {
let pubkey = fs::read_to_string(home.join(".ssh/id_rsa.pb")).unwrap();
pubkey.to_string()
} else {
"could not read home directory".to_string()
}
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![show_pubkey])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
// There is more here, but these are the important bits
"allowlist": {
"all": false
},
...
"security": {
"csp": "default-src tauri: 'self'"
},
@nothingismagick
Copy link
Author

@nothingismagick
Copy link
Author

Screenshot 2021-06-29 at 22 42 11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment