@lvce-editor/file-system-process 3.5.0 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +43 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -558,8 +558,42 @@ const getFolderSize = async uri => {
|
|
|
558
558
|
return total;
|
|
559
559
|
};
|
|
560
560
|
|
|
561
|
-
const
|
|
562
|
-
|
|
561
|
+
const fileWacherEvents = Object.create(null);
|
|
562
|
+
const setupWatcher = async (watcherId, uri, onChange) => {
|
|
563
|
+
try {
|
|
564
|
+
const path = fileURLToPath(uri);
|
|
565
|
+
// TODO
|
|
566
|
+
const watcher = fs.watch(path, {});
|
|
567
|
+
const watcherEvents = [];
|
|
568
|
+
fileWacherEvents[watcherId] = watcherEvents;
|
|
569
|
+
for await (const event of watcher) {
|
|
570
|
+
watcherEvents.push(event);
|
|
571
|
+
onChange();
|
|
572
|
+
}
|
|
573
|
+
} catch (error) {
|
|
574
|
+
if (error && error.code === 'ENOENT') {
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
console.error(error);
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
// TODO when socket closes, dispose file watcher for this socket
|
|
582
|
+
const watchFile = async (socket, watcherId, uri) => {
|
|
583
|
+
assertUri(uri);
|
|
584
|
+
fileWacherEvents[watcherId] = [];
|
|
585
|
+
// TODO await promise?
|
|
586
|
+
const onChange = () => {
|
|
587
|
+
// TODO handle error
|
|
588
|
+
socket.send({
|
|
589
|
+
jsonrpc: '2.0',
|
|
590
|
+
method: 'FileSystem.executeWatchCallback',
|
|
591
|
+
params: [watcherId]
|
|
592
|
+
});
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
596
|
+
setupWatcher(watcherId, uri, onChange);
|
|
563
597
|
};
|
|
564
598
|
const unwatchFile = uri => {
|
|
565
599
|
// TODO
|
|
@@ -1618,7 +1652,7 @@ const createRpc = ipc => {
|
|
|
1618
1652
|
};
|
|
1619
1653
|
return rpc;
|
|
1620
1654
|
};
|
|
1621
|
-
const requiresSocket = () => {
|
|
1655
|
+
const requiresSocket$1 = () => {
|
|
1622
1656
|
return false;
|
|
1623
1657
|
};
|
|
1624
1658
|
const preparePrettyError = error => {
|
|
@@ -1628,7 +1662,7 @@ const logError = () => {
|
|
|
1628
1662
|
// handled by renderer worker
|
|
1629
1663
|
};
|
|
1630
1664
|
const handleMessage = event => {
|
|
1631
|
-
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
1665
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket$1;
|
|
1632
1666
|
const actualExecute = event?.target?.execute || execute;
|
|
1633
1667
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
1634
1668
|
};
|
|
@@ -1790,13 +1824,17 @@ const handleElectronMessagePort = async (messagePort, rpcId) => {
|
|
|
1790
1824
|
}
|
|
1791
1825
|
};
|
|
1792
1826
|
|
|
1827
|
+
const requiresSocket = method => {
|
|
1828
|
+
return method === 'FileSystem.watchFile';
|
|
1829
|
+
};
|
|
1793
1830
|
const handleWebSocket = async (handle, request) => {
|
|
1794
1831
|
object(handle);
|
|
1795
1832
|
object(request);
|
|
1796
1833
|
await listen$1({
|
|
1797
1834
|
method: WebSocket,
|
|
1798
1835
|
request,
|
|
1799
|
-
handle
|
|
1836
|
+
handle,
|
|
1837
|
+
requiresSocket
|
|
1800
1838
|
});
|
|
1801
1839
|
};
|
|
1802
1840
|
|