-
Notifications
You must be signed in to change notification settings - Fork 30
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
Version 2 #51
Draft
whizsid
wants to merge
8
commits into
h4llow3En:master
Choose a base branch
from
whizsid:v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Version 2 #51
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f6d80e8
Ensure cross-build compatibility of build.rs
Guiguiprim abdc433
Merge pull request #49 from Guiguiprim/cross-compilation
hoodie fecd89d
Request Authorization
whizsid 387a6b8
Set Badge Count
whizsid 7c2b1df
Builder structs
whizsid c8457cf
feat: convert rust types to objc
whizsid 9b2636d
refactor: separate un api by a module
whizsid 49367e6
feat: un add categories and send notifications basics
whizsid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,4 +1,7 @@ | ||
target | ||
*.swp | ||
Cargo.lock | ||
.vscode | ||
.vscode | ||
simple.app | ||
simple.log | ||
.DS_Store |
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,10 +1,12 @@ | ||
[package] | ||
name = "mac-notification-sys" | ||
version = "0.5.6" | ||
authors = ["Felix Döring <[email protected]>", "Hendrik Sollich <[email protected]>"] | ||
authors = [ | ||
"Felix Döring <[email protected]>", | ||
"Hendrik Sollich <[email protected]>", | ||
] | ||
description = "Thin wrapper around macOS Notifications." | ||
edition = "2018" | ||
rust-version = "1.56" | ||
edition = "2021" | ||
|
||
homepage = "https://github.com/h4llow3En/mac-notification-sys" | ||
repository = "https://github.com/h4llow3En/mac-notification-sys" | ||
|
@@ -14,15 +16,39 @@ license = "MIT" | |
keywords = ["notification", "masOS", "osx", "notify"] | ||
readme = "README.md" | ||
|
||
include = ["Cargo.toml", "build.rs", "objc/*", "src/*.rs", "tests/*.rs"] | ||
include = ["Cargo.toml", "src/*.rs"] | ||
|
||
build = "build.rs" | ||
[[example]] | ||
name = "simple" | ||
|
||
[dependencies] | ||
objc-foundation = "0.1.1" | ||
objc_id = "0.1.1" | ||
time = "0.3" | ||
dirs-next = "2.0.0" | ||
objc2 = "0.4.0" | ||
icrate = { version = "0.0.3", features = [ | ||
"UserNotifications_all", | ||
"Foundation", | ||
"Foundation_NSArray", | ||
"Foundation_NSString", | ||
"Foundation_NSRunLoop", | ||
"Foundation_NSError", | ||
"Foundation_NSDate", | ||
"Foundation_NSDateComponents", | ||
"Foundation_NSURL", | ||
"Foundation_NSMutableDictionary", | ||
"Foundation_NSNumber", | ||
"Foundation_NSProcessInfo", | ||
"Foundation_NSMutableArray", | ||
"UniformTypeIdentifiers" | ||
] } | ||
bitflags = "^2.3" | ||
cron = "^0.12" | ||
url = "^2.4" | ||
futures = "^0.3" | ||
chrono = "^0.4" | ||
uuid = {version = "^1.4", features = ["v4"]} | ||
lazy_static = "^1.4" | ||
|
||
[dev-dependencies] | ||
async-io = "^1.13" | ||
|
||
[build-dependencies] | ||
cc = "1.0.17" | ||
cfg_aliases = "^0.1" |
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 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,29 +1,11 @@ | ||
extern crate cc; | ||
use std::env; | ||
|
||
const DEPLOYMENT_TARGET_VAR: &str = "MACOSX_DEPLOYMENT_TARGET"; | ||
use cfg_aliases::cfg_aliases; | ||
|
||
fn main() { | ||
if cfg!(target_os = "macos") { | ||
let min_version = match env::var(DEPLOYMENT_TARGET_VAR) { | ||
Ok(ver) => ver, | ||
Err(_) => String::from(match env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() { | ||
"x86_64" => "10.8", // NSUserNotificationCenter first showed up here. | ||
"aarch64" => "11.0", // Apple silicon started here. | ||
arch => panic!("unknown arch: {}", arch), | ||
}), | ||
}; | ||
|
||
cc::Build::new() | ||
.file("objc/notify.m") | ||
.flag("-fmodules") | ||
.flag("-Wno-deprecated-declarations") | ||
// `cc` doesn't try to pick up on this automatically, but `clang` needs it to | ||
// generate a "correct" Objective-C symbol table which better matches XCode. | ||
// See https://github.com/h4llow3En/mac-notification-sys/issues/45. | ||
.flag(&format!("-mmacos-version-min={}", min_version)) | ||
.compile("notify"); | ||
|
||
println!("cargo:rerun-if-env-changed={}", DEPLOYMENT_TARGET_VAR); | ||
cfg_aliases! { | ||
watchos: { target_os = "watchos" }, | ||
macos: { target_os = "macos" }, | ||
ios: { all(not(any(target="aarch64-apple-ios-macabi", target="x86_64-apple-ios-macabi")), target_os = "ios") }, | ||
catalyst: { any(target="aarch64-apple-ios-macabi", target="x86_64-apple-ios-macabi") }, | ||
otheros: {not(any(target_os ="watchos", target_os ="macos", target_os = "ios"))} | ||
} | ||
} |
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,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<!--The executable--> | ||
<key>CFBundleExecutable</key> | ||
<string>simple-bin</string><!--This should be the name of the executable inside your MacOS folder--> | ||
|
||
<!--Company name--> | ||
<key>CFBundleIdentifier</key> | ||
<string>com.mac-notification-sys.simple</string> | ||
|
||
<!--Desired application name--> | ||
<key>CFBundleName</key> | ||
<string>Simple</string> | ||
|
||
<!--icons file, located in the Resources folder--> | ||
<key>CFBundleIconFile</key> | ||
<string>rust-logo.icns</string> | ||
|
||
<key>CFBundleDisplayName</key> | ||
<string>Mac Notification SYS Simple</string> | ||
|
||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
</dict> | ||
</plist> |
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,14 @@ | ||
#!/bin/bash | ||
cargo build --example simple | ||
rm -r simple.app | ||
rm simple.log | ||
mkdir simple.app | ||
mkdir simple.app/Contents | ||
mkdir simple.app/Contents/MacOS | ||
mkdir simple.app/Contents/Resources | ||
cp target/debug/examples/simple simple.app/Contents/MacOS/simple-bin | ||
cp bundle/Info.plist simple.app/Contents/ | ||
cp bundle/rust-logo.icns simple.app/Contents/Resources | ||
codesign --force --sign $CERTIFICATE -o runtime --entitlements ./bundle/simple.app.xcent --timestamp\=none --generate-entitlement-der ./simple.app | ||
touch simple.log | ||
open simple.app --stdout ./simple.log --stderr ./simple.log | ||
Binary file not shown.
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,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.security.app-sandbox</key> | ||
<true/> | ||
<key>com.apple.security.files.user-selected.read-only</key> | ||
<true/> | ||
<key>com.apple.security.get-task-allow</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,20 +1,36 @@ | ||
use mac_notification_sys::*; | ||
use std::time::Duration; | ||
|
||
fn main() { | ||
let bundle = get_bundle_identifier_or_default("firefox"); | ||
set_application(&bundle).unwrap(); | ||
use async_io::block_on; | ||
use mac_notification_sys::{*, notification::AuthorizationOptions}; | ||
|
||
Notification::default() | ||
.title("Danger") | ||
.subtitle("Will Robinson") | ||
.message("Run away as fast as you can") | ||
.send() | ||
.unwrap(); | ||
fn main() { | ||
std::thread::spawn(||{ | ||
block_on(async { | ||
println!("Asking for authorization"); | ||
let authorized = request_authorization(AuthorizationOptions::Sound|AuthorizationOptions::Badge).await; | ||
println!("Finished authorization"); | ||
match authorized { | ||
Ok(()) => { | ||
println!("User authorized for one or many options"); | ||
let badge_updated = set_badge_count(30).await; | ||
match badge_updated { | ||
Ok(()) => { | ||
println!("Badge updated"); | ||
}, | ||
Err(e) => { | ||
println!("Error occured while updating the badge. {:?}", e); | ||
} | ||
} | ||
}, | ||
Err(e) => { | ||
println!("Error occured while authorization step. {:?}", e); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
Notification::default() | ||
.title("NOW") | ||
.message("Without subtitle") | ||
.sound("Submarine") | ||
.send() | ||
.unwrap(); | ||
loop { | ||
run_ns_run_loop_once(); | ||
std::thread::sleep(Duration::from_millis(100)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been playing around with cargo-bundle, do we want to use that here?