From 5867740de3bb394126729c5e7317611767a8a9f4 Mon Sep 17 00:00:00 2001 From: spacemeowx2 Date: Tue, 4 Jul 2023 20:06:42 +0800 Subject: [PATCH] feat(gui): using latest tauri config, remove hacky way --- gui/src-tauri/Cargo.lock | 7 ------- gui/src-tauri/Cargo.toml | 1 - gui/src-tauri/src/main.rs | 29 +++++++++++------------------ gui/src-tauri/tauri.conf.json | 14 ++++++++++++-- gui/src/App.tsx | 2 -- gui/src/pages/RedirectLogin.tsx | 25 ------------------------- 6 files changed, 23 insertions(+), 55 deletions(-) delete mode 100644 gui/src/pages/RedirectLogin.tsx diff --git a/gui/src-tauri/Cargo.lock b/gui/src-tauri/Cargo.lock index 34847e7..fd01a73 100644 --- a/gui/src-tauri/Cargo.lock +++ b/gui/src-tauri/Cargo.lock @@ -2178,7 +2178,6 @@ dependencies = [ "tauri", "tauri-build", "tokio", - "urlencoding", ] [[package]] @@ -3075,12 +3074,6 @@ dependencies = [ "serde", ] -[[package]] -name = "urlencoding" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8db7427f936968176eaa7cdf81b7f98b980b18495ec28f1b5791ac3bfe3eea9" - [[package]] name = "utf-8" version = "0.7.6" diff --git a/gui/src-tauri/Cargo.toml b/gui/src-tauri/Cargo.toml index ba4bba9..b1d31c4 100644 --- a/gui/src-tauri/Cargo.toml +++ b/gui/src-tauri/Cargo.toml @@ -25,7 +25,6 @@ tauri = { version = "1.4.1", features = [ serde = { version = "1.0.164", features = ["derive"] } serde_json = "1.0.97" tokio = { version = "1.28.2", features = ["time"] } -urlencoding = "2.1.2" [features] # this feature is used for production builds or when `devPath` points to the filesystem diff --git a/gui/src-tauri/src/main.rs b/gui/src-tauri/src/main.rs index 9424797..cc5a377 100644 --- a/gui/src-tauri/src/main.rs +++ b/gui/src-tauri/src/main.rs @@ -15,14 +15,12 @@ function onSelectUserClick(e) { } e.preventDefault(); - // very hacky way... - window.ipc.postMessage(JSON.stringify({ - "cmd":"tauri", - "callback":0, - "error":0, + // a little official way... + window.__TAURI_INVOKE__({ "__tauriModule":"Event", + "cmd": "tauri", "message":{"cmd":"emit","event":"login","payload":{"url":element.href}} - })) + }) } function detectAndInject() { const element = document.getElementById('authorize-switch-approval-link'); @@ -74,18 +72,13 @@ document.addEventListener("DOMContentLoaded", () => {{ #[tauri::command] async fn open_login_window(app: tauri::AppHandle, url: String) -> Option { - let encoded = urlencoding::encode(&url); - let window = WindowBuilder::new( - &app, - "login", - tauri::WindowUrl::App(format!("/redirect?url={encoded}").into()), - ) - .title("Login") - .center() - .inner_size(1040.0, 960.0) - .initialization_script(INIT_SCRIPT) - .build() - .ok()?; + let window = WindowBuilder::new(&app, "login", tauri::WindowUrl::App(url.into())) + .title("Login") + .center() + .inner_size(1040.0, 960.0) + .initialization_script(INIT_SCRIPT) + .build() + .ok()?; let result: Arc>> = Arc::new(Mutex::new(None)); let r2 = result.clone(); let r3 = result.clone(); diff --git a/gui/src-tauri/tauri.conf.json b/gui/src-tauri/tauri.conf.json index 15ddca7..6777593 100644 --- a/gui/src-tauri/tauri.conf.json +++ b/gui/src-tauri/tauri.conf.json @@ -1,4 +1,5 @@ { + "$schema": "https://github.com/tauri-apps/tauri/raw/tauri-v1.4.1/core/tauri-config-schema/schema.json", "build": { "beforeDevCommand": "pnpm dev", "beforeBuildCommand": "pnpm build", @@ -69,7 +70,16 @@ ] }, "security": { - "csp": null + "csp": null, + "dangerousRemoteDomainIpcAccess": [ + { + "windows": [ + "login" + ], + "domain": "accounts.nintendo.com", + "enableTauriAPI": true + } + ] }, "updater": { "active": false, @@ -93,4 +103,4 @@ } ] } -} +} \ No newline at end of file diff --git a/gui/src/App.tsx b/gui/src/App.tsx index 7efa47e..f2c65bc 100644 --- a/gui/src/App.tsx +++ b/gui/src/App.tsx @@ -4,7 +4,6 @@ import { Layout } from "components/Layout"; import { Home } from "pages/Home"; import { Settings } from "pages/Settings"; import { Guide } from 'pages/Guide'; -import { RedirectLogin } from 'pages/RedirectLogin'; import { useShowWindow } from 'hooks/useShowWindow'; function App() { @@ -15,7 +14,6 @@ function App() { } /> } /> } /> - } /> ); diff --git a/gui/src/pages/RedirectLogin.tsx b/gui/src/pages/RedirectLogin.tsx deleted file mode 100644 index 62ff328..0000000 --- a/gui/src/pages/RedirectLogin.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import { Loading } from 'components/Loading'; -import React, { useEffect } from 'react' -import { useTranslation } from 'react-i18next'; -import { useLocation } from 'react-use'; - -export const RedirectLogin: React.FC = () => { - const { t } = useTranslation(); - const state = useLocation(); - - useEffect(() => { - const search = state.search ?? ''; - - const index = search.indexOf('url='); - if (index === -1) { - return; - } - const url = decodeURIComponent(search.substring(index + 4)); - - window.location.href = url; - }, [state]) - - return
- {t('正在跳转到登录页面...')} -
-}