Skip to content

Commit f302dc3

Browse files
committed
Move local plugin install command into plugins_ext
1 parent 2ca5112 commit f302dc3

5 files changed

Lines changed: 33 additions & 36 deletions

File tree

crates-tauri/yaak-app/src/lib.rs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ use yaak_grpc::{Code, ServiceDefinition, serialize_message};
3737
use yaak_mac_window::AppHandleMacWindowExt;
3838
use yaak_models::models::{
3939
AnyModel, CookieJar, Environment, GrpcConnection, GrpcConnectionState, GrpcEvent,
40-
GrpcEventType, HttpRequest, HttpResponse, HttpResponseEvent, HttpResponseState, Plugin,
41-
PluginSource, Workspace, WorkspaceMeta,
40+
GrpcEventType, HttpRequest, HttpResponse, HttpResponseEvent, HttpResponseState, Workspace,
41+
WorkspaceMeta,
4242
};
4343
use yaak_models::util::{BatchUpsertResult, UpdateSource, get_workspace_export_resources};
4444
use yaak_plugins::events::{
@@ -1345,35 +1345,6 @@ async fn cmd_send_http_request<R: Runtime>(
13451345
Ok(r)
13461346
}
13471347

1348-
#[tauri::command]
1349-
async fn cmd_install_plugin<R: Runtime>(
1350-
directory: &str,
1351-
url: Option<String>,
1352-
plugin_manager: State<'_, PluginManager>,
1353-
app_handle: AppHandle<R>,
1354-
window: WebviewWindow<R>,
1355-
) -> YaakResult<Plugin> {
1356-
let plugin = app_handle.db().upsert_plugin(
1357-
&Plugin {
1358-
directory: directory.into(),
1359-
url,
1360-
enabled: true,
1361-
source: PluginSource::Filesystem,
1362-
..Default::default()
1363-
},
1364-
&UpdateSource::from_window_label(window.label()),
1365-
)?;
1366-
1367-
plugin_manager
1368-
.add_plugin(
1369-
&PluginContext::new(Some(window.label().to_string()), window.workspace_id()),
1370-
&plugin,
1371-
)
1372-
.await?;
1373-
1374-
Ok(plugin)
1375-
}
1376-
13771348
#[tauri::command]
13781349
async fn cmd_reload_plugins<R: Runtime>(
13791350
app_handle: AppHandle<R>,
@@ -1658,7 +1629,6 @@ pub fn run() {
16581629
cmd_workspace_actions,
16591630
cmd_folder_actions,
16601631
cmd_import_data,
1661-
cmd_install_plugin,
16621632
cmd_metadata,
16631633
cmd_new_child_window,
16641634
cmd_new_main_window,
@@ -1727,6 +1697,7 @@ pub fn run() {
17271697
git_ext::cmd_git_rm_remote,
17281698
//
17291699
// Plugin commands
1700+
plugins_ext::cmd_plugins_install_from_directory,
17301701
plugins_ext::cmd_plugins_search,
17311702
plugins_ext::cmd_plugins_install,
17321703
plugins_ext::cmd_plugins_uninstall,

crates-tauri/yaak-app/src/plugins_ext.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use tauri::{
2222
use tokio::sync::Mutex;
2323
use ts_rs::TS;
2424
use yaak_api::yaak_api_client;
25-
use yaak_models::models::Plugin;
25+
use yaak_models::models::{Plugin, PluginSource};
26+
use yaak_models::util::UpdateSource;
2627
use yaak_plugins::api::{
2728
PluginNameVersion, PluginSearchResponse, PluginUpdatesResponse, check_plugin_updates,
2829
search_plugins,
@@ -164,6 +165,28 @@ pub async fn cmd_plugins_install<R: Runtime>(
164165
Ok(())
165166
}
166167

168+
#[command]
169+
pub async fn cmd_plugins_install_from_directory<R: Runtime>(
170+
window: WebviewWindow<R>,
171+
directory: &str,
172+
) -> Result<Plugin> {
173+
let plugin = window.db().upsert_plugin(
174+
&Plugin {
175+
directory: directory.into(),
176+
url: None,
177+
enabled: true,
178+
source: PluginSource::Filesystem,
179+
..Default::default()
180+
},
181+
&UpdateSource::from_window_label(window.label()),
182+
)?;
183+
184+
let plugin_manager = Arc::new((*window.state::<PluginManager>()).clone());
185+
plugin_manager.add_plugin(&window.plugin_context(), &plugin).await?;
186+
187+
Ok(plugin)
188+
}
189+
167190
#[command]
168191
pub async fn cmd_plugins_uninstall<R: Runtime>(
169192
plugin_id: &str,

crates/yaak-plugins/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ export async function checkPluginUpdates() {
2424
export async function updateAllPlugins() {
2525
return invoke<PluginNameVersion[]>('cmd_plugins_update_all', {});
2626
}
27+
28+
export async function installPluginFromDirectory(directory: string) {
29+
return invoke<void>('cmd_plugins_install_from_directory', { directory });
30+
}

src-web/hooks/useInstallPlugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { invokeCmd } from '../lib/tauri';
1+
import { installPluginFromDirectory } from '@yaakapp-internal/plugins';
22
import { useFastMutation } from './useFastMutation';
33

44
export function useInstallPlugin() {
55
return useFastMutation<void, unknown, string>({
66
mutationKey: ['install_plugin'],
77
mutationFn: async (directory: string) => {
8-
await invokeCmd('cmd_install_plugin', { directory });
8+
await installPluginFromDirectory(directory);
99
},
1010
});
1111
}

src-web/lib/tauri.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ type TauriCmd =
3636
| 'cmd_http_request_body'
3737
| 'cmd_http_response_body'
3838
| 'cmd_import_data'
39-
| 'cmd_install_plugin'
4039
| 'cmd_metadata'
4140
| 'cmd_restart'
4241
| 'cmd_new_child_window'

0 commit comments

Comments
 (0)