summary history branches tags files
commit:7cf97712961dc6f585d3f374e99dbafb67816b17
author:Trevor Bentley
committer:Trevor Bentley
date:Sun Jun 30 13:57:38 2019 +0200
parents:dcd85b08722d36db995adb8365a09078b1f6ae79
Bump fruitbasket dep and register connectr URI
diff --git a/Cargo.toml b/Cargo.toml
line changes: +1/-1
index e961cc7..7707b1f
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -53,7 +53,7 @@ ctrlc = "3.1"
 rustfm-scrobble = {version="0.9.1", optional = true}
 
 [dependencies.fruitbasket]
-version = "0.6"
+version = "^0.7"
 features = ["logging"]
 
 [target."cfg(windows)".dependencies]

diff --git a/src/lib.rs b/src/lib.rs
line changes: +2/-0
index 719c248..659c906
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -93,6 +93,7 @@ pub trait TStatusBar {
     fn sel_item(&mut self, sender: u64);
     fn unsel_item(&mut self, sender: u64);
     fn set_tooltip(&mut self, text: &str);
+    fn register_url_handler(&mut self);
     fn run(&mut self, block: bool);
 }
 
@@ -114,6 +115,7 @@ impl TStatusBar for DummyStatusBar {
     fn sel_item(&mut self, _: u64) {}
     fn unsel_item(&mut self, _: u64) {}
     fn set_tooltip(&mut self, _: &str) {}
+    fn register_url_handler(&mut self) {}
     fn run(&mut self, _: bool) {}
 }
 

diff --git a/src/main.rs b/src/main.rs
line changes: +8/-0
index 60b8168..c5e355a
--- a/src/main.rs
+++ b/src/main.rs
@@ -1118,6 +1118,13 @@ fn main() {
         .icon("connectr.icns")
         .version(env!("CARGO_PKG_VERSION"))
         .plist_key("LSBackgroundOnly", "1")
+        // Register "connectr://" URI scheme.
+        .plist_raw_string("
+  CFBundleURLTypes = ( {
+    CFBundleTypeRole = \"Viewer\";
+    CFBundleURLName = \"Connectr URL\";
+    CFBundleURLSchemes = (\"connectr\");
+  } );\n".into())
         .resource(icon.to_str().unwrap())
         .resource(touchbar_icon.to_str().unwrap())
         .resource(clientid_script.to_str().unwrap())
@@ -1159,6 +1166,7 @@ fn main() {
 
     let mut status = connectr::StatusBar::new(tx.clone());
     info!("Created status bar.");
+    status.register_url_handler();
     loading_menu(&mut status);
     let mut touchbar = TouchbarUI::init(tx);
     info!("Created touchbar.");

diff --git a/src/osx/mod.rs b/src/osx/mod.rs
line changes: +17/-0
index 9c7912e..3ea23e9
--- a/src/osx/mod.rs
+++ b/src/osx/mod.rs
@@ -216,6 +216,23 @@ impl TStatusBar for OSXStatusBar {
             let _: () = msg_send![target, setState: 0];
         }
     }
+    fn register_url_handler(&mut self) {
+        unsafe {
+            let cls = Class::get("NSAppleEventManager").unwrap();
+            let manager: *mut Object = msg_send![cls, sharedAppleEventManager];
+            let objc = self.object.take_objc();
+            let _ = msg_send![objc, handleURLEvent: 0 withReplyEvent: 0];
+            let _ = msg_send![manager, setEventHandler: objc
+                              andSelector: sel!(handleURLEvent:withReplyEvent:)
+                              forEventClass: 0x4755524c
+                              andEventID: 0x4755524c];
+            info!("Registered URL handler");
+            //let cb: NSCallback = Box::new(move |_sender, _tx| {
+            //    info!("URL callback");
+            //});
+            //self.object.add_callback(objc, cb);
+        }
+    }
     fn run(&mut self, block: bool) {
         let period = match block {
             true => fruitbasket::RunPeriod::Forever,

diff --git a/src/osx/rustnsobject.rs b/src/osx/rustnsobject.rs
line changes: +8/-2
index 666b573..05e5f0d
--- a/src/osx/rustnsobject.rs
+++ b/src/osx/rustnsobject.rs
@@ -115,7 +115,7 @@ impl INSObject for ObjcSubclass {
     fn class() -> &'static Class {
         OBJC_SUBCLASS_REGISTER_CLASS.call_once(|| {
             let superclass = NSObject::class();
-            let mut decl = ClassDecl::new("ObjcSubclass", superclass).unwrap();
+            let mut decl = ClassDecl::new("ConnectrObjcSubclass", superclass).expect("Failed to create custom ObjC class.");
             decl.add_ivar::<u64>("_rustdata");
 
             extern fn objc_cb(this: &mut Object, _cmd: Sel, sender: u64) {
@@ -136,6 +136,10 @@ impl INSObject for ObjcSubclass {
                 unsafe {*this.get_ivar("_rustdata")}
             }
 
+            extern fn objc_url(this: &Object, _cmd: Sel, event: u64, reply: u64) {
+                info!("connectr URL support not implemented yet.");
+            }
+
             unsafe {
                 let f: extern fn(&mut Object, Sel, u64) = objc_cb;
                 decl.add_method(sel!(cb:), f);
@@ -143,11 +147,13 @@ impl INSObject for ObjcSubclass {
                 decl.add_method(sel!(setRustData:), f);
                 let f: extern fn(&Object, Sel) -> u64 = objc_get_rust_data;
                 decl.add_method(sel!(rustData), f);
+                let f: extern fn(&Object, Sel, u64, u64) = objc_url;
+                decl.add_method(sel!(handleURLEvent:withReplyEvent:), f);
             }
 
             decl.register();
         });
 
-        Class::get("ObjcSubclass").unwrap()
+        Class::get("ConnectrObjcSubclass").unwrap()
     }
 }