Skip to content

Commit

Permalink
chore: w64 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastien Sevajol committed May 20, 2024
1 parent 5b94b9c commit d4e6cdc
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 40 deletions.
35 changes: 17 additions & 18 deletions systray/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,23 @@ impl Config {
Self::from_ini(config_ini)
}

#[cfg(target_os = "linux")]
pub fn from_ini(config_ini: Ini) -> Result<Self, Error> {
#[cfg(target_os = "linux")]
{
let icons_path = match config_ini.get_from(Some("server"), "icons_path") {
Some(icon_path_) => Path::new(icon_path_),
None => {
return Err(Error::ReadConfigError(
"Unable to find server icons_path config".to_string(),
))
}
};
Ok(Self {
icons_path: icons_path.to_str().unwrap().to_string(),
})
}
#[cfg(target_os = "windows")]
{
Ok(Self {})
}
let icons_path = match config_ini.get_from(Some("server"), "icons_path") {
Some(icon_path_) => Path::new(icon_path_),
None => {
return Err(Error::ReadConfigError(
"Unable to find server icons_path config".to_string(),
))
}
};
Ok(Self {
icons_path: icons_path.to_str().unwrap().to_string(),
})
}

#[cfg(target_os = "windows")]
pub fn from_ini(_config_ini: Ini) -> Result<Self, Error> {
Ok(Self {})
}
}
8 changes: 4 additions & 4 deletions systray/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ fn run() -> Result<()> {
}
});

let activity_state_ = activity_state.clone();
let main_sender_ = main_sender.clone();
let activity_state_ = activity_state_.clone();
let main_sender_ = main_sender_.clone();
// TODO : See if we can use multiple viewports (https://github.com/emilk/egui/tree/master/examples/multiple_viewports)
loop {
match user_request_receiver.recv_timeout(Duration::from_millis(150)) {
Expand Down Expand Up @@ -152,8 +152,8 @@ fn run() -> Result<()> {

// When these lines are reached, tray is finished so, close application
log::info!("Stopping ...");
stop_signal.swap(true, Ordering::Relaxed);
main_sender
stop_signal_.swap(true, Ordering::Relaxed);
main_sender_
.send(DaemonMessage::Stop)
.map_err(|e| Error::Unexpected(format!("Unable to ask manager to stop : '{}'", e)))?;
log::info!("Finished");
Expand Down
60 changes: 44 additions & 16 deletions systray/src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use std::process::Command;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::RecvTimeoutError;
use std::sync::{mpsc, Arc, Mutex};
use std::time::Duration;
use crossbeam_channel::Sender;
use tray_item::TrayItem;

use trsync_manager_configure::run::run as run_configure;
use trsync_core::activity::ActivityState;
use trsync_core::error::ErrorExchanger;
use trsync_core::sync::SyncExchanger;
use trsync_core::user::{MonitorWindowPanel, UserRequest};
use trsync_manager::message::DaemonMessage;

use crate::icon::Icon;
use crate::state::{Activity, ActivityState};

enum Message {
Quit,
Expand All @@ -18,34 +21,59 @@ pub fn run_tray(
main_sender: Sender<DaemonMessage>,
activity_state: Arc<Mutex<ActivityState>>,
stop_signal: Arc<AtomicBool>,
user_request_sender: Sender<UserRequest>,
sync_exchanger: Arc<Mutex<SyncExchanger>>,
error_exchanger: Arc<Mutex<ErrorExchanger>>,
) -> Result<(), String> {
let mut current_icon = Icon::Idle;
let activity_state_ = activity_state.clone();
let main_sender_quit = main_sender.clone();

// Icon
let mut tray = match TrayItem::new("Tracim", "trsync_idle") {
Ok(tray_) => tray_,
Err(error) => return Err(format!("Unable to create tray item : '{}'", error)),
};

let mut current_icon = Icon::Idle;
match tray.add_menu_item("Configurer", move || {
log::info!("Run configure window");
let main_sender_ = main_sender.clone();
if let Err(error) = run_configure(main_sender_) {
return log::error!("Unable to run configure window : '{}'", error);
};
// Monitor item
let window_sender_ = user_request_sender.clone();
if let Err(error) = tray.add_menu_item("Moniteur", move || {
log::info!("Request monitor window open");
if window_sender_
.send(UserRequest::OpenMonitorWindow(MonitorWindowPanel::Root))
.is_err()
{
log::error!("Unable to send monitor window open request")
}
}) {
Err(error) => return Err(format!("Unable to add menu item : '{:?}'", error)),
_ => {}
return Err(format!("Unable to add menu item : '{:?}'", error));
};

let (tx, rx) = mpsc::channel();
// Configure item
let window_sender_ = user_request_sender.clone();
if let Err(error) = tray.add_menu_item("Configurer", move || {
log::info!("Request configure window open");
if window_sender_
.send(UserRequest::OpenConfigurationWindow)
.is_err()
{
log::error!("Unable to send configure window open request")
}
}) {
return Err(format!("Unable to add menu item : '{:?}'", error));
};

match tray.add_menu_item("Quitter", move || {
// Quit item
let (tx, rx) = mpsc::channel();
let menu_stop_signal = stop_signal.clone();
let main_sender_ = main_sender_quit.clone();
let window_sender_ = user_request_sender.clone();
if let Err(error) = tray.add_menu_item("Quitter", move || {
main_sender_.send(DaemonMessage::Stop).unwrap_or(());
tx.send(Message::Quit)
.expect("This channel must not been closed");
}) {
Err(error) => return Err(format!("Unable to send quit message : '{:?}'", error)),
_ => {}
return Err(format!("Unable to add menu item : '{:?}'", error));
};

loop {
Expand Down
4 changes: 2 additions & 2 deletions trsync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trsync_core = { path = "../core" }
# Core
walkdir = "2.3.2"
chrono = "0.4.19"
async-std = { version = "1.9.0", features = ["tokio1"] }
async-std = { version = "1.10.0", features = ["tokio1"] }
rpassword = "6.0.1"
bytes = "1.1.0"
tokio = { version = "1.17.0", features = ["time"] }
Expand All @@ -35,7 +35,7 @@ notify = "4.0.17"
# Cli args
structopt = "0.3.23"
# Database
rusqlite = "0.27.0"
rusqlite = { version = "0.27.0", features = ["bundled"] }
# Http client
reqwest = { version = "0.11.4", features = ["blocking", "json", "stream", "multipart"] }
futures-util = "0.3.17" # required to call .next() on reqwest Stream
Expand Down

0 comments on commit d4e6cdc

Please sign in to comment.