Skip to content

Commit

Permalink
feat: add force quit command
Browse files Browse the repository at this point in the history
  • Loading branch information
reyamir committed Jul 2, 2024
1 parent 783a453 commit 72da83d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
4 changes: 2 additions & 2 deletions apps/desktop2/src/routes/panel.$account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import * as ScrollArea from "@radix-ui/react-scroll-area";
import * as Tabs from "@radix-ui/react-tabs";
import { useQuery } from "@tanstack/react-query";
import { createFileRoute } from "@tanstack/react-router";
import { invoke } from "@tauri-apps/api/core";
import { Menu, MenuItem, PredefinedMenuItem } from "@tauri-apps/api/menu";
import { getCurrent } from "@tauri-apps/api/window";
import { exit } from "@tauri-apps/plugin-process";
import { open } from "@tauri-apps/plugin-shell";
import { type ReactNode, useCallback, useEffect, useRef } from "react";
import { Virtualizer } from "virtua";
Expand Down Expand Up @@ -98,7 +98,7 @@ function Screen() {
PredefinedMenuItem.new({ item: "Separator" }),
MenuItem.new({
text: "Quit",
action: async () => await exit(0),
action: async () => await invoke("force_quit"),
}),
]);

Expand Down
3 changes: 3 additions & 0 deletions packages/system/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ try {
async openMainWindow() : Promise<void> {
await TAURI_INVOKE("open_main_window");
},
async forceQuit() : Promise<void> {
await TAURI_INVOKE("force_quit");
},
async setBadge(count: number) : Promise<void> {
await TAURI_INVOKE("set_badge", { count });
}
Expand Down
36 changes: 21 additions & 15 deletions src-tauri/src/commands/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,21 +219,6 @@ pub fn open_window(window: Window, app_handle: tauri::AppHandle) -> Result<(), S
Ok(())
}

#[tauri::command]
#[specta::specta]
pub fn set_badge(count: i32) {
#[cfg(target_os = "macos")]
unsafe {
let label = if count == 0 {
nil
} else {
NSString::alloc(nil).init_str(&format!("{}", count))
};
let dock_tile: cocoa::base::id = msg_send![NSApp(), dockTile];
let _: cocoa::base::id = msg_send![dock_tile, setBadgeLabel: label];
}
}

#[tauri::command]
#[specta::specta]
pub fn open_main_window(app: tauri::AppHandle) {
Expand All @@ -255,3 +240,24 @@ pub fn open_main_window(app: tauri::AppHandle) {
window.make_transparent().unwrap();
}
}

#[tauri::command]
#[specta::specta]
pub fn force_quit() {
std::process::exit(0)
}

#[tauri::command]
#[specta::specta]
pub fn set_badge(count: i32) {
#[cfg(target_os = "macos")]
unsafe {
let label = if count == 0 {
nil
} else {
NSString::alloc(nil).init_str(&format!("{}", count))
};
let dock_tile: cocoa::base::id = msg_send![NSApp(), dockTile];
let _: cocoa::base::id = msg_send![dock_tile, setBadgeLabel: label];
}
}
1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ fn main() {
commands::window::reload_column,
commands::window::open_window,
commands::window::open_main_window,
commands::window::force_quit,
commands::window::set_badge
]);

Expand Down

0 comments on commit 72da83d

Please sign in to comment.