Make capture example its own crate

Nathan Sobo created

Change summary

Cargo.lock                    | 15 +++++++++++++++
crates/capture/Cargo.toml     | 21 +++++++++++++++++++++
crates/capture/build.rs       |  3 +++
crates/capture/script/capture |  5 +++++
crates/capture/src/main.rs    | 10 ++++++----
crates/gpui/Cargo.toml        |  5 -----
crates/gpui/build.rs          |  3 ---
crates/gpui/script/capture    |  4 ----
8 files changed, 50 insertions(+), 16 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -750,6 +750,21 @@ dependencies = [
  "winx",
 ]
 
+[[package]]
+name = "capture"
+version = "0.1.0"
+dependencies = [
+ "block",
+ "cocoa",
+ "core-foundation",
+ "core-graphics",
+ "foreign-types",
+ "gpui",
+ "log",
+ "objc",
+ "simplelog",
+]
+
 [[package]]
 name = "castaway"
 version = "0.1.2"

crates/capture/Cargo.toml 🔗

@@ -0,0 +1,21 @@
+[package]
+name = "capture"
+version = "0.1.0"
+edition = "2021"
+description = "An example of screen capture"
+
+[package.metadata.bundle]
+name = "Capture"
+identifier = "dev.zed.Capture"
+
+[dependencies]
+gpui = { path = "../gpui" }
+
+block = "0.1"
+cocoa = "0.24"
+core-foundation = "0.9.3"
+core-graphics = "0.22.3"
+foreign-types = "0.3"
+log = { version = "0.4.16", features = ["kv_unstable_serde"] }
+objc = "0.2"
+simplelog = "0.9"

crates/capture/script/capture 🔗

@@ -0,0 +1,5 @@
+#!/bin/bash
+
+cargo bundle
+TTY=`tty`
+open ../../target/debug/bundle/osx/Capture.app --stdout $TTY --stderr $TTY

crates/gpui/examples/capture.rs → crates/capture/src/main.rs 🔗

@@ -33,10 +33,12 @@ fn main() {
 
         unsafe {
             let block = ConcreteBlock::new(move |content: id, error: id| {
-                println!("got response with shareable content");
-                dbg!(content);
-                dbg!(error);
-                dbg!(string_from_objc(msg_send![error, localizedDescription]));
+                println!(
+                    "got response with shareable content {:?} {:?} {:?}",
+                    content,
+                    error,
+                    string_from_objc(msg_send![error, localizedDescription]),
+                )
             });
 
             let _: id = msg_send![

crates/gpui/Cargo.toml 🔗

@@ -12,11 +12,6 @@ doctest = false
 [features]
 test-support = ["backtrace", "dhat", "env_logger", "collections/test-support"]
 
-[package.metadata.bundle.example.capture]
-name = "Capture"
-identifier = "rs.gpui.examples.Capture"
-description = "An example of screen capture"
-
 [dependencies]
 collections = { path = "../collections" }
 gpui_macros = { path = "../gpui_macros" }

crates/gpui/build.rs 🔗

@@ -9,9 +9,6 @@ fn main() {
     compile_context_predicate_parser();
     compile_metal_shaders();
     generate_shader_bindings();
-
-    // Support screen capture
-    println!("cargo:rustc-link-lib=framework=ScreenCaptureKit");
 }
 
 fn generate_dispatch_bindings() {

crates/gpui/script/capture 🔗

@@ -1,4 +0,0 @@
-#!/bin/bash
-
-cargo bundle --example capture
-open ../../target/debug/examples/bundle/osx/Capture.app