macos tray
This commit is contained in:
parent
4a8578ee85
commit
03ae220f71
@ -163,7 +163,8 @@ pub fn core_main() -> Option<Vec<String>> {
|
|||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
std::thread::spawn(move || crate::start_server(true));
|
std::thread::spawn(move || crate::start_server(true));
|
||||||
// to-do: for flutter, starting tray not ready yet, or we can reuse sciter's tray implementation.
|
crate::tray::make_tray();
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
{
|
{
|
||||||
|
32
src/tray.rs
32
src/tray.rs
@ -173,3 +173,35 @@ fn is_service_stoped() -> bool {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
pub fn make_tray() {
|
||||||
|
use tray_item::TrayItem;
|
||||||
|
let mode = dark_light::detect();
|
||||||
|
let mut icon_path = "";
|
||||||
|
match mode {
|
||||||
|
dark_light::Mode::Dark => {
|
||||||
|
icon_path = "mac-tray-light.png";
|
||||||
|
},
|
||||||
|
dark_light::Mode::Light => {
|
||||||
|
icon_path = "mac-tray-dark.png";
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if let Ok(mut tray) = TrayItem::new(&crate::get_app_name(), icon_path) {
|
||||||
|
tray.add_label(&format!(
|
||||||
|
"{} {}",
|
||||||
|
crate::get_app_name(),
|
||||||
|
crate::lang::translate("Service is running".to_owned())
|
||||||
|
))
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
let inner = tray.inner_mut();
|
||||||
|
inner.add_quit_item(&crate::lang::translate("Quit".to_owned()));
|
||||||
|
inner.display();
|
||||||
|
} else {
|
||||||
|
loop {
|
||||||
|
std::thread::sleep(std::time::Duration::from_secs(3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -63,12 +63,7 @@ fn check_connect_status(
|
|||||||
|
|
||||||
pub fn start(args: &mut [String]) {
|
pub fn start(args: &mut [String]) {
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
if args.len() == 1 && args[0] == "--server" {
|
macos::show_dock();
|
||||||
macos::make_tray();
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
macos::show_dock();
|
|
||||||
}
|
|
||||||
#[cfg(all(target_os = "linux", feature = "inline"))]
|
#[cfg(all(target_os = "linux", feature = "inline"))]
|
||||||
{
|
{
|
||||||
#[cfg(feature = "appimage")]
|
#[cfg(feature = "appimage")]
|
||||||
|
@ -233,33 +233,7 @@ pub fn make_tray() {
|
|||||||
unsafe {
|
unsafe {
|
||||||
set_delegate(None);
|
set_delegate(None);
|
||||||
}
|
}
|
||||||
use tray_item::TrayItem;
|
crate::tray::make_tray();
|
||||||
let mode = dark_light::detect();
|
|
||||||
let mut icon_path = "";
|
|
||||||
match mode {
|
|
||||||
dark_light::Mode::Dark => {
|
|
||||||
icon_path = "mac-tray-light.png";
|
|
||||||
},
|
|
||||||
dark_light::Mode::Light => {
|
|
||||||
icon_path = "mac-tray-dark.png";
|
|
||||||
},
|
|
||||||
}
|
|
||||||
if let Ok(mut tray) = TrayItem::new(&crate::get_app_name(), icon_path) {
|
|
||||||
tray.add_label(&format!(
|
|
||||||
"{} {}",
|
|
||||||
crate::get_app_name(),
|
|
||||||
crate::lang::translate("Service is running".to_owned())
|
|
||||||
))
|
|
||||||
.ok();
|
|
||||||
|
|
||||||
let inner = tray.inner_mut();
|
|
||||||
inner.add_quit_item(&crate::lang::translate("Quit".to_owned()));
|
|
||||||
inner.display();
|
|
||||||
} else {
|
|
||||||
loop {
|
|
||||||
std::thread::sleep(std::time::Duration::from_secs(3));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_main_window() {
|
pub fn check_main_window() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user