mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-19 09:22:12 +00:00
open links in browser
This commit is contained in:
1 parent
8d6885d58b
commit
358253b7a9
9 files changed
+90
No files matched your search
@@ -12,3 +12,4 @@ pub mod queries;
|
||||
pub mod selection;
|
||||
pub mod statistics;
|
||||
pub mod storage;
|
||||
pub mod system;
|
||||
@@ -0,0 +1,18 @@
|
||||
//! What the app asks of the system, outside of the files.
|
||||
|
||||
use tauri::{AppHandle, Runtime};
|
||||
use tauri_plugin_opener::OpenerExt;
|
||||
|
||||
/// Opens a web page (or an email to write) with the app of the system for it: the links of the
|
||||
/// page are not followed in the window of the app. Only `http`, `https` and `mailto` addresses are
|
||||
/// opened.
|
||||
#[tauri::command(async)]
|
||||
pub fn open_url<R: Runtime>(app: AppHandle<R>, url: String) -> Result<(), String> {
|
||||
let allowed = ["http://", "https://", "mailto:"];
|
||||
if !allowed.iter().any(|scheme| url.starts_with(scheme)) {
|
||||
return Err(format!("{url} is not a web address"));
|
||||
}
|
||||
app.opener()
|
||||
.open_url(url, None::<&str>)
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
@@ -50,6 +50,7 @@ pub fn run() {
|
||||
));
|
||||
register_commands(builder)
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.setup(|app| {
|
||||
let handle = app.handle().clone();
|
||||
let emit: state::Emit = std::sync::Arc::new(move |event, payload| {
|
||||
@@ -193,6 +194,8 @@ fn register_commands<R: tauri::Runtime>(builder: tauri::Builder<R>) -> tauri::Bu
|
||||
disk::reload_files,
|
||||
disk::export_files,
|
||||
disk::list_folder,
|
||||
// the system
|
||||
system::open_url,
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user