Skip to content

Commit

Permalink
refactor: remove macos dock icon
Browse files Browse the repository at this point in the history
  • Loading branch information
cs50victor committed Mar 24, 2024
1 parent ecaae62 commit 853ee32
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 84 deletions.
22 changes: 22 additions & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2021"
tauri-build = { version = "1", features = [] }

[dependencies]
tauri = { version = "1", features = [ "system-tray", "shell-open"] }
tauri = { version = "1", features = [ "shell-all", "system-tray"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"

Expand Down
119 changes: 38 additions & 81 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use tauri::{
api::shell::open, AppHandle, CustomMenuItem, Manager,
SystemTray, SystemTrayEvent, SystemTrayMenu,
SystemTrayMenuItem, SystemTraySubmenu,
api::shell::open, AppHandle, CustomMenuItem, Manager, SystemTray, SystemTrayEvent,
SystemTrayMenu, SystemTrayMenuItem, SystemTraySubmenu,
};

// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command
Expand All @@ -13,122 +12,80 @@ fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}


const links: [(&str, &str, &str); 5] = [
// social links
("open-social-netlify", "Netlify","https://app.netlify.com/teams/christopherbiscardi/overview"),
("open-social-youtube", "YouTube","https://www.youtube.com/@chrisbiscardi"),
("open-social-twitter", "Twitter","https://twitter.com/"),
const links: [(&str, &str, &str); 2] = [
// github links
("open-github-rust-adventure", "Rust Adventure","https://github.com/rust-adventure"),
("open-github-bevy", "Bevy","https://github.com/bevyengine/bevy"),
("open-github-source", "OS1", "https://github.com/cs50victor/os1"),
("open-send-feedback", "Send Feedback", "https://dm.new/vic"),
];

fn main() {
let sub_menu_social = {
let mut menu = SystemTrayMenu::new();
for (id, label, _url) in
links.iter().filter(|(id, label, _url)| {
id.starts_with("open-social")
})
{
menu = menu.add_item(CustomMenuItem::new(
id.to_string(),
label.to_string(),
));
}

SystemTraySubmenu::new("Social", menu)
};
let sub_menu_github = {
let mut menu = SystemTrayMenu::new();
for (id, label, _url) in
links.iter().filter(|(id, label, _url)| {
id.starts_with("open-github")
})
links.iter().filter(|(id, label, _url)| id.starts_with("open-github"))
{
menu = menu.add_item(CustomMenuItem::new(
id.to_string(),
label.to_string(),
));
menu = menu.add_item(CustomMenuItem::new(id.to_string(), label.to_string()));
}

SystemTraySubmenu::new("GitHub", menu)
};

let tray_menu = SystemTrayMenu::new()
.add_item(CustomMenuItem::new(
"quit".to_string(),
"Quit",
))
.add_submenu(sub_menu_social)
.add_item(CustomMenuItem::new("quit".to_string(), "Quit"))
.add_submenu(sub_menu_github)
.add_native_item(SystemTrayMenuItem::Separator)
.add_item(CustomMenuItem::new(
"visibility-toggle".to_string(),
"Hide",
));
.add_item(CustomMenuItem::new("open-send-feedback".to_string(), "Send Feedback"))
.add_native_item(SystemTrayMenuItem::Separator)
.add_item(CustomMenuItem::new("visibility-toggle".to_string(), "Hide"));

let tray = SystemTray::new().with_menu(tray_menu);

tauri::Builder::default()
let mut app = tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
.system_tray(tray)
.on_system_tray_event(on_system_tray_event)
.build(tauri::generate_context!())
.expect("error while running tauri application")
.run(|_app_handle, event| match event {
tauri::RunEvent::ExitRequested {
api, ..
} => {
api.prevent_exit();
}
_ => {}
});
.expect("error while running tauri application");

#[cfg(target_os = "macos")]
app.set_activation_policy(tauri::ActivationPolicy::Accessory);
app.run(|_app_handle, event| match event {
tauri::RunEvent::ExitRequested { api, .. } => {
api.prevent_exit();
},
_ => {},
});
}

fn on_system_tray_event(
app: &AppHandle,
event: SystemTrayEvent,
) {
fn on_system_tray_event(app: &AppHandle, event: SystemTrayEvent) {
match event {
SystemTrayEvent::MenuItemClick { id, .. } => {
let item_handle =
app.tray_handle().get_item(&id);
let item_handle = app.tray_handle().get_item(&id);
dbg!(&id);
match id.as_str() {
"visibility-toggle" => {
let window =
app.get_window("main").unwrap();
let window = app.get_window("main").unwrap();
match window.is_visible() {
Ok(true) => {
window.hide().unwrap();
item_handle.set_title("Show").unwrap();
window.hide().unwrap();
item_handle.set_title("Show").unwrap();
},
Ok(false) => {
window.show();
item_handle.set_title("Hide").unwrap();

window.show();
item_handle.set_title("Hide").unwrap();
},
Err(e) => unimplemented!("what kind of errors happen here?"),
}
}
},
"quit" => app.exit(0),
s if s.starts_with("open-") => {
if let Some(link) = links
.iter()
.find(|(id, ..)| id == &s)
{
open(
&app.shell_scope(),
link.2,
None,
)
.unwrap();
if let Some(link) = links.iter().find(|(id, ..)| id == &s) {
open(&app.shell_scope(), link.2, None).unwrap();
}
}
_ => {}
},
_ => {},
}
}
_ => {}
},
_ => {},
}
}
}
4 changes: 3 additions & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"allowlist": {
"all": false,
"shell": {
"all": false,
"all": true,
"execute": true,
"sidecar": true,
"open": true
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@
}
body {
/* @apply bg-foreground text-background; */
@apply bg-[#353535] text-background;
@apply bg-[#212121] text-background;
}
}

0 comments on commit 853ee32

Please sign in to comment.