Skip to content

Commit 1054f8b

Browse files
authored
Remove green dot in favor of cutout for tray item (#128)
1 parent 47a5d10 commit 1054f8b

File tree

11 files changed

+12
-185
lines changed

11 files changed

+12
-185
lines changed

apps/desktop/src-tauri/Cargo.lock

Lines changed: 0 additions & 98 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/desktop/src-tauri/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ tokio = { version = "1", features = [
4444
tauri-plugin-websocket = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
4545
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
4646
tauri-plugin-single-instance = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
47-
dark-light = "1.0.0"
4847

4948
# macos dependencies
5049
[target.'cfg(target_os = "macos")'.dependencies]
-401 Bytes
Binary file not shown.
Binary file not shown.
-111 Bytes
Loading

apps/desktop/src-tauri/src/commands.rs

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
11
use tauri::{Manager, State, SystemTrayHandle, Window};
22

3-
use crate::{constants::*, Clickthrough, Storage};
4-
5-
#[tauri::command]
6-
pub fn sync_theme(window: Window, storage: State<Storage>, value: String) {
7-
let mut theme = storage.theme.lock().unwrap();
8-
match value.as_str() {
9-
"light" => *theme = ThemeType::Light,
10-
"dark" => *theme = ThemeType::Dark,
11-
_ => {}
12-
};
13-
14-
// update the tray icon
15-
let app = window.app_handle();
16-
let clickthrough = get_clickthrough(app.state::<Clickthrough>());
17-
let tray_handle = app.tray_handle();
18-
let theme = *theme;
19-
20-
update_tray_icon(tray_handle, theme, clickthrough);
21-
}
3+
use crate::{constants::*, Clickthrough};
224

235
#[tauri::command]
246
pub fn open_settings(window: Window, update: bool) {
@@ -94,27 +76,18 @@ fn _set_clickthrough(value: bool, window: &Window, clickthrough: State<Clickthro
9476
// update the tray icon
9577
update_tray_icon(
9678
window.app_handle().tray_handle(),
97-
*window.app_handle().state::<Storage>().theme.lock().unwrap(),
9879
value,
9980
);
10081
}
10182

102-
// BUG: there is a bug if you have an inverted menubar it will be dark and we still load the wrong icon
103-
// TODO: investigate if this is easy to do with tauri alone
104-
fn update_tray_icon(tray: SystemTrayHandle, theme: ThemeType, clickthrough: bool) {
105-
let icon = if theme == ThemeType::Dark {
106-
if clickthrough {
107-
tauri::Icon::Raw(include_bytes!("../icons/tray/icon-pinned.png").to_vec())
108-
} else {
109-
tauri::Icon::Raw(include_bytes!("../icons/tray/icon.png").to_vec())
110-
}
83+
fn update_tray_icon(tray: SystemTrayHandle, clickthrough: bool) {
84+
let icon;
85+
if clickthrough {
86+
icon = tauri::Icon::Raw(include_bytes!("../icons/tray/icon-pinned.png").to_vec());
11187
} else {
112-
if clickthrough {
113-
tauri::Icon::Raw(include_bytes!("../icons/tray/icon-pinned-dark.png").to_vec())
114-
} else {
115-
tauri::Icon::Raw(include_bytes!("../icons/tray/icon-dark.png").to_vec())
116-
}
117-
};
88+
icon = tauri::Icon::Raw(include_bytes!("../icons/tray/icon.png").to_vec());
89+
}
90+
91+
tray.set_icon(icon);
11892

119-
tray.set_icon(icon).unwrap();
12093
}

apps/desktop/src-tauri/src/constants.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,3 @@ pub const TRAY_QUIT: &str = "quit";
1212

1313
/// random events
1414
pub const SHOW_UPDATE_MODAL: &str = "show_update_modal";
15-
16-
#[derive(PartialEq, Copy, Clone, Debug)]
17-
pub enum ThemeType {
18-
Light,
19-
Dark,
20-
}

apps/desktop/src-tauri/src/main.rs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod window_custom;
1515

1616
use crate::commands::*;
1717
use constants::*;
18-
use std::sync::{atomic::AtomicBool, Mutex};
18+
use std::sync::atomic::AtomicBool;
1919
use tauri::{generate_handler, Manager};
2020
use tauri_plugin_window_state::StateFlags;
2121
use tray::{create_tray_items, handle_tray_events};
@@ -26,12 +26,6 @@ use tauri::{App, Window};
2626

2727
pub struct Clickthrough(AtomicBool);
2828

29-
// play with a struct with interior mutability
30-
#[derive(Debug)]
31-
pub struct Storage {
32-
theme: Mutex<ThemeType>,
33-
}
34-
3529
#[cfg(target_os = "macos")]
3630
fn apply_macos_specifics(_app: &mut App, window: &Window) {
3731
window.set_visisble_on_all_workspaces(true);
@@ -49,12 +43,9 @@ fn main() {
4943
.plugin(window_state_plugin.build())
5044
.plugin(tauri_plugin_websocket::init())
5145
.plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
52-
println!("{}, {argv:?}, {cwd}", app.package_info().name);
46+
println!("{}, {argv:?}, {cwd}", app.package_info().name);
5347
}))
5448
.manage(Clickthrough(AtomicBool::new(false)))
55-
.manage(Storage {
56-
theme: Mutex::new(ThemeType::Dark),
57-
})
5849
.setup(|app| {
5950
let window = app.get_window(MAIN_WINDOW_NAME).unwrap();
6051
let settings = app.get_window(SETTINGS_WINDOW_NAME).unwrap();
@@ -84,16 +75,6 @@ fn main() {
8475
settings.open_devtools();
8576
}
8677

87-
let mode = dark_light::detect();
88-
let mode_string = match mode {
89-
dark_light::Mode::Dark => "dark",
90-
dark_light::Mode::Light => "light",
91-
_ => "dark",
92-
};
93-
94-
// sync the theme
95-
sync_theme(window, app.state::<Storage>(), mode_string.to_string());
96-
9778
Ok(())
9879
})
9980
// Add the system tray
@@ -104,7 +85,6 @@ fn main() {
10485
toggle_clickthrough,
10586
get_clickthrough,
10687
set_clickthrough,
107-
sync_theme,
10888
open_devtools,
10989
close_settings,
11090
open_settings

apps/desktop/src-tauri/tauri.conf.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"systemTray": {
2121
"iconPath": "icons/tray/icon.png",
22-
"iconAsTemplate": false
22+
"iconAsTemplate": true
2323
},
2424
"allowlist": {
2525
"os": {

apps/desktop/src/App.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ import { useAlign } from "./hooks/use-align";
1111
import { useDisableWebFeatures } from "./hooks/use-disable-context-menu";
1212
import { useUpdate } from "./hooks/use-update";
1313
import { useAppStore } from "./store";
14-
import { useThemeSync } from "./hooks/use-theme-sync";
1514
import { Toaster } from "./components/ui/toaster";
1615
import { useEffect } from "react";
1716

1817
function App() {
1918
useSocket();
20-
useThemeSync();
2119
useDisableWebFeatures();
2220

2321
useEffect(() => {

apps/desktop/src/hooks/use-theme-sync.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)