Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
callmeclover committed May 31, 2024
2 parents e1f19fd + b906750 commit 31af2c4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ features = [
version = "0.5.0"
optional = true

[target.x86_64-apple-darwin.dependencies]
cocoa-foundation = "0.1.2"
objc = "0.2.7"

[build-dependencies]
winresource = "0.1"

Expand Down
43 changes: 42 additions & 1 deletion src/func.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#[cfg(target_os = "macos")]
use cocoa_foundation::base::id;
#[cfg(target_os = "macos")]
use cocoa_foundation::foundation::NSDefaultRunLoopMode;
#[cfg(target_os = "macos")]
use cocoa_foundation::foundation::NSRunLoop;
#[cfg(target_os = "macos")]
use objc::{class, msg_send, sel, sel_impl};

#[allow(clippy::wildcard_imports)]
use crate::{
get_config, lists::*, Speed, SPEED_WEIGHTED_LISTS_FAST, SPEED_WEIGHTED_LISTS_NORMAL,
Expand Down Expand Up @@ -306,6 +315,14 @@ fn quote(tts: &mut Tts, rng: &mut rand::rngs::ThreadRng) {
let quote: &str = list[index2.sample(rng)].0;
println!("{quote}");
let _ = tts.speak(quote, true);
#[cfg(target_os = "macos")]
{
let run_loop: id = unsafe { NSRunLoop::currentRunLoop() };
unsafe {
let date: id = msg_send![class!(NSDate), distantFuture];
let _: () = msg_send![run_loop, runMode:NSDefaultRunLoopMode beforeDate:date];
}
}
}

fn quote_gen(tts: &mut Tts) {
Expand All @@ -315,6 +332,14 @@ fn quote_gen(tts: &mut Tts) {
let quote: &str = &gen_sentence(SentenceConfigBuilder::random().build());
println!("{quote}");
let _ = tts.speak(quote, true);
#[cfg(target_os = "macos")]
{
let run_loop: id = unsafe { NSRunLoop::currentRunLoop() };
unsafe {
let date: id = msg_send![class!(NSDate), distantFuture];
let _: () = msg_send![run_loop, runMode:NSDefaultRunLoopMode beforeDate:date];
}
}
}

async fn quote_gen_ext(tts: &mut Tts) {
Expand All @@ -339,13 +364,29 @@ async fn quote_gen_ext(tts: &mut Tts) {
.unwrap();
println!("{quote}");
let _ = tts.speak(quote, true);
#[cfg(target_os = "macos")]
{
let run_loop: id = unsafe { NSRunLoop::currentRunLoop() };
unsafe {
let date: id = msg_send![class!(NSDate), distantFuture];
let _: () = msg_send![run_loop, runMode:NSDefaultRunLoopMode beforeDate:date];
}
}
}
}

fn screenshot(tts: &mut Tts) {
println!("hahahahah i am going to screenshot everything");
let _ = tts.speak("hahahahah i am going to screenshot everything", true);
let screens: Vec<Screen> = Screen::all().unwrap();
#[cfg(target_os = "macos")]
{
let run_loop: id = unsafe { NSRunLoop::currentRunLoop() };
unsafe {
let date: id = msg_send![class!(NSDate), distantFuture];
let _: () = msg_send![run_loop, runMode:NSDefaultRunLoopMode beforeDate:date];
}
}
let screens: Vec<Screen> = Screen::all().unwrap();

for screen in screens {
let time: String = convert_to_human_readable(Local::now().to_string().as_str());
Expand Down

0 comments on commit 31af2c4

Please sign in to comment.