forked from laurent22/joplin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Web: Live-reload dev plugins on change
- Loading branch information
1 parent
d9df2dc
commit a96d654
Showing
15 changed files
with
154 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/app-mobile/components/plugins/utils/useOnDevPluginsUpdated.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import useAsyncEffect from '@joplin/lib/hooks/useAsyncEffect'; | ||
import shim from '@joplin/lib/shim'; | ||
import time from '@joplin/lib/time'; | ||
import { join } from 'path'; | ||
import { useRef } from 'react'; | ||
|
||
type OnDevPluginChange = ()=> void; | ||
|
||
const useOnDevPluginsUpdated = (onDevPluginChange: OnDevPluginChange, devPluginPath: string, pluginSupportEnabled: boolean) => { | ||
const onDevPluginChangeRef = useRef(onDevPluginChange); | ||
onDevPluginChangeRef.current = onDevPluginChange; | ||
const isFirstUpdateRef = useRef(true); | ||
|
||
useAsyncEffect(async (event) => { | ||
if (!devPluginPath || !pluginSupportEnabled) return; | ||
|
||
const itemToLastModTime = new Map<string, number>(); | ||
|
||
while (!event.cancelled) { | ||
const publishFolder = join(devPluginPath, 'publish'); | ||
const dirStats = await shim.fsDriver().readDirStats(publishFolder); | ||
let hasChange = false; | ||
for (const item of dirStats) { | ||
if (item.path.endsWith('.jpl')) { | ||
const lastModTime = itemToLastModTime.get(item.path); | ||
const modTime = item.mtime.getTime(); | ||
if (lastModTime === undefined || lastModTime < modTime) { | ||
itemToLastModTime.set(item.path, modTime); | ||
hasChange = true; | ||
} | ||
} | ||
} | ||
|
||
if (hasChange) { | ||
if (isFirstUpdateRef.current) { | ||
// Avoid sending an event the first time the hook is called. The first iteration | ||
// collects initial timestamp information. In that case, hasChange | ||
// will always be true, even with no plugin reload. | ||
isFirstUpdateRef.current = false; | ||
} else { | ||
onDevPluginChangeRef.current(); | ||
} | ||
} | ||
|
||
await time.sleep(5); | ||
} | ||
}, [devPluginPath, pluginSupportEnabled]); | ||
}; | ||
|
||
export default useOnDevPluginsUpdated; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters