Skip to content

Commit

Permalink
Finished for now
Browse files Browse the repository at this point in the history
  • Loading branch information
d-exclaimation committed Dec 18, 2022
1 parent e6d80cd commit e9fd32b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
27 changes: 23 additions & 4 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,33 @@
windows_subsystem = "windows"
)]

#[derive(serde::Serialize)]
struct CustomResponse {
message: String,
}

async fn something_else() -> Option<String> {
Some("All goods from the frontend 👍".into())
}

#[tauri::command]
fn ok() -> String {
String::from("All goods here 👍")
async fn something(
window: tauri::Window
) -> Result<CustomResponse, String> {
println!("All goods here 👍 at native level, passing back to {}", window.label());
let result: Option<String> = something_else().await;
if let Some(message) = result {
Ok(CustomResponse {
message
})
} else {
Err("No result".into())
}
}

fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![ok])
.invoke_handler(tauri::generate_handler![something])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
}
6 changes: 3 additions & 3 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.tauri.dev",
"longDescription": "",
"identifier": "",
"longDescription": "Apollo Sandbox on desktop",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
Expand All @@ -39,7 +39,7 @@
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"shortDescription": "ApolloSandbox.app",
"targets": "all",
"windows": {
"certificateThumbprint": null,
Expand Down
11 changes: 6 additions & 5 deletions ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

<script src="https://embeddable-sandbox.cdn.apollographql.com/_latest/embeddable-sandbox.umd.production.min.js"></script>
<script>
// new window.EmbeddedSandbox({
// target: "#sandbox"
// });
new window.EmbeddedSandbox({
target: "#sandbox"
});

const { invoke } = window.__TAURI__.tauri;

invoke("ok")
.then(response => console.log(response));
invoke("something")
.then(({message}) => console.log(message))
.catch(error => console.error(error));
</script>
</html>

0 comments on commit e9fd32b

Please sign in to comment.