Created
June 29, 2021 19:05
-
-
Save nothingismagick/4cef55c21151685945b257fb5737ef02 to your computer and use it in GitHub Desktop.
Minimal Tauri "read public key" translation from Electron Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// There is more here, but these are the important bits | |
"allowlist": { | |
"all": false | |
}, | |
... | |
"security": { | |
"csp": "default-src tauri: 'self'" | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For posterity, here are the relevant tweets:
Challenge:
https://twitter.com/MarshallOfSound/status/1409809802251825154
Response:
https://twitter.com/TauriApps/status/1409951686551085064