Merge pull request #227

* Search and install plugins PoC

* Checksum

* Tab sidebar for settings

* Fix nested tabs, and tweaks

* Table for plugin results

* Deep links working

* Focus window during deep links

* Merge branch 'master' into plugin-directory

* More stuff
This commit is contained in:
Gregory Schier
2025-06-22 07:06:43 -07:00
committed by GitHub
parent b8e6dbc7c7
commit b5620fcdf3
56 changed files with 1222 additions and 444 deletions

View File

@@ -1,25 +1,74 @@
use crate::error::Result;
use crate::import::import_data;
use log::{info, warn};
use tauri::{Manager, Runtime, UriSchemeContext};
use std::collections::HashMap;
use tauri::{AppHandle, Emitter, Manager, Runtime, Url};
use tauri_plugin_dialog::{DialogExt, MessageDialogButtons, MessageDialogKind};
use yaak_plugins::api::get_plugin;
use yaak_plugins::events::{Color, ShowToastRequest};
use yaak_plugins::install::download_and_install;
pub(crate) fn handle_uri_scheme<R: Runtime>(
a: UriSchemeContext<R>,
req: http::Request<Vec<u8>>,
) -> http::Response<Vec<u8>> {
println!("------------- Yaak URI scheme invoked!");
let uri = req.uri();
let window = a
.app_handle()
.get_webview_window(a.webview_label())
.expect("Failed to get webview window for URI scheme event");
info!("Yaak URI scheme invoked with {uri:?} {window:?}");
pub(crate) async fn handle_deep_link<R: Runtime>(
app_handle: &AppHandle<R>,
url: &Url,
) -> Result<()> {
let command = url.domain().unwrap_or_default();
info!("Yaak URI scheme invoked {}?{}", command, url.query().unwrap_or_default());
let path = uri.path();
if path == "/data/import" {
warn!("TODO: import data")
} else if path == "/plugins/install" {
warn!("TODO: install plugin")
let query_map: HashMap<String, String> = url.query_pairs().into_owned().collect();
let windows = app_handle.webview_windows();
let (_, window) = windows.iter().next().unwrap();
match command {
"install-plugin" => {
let name = query_map.get("name").unwrap();
let version = query_map.get("version").cloned();
let plugin_version = get_plugin(&app_handle, &name, version).await?;
_ = window.set_focus();
let confirmed_install = app_handle
.dialog()
.message(format!(
"Install plugin {}@{}?",
plugin_version.name, plugin_version.version
))
.kind(MessageDialogKind::Info)
.buttons(MessageDialogButtons::OkCustom("Install".to_string()))
.blocking_show();
if !confirmed_install {
// Cancelled installation
return Ok(());
}
download_and_install(window, &plugin_version).await?;
app_handle.emit(
"show_toast",
ShowToastRequest {
message: format!(
"Installed {}@{}",
plugin_version.name, plugin_version.version
),
color: Some(Color::Success),
icon: None,
},
)?;
}
"import-data" => {
let file_path = query_map.get("path").unwrap();
let results = import_data(window, file_path).await?;
_ = window.set_focus();
window.emit(
"show_toast",
ShowToastRequest {
message: format!("Imported data for {} workspaces", results.workspaces.len()),
color: Some(Color::Success),
icon: None,
},
)?;
}
_ => {
warn!("Unknown deep link command: {command}");
}
}
let msg = format!("No handler found for {path}");
tauri::http::Response::builder().status(404).body(msg.as_bytes().to_vec()).unwrap()
Ok(())
}