From 83f111b73b36a39f5618e34461d1ac046aecc5fc Mon Sep 17 00:00:00 2001 From: Sam Wray Date: Tue, 4 May 2021 21:39:54 +0100 Subject: [PATCH] feat(recent-documents): adds a recent documents list for macOS abstracts the file opening code to a function for reusability fixes #527 --- src/background.js | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/background.js b/src/background.js index 3d4203fff..05d3b9113 100644 --- a/src/background.js +++ b/src/background.js @@ -248,6 +248,18 @@ protocol.registerSchemesAsPrivileged([ } ]); +function openFile(filePath) { + app.addRecentDocument(filePath); + + windows["mainWindow"].webContents.send("open-preset", filePath); +} + +app.on("open-file", (event, filePath) => { + event.preventDefault(); + + openFile(filePath); +}); + const isMac = process.platform === "darwin"; function setCurrentProject(name) { @@ -290,13 +302,26 @@ function generateMenuTemplate() { }); if (!result.canceled) { - windows["mainWindow"].webContents.send( - "open-preset", - result.filePaths[0] - ); + const filePath = result.filePaths[0]; + openFile(filePath); } } }, + ...(isMac + ? [ + { + label: "Open Recent", + role: "recentdocuments", + submenu: [ + { + label: "Clear Recent", + role: "clearrecentdocuments" + } + ] + } + ] + : []), + { type: "separator" }, { label: "Save Preset", accelerator: "CmdOrCtrl+Shift+S",