|
|
@ -38,7 +38,6 @@ export class FSPlugin extends ElectronBasePlugin { |
|
|
|
const foldersToDelete: string[] = [] |
|
|
|
const foldersToDelete: string[] = [] |
|
|
|
if (openedFolders && openedFolders.length) { |
|
|
|
if (openedFolders && openedFolders.length) { |
|
|
|
for (const folder of openedFolders) { |
|
|
|
for (const folder of openedFolders) { |
|
|
|
console.log('opening folder', folder) |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
const stat = await fs.stat(folder) |
|
|
|
const stat = await fs.stat(folder) |
|
|
|
if (stat.isDirectory()) { |
|
|
|
if (stat.isDirectory()) { |
|
|
@ -54,14 +53,12 @@ export class FSPlugin extends ElectronBasePlugin { |
|
|
|
this.call('electronconfig', 'writeConfig', { 'recentFolders': newFolders }) |
|
|
|
this.call('electronconfig', 'writeConfig', { 'recentFolders': newFolders }) |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
console.log('no opened folders') |
|
|
|
|
|
|
|
createWindow() |
|
|
|
createWindow() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async removeCloseListener(): Promise<void> { |
|
|
|
async removeCloseListener(): Promise<void> { |
|
|
|
for (const client of this.clients) { |
|
|
|
for (const client of this.clients) { |
|
|
|
console.log('removeCloseListener', client.webContentsId) |
|
|
|
|
|
|
|
client.window.removeAllListeners() |
|
|
|
client.window.removeAllListeners() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -96,13 +93,12 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
constructor(webContentsId: number, profile: Profile) { |
|
|
|
constructor(webContentsId: number, profile: Profile) { |
|
|
|
super(webContentsId, profile) |
|
|
|
super(webContentsId, profile) |
|
|
|
this.onload(() => { |
|
|
|
this.onload(() => { |
|
|
|
//console.log('fsPluginClient onload')
|
|
|
|
|
|
|
|
if(!isPackaged) { |
|
|
|
if(!isPackaged) { |
|
|
|
this.window.webContents.openDevTools() |
|
|
|
this.window.webContents.openDevTools() |
|
|
|
} |
|
|
|
} |
|
|
|
this.window.on('close', async () => { |
|
|
|
this.window.on('close', async () => { |
|
|
|
console.log('close', this.webContentsId) |
|
|
|
|
|
|
|
await this.removeFromOpenedFolders(this.workingDir) |
|
|
|
await this.removeFromOpenedFolders(this.workingDir) |
|
|
|
|
|
|
|
await this.closeWatch() |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
@ -111,7 +107,6 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
// best for non recursive
|
|
|
|
// best for non recursive
|
|
|
|
async readdir(path: string): Promise<string[]> { |
|
|
|
async readdir(path: string): Promise<string[]> { |
|
|
|
// call node fs.readdir
|
|
|
|
// call node fs.readdir
|
|
|
|
console.log('readdir', path) |
|
|
|
|
|
|
|
if (!path) return [] |
|
|
|
if (!path) return [] |
|
|
|
const startTime = Date.now() |
|
|
|
const startTime = Date.now() |
|
|
|
const files = await fs.readdir(this.fixPath(path), { |
|
|
|
const files = await fs.readdir(this.fixPath(path), { |
|
|
@ -126,14 +121,12 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
isDirectory |
|
|
|
isDirectory |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
console.log('readdir', result, Date.now() - startTime) |
|
|
|
|
|
|
|
return result |
|
|
|
return result |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async glob(path: string, pattern: string, options?: GlobOptions): Promise<string[] | Path[]> { |
|
|
|
async glob(path: string, pattern: string, options?: GlobOptions): Promise<string[] | Path[]> { |
|
|
|
|
|
|
|
|
|
|
|
path = this.fixPath(path) |
|
|
|
path = this.fixPath(path) |
|
|
|
console.log('glob', path, pattern, options) |
|
|
|
|
|
|
|
const files = await glob(path + pattern, { |
|
|
|
const files = await glob(path + pattern, { |
|
|
|
withFileTypes: true, |
|
|
|
withFileTypes: true, |
|
|
|
...options |
|
|
|
...options |
|
|
@ -153,24 +146,20 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
isDirectory: (file as Path).isDirectory(), |
|
|
|
isDirectory: (file as Path).isDirectory(), |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
//console.log('glob', result)
|
|
|
|
|
|
|
|
return result |
|
|
|
return result |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async readFile(path: string, options: any): Promise<string | undefined> { |
|
|
|
async readFile(path: string, options: any): Promise<string | undefined> { |
|
|
|
//console.log('readFile', path, options)
|
|
|
|
|
|
|
|
// hacky fix for TS error
|
|
|
|
// hacky fix for TS error
|
|
|
|
if (!path) return undefined |
|
|
|
if (!path) return undefined |
|
|
|
try { |
|
|
|
try { |
|
|
|
return (fs as any).readFile(this.fixPath(path), options) |
|
|
|
return (fs as any).readFile(this.fixPath(path), options) |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
//console.log('readFile error', e)
|
|
|
|
|
|
|
|
return undefined |
|
|
|
return undefined |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async writeFile(path: string, content: string, options: any): Promise<void> { |
|
|
|
async writeFile(path: string, content: string, options: any): Promise<void> { |
|
|
|
//console.log('writeFile', path, content, options)
|
|
|
|
|
|
|
|
this.trackDownStreamUpdate[path] = content |
|
|
|
this.trackDownStreamUpdate[path] = content |
|
|
|
return (fs as any).writeFile(this.fixPath(path), content, options) |
|
|
|
return (fs as any).writeFile(this.fixPath(path), content, options) |
|
|
|
} |
|
|
|
} |
|
|
@ -180,7 +169,6 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async rmdir(path: string): Promise<void> { |
|
|
|
async rmdir(path: string): Promise<void> { |
|
|
|
console.log('rmdir', this.fixPath(path)) |
|
|
|
|
|
|
|
return fs.rm(this.fixPath(path), { |
|
|
|
return fs.rm(this.fixPath(path), { |
|
|
|
recursive: true |
|
|
|
recursive: true |
|
|
|
}) |
|
|
|
}) |
|
|
@ -197,14 +185,12 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
async stat(path: string): Promise<any> { |
|
|
|
async stat(path: string): Promise<any> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const stat = await fs.stat(this.fixPath(path)) |
|
|
|
const stat = await fs.stat(this.fixPath(path)) |
|
|
|
////console.log('stat', path, stat)
|
|
|
|
|
|
|
|
const isDirectory = stat.isDirectory() |
|
|
|
const isDirectory = stat.isDirectory() |
|
|
|
return { |
|
|
|
return { |
|
|
|
...stat, |
|
|
|
...stat, |
|
|
|
isDirectoryValue: isDirectory |
|
|
|
isDirectoryValue: isDirectory |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
//console.log('stat error', e)
|
|
|
|
|
|
|
|
return undefined |
|
|
|
return undefined |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -218,7 +204,6 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
isDirectoryValue: isDirectory |
|
|
|
isDirectoryValue: isDirectory |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
//console.log('lstat error', e)
|
|
|
|
|
|
|
|
return undefined |
|
|
|
return undefined |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -235,7 +220,6 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
|
|
|
|
|
|
|
|
async watch(): Promise<void> { |
|
|
|
async watch(): Promise<void> { |
|
|
|
if (this.watcher) this.watcher.close() |
|
|
|
if (this.watcher) this.watcher.close() |
|
|
|
console.log('watch', this.workingDir) |
|
|
|
|
|
|
|
this.watcher = |
|
|
|
this.watcher = |
|
|
|
chokidar.watch(this.workingDir, { |
|
|
|
chokidar.watch(this.workingDir, { |
|
|
|
ignorePermissionErrors: true, ignoreInitial: true, |
|
|
|
ignorePermissionErrors: true, ignoreInitial: true, |
|
|
@ -245,7 +229,6 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
}).on('all', async (eventName, path, stats) => { |
|
|
|
}).on('all', async (eventName, path, stats) => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('change', eventName, path, stats) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let pathWithoutPrefix = path.replace(this.workingDir, '') |
|
|
|
let pathWithoutPrefix = path.replace(this.workingDir, '') |
|
|
|
pathWithoutPrefix = convertPathToPosix(pathWithoutPrefix) |
|
|
|
pathWithoutPrefix = convertPathToPosix(pathWithoutPrefix) |
|
|
@ -255,7 +238,6 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
// remove workingDir from path
|
|
|
|
// remove workingDir from path
|
|
|
|
const newContent = await fs.readFile(path, 'utf-8') |
|
|
|
const newContent = await fs.readFile(path, 'utf-8') |
|
|
|
|
|
|
|
|
|
|
|
console.log('change', pathWithoutPrefix, this.trackDownStreamUpdate) |
|
|
|
|
|
|
|
const currentContent = this.trackDownStreamUpdate[pathWithoutPrefix] |
|
|
|
const currentContent = this.trackDownStreamUpdate[pathWithoutPrefix] |
|
|
|
|
|
|
|
|
|
|
|
if (currentContent !== newContent) { |
|
|
|
if (currentContent !== newContent) { |
|
|
@ -278,7 +260,6 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async closeWatch(): Promise<void> { |
|
|
|
async closeWatch(): Promise<void> { |
|
|
|
console.log('closing Watcher', this.webContentsId) |
|
|
|
|
|
|
|
if (this.watcher) this.watcher.close() |
|
|
|
if (this.watcher) this.watcher.close() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -299,11 +280,9 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async removeFromOpenedFolders(path: string): Promise<void> { |
|
|
|
async removeFromOpenedFolders(path: string): Promise<void> { |
|
|
|
console.log('removeFromOpenedFolders', path) |
|
|
|
|
|
|
|
const config = await this.call('electronconfig' as any, 'readConfig') |
|
|
|
const config = await this.call('electronconfig' as any, 'readConfig') |
|
|
|
config.openedFolders = config.openedFolders || [] |
|
|
|
config.openedFolders = config.openedFolders || [] |
|
|
|
config.openedFolders = config.openedFolders.filter((p: string) => p !== path) |
|
|
|
config.openedFolders = config.openedFolders.filter((p: string) => p !== path) |
|
|
|
console.log('removeFromOpenedFolders', config) |
|
|
|
|
|
|
|
writeConfig(config) |
|
|
|
writeConfig(config) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -362,13 +341,11 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
await this.updateRecentFolders(path) |
|
|
|
await this.updateRecentFolders(path) |
|
|
|
await this.updateOpenedFolders(path) |
|
|
|
await this.updateOpenedFolders(path) |
|
|
|
this.window.setTitle(this.workingDir) |
|
|
|
this.window.setTitle(this.workingDir) |
|
|
|
console.log('setWorkingDir', path) |
|
|
|
|
|
|
|
this.watch() |
|
|
|
this.watch() |
|
|
|
this.emit('workingDirChanged', path) |
|
|
|
this.emit('workingDirChanged', path) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async setWorkingDir(path: string): Promise<void> { |
|
|
|
async setWorkingDir(path: string): Promise<void> { |
|
|
|
console.log('setWorkingDir', path) |
|
|
|
|
|
|
|
this.workingDir = path |
|
|
|
this.workingDir = path |
|
|
|
await this.updateRecentFolders(path) |
|
|
|
await this.updateRecentFolders(path) |
|
|
|
await this.updateOpenedFolders(path) |
|
|
|
await this.updateOpenedFolders(path) |
|
|
|