|
|
@ -148,9 +148,13 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async rmdir(path: string): Promise<void> { |
|
|
|
async rmdir(path: string): Promise<void> { |
|
|
|
return fs.rm(this.fixPath(path), { |
|
|
|
if (this.watcher) await this.watcher.close() |
|
|
|
|
|
|
|
await fs.rm(this.fixPath(path), { |
|
|
|
recursive: true, |
|
|
|
recursive: true, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
this.emit('change', 'unlinkDir', path) |
|
|
|
|
|
|
|
await this.watch() |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async unlink(path: string): Promise<void> { |
|
|
|
async unlink(path: string): Promise<void> { |
|
|
@ -199,7 +203,9 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async watch(): Promise<void> { |
|
|
|
async watch(): Promise<void> { |
|
|
|
|
|
|
|
|
|
|
|
if (this.watcher) this.watcher.close() |
|
|
|
if (this.watcher) this.watcher.close() |
|
|
|
|
|
|
|
try{ |
|
|
|
this.watcher = chokidar |
|
|
|
this.watcher = chokidar |
|
|
|
.watch(this.workingDir, { |
|
|
|
.watch(this.workingDir, { |
|
|
|
ignorePermissionErrors: true, |
|
|
|
ignorePermissionErrors: true, |
|
|
@ -207,11 +213,14 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
ignored: [ |
|
|
|
ignored: [ |
|
|
|
'**/.git/index.lock', // this file is created and unlinked all the time when git is running on Windows
|
|
|
|
'**/.git/index.lock', // this file is created and unlinked all the time when git is running on Windows
|
|
|
|
], |
|
|
|
], |
|
|
|
|
|
|
|
depth: 20 |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
.on('all', async (eventName, path, stats) => { |
|
|
|
.on('all', async (eventName, path, stats) => { |
|
|
|
let pathWithoutPrefix = path.replace(this.workingDir, '') |
|
|
|
let pathWithoutPrefix = path.replace(this.workingDir, '') |
|
|
|
pathWithoutPrefix = convertPathToPosix(pathWithoutPrefix) |
|
|
|
pathWithoutPrefix = convertPathToPosix(pathWithoutPrefix) |
|
|
|
if (pathWithoutPrefix.startsWith('/')) pathWithoutPrefix = pathWithoutPrefix.slice(1) |
|
|
|
if (pathWithoutPrefix.startsWith('/')) pathWithoutPrefix = pathWithoutPrefix.slice(1) |
|
|
|
|
|
|
|
|
|
|
|
if (eventName === 'change') { |
|
|
|
if (eventName === 'change') { |
|
|
|
// remove workingDir from path
|
|
|
|
// remove workingDir from path
|
|
|
|
const newContent = await fs.readFile(path, 'utf-8') |
|
|
|
const newContent = await fs.readFile(path, 'utf-8') |
|
|
@ -233,6 +242,16 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
.on('error', error => { |
|
|
|
|
|
|
|
this.watcher.close() |
|
|
|
|
|
|
|
if(error.message.includes('ENOSPC')) { |
|
|
|
|
|
|
|
this.emit('error', 'ENOSPC') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
console.log(`Watcher error: ${error}`) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}catch(e){ |
|
|
|
|
|
|
|
console.log('error watching', e) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async closeWatch(): Promise<void> { |
|
|
|
async closeWatch(): Promise<void> { |
|
|
@ -274,7 +293,7 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
writeConfig(config) |
|
|
|
writeConfig(config) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async selectFolder(path?: string): Promise<string> { |
|
|
|
async selectFolder(path?: string, title?: string): Promise<string> { |
|
|
|
let dirs: string[] | undefined |
|
|
|
let dirs: string[] | undefined |
|
|
|
if (!path) { |
|
|
|
if (!path) { |
|
|
|
dirs = dialog.showOpenDialogSync(this.window, { |
|
|
|
dirs = dialog.showOpenDialogSync(this.window, { |
|
|
|