mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-25 19:01:38 +01:00
Tweak workspace settings and a bunch of small things
This commit is contained in:
@@ -35,13 +35,7 @@ use yaak_models::models::{
|
||||
};
|
||||
use yaak_models::query_manager::QueryManagerExt;
|
||||
use yaak_models::util::{BatchUpsertResult, UpdateSource, get_workspace_export_resources};
|
||||
use yaak_plugins::events::{
|
||||
CallGrpcRequestActionArgs, CallGrpcRequestActionRequest, CallHttpRequestActionArgs,
|
||||
CallHttpRequestActionRequest, FilterResponse, GetGrpcRequestActionsResponse,
|
||||
GetHttpAuthenticationConfigResponse, GetHttpAuthenticationSummaryResponse,
|
||||
GetHttpRequestActionsResponse, GetTemplateFunctionsResponse, InternalEvent,
|
||||
InternalEventPayload, JsonPrimitive, PluginWindowContext, RenderPurpose,
|
||||
};
|
||||
use yaak_plugins::events::{CallGrpcRequestActionArgs, CallGrpcRequestActionRequest, CallHttpRequestActionArgs, CallHttpRequestActionRequest, Color, FilterResponse, GetGrpcRequestActionsResponse, GetHttpAuthenticationConfigResponse, GetHttpAuthenticationSummaryResponse, GetHttpRequestActionsResponse, GetTemplateFunctionsResponse, InternalEvent, InternalEventPayload, JsonPrimitive, PluginWindowContext, RenderPurpose, ShowToastRequest};
|
||||
use yaak_plugins::manager::PluginManager;
|
||||
use yaak_plugins::plugin_meta::PluginMetadata;
|
||||
use yaak_plugins::template_callback::PluginTemplateCallback;
|
||||
@@ -1053,21 +1047,6 @@ async fn cmd_install_plugin<R: Runtime>(
|
||||
)?)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn cmd_uninstall_plugin<R: Runtime>(
|
||||
plugin_id: &str,
|
||||
plugin_manager: State<'_, PluginManager>,
|
||||
window: WebviewWindow<R>,
|
||||
app_handle: AppHandle<R>,
|
||||
) -> YaakResult<Plugin> {
|
||||
let plugin =
|
||||
app_handle.db().delete_plugin_by_id(plugin_id, &UpdateSource::from_window(&window))?;
|
||||
|
||||
plugin_manager.uninstall(&PluginWindowContext::new(&window), plugin.directory.as_str()).await?;
|
||||
|
||||
Ok(plugin)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn cmd_create_grpc_request<R: Runtime>(
|
||||
workspace_id: &str,
|
||||
@@ -1256,6 +1235,14 @@ pub fn run() {
|
||||
for url in event.urls() {
|
||||
if let Err(e) = handle_deep_link(&app_handle, &url).await {
|
||||
warn!("Failed to handle deep link {}: {e:?}", url.to_string());
|
||||
let _ = app_handle.emit(
|
||||
"show_toast",
|
||||
ShowToastRequest {
|
||||
message: format!("Error handling deep link: {}", e.to_string()),
|
||||
color: Some(Color::Danger),
|
||||
icon: None,
|
||||
},
|
||||
);
|
||||
};
|
||||
}
|
||||
});
|
||||
@@ -1316,7 +1303,6 @@ pub fn run() {
|
||||
cmd_send_http_request,
|
||||
cmd_template_functions,
|
||||
cmd_template_tokens_to_string,
|
||||
cmd_uninstall_plugin,
|
||||
//
|
||||
//
|
||||
// Migrated commands
|
||||
|
||||
@@ -2,8 +2,11 @@ use crate::error::Result;
|
||||
use crate::import::import_data;
|
||||
use log::{info, warn};
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use tauri::{AppHandle, Emitter, Manager, Runtime, Url};
|
||||
use tauri_plugin_dialog::{DialogExt, MessageDialogButtons, MessageDialogKind};
|
||||
use yaak_common::api_client::yaak_api_client;
|
||||
use yaak_models::util::generate_id;
|
||||
use yaak_plugins::events::{Color, ShowToastRequest};
|
||||
use yaak_plugins::install::download_and_install;
|
||||
|
||||
@@ -25,9 +28,12 @@ pub(crate) async fn handle_deep_link<R: Runtime>(
|
||||
_ = window.set_focus();
|
||||
let confirmed_install = app_handle
|
||||
.dialog()
|
||||
.message(format!("Install plugin {name} {version:?}?",))
|
||||
.message(format!("Install plugin {name} {version:?}?"))
|
||||
.kind(MessageDialogKind::Info)
|
||||
.buttons(MessageDialogButtons::OkCustom("Install".to_string()))
|
||||
.buttons(MessageDialogButtons::OkCancelCustom(
|
||||
"Install".to_string(),
|
||||
"Cancel".to_string(),
|
||||
))
|
||||
.blocking_show();
|
||||
if !confirmed_install {
|
||||
// Cancelled installation
|
||||
@@ -45,8 +51,51 @@ pub(crate) async fn handle_deep_link<R: Runtime>(
|
||||
)?;
|
||||
}
|
||||
"import-data" => {
|
||||
let file_path = query_map.get("path").unwrap();
|
||||
let results = import_data(window, file_path).await?;
|
||||
let mut file_path = query_map.get("path").map(|s| s.to_owned());
|
||||
let name = query_map.get("name").map(|s| s.to_owned()).unwrap_or("data".to_string());
|
||||
|
||||
if let Some(file_url) = query_map.get("url") {
|
||||
let confirmed_import = app_handle
|
||||
.dialog()
|
||||
.message(format!("Import {name} from {file_url}?"))
|
||||
.kind(MessageDialogKind::Info)
|
||||
.buttons(MessageDialogButtons::OkCancelCustom(
|
||||
"Import".to_string(),
|
||||
"Cancel".to_string(),
|
||||
))
|
||||
.blocking_show();
|
||||
if !confirmed_import {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let resp = yaak_api_client(app_handle)?.get(file_url).send().await?;
|
||||
let json = resp.bytes().await?;
|
||||
let p = app_handle
|
||||
.path()
|
||||
.temp_dir()?
|
||||
.join(format!("import-{}", generate_id()))
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
fs::write(&p, json)?;
|
||||
file_path = Some(p);
|
||||
}
|
||||
|
||||
let file_path = match file_path {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
app_handle.emit(
|
||||
"show_toast",
|
||||
ShowToastRequest {
|
||||
message: "Failed to import data".to_string(),
|
||||
color: Some(Color::Danger),
|
||||
icon: None,
|
||||
},
|
||||
)?;
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
let results = import_data(window, &file_path).await?;
|
||||
_ = window.set_focus();
|
||||
window.emit(
|
||||
"show_toast",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const COMMANDS: &[&str] = &["search", "install", "updates"];
|
||||
const COMMANDS: &[&str] = &["search", "install", "updates", "uninstall"];
|
||||
|
||||
fn main() {
|
||||
tauri_plugin::Builder::new(COMMANDS).build();
|
||||
|
||||
@@ -13,6 +13,10 @@ export async function installPlugin(name: string, version: string | null) {
|
||||
return invoke<string>('plugin:yaak-plugins|install', { name, version });
|
||||
}
|
||||
|
||||
export async function uninstallPlugin(pluginId: string) {
|
||||
return invoke<string>('plugin:yaak-plugins|uninstall', { pluginId });
|
||||
}
|
||||
|
||||
export async function checkPluginUpdates() {
|
||||
return invoke<PluginUpdatesResponse>('plugin:yaak-plugins|updates', {});
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
[default]
|
||||
description = "Default permissions for the plugin"
|
||||
permissions = ["allow-search", "allow-install", "allow-updates"]
|
||||
permissions = ["allow-search", "allow-install", "allow-uninstall", "allow-updates"]
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use crate::api::{
|
||||
PluginSearchResponse, PluginUpdatesResponse, check_plugin_updates, search_plugins,
|
||||
check_plugin_updates, search_plugins, PluginSearchResponse, PluginUpdatesResponse,
|
||||
};
|
||||
use crate::error::Result;
|
||||
use crate::install::download_and_install;
|
||||
use tauri::{AppHandle, Runtime, WebviewWindow, command};
|
||||
use crate::install::{delete_and_uninstall, download_and_install};
|
||||
use tauri::{command, AppHandle, Runtime, WebviewWindow};
|
||||
use yaak_models::models::Plugin;
|
||||
|
||||
#[command]
|
||||
pub(crate) async fn search<R: Runtime>(
|
||||
@@ -23,6 +24,14 @@ pub(crate) async fn install<R: Runtime>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
pub(crate) async fn uninstall<R: Runtime>(
|
||||
plugin_id: &str,
|
||||
window: WebviewWindow<R>,
|
||||
) -> Result<Plugin> {
|
||||
delete_and_uninstall(&window, plugin_id).await
|
||||
}
|
||||
|
||||
#[command]
|
||||
pub(crate) async fn updates<R: Runtime>(app_handle: AppHandle<R>) -> Result<PluginUpdatesResponse> {
|
||||
check_plugin_updates(&app_handle).await
|
||||
|
||||
@@ -13,6 +13,13 @@ use yaak_models::models::Plugin;
|
||||
use yaak_models::query_manager::QueryManagerExt;
|
||||
use yaak_models::util::UpdateSource;
|
||||
|
||||
pub async fn delete_and_uninstall<R: Runtime>(window: &WebviewWindow<R>, plugin_id: &str) -> Result<Plugin> {
|
||||
let plugin_manager = window.state::<PluginManager>();
|
||||
let plugin = window.db().delete_plugin_by_id(plugin_id, &UpdateSource::from_window(&window))?;
|
||||
plugin_manager.uninstall(&PluginWindowContext::new(&window), plugin.directory.as_str()).await?;
|
||||
Ok(plugin)
|
||||
}
|
||||
|
||||
pub async fn download_and_install<R: Runtime>(
|
||||
window: &WebviewWindow<R>,
|
||||
name: &str,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::commands::{install, search, updates};
|
||||
use crate::commands::{install, search, uninstall, updates};
|
||||
use crate::manager::PluginManager;
|
||||
use log::info;
|
||||
use std::process::exit;
|
||||
use tauri::plugin::{Builder, TauriPlugin};
|
||||
use tauri::{Manager, RunEvent, Runtime, State, generate_handler};
|
||||
use tauri::{generate_handler, Manager, RunEvent, Runtime, State};
|
||||
|
||||
mod commands;
|
||||
pub mod error;
|
||||
@@ -22,7 +22,7 @@ pub mod plugin_meta;
|
||||
|
||||
pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
||||
Builder::new("yaak-plugins")
|
||||
.invoke_handler(generate_handler![search, install, updates])
|
||||
.invoke_handler(generate_handler![search, install, uninstall, updates])
|
||||
.setup(|app_handle, _| {
|
||||
let manager = PluginManager::new(app_handle.clone());
|
||||
app_handle.manage(manager.clone());
|
||||
|
||||
Reference in New Issue
Block a user