Skip to content

Commit 9d9e7a1

Browse files
author
hongyu9
committed
feat: 修复无法启动的问题
1 parent be3898b commit 9d9e7a1

10 files changed

Lines changed: 217 additions & 118 deletions

File tree

src-tauri/src/plugins/window/permissions/default.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ permissions = [
1111
"allow-show-send-modal-window",
1212
"allow-hide-send-modal-window",
1313
"allow-close-send-modal-window",
14+
"allow-show-onboarding-window",
15+
"allow-hide-onboarding-window",
1416
]

src-tauri/src/plugins/window/src/commands/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use tauri::{async_runtime::spawn, AppHandle, Manager, Runtime, WebviewWindow};
22

3+
pub mod onboarding;
34
pub mod send_modal;
5+
pub use onboarding::*;
46
pub use send_modal::*;
57

68
// 主窗口的label
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use tauri::{command, AppHandle, Manager, Runtime};
2+
3+
pub static ONBOARDING_WINDOW_LABEL: &str = "onboarding";
4+
5+
// 显示 Onboarding 窗口
6+
#[command]
7+
pub async fn show_onboarding_window<R: Runtime>(app_handle: AppHandle<R>) -> Result<(), String> {
8+
println!("[onboarding] Attempting to show onboarding window");
9+
10+
let window = app_handle.get_webview_window(ONBOARDING_WINDOW_LABEL);
11+
12+
if let Some(window) = window {
13+
println!("[onboarding] Found onboarding window, showing");
14+
15+
// 显示窗口
16+
let _ = window.show();
17+
let _ = window.unminimize();
18+
let _ = window.set_focus();
19+
20+
println!("[onboarding] Window shown successfully");
21+
} else {
22+
println!("[onboarding] ERROR: onboarding window not found! Make sure it's defined in tauri.conf.json");
23+
return Err("Onboarding window not found".to_string());
24+
}
25+
26+
Ok(())
27+
}
28+
29+
// 隐藏 Onboarding 窗口
30+
#[command]
31+
pub async fn hide_onboarding_window<R: Runtime>(app_handle: AppHandle<R>) -> Result<(), String> {
32+
if let Some(window) = app_handle.get_webview_window(ONBOARDING_WINDOW_LABEL) {
33+
let _ = window.hide();
34+
}
35+
Ok(())
36+
}

src-tauri/src/plugins/window/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
1919
commands::show_send_modal_window,
2020
commands::hide_send_modal_window,
2121
commands::close_send_modal_window,
22+
commands::show_onboarding_window,
23+
commands::hide_onboarding_window,
2224
])
2325
.build()
2426
}

src-tauri/tauri.conf.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,24 @@
101101
"width": 1920,
102102
"x": 0,
103103
"y": 0
104+
},
105+
{
106+
"center": true,
107+
"decorations": true,
108+
"dragDropEnabled": false,
109+
"height": 700,
110+
"label": "onboarding",
111+
"maxHeight": 900,
112+
"maximizable": false,
113+
"minHeight": 600,
114+
"minWidth": 720,
115+
"resizable": true,
116+
"skipTaskbar": false,
117+
"title": "欢迎使用 WeCut",
118+
"transparent": false,
119+
"url": "index.html/#/onboarding",
120+
"visible": false,
121+
"width": 720
104122
}
105123
]
106124
},

src/App.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { openUrl } from "@tauri-apps/plugin-opener";
55
import { useBoolean, useEventListener, useKeyPress, useMount } from "ahooks";
66
import { ConfigProvider, theme } from "antd";
77
import { isString } from "es-toolkit";
8+
import { useEffect } from "react";
89
import { RouterProvider } from "react-router-dom";
910
import { useSnapshot } from "valtio";
1011
import { LISTEN_KEY, PRESET_SHORTCUT } from "./constants";
@@ -17,6 +18,7 @@ import { getAntdLocale, i18n } from "./locales";
1718
import {
1819
applyMainWindowLayout,
1920
hideWindow,
21+
showOnboardingWindow,
2022
showWindow,
2123
} from "./plugins/window";
2224
import { router } from "./router";
@@ -48,12 +50,14 @@ const App = () => {
4850

4951
// 生成 antd 的颜色变量
5052
generateColorVars();
53+
});
5154

52-
// 若未完成引导,跳转到引导页
53-
if (!globalStore.app.hasCompletedOnboarding) {
54-
router.navigate("/onboarding");
55+
// 若未完成引导,显示引导窗口(在 RouterProvider 渲染后执行)
56+
useEffect(() => {
57+
if (ready && !globalStore.app.hasCompletedOnboarding) {
58+
showOnboardingWindow();
5559
}
56-
});
60+
}, [ready]);
5761

5862
// 监听语言的变化
5963
useImmediateKey(globalStore.appearance, "language", i18n.changeLanguage);

src/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const UPDATE_MESSAGE_KEY = "app-update-message";
1010

1111
export const WINDOW_LABEL = {
1212
MAIN: "main",
13+
ONBOARDING: "onboarding",
1314
PREFERENCE: "preference",
1415
SCREENSHOT: "screenshot",
1516
SEND_MODAL: "send-modal",

0 commit comments

Comments
 (0)