-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try to implement singleton instead (failed)
- Loading branch information
Showing
1 changed file
with
12 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |