1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-11 18:24:43 +02:00

Revert "Desktop: Stop watching external edits when closing editor (#1981)"

Due to this issue:

https://discourse.joplinapp.org/t/joplin-version-1-0-173/4232/7

This reverts commit 0eb51e6bb0.
This commit is contained in:
Laurent Cozic 2019-11-12 17:51:57 +00:00
parent 45cca9e002
commit 15f09ef169

View File

@ -195,8 +195,24 @@ class ExternalEditWatcher {
};
}
async spawn(path, args, options) {
async spawnCommand(path, args, options) {
return new Promise((resolve, reject) => {
// App bundles need to be opened using the `open` command.
// Additional args can be specified after --args, and the
// -n flag is needed to ensure that the app is always launched
// with the arguments. Without it, if the app is already opened,
// it will just bring it to the foreground without opening the file.
// So the full command is:
//
// open -n /path/to/editor.app --args -app-flag -bla /path/to/file.md
//
if (shim.isMac() && fileExtension(path) === 'app') {
args = args.slice();
args.splice(0, 0, '--args');
args.splice(0, 0, path);
args.splice(0, 0, '-n');
path = 'open';
}
const wrapError = error => {
if (!error) return error;
@ -221,61 +237,12 @@ class ExternalEditWatcher {
clearInterval(iid);
reject(wrapError(error));
});
if (options.onClose) {
subProcess.on('close', options.onClose);
}
} catch (error) {
throw wrapError(error);
}
});
}
async spawnDefault(file, onClose) {
// windows
let path = '';
if (shim.isWindows()) {
path = 'start';
} else if (shim.isMac()) {
path = 'open';
} else if (shim.isLinux() || shim.isFreeBSD()) {
path = 'xdg-open';
} else {
// Fallback on the electron open method
return new Promise((resolve, reject) => {
if (bridge().openExternal(`file://${file}`)) {
resolve();
} else {
reject(new Error(`Could not open file: ${file}`));
}
});
}
return this.spawn(path, [file], { onClose: onClose });
}
async spawnCommand(path, args, options) {
// App bundles need to be opened using the `open` command.
// Additional args can be specified after --args, and the
// -n flag is needed to ensure that the app is always launched
// with the arguments. Without it, if the app is already opened,
// it will just bring it to the foreground without opening the file.
// So the full command is:
//
// open -n /path/to/editor.app --args -app-flag -bla /path/to/file.md
//
if (shim.isMac() && fileExtension(path) === 'app') {
args = args.slice();
args.splice(0, 0, '--args');
args.splice(0, 0, path);
args.splice(0, 0, '-n');
path = 'open';
}
return this.spawn(path, args, options);
}
async openAndWatch(note) {
if (!note || !note.id) {
this.logger().warn('ExternalEditWatcher: Cannot open note: ', note);
@ -285,16 +252,12 @@ class ExternalEditWatcher {
const filePath = await this.writeNoteToFile_(note);
this.watch(filePath);
const onClose = () => {
this.stopWatching(note.id);
};
const cmd = this.textEditorCommand();
if (!cmd) {
await this.spawnDefault(filePath, onClose);
bridge().openExternal(`file://${filePath}`);
} else {
cmd.args.push(filePath);
await this.spawnCommand(cmd.path, cmd.args, { detached: true, onClose: onClose });
await this.spawnCommand(cmd.path, cmd.args, { detached: true });
}
this.dispatch({