Skip to content

Commit

Permalink
easy
Browse files Browse the repository at this point in the history
  • Loading branch information
0-don committed Sep 27, 2023
1 parent 138da3d commit ccb0f9d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src-tauri/src/commands/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use tauri_plugin_positioner::{Position, WindowExt};
pub fn window_display_toggle() {
let win = APP.get().unwrap().get_window("main").unwrap();

println!("Window is visible: {:?}", win.is_visible());

if win.is_visible().unwrap() {
println!("Hiding window");
let _ = win.hide();
Expand Down
32 changes: 30 additions & 2 deletions src-tauri/src/utils/tray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ pub fn system_tray_event(app: &tauri::AppHandle, event: SystemTrayEvent) {
let _ = win.show();
let _ = win.set_focus();
}
SystemTrayEvent::RightClick {
position: _,
size: _,
..
} => {
println!("Clicked on tray icon");
let win = app.get_window("main").unwrap();
let _ = win.move_window(Position::TrayCenter);
init_hotkey();
let _ = win.show();
let _ = win.set_focus();
}
SystemTrayEvent::DoubleClick {
position: _,
size: _,
..
} => {
println!("Clicked on tray icon");
let win = app.get_window("main").unwrap();
let _ = win.move_window(Position::TrayCenter);
init_hotkey();
let _ = win.show();
let _ = win.set_focus();
}
SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() {
"open" => {
let win = app.get_window("main").unwrap();
Expand All @@ -35,8 +59,12 @@ pub fn system_tray_event(app: &tauri::AppHandle, event: SystemTrayEvent) {
let _ = win.set_focus();
}
"quit" => app.exit(1),
_ => {}
_ => {
println!("Unhandled tray event");
}
},
_ => {}
_ => {
println!("Unhandled tray event");
}
}
}
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const Index = () => {
onMount(async () => {
appWindow.onFocusChanged(async ({ payload }) => {
if (!payload) {
await appWindow.hide();
// await appWindow.hide();
removeAllHotkeyListeners();
}
});
Expand Down
6 changes: 5 additions & 1 deletion src/utils/hotkeyRegister.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { invoke } from "@tauri-apps/api";
import {
isRegistered,
register,
registerAll,
unregister,
Expand Down Expand Up @@ -31,6 +32,8 @@ export async function registerHotkeys(hotkeys: Hotkey[]) {
const { getCurrentSidebarIcon, updateSidebarIcons } = AppStore;
const { clipboards, clipboardRef } = ClipboardStore;

// await sleep(1000);
//
// await unregisterAll();

// ############################################
Expand All @@ -40,9 +43,10 @@ export async function registerHotkeys(hotkeys: Hotkey[]) {
// Display and hide the app window
const windowHotkey = hotkeys.find((h) => h.event === "window_display_toggle");

if (windowHotkey?.status) {
if (windowHotkey?.status && !(await isRegistered(windowHotkey.shortcut))) {
try {
await register(windowHotkey.shortcut, () => {
console.log("window_display_toggle");
updateSidebarIcons("Recent Clipboards");
invoke("window_display_toggle");
});
Expand Down

0 comments on commit ccb0f9d

Please sign in to comment.