Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ mod organize_type;

use std::collections::BTreeMap;

use ::tray_icon::TrayIcon;
use config::Config;
use consts::{APPNAME, BOLD_FONT_TTF, ICON_FONT_TTF, MEDIUM_FONT, MEDIUM_FONT_TTF};
use iced::{Task, daemon, window::Id};
use interprocess::local_socket::{self, GenericNamespaced, ToNsName, traits::Stream};
use tray_icon::create_tray_icon;
use window::AppWindow;

fn main() -> Result<(), iced::Error> {
Expand All @@ -36,13 +36,10 @@ fn main() -> Result<(), iced::Error> {
return Ok(());
};

#[cfg(not(target_os = "linux"))]
let _tray_icon = create_tray_icon();

#[cfg(target_os = "linux")]
std::thread::spawn(|| {
gtk::init().expect("GTK must be initialized");
let _tray_icon = create_tray_icon();
let _tray_icon = tray_icon::create_tray_icon();
gtk::main();
});

Expand All @@ -65,6 +62,7 @@ pub struct App {

config: Config,
windows: BTreeMap<Id, AppWindow>,
tray_icon: Option<TrayIcon>,
}

#[derive(Debug, Clone)]
Expand All @@ -80,6 +78,7 @@ pub enum Message {
ExitApp,
Settings(Id, settings::Message),
Capture(Id, capture::Message),
CreateTrayIcon,
}

impl App {
Expand All @@ -97,6 +96,11 @@ impl App {
}
Err(_) => (Config::default(), Task::done(Message::OpenSettingsWindow)),
};
let task = Task::batch([
task,
#[cfg(not(target_os = "linux"))]
Task::done(Message::CreateTrayIcon),
]);

(
App {
Expand All @@ -106,6 +110,7 @@ impl App {

config,
windows: BTreeMap::new(),
tray_icon: None,
},
task,
)
Expand Down
4 changes: 4 additions & 0 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
capture::{self, Capture},
consts::APPICON,
settings::{self, Settings},
tray_icon::create_tray_icon,
window::AppWindow,
};

Expand Down Expand Up @@ -196,6 +197,9 @@ impl App {
return Task::batch(tasks);
}
}
Message::CreateTrayIcon => {
self.tray_icon = Some(create_tray_icon());
}
}
Task::none()
}
Expand Down