Skip to content

Commit

Permalink
Save to documents folder by default
Browse files Browse the repository at this point in the history
  • Loading branch information
unageek committed Mar 9, 2022
1 parent d10c83a commit a36ff22
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,14 @@ function countJobs(filter: JobFilter = () => true): number {
);
}

function defaultSavePath(): string {
try {
return path.join(app.getPath("documents"), "Untitled.graphest");
} catch {
return "";
}
}

function deprioritize(job: Job) {
if (activeJobs.length <= MAX_ACTIVE_JOBS && sleepingJobs.length === 0) {
job.proc?.stdin?.write("\n");
Expand Down Expand Up @@ -718,7 +726,7 @@ async function open() {
if (!mainWindow) return;

const result = await dialog.showOpenDialog(mainWindow, {
defaultPath: currentPath,
defaultPath: currentPath ?? defaultSavePath(),
filters: [{ name: "Graphest Document", extensions: ["graphest"] }],
});
if (result.filePaths.length !== 1) return;
Expand Down Expand Up @@ -817,7 +825,7 @@ async function save(doc: Document, to: SaveTo): Promise<boolean> {
let path = currentPath;
if (to === SaveTo.NewFile || path === undefined) {
const result = await dialog.showSaveDialog(mainWindow, {
defaultPath: path,
defaultPath: path ?? defaultSavePath(),
filters: [{ name: "Graphest Document", extensions: ["graphest"] }],
});
if (!result.filePath) return false;
Expand Down

0 comments on commit a36ff22

Please sign in to comment.