From 9ae22b58d843d9a39212028478598c19a49bc2e6 Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 21 Apr 2021 17:52:31 -0300 Subject: [PATCH 1/3] Added events for url handling and create example --- Cargo.toml | 4 ++ examples/url_handler/Cargo.toml | 12 ++++++ examples/url_handler/src/main.rs | 67 ++++++++++++++++++++++++++++++++ glutin/src/application.rs | 3 ++ native/src/event.rs | 4 ++ winit/src/application.rs | 3 ++ 6 files changed, 93 insertions(+) create mode 100644 examples/url_handler/Cargo.toml create mode 100644 examples/url_handler/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 6d894eba..f00a197c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -84,6 +84,7 @@ members = [ "examples/todos", "examples/tour", "examples/tooltip", + "examples/url_handler", ] [dependencies] @@ -91,6 +92,9 @@ iced_core = { version = "0.4", path = "core" } iced_futures = { version = "0.3", path = "futures" } thiserror = "1.0" +[patch.crates-io] +winit = { git="https://github.com/cryptowatch/winit", rev="f9180f3b3c0f4fb8fd8c65bd0adf641cd6b32dd0" } + [target.'cfg(not(target_arch = "wasm32"))'.dependencies] iced_winit = { version = "0.3", path = "winit" } iced_glutin = { version = "0.2", path = "glutin", optional = true } diff --git a/examples/url_handler/Cargo.toml b/examples/url_handler/Cargo.toml new file mode 100644 index 00000000..595bdac0 --- /dev/null +++ b/examples/url_handler/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "url_handler" +version = "0.1.0" +authors = ["Héctor Ramón Jiménez "] +edition = "2018" +publish = false + +[dependencies] +iced = { path = "../.." } +iced_native = { path = "../../native" } +syslog="4.0" +log="0.4" \ No newline at end of file diff --git a/examples/url_handler/src/main.rs b/examples/url_handler/src/main.rs new file mode 100644 index 00000000..56d81031 --- /dev/null +++ b/examples/url_handler/src/main.rs @@ -0,0 +1,67 @@ +use iced::{ + executor, Application, Command, Clipboard, + Container, Element, Length, Settings, Subscription, Text, +}; +use iced_native::Event; + +pub fn main() -> iced::Result { + App::run(Settings::default()) +} + +#[derive(Debug, Default)] +struct App { + url: Option, +} + +#[derive(Debug, Clone)] +enum Message { + EventOccurred(iced_native::Event), +} + +impl Application for App { + type Executor = executor::Default; + type Message = Message; + type Flags = (); + + fn new(_flags: ()) -> (App, Command) { + (App::default(), Command::none()) + } + + fn title(&self) -> String { + String::from("Url - Iced") + } + + fn update( + &mut self, + message: Message, + _clipboard: &mut Clipboard, + ) -> Command { + match message { + Message::EventOccurred(event) => { + if let Event::UrlReceived(url) = event{ + self.url = Some(url); + } + } + }; + + Command::none() + } + + fn subscription(&self) -> Subscription { + iced_native::subscription::events().map(Message::EventOccurred) + } + + fn view(&mut self) -> Element { + let content = match &self.url{ + Some(url) => Text::new(format!("{}", url)), + None => Text::new("No URL received yet!") + }; + + Container::new(content.size(48)) + .width(Length::Fill) + .height(Length::Fill) + .center_x() + .center_y() + .into() + } +} diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 79fcf745..55293b3b 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -237,6 +237,9 @@ async fn run_instance( context.window().request_redraw(); } + event::Event::ReceivedUrl(url) => { + events.push(iced_native::Event::UrlReceived(url)); + } event::Event::UserEvent(message) => { messages.push(message); } diff --git a/native/src/event.rs b/native/src/event.rs index 205bb797..59c5c0cb 100644 --- a/native/src/event.rs +++ b/native/src/event.rs @@ -23,6 +23,10 @@ pub enum Event { /// A touch event Touch(touch::Event), + + // TODO: System(system::Event)? + /// A url was received. + UrlReceived(String), } /// The status of an [`Event`] after being processed. diff --git a/winit/src/application.rs b/winit/src/application.rs index b1d5f418..9f51ae68 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -310,6 +310,9 @@ async fn run_instance( window.request_redraw(); } + event::Event::ReceivedUrl(url) => { + events.push(iced_native::Event::UrlReceived(url)); + } event::Event::UserEvent(message) => { messages.push(message); } From 96a462d2f2cb608ad14c93cc55896108a2dccb2b Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 9 Jun 2021 15:00:01 -0300 Subject: [PATCH 2/3] Use new enum variant and new winit repo --- Cargo.toml | 2 +- examples/url_handler/Cargo.toml | 4 +--- examples/url_handler/src/main.rs | 18 ++++++++++++------ glutin/src/application.rs | 5 +++-- native/src/event.rs | 25 +++++++++++++++++++++---- winit/src/application.rs | 5 +++-- 6 files changed, 41 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f00a197c..789ece88 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -93,7 +93,7 @@ iced_futures = { version = "0.3", path = "futures" } thiserror = "1.0" [patch.crates-io] -winit = { git="https://github.com/cryptowatch/winit", rev="f9180f3b3c0f4fb8fd8c65bd0adf641cd6b32dd0" } +winit = { git="https://github.com/iced-rs/winit", rev="152eda9b2d995dd0f5b886a53bddac7c75738b47" } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] iced_winit = { version = "0.3", path = "winit" } diff --git a/examples/url_handler/Cargo.toml b/examples/url_handler/Cargo.toml index 595bdac0..911b2f25 100644 --- a/examples/url_handler/Cargo.toml +++ b/examples/url_handler/Cargo.toml @@ -7,6 +7,4 @@ publish = false [dependencies] iced = { path = "../.." } -iced_native = { path = "../../native" } -syslog="4.0" -log="0.4" \ No newline at end of file +iced_native = { path = "../../native" } \ No newline at end of file diff --git a/examples/url_handler/src/main.rs b/examples/url_handler/src/main.rs index 56d81031..f14e5227 100644 --- a/examples/url_handler/src/main.rs +++ b/examples/url_handler/src/main.rs @@ -1,8 +1,11 @@ use iced::{ - executor, Application, Command, Clipboard, - Container, Element, Length, Settings, Subscription, Text, + executor, Application, Clipboard, Command, Container, Element, Length, + Settings, Subscription, Text, +}; +use iced_native::{ + event::{MacOS, PlatformSpecific}, + Event, }; -use iced_native::Event; pub fn main() -> iced::Result { App::run(Settings::default()) @@ -38,7 +41,10 @@ impl Application for App { ) -> Command { match message { Message::EventOccurred(event) => { - if let Event::UrlReceived(url) = event{ + if let Event::PlatformSpecific(PlatformSpecific::MacOS( + MacOS::ReceivedUrl(url), + )) = event + { self.url = Some(url); } } @@ -52,9 +58,9 @@ impl Application for App { } fn view(&mut self) -> Element { - let content = match &self.url{ + let content = match &self.url { Some(url) => Text::new(format!("{}", url)), - None => Text::new("No URL received yet!") + None => Text::new("No URL received yet!"), }; Container::new(content.size(48)) diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 55293b3b..22dff149 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -237,8 +237,9 @@ async fn run_instance( context.window().request_redraw(); } - event::Event::ReceivedUrl(url) => { - events.push(iced_native::Event::UrlReceived(url)); + event::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url))) => { + use iced_native::event; + events.push(iced_native::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url)))); } event::Event::UserEvent(message) => { messages.push(message); diff --git a/native/src/event.rs b/native/src/event.rs index 59c5c0cb..1c26b5f2 100644 --- a/native/src/event.rs +++ b/native/src/event.rs @@ -23,10 +23,27 @@ pub enum Event { /// A touch event Touch(touch::Event), - - // TODO: System(system::Event)? - /// A url was received. - UrlReceived(String), + + /// A platform specific event + PlatformSpecific(PlatformSpecific), +} + +/// A platform specific event +#[derive(Debug, Clone, PartialEq)] +pub enum PlatformSpecific { + /// A MacOS specific event + MacOS(MacOS), +} + +/// Describes an event specific to MacOS +#[derive(Debug, Clone, PartialEq)] +pub enum MacOS { + /// Triggered when the app receives an URL from the system + /// + /// _**Note:** For this event to be triggered, the executable needs to be properly [bundled]!_ + /// + /// [bundled]: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW19 + ReceivedUrl(String), } /// The status of an [`Event`] after being processed. diff --git a/winit/src/application.rs b/winit/src/application.rs index 9f51ae68..ce57bd1d 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -310,8 +310,9 @@ async fn run_instance( window.request_redraw(); } - event::Event::ReceivedUrl(url) => { - events.push(iced_native::Event::UrlReceived(url)); + event::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url))) => { + use iced_native::event; + events.push(iced_native::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url)))); } event::Event::UserEvent(message) => { messages.push(message); From 612585109ffc9a14a507c3c8423c6aa790c35cbf Mon Sep 17 00:00:00 2001 From: Richard Date: Mon, 14 Jun 2021 17:21:55 -0300 Subject: [PATCH 3/3] Use `winit` and `glutin` forks in `iced-rs` org --- Cargo.toml | 3 --- glutin/Cargo.toml | 6 ++++-- glutin/src/application.rs | 10 ++++++++-- winit/Cargo.toml | 6 +++++- winit/src/application.rs | 10 ++++++++-- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 789ece88..329877c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -92,9 +92,6 @@ iced_core = { version = "0.4", path = "core" } iced_futures = { version = "0.3", path = "futures" } thiserror = "1.0" -[patch.crates-io] -winit = { git="https://github.com/iced-rs/winit", rev="152eda9b2d995dd0f5b886a53bddac7c75738b47" } - [target.'cfg(not(target_arch = "wasm32"))'.dependencies] iced_winit = { version = "0.3", path = "winit" } iced_glutin = { version = "0.2", path = "glutin", optional = true } diff --git a/glutin/Cargo.toml b/glutin/Cargo.toml index 92aa5018..913ff5b8 100644 --- a/glutin/Cargo.toml +++ b/glutin/Cargo.toml @@ -13,8 +13,10 @@ categories = ["gui"] [features] debug = ["iced_winit/debug"] -[dependencies] -glutin = "0.27" +[dependencies.glutin] +version = "0.27" +git = "https://github.com/iced-rs/glutin" +rev = "be6793b5b3defc9452cd1c896cd315ed7442d546" [dependencies.iced_native] version = "0.4" diff --git a/glutin/src/application.rs b/glutin/src/application.rs index 22dff149..a8e5dbf9 100644 --- a/glutin/src/application.rs +++ b/glutin/src/application.rs @@ -237,9 +237,15 @@ async fn run_instance( context.window().request_redraw(); } - event::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url))) => { + event::Event::PlatformSpecific(event::PlatformSpecific::MacOS( + event::MacOS::ReceivedUrl(url), + )) => { use iced_native::event; - events.push(iced_native::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url)))); + events.push(iced_native::Event::PlatformSpecific( + event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl( + url, + )), + )); } event::Event::UserEvent(message) => { messages.push(message); diff --git a/winit/Cargo.toml b/winit/Cargo.toml index 4bb46029..b926a9c5 100644 --- a/winit/Cargo.toml +++ b/winit/Cargo.toml @@ -14,11 +14,15 @@ categories = ["gui"] debug = ["iced_native/debug"] [dependencies] -winit = "0.25" window_clipboard = "0.2" log = "0.4" thiserror = "1.0" +[dependencies.winit] +version = "0.25" +git = "https://github.com/iced-rs/winit" +rev = "9c358959ed99736566d50a511b03d2fed3aac2ae" + [dependencies.iced_native] version = "0.4" path = "../native" diff --git a/winit/src/application.rs b/winit/src/application.rs index ce57bd1d..49f2f513 100644 --- a/winit/src/application.rs +++ b/winit/src/application.rs @@ -310,9 +310,15 @@ async fn run_instance( window.request_redraw(); } - event::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url))) => { + event::Event::PlatformSpecific(event::PlatformSpecific::MacOS( + event::MacOS::ReceivedUrl(url), + )) => { use iced_native::event; - events.push(iced_native::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url)))); + events.push(iced_native::Event::PlatformSpecific( + event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl( + url, + )), + )); } event::Event::UserEvent(message) => { messages.push(message);