From 41dfa15feb2a72f8142534fe8268c7d67f7c9b54 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Mon, 22 Jul 2024 17:55:28 -0700 Subject: [PATCH] Various tweaks --- plugin-runtime/src/index.worker.ts | 22 ++++++++++++++----- src-tauri/src/analytics.rs | 2 +- src-tauri/src/notifications.rs | 4 ++++ .../tauri-plugin-plugin-runtime/src/nodejs.rs | 4 ++-- src-web/components/ImportDataDialog.tsx | 4 +++- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/plugin-runtime/src/index.worker.ts b/plugin-runtime/src/index.worker.ts index 78c2c227..97d03dba 100644 --- a/plugin-runtime/src/index.worker.ts +++ b/plugin-runtime/src/index.worker.ts @@ -4,12 +4,20 @@ import { parentPort, workerData } from 'node:worker_threads'; import { ParentToWorkerEvent } from './PluginHandle'; import { PluginInfo } from './plugins'; -new Promise(async () => { +new Promise(async (resolve, reject) => { const { pluginDir } = workerData; const pathMod = path.join(pluginDir, 'build/index.js'); const pathPkg = path.join(pluginDir, 'package.json'); - const pkg = JSON.parse(readFileSync(pathPkg, 'utf8')); + let pkg: { [x: string]: any }; + try { + pkg = JSON.parse(readFileSync(pathPkg, 'utf8')); + } catch (err) { + // TODO: Do something better here + reject(err); + return; + } + const mod = (await import(`file://${pathMod}`)).default ?? {}; const info: PluginInfo = { @@ -43,15 +51,15 @@ new Promise(async () => { }); } - parentPort!.on('message', (msg: ParentToWorkerEvent) => { + parentPort!.on('message', async (msg: ParentToWorkerEvent) => { try { const ctx = { todo: 'implement me' }; if (msg.name === 'run-import') { - reply(msg, mod.pluginHookImport(ctx, msg.payload)); + reply(msg, await mod.pluginHookImport(ctx, msg.payload)); } else if (msg.name === 'run-filter') { - reply(msg, mod.pluginHookResponseFilter(ctx, msg.payload)); + reply(msg, await mod.pluginHookResponseFilter(ctx, msg.payload)); } else if (msg.name === 'run-export') { - reply(msg, mod.pluginHookExport(ctx, msg.payload)); + reply(msg, await mod.pluginHookExport(ctx, msg.payload)); } else if (msg.name === 'info') { reply(msg, info); } else { @@ -61,6 +69,8 @@ new Promise(async () => { replyErr(msg, err); } }); + + resolve(); }).catch((err) => { console.log('failed to boot plugin', err); }); diff --git a/src-tauri/src/analytics.rs b/src-tauri/src/analytics.rs index ff9e0bf3..3171a95e 100644 --- a/src-tauri/src/analytics.rs +++ b/src-tauri/src/analytics.rs @@ -189,7 +189,7 @@ pub async fn track_event( // Disable analytics actual sending in dev if is_dev() { - debug!("track: {}", event); + debug!("track: {} {}", event, attributes_json); return; } diff --git a/src-tauri/src/notifications.rs b/src-tauri/src/notifications.rs index 65f4b755..971010d8 100644 --- a/src-tauri/src/notifications.rs +++ b/src-tauri/src/notifications.rs @@ -70,6 +70,10 @@ impl YaakNotifier { ("launches", num_launches.to_string()), ]); let resp = req.send().await.map_err(|e| e.to_string())?; + if resp.status().to_string() != "200" { + return Ok(()); + } + let notification = resp .json::() .await diff --git a/src-tauri/tauri-plugin-plugin-runtime/src/nodejs.rs b/src-tauri/tauri-plugin-plugin-runtime/src/nodejs.rs index bfbc303d..e00768ba 100644 --- a/src-tauri/tauri-plugin-plugin-runtime/src/nodejs.rs +++ b/src-tauri/tauri-plugin-plugin-runtime/src/nodejs.rs @@ -55,9 +55,9 @@ pub async fn node_start(app: &AppHandle, temp_dir: &PathBuf) -> S // read events such as stdout while let Some(event) = rx.recv().await { if let CommandEvent::Stdout(line) = event { - println!("{}", String::from_utf8_lossy(line.as_slice())); + print!("{}", String::from_utf8_lossy(line.as_slice())); } else if let CommandEvent::Stderr(line) = event { - println!("{}", String::from_utf8_lossy(line.as_slice())); + print!("{}", String::from_utf8_lossy(line.as_slice())); } } }); diff --git a/src-web/components/ImportDataDialog.tsx b/src-web/components/ImportDataDialog.tsx index 90e47607..8d65d496 100644 --- a/src-web/components/ImportDataDialog.tsx +++ b/src-web/components/ImportDataDialog.tsx @@ -14,8 +14,10 @@ export function ImportDataDialog({ importData }: Props) {
    -
  • Postman Collection v2+
  • +
  • OpenAPI 3.0, 3.1
  • +
  • Postman Collection v2, v2.1
  • Insomnia v4+
  • +
  • Swagger 2.0
  • Curl commands