Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(electron): Prevent promises both resolving and rejecting #1618

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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