Commit 91bd3824 authored by Roman Alifanov's avatar Roman Alifanov

add support of `command://` prefix

parent f93d499c
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
<property name="resource-uri">/ru/ximperlinux/Welcome/gnome/overview.svg</property> <property name="resource-uri">/ru/ximperlinux/Welcome/gnome/overview.svg</property>
<property name="head" translatable="yes">Get an Overview</property> <property name="head" translatable="yes">Get an Overview</property>
<property name="body" translatable="yes" comments="Translators: 'Windows' is referring to the operating system and should not be translated">The overview shows all your apps and windows. Press the Super (Windows) key to open it.</property> <property name="body" translatable="yes" comments="Translators: 'Windows' is referring to the operating system and should not be translated">The overview shows all your apps and windows. Press the Super (Windows) key to open it.</property>
<property name="button-label" translatable="yes">Test command button</property>
<property name="button-url">command://xdg-open https://wiki.ximperlinux.ru</property>
</object> </object>
</child> </child>
<child> <child>
......
use gtk::{gio, glib, prelude::*, subclass::prelude::*}; use gtk::{gio, glib, prelude::*, subclass::prelude::*};
use std::process::Command as Cmd;
mod imp { mod imp {
use std::cell::{OnceCell, RefCell}; use std::cell::{OnceCell, RefCell};
...@@ -65,8 +66,33 @@ mod imp { ...@@ -65,8 +66,33 @@ mod imp {
if let Some(url) = self.button_url.borrow().clone() { if let Some(url) = self.button_url.borrow().clone() {
let button = self.action_button.get(); let button = self.action_button.get();
button.connect_clicked(move |_| { button.connect_clicked(move |_| {
let _ = gio::AppInfo::launch_default_for_uri(&url, None::<&gio::AppLaunchContext>); if url.starts_with("command://") {
let command = url.trim_start_matches("command://");
let output = Cmd::new("sh")
.arg("-c")
.arg(command)
.output();
match output {
Ok(output) => {
if output.status.success() {
log::info!("Command executed successfully");
} else {
log::error!("Command failed: {:?}", output.status);
}
}
Err(e) => {
log::error!("Failed to execute command: {}", e);
}
}
}
else {
let _ = gio::AppInfo::launch_default_for_uri(&url, None::<&gio::AppLaunchContext>);
}
}); });
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment