mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-10-26 19:24:31 +03:00
Removed all "experimental" watchers
This commit is contained in:
parent
f96f151bdb
commit
1af8d7637a
@ -24,7 +24,6 @@
|
||||
"dependencies": {
|
||||
"@atom/fuzzy-native": "^1.2.1",
|
||||
"@atom/source-map-support": "^0.3.4",
|
||||
"@atom/watcher": "^1.3.5",
|
||||
"@babel/core": "7.18.6",
|
||||
"about": "file:packages/about",
|
||||
"archive-view": "https://codeload.github.com/atom/archive-view/legacy.tar.gz/refs/tags/v0.66.0",
|
||||
|
@ -3,7 +3,6 @@ const path = require('path');
|
||||
|
||||
const { Emitter, Disposable, CompositeDisposable } = require('event-kit');
|
||||
const nsfw = require('nsfw');
|
||||
const watcher = require('@atom/watcher');
|
||||
const { NativeWatcherRegistry } = require('./native-watcher-registry');
|
||||
|
||||
// Private: Associate native watcher action flags with descriptive String equivalents.
|
||||
@ -165,122 +164,6 @@ class NativeWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
// Private: Emulate a "filesystem watcher" by subscribing to Pulsar events like buffers being saved. This will miss
|
||||
// any changes made to files outside of Pulsar, but it also has no overhead.
|
||||
class AtomNativeWatcher extends NativeWatcher {
|
||||
async doStart() {
|
||||
const getRealPath = givenPath => {
|
||||
if (!givenPath) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
return new Promise(resolve => {
|
||||
fs.realpath(givenPath, (err, resolvedPath) => {
|
||||
err ? resolve(null) : resolve(resolvedPath);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
this.subs.add(
|
||||
atom.workspace.observeTextEditors(async editor => {
|
||||
let realPath = await getRealPath(editor.getPath());
|
||||
if (!realPath || !realPath.startsWith(this.normalizedPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const announce = (action, oldPath) => {
|
||||
const payload = { action, path: realPath };
|
||||
if (oldPath) payload.oldPath = oldPath;
|
||||
this.onEvents([payload]);
|
||||
};
|
||||
|
||||
const buffer = editor.getBuffer();
|
||||
|
||||
this.subs.add(buffer.onDidConflict(() => announce('modified')));
|
||||
this.subs.add(buffer.onDidReload(() => announce('modified')));
|
||||
this.subs.add(
|
||||
buffer.onDidSave(event => {
|
||||
if (event.path === realPath) {
|
||||
announce('modified');
|
||||
} else {
|
||||
const oldPath = realPath;
|
||||
realPath = event.path;
|
||||
announce('renamed', oldPath);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
this.subs.add(buffer.onDidDelete(() => announce('deleted')));
|
||||
|
||||
this.subs.add(
|
||||
buffer.onDidChangePath(newPath => {
|
||||
if (newPath !== this.normalizedPath) {
|
||||
const oldPath = this.normalizedPath;
|
||||
this.normalizedPath = newPath;
|
||||
announce('renamed', oldPath);
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
// Giant-ass brittle hack to hook files (and eventually directories) created from the TreeView.
|
||||
const treeViewPackage = await atom.packages.getLoadedPackage('tree-view');
|
||||
if (!treeViewPackage) return;
|
||||
await treeViewPackage.activationPromise;
|
||||
const treeViewModule = treeViewPackage.mainModule;
|
||||
if (!treeViewModule) return;
|
||||
const treeView = treeViewModule.getTreeViewInstance();
|
||||
|
||||
const isOpenInEditor = async eventPath => {
|
||||
const openPaths = await Promise.all(
|
||||
atom.workspace
|
||||
.getTextEditors()
|
||||
.map(editor => getRealPath(editor.getPath()))
|
||||
);
|
||||
return openPaths.includes(eventPath);
|
||||
};
|
||||
|
||||
this.subs.add(
|
||||
treeView.onFileCreated(async event => {
|
||||
const realPath = await getRealPath(event.path);
|
||||
if (!realPath) return;
|
||||
|
||||
this.onEvents([{ action: 'added', path: realPath }]);
|
||||
})
|
||||
);
|
||||
|
||||
this.subs.add(
|
||||
treeView.onEntryDeleted(async event => {
|
||||
const realPath = await getRealPath(event.path);
|
||||
if (!realPath || (await isOpenInEditor(realPath))) return;
|
||||
|
||||
this.onEvents([{ action: 'deleted', path: realPath }]);
|
||||
})
|
||||
);
|
||||
|
||||
this.subs.add(
|
||||
treeView.onEntryMoved(async event => {
|
||||
const [realNewPath, realOldPath] = await Promise.all([
|
||||
getRealPath(event.newPath),
|
||||
getRealPath(event.initialPath)
|
||||
]);
|
||||
if (
|
||||
!realNewPath ||
|
||||
!realOldPath ||
|
||||
(await isOpenInEditor(realNewPath)) ||
|
||||
(await isOpenInEditor(realOldPath))
|
||||
)
|
||||
return;
|
||||
|
||||
this.onEvents([
|
||||
{ action: 'renamed', path: realNewPath, oldPath: realOldPath }
|
||||
]);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Private: Implement a native watcher by translating events from an NSFW watcher.
|
||||
class NSFWNativeWatcher extends NativeWatcher {
|
||||
async doStart(rootPath, eventCallback, errorCallback) {
|
||||
@ -633,7 +516,7 @@ class PathWatcherManager {
|
||||
|
||||
await Promise.all(
|
||||
Array.from(current.live, async ([root, native]) => {
|
||||
const w = await replacement.createWatcher(root, {}, () => {});
|
||||
const w = await replacement.createWatcher(root, () => {});
|
||||
native.reattachTo(w.native, root, w.native.options || {});
|
||||
})
|
||||
);
|
||||
@ -649,88 +532,39 @@ class PathWatcherManager {
|
||||
this.setting = setting;
|
||||
this.live = new Map();
|
||||
|
||||
const initLocal = NativeConstructor => {
|
||||
this.nativeRegistry = new NativeWatcherRegistry(normalizedPath => {
|
||||
const nativeWatcher = new NativeConstructor(normalizedPath);
|
||||
this.nativeRegistry = new NativeWatcherRegistry(normalizedPath => {
|
||||
const nativeWatcher = new NSFWNativeWatcher(normalizedPath);
|
||||
|
||||
this.live.set(normalizedPath, nativeWatcher);
|
||||
const sub = nativeWatcher.onWillStop(() => {
|
||||
this.live.delete(normalizedPath);
|
||||
sub.dispose();
|
||||
});
|
||||
|
||||
return nativeWatcher;
|
||||
this.live.set(normalizedPath, nativeWatcher);
|
||||
const sub = nativeWatcher.onWillStop(() => {
|
||||
this.live.delete(normalizedPath);
|
||||
sub.dispose();
|
||||
});
|
||||
};
|
||||
|
||||
if (setting === 'atom') {
|
||||
initLocal(AtomNativeWatcher);
|
||||
} else if (setting === 'experimental') {
|
||||
//
|
||||
} else if (setting === 'poll') {
|
||||
//
|
||||
} else {
|
||||
initLocal(NSFWNativeWatcher);
|
||||
}
|
||||
return nativeWatcher;
|
||||
});
|
||||
|
||||
this.isShuttingDown = false;
|
||||
}
|
||||
|
||||
useExperimentalWatcher() {
|
||||
return this.setting === 'experimental' || this.setting === 'poll';
|
||||
}
|
||||
|
||||
// Private: Create a {PathWatcher} tied to this global state. See {watchPath} for detailed arguments.
|
||||
async createWatcher(rootPath, options, eventCallback) {
|
||||
async createWatcher(rootPath, eventCallback) {
|
||||
if (this.isShuttingDown) {
|
||||
await this.constructor.transitionPromise;
|
||||
return PathWatcherManager.active().createWatcher(
|
||||
rootPath,
|
||||
options,
|
||||
eventCallback
|
||||
);
|
||||
}
|
||||
|
||||
if (this.useExperimentalWatcher()) {
|
||||
if (this.setting === 'poll') {
|
||||
options.poll = true;
|
||||
}
|
||||
|
||||
const w = await watcher.watchPath(rootPath, options, eventCallback);
|
||||
this.live.set(rootPath, w.native);
|
||||
return w;
|
||||
}
|
||||
|
||||
const w = new PathWatcher(this.nativeRegistry, rootPath, options);
|
||||
const w = new PathWatcher(this.nativeRegistry, rootPath);
|
||||
w.onDidChange(eventCallback);
|
||||
await w.getStartPromise();
|
||||
return w;
|
||||
}
|
||||
|
||||
// Private: Directly access the {NativeWatcherRegistry}.
|
||||
getRegistry() {
|
||||
if (this.useExperimentalWatcher()) {
|
||||
return watcher.getRegistry();
|
||||
}
|
||||
|
||||
return this.nativeRegistry;
|
||||
}
|
||||
|
||||
// Private: Sample watcher usage statistics. Only available for experimental watchers.
|
||||
status() {
|
||||
if (this.useExperimentalWatcher()) {
|
||||
return watcher.status();
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// Private: Return a {String} depicting the currently active native watchers.
|
||||
print() {
|
||||
if (this.useExperimentalWatcher()) {
|
||||
return watcher.printWatchers();
|
||||
}
|
||||
|
||||
return this.nativeRegistry.print();
|
||||
}
|
||||
|
||||
@ -738,10 +572,6 @@ class PathWatcherManager {
|
||||
//
|
||||
// Returns a {Promise} that resolves when all native watcher resources are disposed.
|
||||
stopAllWatchers() {
|
||||
if (this.useExperimentalWatcher()) {
|
||||
return watcher.stopAllWatchers();
|
||||
}
|
||||
|
||||
return Promise.all(Array.from(this.live, ([, w]) => w.stop()));
|
||||
}
|
||||
}
|
||||
@ -788,7 +618,6 @@ class PathWatcherManager {
|
||||
function watchPath(rootPath, options, eventCallback) {
|
||||
return PathWatcherManager.active().createWatcher(
|
||||
rootPath,
|
||||
options,
|
||||
eventCallback
|
||||
);
|
||||
}
|
||||
@ -804,19 +633,5 @@ watchPath.printWatchers = function() {
|
||||
return PathWatcherManager.active().print();
|
||||
};
|
||||
|
||||
// Private: Access the active {NativeWatcherRegistry}.
|
||||
watchPath.getRegistry = function() {
|
||||
return PathWatcherManager.active().getRegistry();
|
||||
};
|
||||
|
||||
// Private: Sample usage statistics for the active watcher.
|
||||
watchPath.status = function() {
|
||||
return PathWatcherManager.active().status();
|
||||
};
|
||||
|
||||
// Private: Configure @atom/watcher ("experimental") directly.
|
||||
watchPath.configure = function(...args) {
|
||||
return watcher.configure(...args);
|
||||
};
|
||||
|
||||
module.exports = { watchPath, stopAllWatchers };
|
||||
|
Loading…
Reference in New Issue
Block a user