Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split sync and async API #50

Merged
merged 7 commits into from
Dec 31, 2024
Merged

Split sync and async API #50

merged 7 commits into from
Dec 31, 2024

Conversation

edfloreshz
Copy link
Collaborator

This pull request introduces several changes to the codebase to add support for both synchronous and asynchronous detection and subscription to system theme changes.

The changes include modifications to dependencies, new feature flags, and refactoring of existing code to accommodate the new functionality.

Warning

These are breaking changes, we should consider shipping v2.0.0 after merging this.

Dependency and feature flag updates:

  • Cargo.toml: Added sync feature flag and updated pollster to be optional. Introduced new example paths for sync and added the cocoa and objc dependencies for macOS support.

Refactoring and new functionality:

  • src/lib.rs: Moved the Mode enum to a new mode module and updated the detect and subscribe functions to support both synchronous and asynchronous operations.
  • src/mode.rs: Created a new module for the Mode enum and its associated methods.
  • src/platforms/*: Refactored platform-specific detection and subscription functions to support both synchronous and asynchronous operations. This includes changes in macOS, freedesktop, websys, and windows modules.

Example updates:

  • examples/async.rs: Added a new asynchronous example demonstrating the use of the detect and subscribe functions.
  • examples/sync.rs: Added a new synchronous example demonstrating the use of the detect and subscribe functions.
  • Removed outdated examples detect.rs and notify.rs as they were replaced by the new async.rs and sync.rs examples.

Fixes:

Cargo.toml Outdated Show resolved Hide resolved
@edfloreshz edfloreshz requested a review from Be-ing December 11, 2024 00:26
@edfloreshz
Copy link
Collaborator Author

I'll go ahead and merge this.

@edfloreshz edfloreshz merged commit b5f436a into main Dec 31, 2024
4 checks passed
This was referenced Dec 31, 2024
Comment on lines +9 to +27
let user_defaults: *mut NSObject = msg_send![class!(NSUserDefaults), standardUserDefaults];
let apple_domain = NSString::from_str("Apple Global Domain");
let dict: *mut NSObject = msg_send![user_defaults, persistentDomainForName:&*apple_domain];

if !dict.is_null() {
let style_key = NSString::from_str("AppleInterfaceStyle");
let style: *mut NSObject = msg_send![dict, objectForKey:&*style_key];

if !style.is_null() {
// Compare with "Dark"
let dark_str = NSString::from_str("Dark");
let is_dark: bool = msg_send![style, isEqualToString:&*dark_str];
is_dark
} else {
false
}
} else {
false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip: You can avoid the brittle msg_send! here by importing NSUserDefaults from objc2-foundation (might have to modify Cargo.toml to include the "NSUserDefaults" Cargo feature first).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

macOS: Notes on notification detection
3 participants