Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/cpp/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,8 @@ pub unsafe extern "C" fn slint_set_xdg_app_id(_app_id: &SharedString) {
pub unsafe extern "C" fn slint_detect_operating_system() -> OperatingSystemType {
i_slint_core::detect_operating_system()
}

#[unsafe(no_mangle)]
pub extern "C" fn open_url(url: &SharedString) {
i_slint_core::open_url(url)
}
4 changes: 4 additions & 0 deletions internal/compiler/expression_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub enum BuiltinFunction {
StartTimer,
StopTimer,
RestartTimer,
OpenUrl,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -276,6 +277,7 @@ declare_builtin_function_types!(
StartTimer: (Type::ElementReference) -> Type::Void,
StopTimer: (Type::ElementReference) -> Type::Void,
RestartTimer: (Type::ElementReference) -> Type::Void,
OpenUrl: (Type::String) -> Type::Void
);

impl BuiltinFunction {
Expand Down Expand Up @@ -369,6 +371,7 @@ impl BuiltinFunction {
BuiltinFunction::StartTimer => false,
BuiltinFunction::StopTimer => false,
BuiltinFunction::RestartTimer => false,
BuiltinFunction::OpenUrl => false,
}
}

Expand Down Expand Up @@ -446,6 +449,7 @@ impl BuiltinFunction {
BuiltinFunction::StartTimer => false,
BuiltinFunction::StopTimer => false,
BuiltinFunction::RestartTimer => false,
BuiltinFunction::OpenUrl => false,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions internal/compiler/generator/cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4201,6 +4201,10 @@ fn compile_builtin_function_call(
panic!("internal error: invalid args to RetartTimer {arguments:?}")
}
}
BuiltinFunction::OpenUrl => {
let url = a.next().unwrap();
format!("slint::cbindgen_private::open_url({})", url)
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions internal/compiler/generator/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3454,6 +3454,10 @@ fn compile_builtin_function_call(
panic!("internal error: invalid args to RestartTimer {arguments:?}")
}
}
BuiltinFunction::OpenUrl => {
let url = a.next().unwrap();
quote!(sp::open_url(&#url))
}
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/compiler/llr/optim_passes/inline_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ fn builtin_function_cost(function: &BuiltinFunction) -> isize {
BuiltinFunction::StartTimer => 10,
BuiltinFunction::StopTimer => 10,
BuiltinFunction::RestartTimer => 10,
BuiltinFunction::OpenUrl => isize::MAX,
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/compiler/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ impl LookupObject for SlintInternal {
.or_else(|| f("date-now", b(BuiltinFunction::DateNow)))
.or_else(|| f("valid-date", b(BuiltinFunction::ValidDate)))
.or_else(|| f("parse-date", b(BuiltinFunction::ParseDate)))
.or_else(|| f("open-url", b(BuiltinFunction::OpenUrl)))
}
}

Expand Down
3 changes: 3 additions & 0 deletions internal/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ std = [
"chrono/wasmbind",
"chrono/clock",
"dep:sys-locale",
"dep:webbrowser",
]
# Unsafe feature meaning that there is only one core running and all thread_local are static.
# You can only enable this feature if you are sure that any API of this crate is only called
Expand Down Expand Up @@ -129,6 +130,8 @@ wgpu-27 = { workspace = true, optional = true }

tr = { workspace = true, optional = true }

webbrowser = { version = "1.0.6", optional = true }

[target.'cfg(target_family = "unix")'.dependencies]
gettext-rs = { version = "0.7.1", optional = true, features = ["gettext-system"] }

Expand Down
8 changes: 8 additions & 0 deletions internal/core/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,11 @@ pub fn detect_operating_system() -> OperatingSystemType {
pub fn is_apple_platform() -> bool {
matches!(detect_operating_system(), OperatingSystemType::Macos | OperatingSystemType::Ios)
}

#[cfg_attr(not(feature = "std"), allow(unused))]
pub fn open_url(url: &str) {
#[cfg(feature = "std")]
if let Err(err) = webbrowser::open(url) {
debug_log!("Error opening url {}: {}", url, err);
}
}
6 changes: 6 additions & 0 deletions internal/interpreter/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,12 @@ fn call_builtin_function(
panic!("internal error: argument to RestartTimer must be an element")
}
}
BuiltinFunction::OpenUrl => {
let url: SharedString =
eval_expression(&arguments[0], local_context).try_into().unwrap();
corelib::open_url(&url);
Value::Void
}
}
}

Expand Down
Loading