Skip to content

Commit

Permalink
fix: upgrade api version and related code, windows api have breaking …
Browse files Browse the repository at this point in the history
…changes
  • Loading branch information
HuakunShen committed Aug 28, 2024
1 parent 30cdd00 commit 1ed9b6f
Show file tree
Hide file tree
Showing 10 changed files with 319 additions and 290 deletions.
362 changes: 220 additions & 142 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/desktop/lib/utils/hotkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function registerAppHotkey(hotkeyStr: string) {
info(`Registering hotkey: ${hotkeyStr}`)
return register(hotkeyStr, async (e) => {
if (e.state === "Released") {
const wins = getAllWindows()
const wins = await getAllWindows()
const mainWin = wins.find((w) => w.label === "main")
if (!mainWin) {
return sendNotificationWithPermission(
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/lib/utils/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { SettingsWindowLabel } from "@/lib/constants"
import { $appState } from "@/lib/stores/appState"
import { getAllWebviewWindows, WebviewWindow } from "@tauri-apps/api/webviewWindow"

export function newSettingsPage() {
const allWins = getAllWebviewWindows()
export async function newSettingsPage() {
const allWins = await getAllWebviewWindows()
const existingWin = allWins.find((win) => win.label === SettingsWindowLabel)
if (existingWin) {
existingWin.show()
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"@pinia/nuxt": "^0.5.1",
"@radix-icons/vue": "^1.0.0",
"@supabase/supabase-js": "^2.43.4",
"@tauri-apps/api": "2.0.0-rc.0",
"@tauri-apps/cli": "2.0.0-rc.3",
"@tauri-apps/api": "2.0.0-rc.3",
"@tauri-apps/cli": "2.0.0-rc.7",
"@tauri-apps/plugin-dialog": ">=2.0.0-rc.0",
"@tauri-apps/plugin-fs": "2.0.0-rc.1",
"@tauri-apps/plugin-global-shortcut": "2.0.0-rc.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ objc = "0.2.7"

[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies]
tauri-plugin-global-shortcut = "2.0.0-rc"
tauri-plugin-updater = "2.0.0-rc"
tauri-plugin-updater = "2.0.0-rc.1"
12 changes: 6 additions & 6 deletions apps/desktop/stores/builtinCmdLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ const builtinCmds: BuiltinCmd[] = [
iconifyIcon: "solar:settings-linear",
description: "Open Settings",
function: async () => {
const windows = getAllWebviewWindows()
const windows = await getAllWebviewWindows()
const found = windows.find((w) => w.label === SettingsWindowLabel)
if (found) {
ElNotification.error("Settings Page is already open")
} else {
const win = newSettingsPage()
const win = await newSettingsPage()
setTimeout(() => {
// this is a backup, if window is not properly loaded,
// the show() will not be called within setting page, we call it here with a larger delay,
Expand Down Expand Up @@ -87,8 +87,8 @@ if (rtConfig.public.isDev) {
name: "Open Dev Page",
iconifyIcon: "fa6-brands:dev",
description: "Open Dev Page",
function: () => {
const windows = getAllWebviewWindows()
function: async () => {
const windows = await getAllWebviewWindows()
const found = windows.find((w) => w.label === DevWindowLabel)
if (found) {
ElNotification.error("Debug Page is already open")
Expand All @@ -106,8 +106,8 @@ if (rtConfig.public.isDev) {
name: "Open Debug Page",
iconifyIcon: "carbon:debug",
description: "Open Debug Page",
function: () => {
const windows = getAllWebviewWindows()
function: async () => {
const windows = await getAllWebviewWindows()
const found = windows.find((w) => w.label === DebugWindowLabel)
if (found) {
ElNotification.error("Debug Page is already open")
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"dependencies": {
"@huakunshen/comlink": "^4.4.1",
"@rollup/plugin-typescript": "^11.1.6",
"@tauri-apps/api": "2.0.0-rc.0",
"@tauri-apps/api": "2.0.0-rc.3",
"@tauri-apps/plugin-dialog": ">=2.0.0-rc.0",
"@tauri-apps/plugin-fs": "2.0.0-rc.1",
"@tauri-apps/plugin-global-shortcut": "2.0.0-rc.0",
Expand Down
15 changes: 5 additions & 10 deletions packages/api/src/ui/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,21 @@ export function destroyWindow() {
}

export function windowLabelExists(label: string) {
return _windowApis.getAllWindows().some((w) => w.label === label)
return _windowApis.getAllWindows().then((wins) => wins.some((w) => w.label === label))
}

export function getWindowByLabel(label: string) {
return _windowApis.getAllWindows().find((w) => w.label === label)
return _windowApis.getAllWindows().then((wins) => wins.find((w) => w.label === label))
}

export function closeMainWindow() {
return _windowApis
.getAllWindows()
.find((w) => w.label === "main")
?.close()
return _windowApis.getAllWindows().then((wins) => wins.find((w) => w.label === "main")?.close())
}

export function hideWindow(windowLabel: string) {
return _windowApis
.getAllWindows()
.find((w) => w.label === windowLabel)
?.hide()
.then((wins) => wins.find((w) => w.label === windowLabel)?.hide())
}

export function hideMainWindow() {
Expand All @@ -48,8 +44,7 @@ export function hideMainWindow() {
export function showWindow(windowLabel: string) {
return _windowApis
.getAllWindows()
.find((w) => w.label === windowLabel)
?.show()
.then((wins) => wins.find((w) => w.label === windowLabel)?.show())
}

export function showMainWindow() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

### Permission Table
## Permission Table

<table>
<tr>
Expand Down
Loading

0 comments on commit 1ed9b6f

Please sign in to comment.