summary history branches tags files
commit:f25e35c76ebc1c91dc91cb6d5f3a216abb651cc9
author:Jørgen P. Tjernø
committer:Jørgen P. Tjernø
date:Mon Mar 1 01:45:42 2021 -0800
parents:af5c575f2220c345389373ab6461a832e24ded64
Add file handling to register_url example

Make it so that you can drag & drop a file to the Dock icon of
register_url to have it log a line and terminate.
diff --git a/examples/register_url.rs b/examples/register_url.rs
line changes: +13/-1
index 7a135d8..9ca9aec
--- a/examples/register_url.rs
+++ b/examples/register_url.rs
@@ -102,7 +102,19 @@ CFBundleURLTypes = ( {
                               stopper.stop();
                           }));
 
-    // Run 'forever', until the URL callback fires
+    let stopper = app.stopper();
+    app.register_callback(
+        FruitCallbackKey::Method("application:openFile:"),
+        Box::new(move |file| {
+            // File is a raw NSString.
+            // Fruitbasket has a converter to Rust String:
+            let file: String = fruitbasket::nsstring_to_string(file);
+            info!("Received file: {}", file);
+            stopper.stop();
+        }),
+    );
+
+    // Run 'forever', until one of the URL or file callbacks fire
     info!("Spawned process running!");
     let _ = app.run(RunPeriod::Forever);
     info!("Run loop stopped after URL callback.");