|
|
|
@ -32,6 +32,15 @@ const getBaseName = (pathName: string): string => { |
|
|
|
|
return path.basename(pathName) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function onlyUnique(value: recentFolder, index: number, self: recentFolder[]) { |
|
|
|
|
console.log(index, value) |
|
|
|
|
return self.findIndex((rc, index) => rc.path === value.path) === index |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const deplucateFolderList = (list: recentFolder[]): recentFolder[] => { |
|
|
|
|
return list.filter(onlyUnique) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export class FSPlugin extends ElectronBasePlugin { |
|
|
|
|
clients: FSPluginClient[] = [] |
|
|
|
|
constructor() { |
|
|
|
@ -40,28 +49,28 @@ export class FSPlugin extends ElectronBasePlugin { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async onActivation(): Promise<void> { |
|
|
|
|
const config = await this.call('electronconfig' as any, 'readConfig') |
|
|
|
|
const config = await this.call('electronconfig', 'readConfig') |
|
|
|
|
const openedFolders = (config && config.openedFolders) || [] |
|
|
|
|
const recentFolders = (config && config.recentFolders) || [] |
|
|
|
|
const recentFolders: recentFolder[] = (config && config.recentFolders) || [] |
|
|
|
|
this.call('electronconfig', 'writeConfig', {...config,
|
|
|
|
|
recentFolders: recentFolders, |
|
|
|
|
recentFolders: deplucateFolderList(recentFolders), |
|
|
|
|
openedFolders: openedFolders}) |
|
|
|
|
const foldersToDelete: string[] = [] |
|
|
|
|
if (openedFolders && openedFolders.length) { |
|
|
|
|
for (const folder of openedFolders) { |
|
|
|
|
if (recentFolders && recentFolders.length) { |
|
|
|
|
for (const folder of recentFolders) { |
|
|
|
|
try { |
|
|
|
|
const stat = await fs.stat(folder) |
|
|
|
|
const stat = await fs.stat(folder.path); |
|
|
|
|
if (stat.isDirectory()) { |
|
|
|
|
// do nothing
|
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log('error opening folder', folder, e) |
|
|
|
|
foldersToDelete.push(folder) |
|
|
|
|
foldersToDelete.push(folder.path) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (foldersToDelete.length) { |
|
|
|
|
const newFolders = openedFolders.filter((f: string) => !foldersToDelete.includes(f)) |
|
|
|
|
this.call('electronconfig', 'writeConfig', {recentFolders: newFolders}) |
|
|
|
|
const newFolders = recentFolders.filter((f: recentFolder) => !foldersToDelete.includes(f.path)) |
|
|
|
|
this.call('electronconfig', 'writeConfig', {recentFolders: deplucateFolderList(newFolders)}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
createWindow() |
|
|
|
@ -346,6 +355,7 @@ class FSPluginClient extends ElectronBasePluginClient { |
|
|
|
|
path, |
|
|
|
|
timestamp, |
|
|
|
|
}) |
|
|
|
|
config.recentFolders = deplucateFolderList(config.recentFolders) |
|
|
|
|
writeConfig(config) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|