Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src-tauri/src/plugins/window/permissions/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ permissions = [
"allow-show-send-modal-window",
"allow-hide-send-modal-window",
"allow-close-send-modal-window",
"allow-show-onboarding-window",
"allow-hide-onboarding-window",
]
2 changes: 2 additions & 0 deletions src-tauri/src/plugins/window/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use tauri::{async_runtime::spawn, AppHandle, Manager, Runtime, WebviewWindow};

pub mod onboarding;
pub mod send_modal;
pub use onboarding::*;
pub use send_modal::*;

// 主窗口的label
Expand Down
36 changes: 36 additions & 0 deletions src-tauri/src/plugins/window/src/commands/onboarding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use tauri::{command, AppHandle, Manager, Runtime};

pub static ONBOARDING_WINDOW_LABEL: &str = "onboarding";

// 显示 Onboarding 窗口
#[command]
pub async fn show_onboarding_window<R: Runtime>(app_handle: AppHandle<R>) -> Result<(), String> {
println!("[onboarding] Attempting to show onboarding window");

let window = app_handle.get_webview_window(ONBOARDING_WINDOW_LABEL);

if let Some(window) = window {
println!("[onboarding] Found onboarding window, showing");

// 显示窗口
let _ = window.show();
let _ = window.unminimize();
let _ = window.set_focus();

println!("[onboarding] Window shown successfully");
} else {
println!("[onboarding] ERROR: onboarding window not found! Make sure it's defined in tauri.conf.json");
return Err("Onboarding window not found".to_string());
}

Ok(())
}

// 隐藏 Onboarding 窗口
#[command]
pub async fn hide_onboarding_window<R: Runtime>(app_handle: AppHandle<R>) -> Result<(), String> {
if let Some(window) = app_handle.get_webview_window(ONBOARDING_WINDOW_LABEL) {
let _ = window.hide();
}
Ok(())
}
2 changes: 2 additions & 0 deletions src-tauri/src/plugins/window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
commands::show_send_modal_window,
commands::hide_send_modal_window,
commands::close_send_modal_window,
commands::show_onboarding_window,
commands::hide_onboarding_window,
])
.build()
}
18 changes: 18 additions & 0 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,24 @@
"width": 1920,
"x": 0,
"y": 0
},
{
"center": true,
"decorations": true,
"dragDropEnabled": false,
"height": 700,
"label": "onboarding",
"maxHeight": 900,
"maximizable": false,
"minHeight": 600,
"minWidth": 720,
"resizable": true,
"skipTaskbar": false,
"title": "欢迎使用 WeCut",
"transparent": false,
"url": "index.html/#/onboarding",
"visible": false,
"width": 720
}
]
},
Expand Down
12 changes: 8 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { openUrl } from "@tauri-apps/plugin-opener";
import { useBoolean, useEventListener, useKeyPress, useMount } from "ahooks";
import { ConfigProvider, theme } from "antd";
import { isString } from "es-toolkit";
import { useEffect } from "react";
import { RouterProvider } from "react-router-dom";
import { useSnapshot } from "valtio";
import { LISTEN_KEY, PRESET_SHORTCUT } from "./constants";
Expand All @@ -17,6 +18,7 @@ import { getAntdLocale, i18n } from "./locales";
import {
applyMainWindowLayout,
hideWindow,
showOnboardingWindow,
showWindow,
} from "./plugins/window";
import { router } from "./router";
Expand Down Expand Up @@ -48,12 +50,14 @@ const App = () => {

// 生成 antd 的颜色变量
generateColorVars();
});

// 若未完成引导,跳转到引导页
if (!globalStore.app.hasCompletedOnboarding) {
router.navigate("/onboarding");
// 若未完成引导,显示引导窗口(在 RouterProvider 渲染后执行)
useEffect(() => {
if (ready && !globalStore.app.hasCompletedOnboarding) {
showOnboardingWindow();
}
});
}, [ready]);

// 监听语言的变化
useImmediateKey(globalStore.appearance, "language", i18n.changeLanguage);
Expand Down
1 change: 1 addition & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const UPDATE_MESSAGE_KEY = "app-update-message";

export const WINDOW_LABEL = {
MAIN: "main",
ONBOARDING: "onboarding",
PREFERENCE: "preference",
SCREENSHOT: "screenshot",
SEND_MODAL: "send-modal",
Expand Down
Loading
Loading