Skip to content

Commit

Permalink
feat: restore possibility to start manager
Browse files Browse the repository at this point in the history
  • Loading branch information
buxx committed Sep 24, 2024
1 parent 9d05111 commit b117d75
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions core/src/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ impl Default for ActivityState {
}
}

#[derive(Debug)]
pub struct WrappedActivity {
job_identifier: JobIdentifier,
activity: Activity,
Expand Down
48 changes: 40 additions & 8 deletions manager/src/bin.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
use std::{
sync::{Arc, Mutex},
thread,
};

use anyhow::Result;
use crossbeam_channel::{unbounded, Receiver, Sender};
use daemon::Daemon;
use env_logger::Env;
use trsync_core::{activity::WrappedActivity, config::ManagerConfig};
use message::DaemonMessage;
use trsync_core::{
activity::WrappedActivity, config::ManagerConfig, error::ErrorExchanger, sync::SyncExchanger,
user::UserRequest,
};

pub mod client;
pub mod daemon;
pub mod error;
pub mod message;
pub mod types;

type DaemonMessageChannels = (Sender<DaemonMessage>, Receiver<DaemonMessage>);
type ActivityChannels = (Sender<WrappedActivity>, Receiver<WrappedActivity>);

fn main_() -> Result<()> {
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();

Expand All @@ -20,15 +33,34 @@ fn main_() -> Result<()> {
) = unbounded();

log::info!("Read config");
let config = ManagerConfig::from_env(true)?;
let mut config = ManagerConfig::from_env(true)?;
config.confirm_startup_sync = false;
config.popup_confirm_startup_sync = false;

let sync_exchanger = Arc::new(Mutex::new(SyncExchanger::new()));
let error_exchanger = Arc::new(Mutex::new(ErrorExchanger::new()));
let (_main_sender, main_receiver): DaemonMessageChannels = unbounded();
let (activity_sender, activity_receiver): ActivityChannels = unbounded();
let sync_exchanger = sync_exchanger.clone();
let error_exchanger = error_exchanger.clone();
let (user_request_sender, _): (Sender<UserRequest>, Receiver<UserRequest>) = unbounded();

thread::spawn(move || {
while let Ok(activity) = activity_receiver.recv() {
log::debug!("Activity: {:?}", activity)
}
});

log::info!("Start daemon");
let _config_ = config.clone();
let (_activity_sender, activity_receiver): (
Sender<WrappedActivity>,
Receiver<WrappedActivity>,
) = unbounded();
std::thread::spawn(move || while activity_receiver.recv().is_ok() {});
Daemon::new(
config,
main_receiver,
activity_sender,
user_request_sender,
sync_exchanger,
error_exchanger,
)
.run()?;
log::info!("Daemon finished, exit");

Ok(())
Expand Down

0 comments on commit b117d75

Please sign in to comment.