Skip to content

Commit

Permalink
fix(electron): Prevent promises both resolving and rejecting (#1618)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Lloyd authored and jcesarmobile committed Jun 3, 2019
1 parent b1501e9 commit 43ea1dd
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions electron/src/electron/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ export class FilesystemPluginElectron extends WebPlugin implements FilesystemPlu
reject(`${options.directory} is currently not supported in the Electron implementation.`);
let lookupPath = this.fileLocations[options.directory] + options.path;
this.NodeFS.readFile(lookupPath, options.encoding, (err:any, data:any) => {
if(err)
if(err) {
reject(err);
return;
}

resolve({data});
});
});
Expand All @@ -54,8 +57,11 @@ export class FilesystemPluginElectron extends WebPlugin implements FilesystemPlu
reject(`${options.directory} is currently not supported in the Electron implementation.`);
let lookupPath = this.fileLocations[options.directory] + options.path;
this.NodeFS.writeFile(lookupPath, options.data, options.encoding, (err:any) => {
if (err)
if(err) {
reject(err);
return;
}

resolve();
})
});
Expand All @@ -67,8 +73,11 @@ export class FilesystemPluginElectron extends WebPlugin implements FilesystemPlu
reject(`${options.directory} is currently not supported in the Electron implementation.`);
let lookupPath = this.fileLocations[options.directory] + options.path;
this.NodeFS.appendFile(lookupPath, options.encoding, options.data, (err:any) => {
if(err)
if(err) {
reject(err);
return;
}

resolve();
});
});
Expand All @@ -80,8 +89,11 @@ export class FilesystemPluginElectron extends WebPlugin implements FilesystemPlu
reject(`${options.directory} directory is currently not supported in the Electron implementation.`);
let lookupPath = this.fileLocations[options.directory] + options.path;
this.NodeFS.unlink(lookupPath, (err:any) => {
if(err)
if(err) {
reject(err);
return;
}

resolve();
});
});
Expand All @@ -93,8 +105,11 @@ export class FilesystemPluginElectron extends WebPlugin implements FilesystemPlu
reject(`${options.directory} is currently not supported in the Electron implementation.`);
let lookupPath = this.fileLocations[options.directory] + options.path;
this.NodeFS.mkdir(lookupPath, (err:any) => {
if(err)
if(err) {
reject(err);
return;
}

resolve();
});
});
Expand All @@ -104,8 +119,11 @@ export class FilesystemPluginElectron extends WebPlugin implements FilesystemPlu
rmdir(options: RmdirOptions): Promise<RmdirResult> {
return new Promise((resolve, reject) => {
this.NodeFS.rmdir(options.path, (err:any) => {
if(err)
if(err) {
reject(err);
return;
}

resolve();
});
});
Expand All @@ -115,8 +133,11 @@ export class FilesystemPluginElectron extends WebPlugin implements FilesystemPlu
return new Promise((resolve, reject) => {
let opts = {path: options.path, encoding: 'utf-8'};
this.NodeFS.readdir(opts.path, opts.encoding, (err:any, files: string[]) => {
if (err)
if (err) {
reject(err);
return;
}

resolve({files});
})
});
Expand All @@ -137,8 +158,11 @@ export class FilesystemPluginElectron extends WebPlugin implements FilesystemPlu
reject(`${options.directory} is currently not supported in the Electron implementation.`);
let lookupPath = this.fileLocations[options.directory] + options.path;
this.NodeFS.stat(options.path, (err:any, stats:any) => {
if(err)
if(err) {
reject(err);
return;
}

resolve({type: 'Not Available', size: stats.size, ctime: stats.ctimeMs, mtime: stats.mtimeMs, uri: lookupPath});
});
});
Expand Down

0 comments on commit 43ea1dd

Please sign in to comment.