mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Reload just the changed plugin
This commit is contained in:
parent
f69d495e75
commit
a3b555e1a1
@ -42,9 +42,9 @@ const usePlugins = (
|
||||
const reloadAllRef = useRef(false);
|
||||
reloadAllRef.current ||= pluginRunner !== lastPluginRunner;
|
||||
|
||||
useOnDevPluginsUpdated(() => {
|
||||
logger.info('Dev plugin updated. Reloading...');
|
||||
reloadAllRef.current = true;
|
||||
useOnDevPluginsUpdated(async (pluginId: string) => {
|
||||
logger.info(`Dev plugin ${pluginId} updated. Reloading...`);
|
||||
await PluginService.instance().unloadPlugin(pluginId);
|
||||
setReloadCounter(counter => counter + 1);
|
||||
}, devPluginPath, pluginSupportEnabled);
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
import useAsyncEffect from '@joplin/lib/hooks/useAsyncEffect';
|
||||
import shim from '@joplin/lib/shim';
|
||||
import time from '@joplin/lib/time';
|
||||
import { join } from 'path';
|
||||
import { basename, join } from 'path';
|
||||
import { useRef } from 'react';
|
||||
|
||||
type OnDevPluginChange = ()=> void;
|
||||
type OnDevPluginChange = (id: string)=> void;
|
||||
|
||||
const useOnDevPluginsUpdated = (onDevPluginChange: OnDevPluginChange, devPluginPath: string, pluginSupportEnabled: boolean) => {
|
||||
const onDevPluginChangeRef = useRef(onDevPluginChange);
|
||||
@ -16,10 +16,12 @@ const useOnDevPluginsUpdated = (onDevPluginChange: OnDevPluginChange, devPluginP
|
||||
|
||||
const itemToLastModTime = new Map<string, number>();
|
||||
|
||||
while (!event.cancelled) {
|
||||
const publishFolder = join(devPluginPath, 'publish');
|
||||
const dirStats = await shim.fsDriver().readDirStats(publishFolder);
|
||||
// publishPath should point to the publish/ subfolder of a plugin's development
|
||||
// directory.
|
||||
const checkPluginChange = async (pluginPublishPath: string) => {
|
||||
const dirStats = await shim.fsDriver().readDirStats(pluginPublishPath);
|
||||
let hasChange = false;
|
||||
let changedPluginId = '';
|
||||
for (const item of dirStats) {
|
||||
if (item.path.endsWith('.jpl')) {
|
||||
const lastModTime = itemToLastModTime.get(item.path);
|
||||
@ -27,6 +29,8 @@ const useOnDevPluginsUpdated = (onDevPluginChange: OnDevPluginChange, devPluginP
|
||||
if (lastModTime === undefined || lastModTime < modTime) {
|
||||
itemToLastModTime.set(item.path, modTime);
|
||||
hasChange = true;
|
||||
changedPluginId = basename(item.path, '.jpl');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -38,11 +42,17 @@ const useOnDevPluginsUpdated = (onDevPluginChange: OnDevPluginChange, devPluginP
|
||||
// will always be true, even with no plugin reload.
|
||||
isFirstUpdateRef.current = false;
|
||||
} else {
|
||||
onDevPluginChangeRef.current();
|
||||
onDevPluginChangeRef.current(changedPluginId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await time.sleep(5);
|
||||
while (!event.cancelled) {
|
||||
const publishFolder = join(devPluginPath, 'publish');
|
||||
await checkPluginChange(publishFolder);
|
||||
|
||||
const pollingIntervalSeconds = 5;
|
||||
await time.sleep(pollingIntervalSeconds);
|
||||
}
|
||||
}, [devPluginPath, pluginSupportEnabled]);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user