Skip to content

Commit

Permalink
Add workaround for Linux save dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgarthur committed Mar 24, 2023
1 parent 7d4b3fd commit 2a2c24f
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions src/background.ts
Expand Up @@ -296,9 +296,19 @@ async function saveWorkspaceAs(args: SaveWorkspaceAsArgs) {
if (!dialogResult.canceled) {
result.filePath = dialogResult.filePath!;

await writeScoreFile(dialogResult.filePath!, args.data);
// Hack for Linux: if the filepath doesn't end with the proper extension,
// then add it
// See https://github.com/electron/electron/issues/21935
if (
!result.filePath.endsWith('.byz') &&
!result.filePath.endsWith('.byzx')
) {
result.filePath += '.byz';
}

await writeScoreFile(result.filePath!, args.data);

await addToRecentFiles(dialogResult.filePath!);
await addToRecentFiles(result.filePath!);
createMenu();

result.success = true;
Expand Down Expand Up @@ -338,13 +348,22 @@ async function exportWorkspaceAsPdf(args: ExportWorkspaceAsPdfArgs) {
});

if (!dialogResult.canceled) {
let filePath = dialogResult.filePath!;

// Hack for Linux: if the filepath doesn't end with the proper extension,
// then add it
// See https://github.com/electron/electron/issues/21935
if (!filePath.endsWith('.pdf')) {
filePath += '.pdf';
}

const data = await win.webContents.printToPDF({
pageSize: args.pageSize,
landscape: args.landscape,
});
await fs.writeFile(dialogResult.filePath!, data);
await fs.writeFile(filePath!, data);

await shell.openPath(dialogResult.filePath!);
await shell.openPath(filePath!);
}
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -381,8 +400,17 @@ async function exportWorkspaceAsHtml(args: ExportWorkspaceAsHtmlArgs) {
});

if (!dialogResult.canceled) {
await fs.writeFile(dialogResult.filePath!, args.data);
await shell.openPath(dialogResult.filePath!);
let filePath = dialogResult.filePath!;

// Hack for Linux: if the filepath doesn't end with the proper extension,
// then add it
// See https://github.com/electron/electron/issues/21935
if (!filePath.endsWith('.html')) {
filePath += '.html';
}

await fs.writeFile(filePath!, args.data);
await shell.openPath(filePath!);
}
} catch (error) {
console.error(error);
Expand Down

0 comments on commit 2a2c24f

Please sign in to comment.