mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 17:18:32 +02:00
Don't notify twice
This commit is contained in:
@@ -14,7 +14,7 @@ import { HttpRequestActionPlugin } from '@yaakapp/api/lib/plugins/HttpRequestAct
|
|||||||
import { TemplateFunctionPlugin } from '@yaakapp/api/lib/plugins/TemplateFunctionPlugin';
|
import { TemplateFunctionPlugin } from '@yaakapp/api/lib/plugins/TemplateFunctionPlugin';
|
||||||
import interceptStdout from 'intercept-stdout';
|
import interceptStdout from 'intercept-stdout';
|
||||||
import * as console from 'node:console';
|
import * as console from 'node:console';
|
||||||
import { readFileSync, watch } from 'node:fs';
|
import { Stats, readFileSync, statSync, watch } from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import * as util from 'node:util';
|
import * as util from 'node:util';
|
||||||
import { parentPort, workerData } from 'node:worker_threads';
|
import { parentPort, workerData } from 'node:worker_threads';
|
||||||
@@ -100,8 +100,9 @@ async function initialize() {
|
|||||||
await reloadModule();
|
await reloadModule();
|
||||||
return sendPayload({ type: 'reload_response' }, null);
|
return sendPayload({ type: 'reload_response' }, null);
|
||||||
};
|
};
|
||||||
watch(path.join(pathMod), cb);
|
|
||||||
watch(path.join(pathPkg), cb);
|
watchFile(pathMod, cb);
|
||||||
|
watchFile(pathPkg, cb);
|
||||||
|
|
||||||
const ctx: Context = {
|
const ctx: Context = {
|
||||||
clipboard: {
|
clipboard: {
|
||||||
@@ -298,3 +299,23 @@ function prefixStdout(s: string) {
|
|||||||
return newText.trimEnd();
|
return newText.trimEnd();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const watchedFiles: Record<string, Stats> = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch a file and trigger callback on change.
|
||||||
|
*
|
||||||
|
* We also track the stat for each file because fs.watch will
|
||||||
|
* trigger a "change" event when the access date changes
|
||||||
|
*/
|
||||||
|
function watchFile(filepath: string, cb: (filepath: string) => void) {
|
||||||
|
watch(filepath, (_event, _name) => {
|
||||||
|
const stat = statSync(filepath);
|
||||||
|
if (stat.mtimeMs !== watchedFiles[filepath]?.mtimeMs) {
|
||||||
|
cb(filepath);
|
||||||
|
} else {
|
||||||
|
console.log('SKIPPING SAME FILE STAT', filepath, stat);
|
||||||
|
}
|
||||||
|
watchedFiles[filepath] = stat;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -2104,9 +2104,10 @@ async fn handle_plugin_event<R: Runtime>(
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
let plugin_name = plugin_handle.info().await.unwrap().name;
|
||||||
let toast_event = plugin_handle.build_event_to_send(
|
let toast_event = plugin_handle.build_event_to_send(
|
||||||
&InternalEventPayload::ShowToastRequest(ShowToastRequest {
|
&InternalEventPayload::ShowToastRequest(ShowToastRequest {
|
||||||
message: "Plugin Reloaded".to_string(),
|
message: format!("Reloaded plugin {}", plugin_name),
|
||||||
variant: ToastVariant::Info,
|
variant: ToastVariant::Info,
|
||||||
}),
|
}),
|
||||||
None,
|
None,
|
||||||
|
|||||||
Reference in New Issue
Block a user