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

[Electron] Don't stat for electron save dialog #7197

Merged
merged 1 commit into from
Feb 26, 2020
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
Don't stat for electron save dialog
Signed-off-by: Rob Moran <rob.moran@arm.com>
thegecko committed Feb 24, 2020
commit f60c7da9d5615ebca48e0d556dd1047e65c21495
Original file line number Diff line number Diff line change
@@ -43,17 +43,16 @@ export class ElectronFileDialogService extends DefaultFileDialogService {
const rootNode = await this.getRootNode(folder);
if (rootNode) {
return new Promise<MaybeArray<URI> | undefined>(resolve => {
remote.dialog.showOpenDialog(this.toOpenDialogOptions(rootNode.uri, props), (filePaths: string[] | undefined) => {
remote.dialog.showOpenDialog(this.toOpenDialogOptions(rootNode.uri, props), async (filePaths: string[] | undefined) => {
if (!filePaths || filePaths.length === 0) {
resolve(undefined);
return;
}

const uris = filePaths.map(path => FileUri.create(path));
if (this.canReadWrite(uris)) {
resolve(uris.length === 1 ? uris[0] : uris);
} else {
resolve(undefined);
}
const canAccess = await this.canReadWrite(uris);
const result = canAccess ? uris.length === 1 ? uris[0] : uris : undefined;
resolve(result);
});
});
}
@@ -64,17 +63,21 @@ export class ElectronFileDialogService extends DefaultFileDialogService {
const rootNode = await this.getRootNode(folder);
if (rootNode) {
return new Promise<URI | undefined>(resolve => {
remote.dialog.showSaveDialog(this.toSaveDialogOptions(rootNode.uri, props), (filename: string | undefined) => {
remote.dialog.showSaveDialog(this.toSaveDialogOptions(rootNode.uri, props), async (filename: string | undefined) => {
if (!filename) {
resolve(undefined);
return;
}

const uri = FileUri.create(filename);
if (this.canReadWrite(uri)) {
const exists = await this.fileSystem.exists(uri.toString());
if (!exists) {
resolve(uri);
} else {
resolve(undefined);
return;
}

const canAccess = await this.canReadWrite(uri);
resolve(canAccess ? uri : undefined);
});
});
}