Skip to content

Commit

Permalink
🌱 完成外部唤起测试 #42
Browse files Browse the repository at this point in the history
  • Loading branch information
BTMuli committed Sep 18, 2023
1 parent b0fc874 commit d45d26c
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 1 deletion.
85 changes: 85 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ tauri-build = { version = "1.4", features = [] }
tauri = { version = "1.4", features = ["api-all"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tauri-plugin-deep-link="0.1.2"

[dependencies.tauri-plugin-sql]
git = "https://github.com/tauri-apps/plugins-workspace"
Expand Down
15 changes: 15 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@

use tauri::Manager;

#[tauri::command]
// todo 后续优化
async fn register_deep_link(app_handle: tauri::AppHandle) {
tauri_plugin_deep_link::register(
"teyvatguide",
move |request| {
dbg!(&request);
app_handle.emit_all("test_deep_link", request).unwrap();
},
)
.unwrap();
}

fn main() {
tauri_plugin_deep_link::prepare("teyvatguide");
tauri::Builder::default()
.plugin(tauri_plugin_sql::Builder::default().build())
.setup(|_app| {
Expand All @@ -12,6 +26,7 @@ fn main() {
_window.open_devtools(); // open the devtools on startup
Ok(())
})
.invoke_handler(tauri::generate_handler![register_deep_link])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
17 changes: 16 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { onBeforeMount, onMounted, ref } from "vue";
import TSidebar from "./components/app/t-sidebar.vue";
import TBackTop from "./components/app/t-backTop.vue";
// tauri
import { app, event, fs, window } from "@tauri-apps/api";
import { app, event, fs, tauri, window } from "@tauri-apps/api";
// store
import { useAppStore } from "./store/modules/app";
// utils
Expand All @@ -43,7 +43,10 @@ onBeforeMount(async () => {
onMounted(async () => {
// 获取当前主题
document.documentElement.className = theme.value;
await tauri.invoke("register_deep_link");
console.info("已注册深度链接!");
await listenOnTheme();
await getDeepLink();
});
// 监听主题变化
Expand Down Expand Up @@ -92,12 +95,24 @@ async function createDataDir(): Promise<void> {
// 初始化数据库
async function initData(): Promise<void> {
if (appStore.devEnv) {
console.info("开发环境,跳过数据库初始化!");
return;
}
await TGSqlite.reset();
showSnackbar({
text: "已成功初始化数据库!",
});
console.info("已成功初始化数据库!");
}
async function getDeepLink(): Promise<void> {
console.info("正在监听深度链接!");
await event.listen("test_deep_link", (e) => {
console.log("深度链接已触发!");
console.log(e.payload);
});
}
</script>
<style lang="css">
.app-container {
Expand Down

0 comments on commit d45d26c

Please sign in to comment.