-
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.
- Loading branch information
Showing
17 changed files
with
1,960 additions
and
93 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "yad-mac-agent" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
anyhow = "1" | ||
cacao = "0.3.2" | ||
async-std = { version = "1", features=["tokio1"] } | ||
salvo = "0.37" | ||
yad-mac-observer = { path = "../yad_mac_observer" } | ||
lazy_static = "1.4" | ||
flume = "0.10" |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
mod server; | ||
|
||
use crate::app::server::YadAgentServer; | ||
use async_std::task::JoinHandle; | ||
use cacao::appkit::*; | ||
use lazy_static::lazy_static; | ||
use std::cell::RefCell; | ||
use std::future::Future; | ||
use yad_mac_observer::MacEventObserver; | ||
|
||
pub struct YadAgentApp { | ||
observer: RefCell<MacEventObserver>, | ||
server: YadAgentServer, | ||
} | ||
|
||
impl YadAgentApp { | ||
pub fn new() -> Self { | ||
YadAgentApp { | ||
observer: RefCell::new(MacEventObserver::new()), | ||
server: YadAgentServer::new(), | ||
} | ||
} | ||
|
||
pub fn spawn<F>(future: F) -> JoinHandle<F::Output> | ||
where | ||
F: Future + Send + 'static, | ||
F::Output: Send + 'static, | ||
{ | ||
async_std::task::spawn(future) | ||
} | ||
} | ||
|
||
impl AppDelegate for YadAgentApp { | ||
fn did_finish_launching(&self) { | ||
self.observer.borrow_mut().start(); | ||
} | ||
|
||
fn will_terminate(&self) { | ||
self.observer.borrow_mut().stop(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use crate::app::YadAgentApp; | ||
// use crate::RUNTIME; | ||
use async_std::task::JoinHandle; | ||
use flume::{bounded, Receiver, Sender}; | ||
use lazy_static::lazy_static; | ||
use salvo::prelude::*; | ||
|
||
lazy_static! { | ||
static ref SHUTDOWN_CHANNEL: (Sender<()>, Receiver<()>) = bounded(1); | ||
} | ||
|
||
pub struct YadAgentServer { | ||
handle: JoinHandle<()>, | ||
} | ||
|
||
impl YadAgentServer { | ||
pub fn new() -> Self { | ||
let handle = YadAgentApp::spawn(Self::init_server()); | ||
YadAgentServer { handle } | ||
} | ||
|
||
async fn init_server() { | ||
let router = Router::new().get(hello_world); | ||
let server = Server::new(TcpListener::bind("127.0.0.1:7878")).serve_with_graceful_shutdown( | ||
router, | ||
async { | ||
SHUTDOWN_CHANNEL | ||
.1 | ||
.recv_async() | ||
.await | ||
.expect("Shutdown signal received"); | ||
}, | ||
); | ||
server.await; | ||
} | ||
|
||
pub fn shutdown() { | ||
SHUTDOWN_CHANNEL.0.send_async(()); | ||
} | ||
} | ||
|
||
#[handler] | ||
async fn hello_world(res: &mut Response) { | ||
res.render("Hello world!"); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
mod app; | ||
|
||
// use crate::app::RUNTIME; | ||
use cacao::appkit::*; | ||
use salvo::prelude::*; | ||
use std::thread; | ||
use yad_mac_observer::MacEventObserver; | ||
|
||
fn main() { | ||
let mut app = App::new("dev.bysensa.yad.agent", app::YadAgentApp::new()); | ||
thread::spawn(|| { | ||
let receiver = MacEventObserver::receiver(); | ||
while let Ok(event) = receiver.recv() { | ||
dbg!(event); | ||
} | ||
}); | ||
app.run(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "yad-mac-observer" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[[example]] | ||
name = "usage" | ||
|
||
[dependencies] | ||
objc = "0.2.7" | ||
objc_id = "0.1.1" | ||
cocoa = "0.24.1" | ||
cacao = "0.3.2" | ||
objc-foundation = "0.1.1" | ||
serde = { version = "1", features = ["derive"] } | ||
lazy_static = "1.4.0" | ||
flume = "0.10.14" | ||
chrono = "0.4.23" | ||
#https://docs.rs/thingbuf/0.1.3/thingbuf/mpsc/index.html | ||
#thingbuf = "0.1.3" |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::thread; | ||
use yad_mac_observer::MacEventObserver; | ||
|
||
#[derive(Default)] | ||
struct ExampleApp {} | ||
|
||
impl cacao::appkit::AppDelegate for ExampleApp {} | ||
|
||
fn main() { | ||
let app = cacao::appkit::App::new("dev.bysensa.yad", ExampleApp::default()); | ||
let event_receiver = MacEventObserver::receiver(); | ||
let mut observer = MacEventObserver::new(); | ||
observer.start(); | ||
let _handle = thread::spawn(move || { | ||
while let Ok(event) = event_receiver.recv() { | ||
dbg!(event); | ||
} | ||
}); | ||
app.run(); | ||
} |
Oops, something went wrong.