backport upgrade of Tauri API

master
Niko PLP 3 months ago
parent fcba765ca0
commit 89074a647d
  1. 2
      helpers/ngaccount/web/index.html
  2. 3
      helpers/ngaccount/web/package.json
  3. 42
      helpers/ngaccount/web/src/routes/Create.svelte
  4. 35
      ng-app/src-tauri/src/lib.rs
  5. 31
      ng-app/src/App.svelte
  6. 34
      ng-app/src/api.ts
  7. 2
      ng-app/src/lib/NoWallet.svelte
  8. 18
      ng-app/src/routes/WalletCreate.svelte

@ -58,7 +58,7 @@
<title>NextGraph</title>
<style>
.splashing {
height: 95vh;display: grid;
height: 100vh;display: flex; justify-content: center; width: 100%;
}
.noshow {
display: none !important;

@ -10,8 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"@tauri-apps/api": "2.0.0-alpha.8",
"@tauri-apps/plugin-window": "2.0.0-alpha.1",
"@tauri-apps/api": "2.9.0",
"flowbite": "^1.6.5",
"flowbite-svelte": "^0.37.1",
"svelte-spa-router": "^3.3.0"

@ -20,6 +20,7 @@
import { onMount } from "svelte";
let domain = import.meta.env.NG_ACCOUNT_DOMAIN;
const param = new URLSearchParams($querystring);
let web = param.get("web");
let ca = param.get("ca");
let go_back = true;
let wait = false;
@ -55,19 +56,14 @@
async function close(result) {
// @ts-ignore
if (window.__TAURI__) {
if (!web) {
go_back = false;
if (result) {
error = "Closing due to " + (result.error || "an error");
}
let window_api = await import("@tauri-apps/plugin-window");
let main = window_api.Window.getByLabel("main");
if (main) {
wait = true;
await main.emit("error", result);
} else {
await window_api.getCurrent().close();
}
let event_api = await import("@tauri-apps/api/event");
wait = true;
await event_api.emitTo("main", "error", result);
} else {
if (result && result.url) {
error = "We are redirecting you...";
@ -82,20 +78,30 @@
async function success(result) {
// @ts-ignore
if (window.__TAURI__) {
let window_api = await import("@tauri-apps/plugin-window");
let main = window_api.Window.getByLabel("main");
if (main) {
await main.emit("accepted", result);
} else {
await window_api.getCurrent().close();
}
if (!web) {
let event_api = await import("@tauri-apps/api/event");
await event_api.emitTo("main", "accepted", result);
} else {
window.location.href = result.url;
}
}
async function bootstrap() {}
async function bootstrap() {
if (!web) {
try {
let window_api = await import("@tauri-apps/api/window");
const unlisten = await window_api
.getCurrentWindow()
.onCloseRequested(async (event) => {
let event_api = await import("@tauri-apps/api/event");
await event_api.emitTo("main", "close");
//event.preventDefault();
});
} catch (e) {
console.error(e);
}
}
}
let error;
onMount(() => bootstrap());

@ -336,22 +336,29 @@ async fn open_window(
label: String,
title: String,
app: tauri::AppHandle,
) -> Result<(), ()> {
) -> Result<bool, ()> {
log_debug!("open window url {:?}", url);
let _already_exists = app.get_window(&label);
#[cfg(desktop)]
if _already_exists.is_some() {
let _ = _already_exists.unwrap().close();
std::thread::sleep(std::time::Duration::from_secs(1));
//let _ = _already_exists.unwrap().close();
//std::thread::sleep(std::time::Duration::from_secs(1));
return Ok(true);
}
let mut config = WindowConfig::default();
config.label = label;
config.url = tauri::WindowUrl::External(url.parse().unwrap());
config.title = title;
let _register_window = tauri::WindowBuilder::from_config(&app, config)
match tauri::WebviewWindowBuilder::from_config(&app, &config)
.unwrap()
.build()
.unwrap();
Ok(())
{
Ok(_) => {}
Err(e) => {
return Ok(true);
}
}
Ok(false)
}
#[tauri::command(rename_all = "snake_case")]
@ -634,7 +641,7 @@ async fn sparql_update(
match res {
AppResponse::V0(AppResponseV0::Error(e)) => Err(e),
AppResponse::V0(AppResponseV0::Commits(commits)) => Ok(commits),
_ => Err(NgError::InvalidResponse.to_string())
_ => Err(NgError::InvalidResponse.to_string()),
}
}
@ -791,11 +798,17 @@ async fn doc_create(
crdt: String,
class_name: String,
destination: String,
store_repo: Option<StoreRepo>
store_repo: Option<StoreRepo>,
) -> Result<String, String> {
nextgraph::local_broker::doc_create_with_store_repo(session_id, crdt, class_name, destination, store_repo)
.await
.map_err(|e| e.to_string())
nextgraph::local_broker::doc_create_with_store_repo(
session_id,
crdt,
class_name,
destination,
store_repo,
)
.await
.map_err(|e| e.to_string())
}
#[tauri::command(rename_all = "snake_case")]

@ -114,21 +114,22 @@
}
}
});
let window_api = await import("@tauri-apps/api/window");
let main = await window_api.Window.getByLabel("main");
unsub_main_close = await main.onCloseRequested(async (event) => {
//console.log("onCloseRequested main");
await main.emit("close_all", {});
let registration = window_api.Window.getByLabel("registration");
if (registration) {
await registration.close();
}
let viewer = window_api.Window.getByLabel("viewer");
if (viewer) {
await viewer.close();
}
});
if (tauri_platform != "android" && tauri_platform != "ios") {
let window_api = await import("@tauri-apps/api/window");
let main = await window_api.Window.getByLabel("main");
unsub_main_close = await main.onCloseRequested(async (event) => {
//console.log("onCloseRequested main");
await main.emit("close_all", {});
let registration = window_api.Window.getByLabel("registration");
if (registration) {
await registration.close();
}
let viewer = window_api.Window.getByLabel("viewer");
if (viewer) {
await viewer.close();
}
});
}
} else {
// ON WEB CLIENTS
window.addEventListener("storage", async (event) => {

@ -107,7 +107,9 @@ const handler = {
return Reflect.apply(sdk[path], caller, args)
}
} else {
let tauri = await import("@tauri-apps/api/tauri");
let tauri = await import("@tauri-apps/api/core");
let event_api = await import("@tauri-apps/api/event");
let window_api = await import("@tauri-apps/api/window");
try {
if (path[0] === "client_info") {
let from_rust = await tauri.invoke("client_info_rust",{});
@ -161,9 +163,8 @@ const handler = {
return from_rust;
} else if (path[0] === "disconnections_subscribe") {
let { getCurrent } = await import("@tauri-apps/plugin-window");
let callback = args[0];
let unlisten = await getCurrent().listen("disconnections", (event) => {
let unlisten = await window_api.getCurrentWindow().listen("disconnections", (event) => {
callback(event.payload).then(()=> {})
})
await tauri.invoke(path[0],{});
@ -182,11 +183,10 @@ const handler = {
else if (path[0] === "file_get") {
let stream_id = (lastStreamId += 1).toString();
//console.log("stream_id",stream_id);
let { getCurrent } = await import("@tauri-apps/plugin-window");
//let session_id = args[0];
let callback = args[3];
let unlisten = await getCurrent().listen(stream_id, async (event) => {
let unlisten = await window_api.getCurrentWindow().listen(stream_id, async (event) => {
//console.log(event.payload);
if (event.payload.V0.FileBinary) {
event.payload.V0.FileBinary = Uint8Array.from(event.payload.V0.FileBinary);
@ -219,15 +219,16 @@ const handler = {
args.map((el,ix) => arg[mapping[path[0]][ix]]=el)
arg.update = Array.from(new Uint8Array(arg.update));
return await tauri.invoke(path[0],arg)
} else if (path[0] === "app_request_stream") {
} else if (path[0] === "app_request_stream" || path[0] === "doc_subscribe" || path[0] === "orm_start") {
let stream_id = (lastStreamId += 1).toString();
//console.log("stream_id",stream_id);
let { getCurrent } = await import("@tauri-apps/plugin-window");
//let session_id = args[0];
let request = args[0];
let callback = args[1];
let request; let callback;
if (path[0] === "app_request_stream") { request = args[0]; callback = args[1]; }
else if (path[0] === "doc_subscribe") { request = await invoke("doc_fetch_repo_subscribe", {repo_o:args[0]}); request.V0.session_id = args[1]; callback = args[2]; }
else if (path[0] === "orm_start") { request = await invoke("new_orm_start", {scope:args[0], shape_type:args[1], session_id:args[2] }); callback = args[3]; }
let unlisten = await getCurrent().listen(stream_id, async (event) => {
let unlisten = await window_api.getCurrentWindow().listen(stream_id, async (event) => {
//console.log(event.payload);
if (event.payload.V0.FileBinary) {
event.payload.V0.FileBinary = Uint8Array.from(event.payload.V0.FileBinary);
@ -251,7 +252,7 @@ const handler = {
let ret = callback(event.payload);
if (ret === true) {
await tauri.invoke("cancel_stream", {stream_id});
} else if (ret.then) {
} else if (ret?.then) {
ret.then(async (val)=> {
if (val === true) {
await tauri.invoke("cancel_stream", {stream_id});
@ -274,7 +275,9 @@ const handler = {
} else if (path[0] === "get_wallets") {
let res = await tauri.invoke(path[0],{});
if (res) for (let e of Object.entries(res)) {
e[1].wallet.V0.content.security_img = Uint8Array.from(e[1].wallet.V0.content.security_img);
const sec = e[1].wallet.V0.content.security_img;
if (sec)
e[1].wallet.V0.content.security_img = Uint8Array.from(sec);
}
return res || {};
@ -282,7 +285,7 @@ const handler = {
let arg = {};
args.map((el,ix) => arg[mapping[path[0]][ix]]=el);
let res = await tauri.invoke(path[0],arg);
if (res) {
if (res && res.V0.content.security_img) {
res.V0.content.security_img = Uint8Array.from(res.V0.content.security_img);
}
return res || {};
@ -297,7 +300,7 @@ const handler = {
} else if (path[0] === "wallet_create") {
let params = args[0];
params.result_with_wallet_file = false;
params.security_img = Array.from(new Uint8Array(params.security_img));
params.security_img = Array.from(new Uint8Array());
return await tauri.invoke(path[0],{params})
} else if (path[0] === "wallet_read_file") {
let file = args[0];
@ -305,7 +308,8 @@ const handler = {
return await tauri.invoke(path[0],{file})
} else if (path[0] === "wallet_import") {
let encrypted_wallet = args[0];
encrypted_wallet.V0.content.security_img = Array.from(new Uint8Array(encrypted_wallet.V0.content.security_img));
if (encrypted_wallet.V0.content.security_img)
encrypted_wallet.V0.content.security_img = Array.from(new Uint8Array(encrypted_wallet.V0.content.security_img));
return await tauri.invoke(path[0],{encrypted_wallet, opened_wallet:args[1], in_memory:args[2]})
} else if (path[0] && path[0].startsWith("get_local_bootstrap")) {
return false;

@ -34,7 +34,7 @@
{@html $t("pages.no_wallet.description")}
</p>
<Alert color="blue" class="max-w-sm mt-3">
If you had created a wallet before 25 Oct 2025, it doesn't work anymore.
If you had created a wallet before 3 Nov 2025, it doesn't work anymore.
please create a new wallet. We are still in alpha, and this can happen
again.
</Alert>

@ -23,7 +23,11 @@
import { t } from "svelte-i18n";
import CenteredLayout from "../lib/CenteredLayout.svelte";
import PasswordInput from "../lib/components/PasswordInput.svelte";
import { redirect_server, bootstrap_redirect } from "./index";
import {
redirect_server,
bootstrap_redirect,
base64UrlEncode,
} from "./index";
// @ts-ignore
import Logo from "../assets/nextgraph.svg?component";
@ -40,11 +44,6 @@
const param = new URLSearchParams($querystring);
function base64UrlEncode(str) {
const base64 = btoa(str); // Standard Base64 encoding
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
}
let tauri_platform = import.meta.env.TAURI_PLATFORM;
let wait: any = false;
@ -252,7 +251,7 @@
};
let ca = await ng.encode_create_account(create);
wait = $t("pages.wallet_create.redirecting_to_registration_page");
window.location.href = bsp_url + "?ca=" + ca;
window.location.href = bsp_url + "?web=1&ca=" + ca;
//window.open(), "_self").focus();
} else {
let create = {
@ -262,7 +261,7 @@
};
wait = $t("pages.wallet_create.complete_in_popup");
let ca = await ng.encode_create_account(create);
let unsub_register = await ng.open_window(
let temp_unsub_register = await ng.open_window(
bsp_url + "?ca=" + ca,
"registration",
"Registration at a Broker",
@ -277,15 +276,18 @@
wait = false;
console.log("got error with payload", payload);
if (payload) registration_error = payload.error;
else registration_error = "You refused the registration";
unsub_register = undefined;
} else if (result == "close") {
console.log("onCloseRequested");
wait = false;
username_pass_ok = false;
registration_error = "You cancelled the registration";
unsub_register = undefined;
}
}
);
if (temp_unsub_register) unsub_register = temp_unsub_register;
}
};
const selectONE = async (event) => {

Loading…
Cancel
Save