Skip to content

Commit

Permalink
Try to implement singleton instead (failed)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbirkert committed Aug 22, 2024
1 parent eaab5e6 commit f40901e
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions qb-mobile/rust/src/api/daemon.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
use std::path::PathBuf;
use std::{
path::PathBuf,
sync::{LazyLock, Mutex},
};

use flutter_rust_bridge::frb;
use qb_core::fs::wrapper::QBFSWrapper;
use qb_daemon::{daemon::QBDaemon, master::QBMaster};

pub struct DaemonWrapper {
daemon: QBDaemon,
}
// TODO: figure out how to make QBDaemon send.
static DAEMON_SINGLETON: LazyLock<Mutex<Option<QBDaemon>>> = LazyLock::new(|| Mutex::new(None));

#[frb(opaque)]
pub struct DaemonWrapper {}

impl DaemonWrapper {
pub async fn init(path: String) -> DaemonWrapper {
pub async fn init(path: String) {
let path: PathBuf = path.into();
let wrapper = QBFSWrapper::new(path);

let master = QBMaster::init(wrapper.clone()).await;
let mut daemon = QBDaemon::init(master, wrapper).await;
daemon.autostart().await;

Self { daemon }
*DAEMON_SINGLETON.lock().unwrap() = Some(daemon);
}
}

0 comments on commit f40901e

Please sign in to comment.