From ec10bb663eff9d8e61f7016c2b731660fe2676a8 Mon Sep 17 00:00:00 2001 From: Sean Boult <996134+Hacksore@users.noreply.github.com> Date: Sun, 5 Nov 2023 11:13:34 -0600 Subject: [PATCH] Clickthrough works --- src-tauri/Cargo.lock | 24 ++++++ src-tauri/Cargo.toml | 1 + ...-ice-2023-11-05T15:27:39.875107Z-48952.txt | 1 + ...-ice-2023-11-05T17:06:28.397207Z-60099.txt | 1 + ...-ice-2023-11-05T17:08:13.132113Z-60370.txt | 1 + ...ice-2023-11-05T17:08:25.155883Z-60429.txt} | 0 ...-ice-2023-11-05T17:10:10.382553Z-60557.txt | 1 + src-tauri/src/main.rs | 74 ++++++++++++++++--- src-tauri/src/window_custom.rs | 69 ++++++++--------- src-tauri/tauri.conf.json | 2 +- src/App.tsx | 2 +- src/components/nav-bar.tsx | 12 +-- src/components/user.tsx | 8 +- src/store.ts | 7 ++ src/views/settings.tsx | 20 +++++ 15 files changed, 168 insertions(+), 55 deletions(-) create mode 100644 src-tauri/rustc-ice-2023-11-05T15:27:39.875107Z-48952.txt create mode 100644 src-tauri/rustc-ice-2023-11-05T17:06:28.397207Z-60099.txt create mode 100644 src-tauri/rustc-ice-2023-11-05T17:08:13.132113Z-60370.txt rename src-tauri/{rustc-ice-2023-11-01T11:31:33.08826Z-40170.txt => rustc-ice-2023-11-05T17:08:25.155883Z-60429.txt} (100%) create mode 100644 src-tauri/rustc-ice-2023-11-05T17:10:10.382553Z-60557.txt diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 05c07e65..2bb4425e 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1974,6 +1974,7 @@ dependencies = [ "tauri", "tauri-build", "tauri-plugin-websocket", + "tokio", ] [[package]] @@ -2766,6 +2767,15 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + [[package]] name = "simd-adler32" version = "0.3.7" @@ -3351,11 +3361,25 @@ dependencies = [ "libc", "mio", "num_cpus", + "parking_lot", "pin-project-lite", + "signal-hook-registry", "socket2 0.5.5", + "tokio-macros", "windows-sys", ] +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "tokio-native-tls" version = "0.3.1" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index d6e71dd4..9ed2ed1b 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -15,6 +15,7 @@ tauri-build = { version = "1.5", features = [] } [dependencies] tauri = { version = "1.5", features = [ "system-tray", "window-set-size", "window-set-always-on-top", "window-start-dragging", "macos-private-api", "devtools", "http-all"] } serde = { version = "1.0", features = ["derive"] } +tokio = { version = "1", features = ["full"] } # Required for asynchronous operations tauri-plugin-websocket = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" } serde_json = "1.0" reqwest = { version = "0.11", features = ["json"] } diff --git a/src-tauri/rustc-ice-2023-11-05T15:27:39.875107Z-48952.txt b/src-tauri/rustc-ice-2023-11-05T15:27:39.875107Z-48952.txt new file mode 100644 index 00000000..6df4a951 --- /dev/null +++ b/src-tauri/rustc-ice-2023-11-05T15:27:39.875107Z-48952.txt @@ -0,0 +1 @@ +thread 'rustc' panicked at \ No newline at end of file diff --git a/src-tauri/rustc-ice-2023-11-05T17:06:28.397207Z-60099.txt b/src-tauri/rustc-ice-2023-11-05T17:06:28.397207Z-60099.txt new file mode 100644 index 00000000..6df4a951 --- /dev/null +++ b/src-tauri/rustc-ice-2023-11-05T17:06:28.397207Z-60099.txt @@ -0,0 +1 @@ +thread 'rustc' panicked at \ No newline at end of file diff --git a/src-tauri/rustc-ice-2023-11-05T17:08:13.132113Z-60370.txt b/src-tauri/rustc-ice-2023-11-05T17:08:13.132113Z-60370.txt new file mode 100644 index 00000000..6df4a951 --- /dev/null +++ b/src-tauri/rustc-ice-2023-11-05T17:08:13.132113Z-60370.txt @@ -0,0 +1 @@ +thread 'rustc' panicked at \ No newline at end of file diff --git a/src-tauri/rustc-ice-2023-11-01T11:31:33.08826Z-40170.txt b/src-tauri/rustc-ice-2023-11-05T17:08:25.155883Z-60429.txt similarity index 100% rename from src-tauri/rustc-ice-2023-11-01T11:31:33.08826Z-40170.txt rename to src-tauri/rustc-ice-2023-11-05T17:08:25.155883Z-60429.txt diff --git a/src-tauri/rustc-ice-2023-11-05T17:10:10.382553Z-60557.txt b/src-tauri/rustc-ice-2023-11-05T17:10:10.382553Z-60557.txt new file mode 100644 index 00000000..203a0907 --- /dev/null +++ b/src-tauri/rustc-ice-2023-11-05T17:10:10.382553Z-60557.txt @@ -0,0 +1 @@ +thread ' \ No newline at end of file diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index c84da27b..de643beb 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -2,37 +2,64 @@ all(not(debug_assertions), target_os = "windows"), windows_subsystem = "windows" )] +#![allow(unused_must_use)] #[cfg(target_os = "macos")] #[macro_use] extern crate objc; -mod window_custom; - use tauri::{ - CustomMenuItem, Manager, RunEvent, SystemTray, SystemTrayEvent, - SystemTrayMenu, + generate_handler, CustomMenuItem, Manager, RunEvent, State, SystemTray, SystemTrayEvent, + SystemTrayMenu, Window, }; use window_custom::WindowExt as _; +mod window_custom; + +use std::sync::atomic::AtomicBool; + +struct Clickthrough(AtomicBool); + +#[tauri::command] +fn toggle_clickthrough(window: Window, enabled: bool, clickthrough: State<'_, Clickthrough>) { + println!("Setting clickthrough to {}", enabled); + + clickthrough + .0 + .store(enabled, std::sync::atomic::Ordering::Relaxed); + + #[cfg(target_os = "macos")] + window.with_webview(move |webview| { + #[cfg(target_os = "macos")] + unsafe { + let _: () = msg_send![webview.ns_window(), setIgnoresMouseEvents: enabled]; + } + }); +} fn main() { // System tray configuration let tray = SystemTray::new().with_menu( SystemTrayMenu::new() - .add_item(CustomMenuItem::new("show_overlayed", "Show Overlayed")) - .add_item(CustomMenuItem::new("quit", "Quit")) + .add_item(CustomMenuItem::new( + "toggle_clickthrough", + "Toogle Clickthrough", + )) + .add_item(CustomMenuItem::new("show_app", "Show Overlayed")) + // add seperator + .add_native_item(tauri::SystemTrayMenuItem::Separator) + .add_item(CustomMenuItem::new("quit", "Quit")), ); let app = tauri::Builder::default() .plugin(tauri_plugin_websocket::init()) + .manage(Clickthrough(AtomicBool::new(false))) .setup(|app| { let window = app.get_window("main").unwrap(); + #[cfg(target_os = "macos")] window.set_transparent_titlebar(true, true); - // Move the window to the center of the screen - window.center().expect("Cannot move window!"); - // Open dev tools + // Open dev tools only when in dev mode #[cfg(debug_assertions)] window.open_devtools(); Ok(()) @@ -42,8 +69,31 @@ fn main() { // Handle system tray events .on_system_tray_event(|app, event| match event { SystemTrayEvent::MenuItemClick { id, .. } => match id.as_str() { + "toggle_clickthrough" => { + let window = app.get_window("main").unwrap(); + let clickthrough = !app + .state::() + .0 + .load(std::sync::atomic::Ordering::Relaxed); + + println!("Setting clickthrough to {}", clickthrough); + app + .state::() + .0 + .store(clickthrough, std::sync::atomic::Ordering::Relaxed); + + #[cfg(target_os = "macos")] + window.with_webview(move |webview| { + #[cfg(target_os = "macos")] + unsafe { + let _: () = msg_send![webview.ns_window(), setIgnoresMouseEvents: clickthrough]; + } + }); + // we might want to knokw on the client + window.emit("toggle_clickthrough", clickthrough).unwrap(); + } "quit" => std::process::exit(0), - "show_overlayed" => { + "show_app" => { let window = app.get_window("main").unwrap(); window.show().unwrap(); window.set_focus().unwrap(); @@ -52,12 +102,12 @@ fn main() { }, _ => {} }) + .invoke_handler(generate_handler![toggle_clickthrough]) .build(tauri::generate_context!()) .expect("An error occured while running the app!"); app.run(|_app_handle, e| match e { - RunEvent::Ready => { - } + RunEvent::Ready => {} _ => {} }) } diff --git a/src-tauri/src/window_custom.rs b/src-tauri/src/window_custom.rs index cf43c5d9..cd540351 100644 --- a/src-tauri/src/window_custom.rs +++ b/src-tauri/src/window_custom.rs @@ -6,41 +6,44 @@ use objc::runtime::YES; use tauri::{Runtime, Window}; pub trait WindowExt { - #[cfg(target_os = "macos")] - fn set_transparent_titlebar(&self, title_transparent: bool, remove_toolbar: bool); + #[cfg(target_os = "macos")] + fn set_transparent_titlebar(&self, title_transparent: bool, remove_toolbar: bool); } impl WindowExt for Window { - #[cfg(target_os = "macos")] - fn set_transparent_titlebar(&self, title_transparent: bool, remove_tool_bar: bool) { - unsafe { - let id = self.ns_window().unwrap() as cocoa::base::id; - NSWindow::setTitlebarAppearsTransparent_(id, cocoa::base::YES); - let mut style_mask = id.styleMask(); - style_mask.set( - NSWindowStyleMask::NSFullSizeContentViewWindowMask, - title_transparent, - ); - id.setStyleMask_(style_mask); - if remove_tool_bar { - let close_button = id.standardWindowButton_(NSWindowButton::NSWindowCloseButton); - let _: () = msg_send![close_button, setHidden: YES]; - let min_button = - id.standardWindowButton_(NSWindowButton::NSWindowMiniaturizeButton); - let _: () = msg_send![min_button, setHidden: YES]; - let zoom_button = id.standardWindowButton_(NSWindowButton::NSWindowZoomButton); - let _: () = msg_send![zoom_button, setHidden: YES]; - } - id.setTitleVisibility_(if title_transparent { - NSWindowTitleVisibility::NSWindowTitleHidden - } else { - NSWindowTitleVisibility::NSWindowTitleVisible - }); - id.setTitlebarAppearsTransparent_(if title_transparent { - cocoa::base::YES - } else { - cocoa::base::NO - }); - } + #[cfg(target_os = "macos")] + fn set_transparent_titlebar(&self, title_transparent: bool, remove_tool_bar: bool) { + unsafe { + let id = self.ns_window().unwrap() as cocoa::base::id; + NSWindow::setTitlebarAppearsTransparent_(id, cocoa::base::YES); + let mut style_mask = id.styleMask(); + style_mask.set( + NSWindowStyleMask::NSFullSizeContentViewWindowMask, + title_transparent, + ); + id.setStyleMask_(style_mask); + if remove_tool_bar { + let close_button = id.standardWindowButton_(NSWindowButton::NSWindowCloseButton); + let _: () = msg_send![close_button, setHidden: YES]; + let min_button = id.standardWindowButton_(NSWindowButton::NSWindowMiniaturizeButton); + let _: () = msg_send![min_button, setHidden: YES]; + let zoom_button = id.standardWindowButton_(NSWindowButton::NSWindowZoomButton); + let _: () = msg_send![zoom_button, setHidden: YES]; + } + id.setTitleVisibility_(if title_transparent { + NSWindowTitleVisibility::NSWindowTitleHidden + } else { + NSWindowTitleVisibility::NSWindowTitleVisible + }); + + // disable shadows + id.setHasShadow_(false); + + id.setTitlebarAppearsTransparent_(if title_transparent { + cocoa::base::YES + } else { + cocoa::base::NO + }); } + } } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index c07f6f51..a2e5c09f 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -13,7 +13,7 @@ "tauri": { "systemTray": { "iconPath": "icons/32x32.png", - "iconAsTemplate": true + "iconAsTemplate":false }, "allowlist": { "all": false, diff --git a/src/App.tsx b/src/App.tsx index f1995b14..9b68a135 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -24,7 +24,7 @@ function App() { }, [location]); return ( -
+
diff --git a/src/components/nav-bar.tsx b/src/components/nav-bar.tsx index 9a0468bf..759a1039 100644 --- a/src/components/nav-bar.tsx +++ b/src/components/nav-bar.tsx @@ -15,20 +15,22 @@ export const NavBar = () => { } if (location.pathname === "/error") { - return null; + return null; } if (location.pathname === "/settings") { - return - - ; + return ( + + + + ); } }, [location.pathname]); return (
overlayed
{getNavLink()}
diff --git a/src/components/user.tsx b/src/components/user.tsx index 24d9f756..3d8675f8 100644 --- a/src/components/user.tsx +++ b/src/components/user.tsx @@ -10,14 +10,16 @@ export const User = ({ item }: { item: OverlayedUser }) => { const talkingClass = item.talking ? "border-green-500" : "border-slate-900"; return ( -
+
avatar
-
{item.username}
+
+ {item.username} +
); }; diff --git a/src/store.ts b/src/store.ts index 748cad41..8f88de0d 100644 --- a/src/store.ts +++ b/src/store.ts @@ -25,12 +25,14 @@ const createUserStateItem = (payload: VoiceStateUser) => { }; export interface AppState { + clickThrough: boolean; me: OverlayedUser | null; currentChannel: string | null; users: Record; } export interface AppActions { + setClickThrough: (enbabled: boolean) => void; setTalking: (id: string, talking: boolean) => void; setUsers: (users: any) => void; clearUsers: () => void; @@ -44,6 +46,7 @@ export const useAppStore = create < AppState & AppActions > ()( // @ts-ignore immer((set) => ({ me: null, + clickThrough: false, currentChannel: null, users: {}, setMe: (data) => @@ -76,5 +79,9 @@ export const useAppStore = create < AppState & AppActions > ()( set((state) => { state.currentChannel = channelId; }), + setClickThrough: (enabled: boolean) => + set((state) => { + state.clickThrough = enabled; + }), })), ); diff --git a/src/views/settings.tsx b/src/views/settings.tsx index 44fca140..684ac594 100644 --- a/src/views/settings.tsx +++ b/src/views/settings.tsx @@ -1,7 +1,27 @@ +import { useAppStore } from "../store"; +import { invoke } from "@tauri-apps/api/tauri"; + export const Settings = () => { + const { setClickThrough, clickThrough } = useAppStore(); + return (

Settings

+