Merge pull request #917 from derezzedex/macos-url
Enable receiving URLs on MacOS
This commit is contained in:
commit
06d0158efb
@ -84,6 +84,7 @@ members = [
|
|||||||
"examples/todos",
|
"examples/todos",
|
||||||
"examples/tour",
|
"examples/tour",
|
||||||
"examples/tooltip",
|
"examples/tooltip",
|
||||||
|
"examples/url_handler",
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
10
examples/url_handler/Cargo.toml
Normal file
10
examples/url_handler/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "url_handler"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
iced = { path = "../.." }
|
||||||
|
iced_native = { path = "../../native" }
|
73
examples/url_handler/src/main.rs
Normal file
73
examples/url_handler/src/main.rs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
use iced::{
|
||||||
|
executor, Application, Clipboard, Command, Container, Element, Length,
|
||||||
|
Settings, Subscription, Text,
|
||||||
|
};
|
||||||
|
use iced_native::{
|
||||||
|
event::{MacOS, PlatformSpecific},
|
||||||
|
Event,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn main() -> iced::Result {
|
||||||
|
App::run(Settings::default())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
struct App {
|
||||||
|
url: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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<Message>) {
|
||||||
|
(App::default(), Command::none())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn title(&self) -> String {
|
||||||
|
String::from("Url - Iced")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(
|
||||||
|
&mut self,
|
||||||
|
message: Message,
|
||||||
|
_clipboard: &mut Clipboard,
|
||||||
|
) -> Command<Message> {
|
||||||
|
match message {
|
||||||
|
Message::EventOccurred(event) => {
|
||||||
|
if let Event::PlatformSpecific(PlatformSpecific::MacOS(
|
||||||
|
MacOS::ReceivedUrl(url),
|
||||||
|
)) = event
|
||||||
|
{
|
||||||
|
self.url = Some(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Command::none()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn subscription(&self) -> Subscription<Message> {
|
||||||
|
iced_native::subscription::events().map(Message::EventOccurred)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view(&mut self) -> Element<Message> {
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
@ -13,8 +13,10 @@ categories = ["gui"]
|
|||||||
[features]
|
[features]
|
||||||
debug = ["iced_winit/debug"]
|
debug = ["iced_winit/debug"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies.glutin]
|
||||||
glutin = "0.27"
|
version = "0.27"
|
||||||
|
git = "https://github.com/iced-rs/glutin"
|
||||||
|
rev = "be6793b5b3defc9452cd1c896cd315ed7442d546"
|
||||||
|
|
||||||
[dependencies.iced_native]
|
[dependencies.iced_native]
|
||||||
version = "0.4"
|
version = "0.4"
|
||||||
|
@ -237,6 +237,16 @@ async fn run_instance<A, E, C>(
|
|||||||
|
|
||||||
context.window().request_redraw();
|
context.window().request_redraw();
|
||||||
}
|
}
|
||||||
|
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) => {
|
event::Event::UserEvent(message) => {
|
||||||
messages.push(message);
|
messages.push(message);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,27 @@ pub enum Event {
|
|||||||
|
|
||||||
/// A touch event
|
/// A touch event
|
||||||
Touch(touch::Event),
|
Touch(touch::Event),
|
||||||
|
|
||||||
|
/// 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.
|
/// The status of an [`Event`] after being processed.
|
||||||
|
@ -14,11 +14,15 @@ categories = ["gui"]
|
|||||||
debug = ["iced_native/debug"]
|
debug = ["iced_native/debug"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
winit = "0.25"
|
|
||||||
window_clipboard = "0.2"
|
window_clipboard = "0.2"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
|
||||||
|
[dependencies.winit]
|
||||||
|
version = "0.25"
|
||||||
|
git = "https://github.com/iced-rs/winit"
|
||||||
|
rev = "9c358959ed99736566d50a511b03d2fed3aac2ae"
|
||||||
|
|
||||||
[dependencies.iced_native]
|
[dependencies.iced_native]
|
||||||
version = "0.4"
|
version = "0.4"
|
||||||
path = "../native"
|
path = "../native"
|
||||||
|
@ -310,6 +310,16 @@ async fn run_instance<A, E, C>(
|
|||||||
|
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
}
|
}
|
||||||
|
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) => {
|
event::Event::UserEvent(message) => {
|
||||||
messages.push(message);
|
messages.push(message);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user