From 9b8da8be9ee8d7fc2898b142474ba95861000ec5 Mon Sep 17 00:00:00 2001 From: Michael Ochmann Date: Sat, 8 Oct 2022 20:52:10 +0200 Subject: [PATCH] added windows build and minor tweaks for `win32` platform --- .gitignore | 1 + contextAPI.js | 2 +- package.json | 18 ++++++++++++++---- src/Ation.js | 18 ++++++++++++++---- src/SettingsManager.js | 1 - src/WindowManager.js | 12 ++++++++++-- 6 files changed, 40 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 3ccf8eb..3ca0b72 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ node_modules dist assets/*.png assets/*.icns +assets/*.ico !assets/dmg_background.png diff --git a/contextAPI.js b/contextAPI.js index f355ecb..8a8d02e 100644 --- a/contextAPI.js +++ b/contextAPI.js @@ -26,7 +26,7 @@ contextBridge.exposeInMainWorld("api", { clearCache : () => webFrame.clearCache(), appVersion : async () => await ipcRenderer.invoke("Ation::appVersion"), fonts : async () => await ipcRenderer.invoke("FontManager::fonts"), - resize : size => ipcRenderer.invoke("SettingsManager::resize", size) + resize : size => ipcRenderer.invoke("WindowManager::resize", size) }); contextBridge.exposeInMainWorld("appSettings", { diff --git a/package.json b/package.json index 57df785..e223ce2 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,9 @@ "dev": "concurrently \"cd src/ui && cross-env BROWSER=none npm start\" \"wait-on tcp:3000 && electron .\"", "build": "npm i && npm run build:assets && npm run build:react", "build:react": "cd src/ui && npm i && npm run build", - "build:assets": "icon-gen -i assets/appIcon.svg -o ./assets --icns && xattr -cr assets/appIcon.svg", - "dist": "npm run clean && npm run build && electron-builder -m", - "clean": "rm -rf node_modules && rm -rf src/public/build/* && rm -rf src/public/node_modules && rm -rf dist && rm -f assets/*.icns" + "build:assets": "icon-gen -i assets/appIcon.svg -o ./assets --icns --ico --ico-name appIcon && xattr -cr assets/appIcon.svg", + "dist": "npm run clean && npm run build && electron-builder -mw", + "clean": "rm -rf node_modules && rm -rf src/public/build/* && rm -rf src/public/node_modules && rm -rf dist && rm -f assets/*.icns rm -f assets/*.ico" }, "author": "Michael Ochmann ", "license": "MIT", @@ -30,10 +30,20 @@ "assets/*.svg", "package.json" ], + "win": { + "target": "nsis", + "icon": "assets/appIcon.ico" + }, "mac": { "category": "public.app-category.productivity", "target": [ - "dmg" + { + "target": "dmg", + "arch": [ + "x64", + "arm64" + ] + } ], "icon": "assets/app.icns", "darkModeSupport": true, diff --git a/src/Ation.js b/src/Ation.js index 1ab25dc..b97cc6c 100644 --- a/src/Ation.js +++ b/src/Ation.js @@ -20,10 +20,12 @@ class Ation { mainMenu; watcher; currentFile; + fileToOpen; constructor() { if (Ation.Instances > 0) throw new Error("Only one Instance of Ation possible"); + this.fileToOpen = null; this.currentFile = ""; this.watcher = null; this.windowManager = new WindowManager(this); @@ -31,16 +33,24 @@ class Ation { this.settingsManager = new SettingsManager(this); this.mainMenu = new MainMenu(this); + ipcMain.handle("Ation::appVersion", () => AppInfo.version); + ipcMain.on("Ation::closeFile", () => this.closeFile()); + app.on("open-file", (_, path) => { this.fileToOpen = path; }); - ipcMain.handle("Ation::appVersion", () => AppInfo.version); - ipcMain.on("Ation::closeFile", () => this.closeFile()); - app.whenReady().then(async () => { this.settingsManager.change(); + // this is a hack for windows, because they do not send the + // `open-file` event, but pass a "cli parameter" as second + // argument + if (!this.fileToOpen) { + if (process.argv.length >= 2) + this.fileToOpen = process.argv[1]; + } + if (this.fileToOpen) this.openFile(this.fileToOpen); protocol.registerFileProtocol("slideimg", (request, callback) => { @@ -64,7 +74,7 @@ class Ation { filters : [ { name : "Markdown files", - extensions : [".md"] + extensions : ["md"] } ] }); diff --git a/src/SettingsManager.js b/src/SettingsManager.js index 7c7d3b5..911213f 100644 --- a/src/SettingsManager.js +++ b/src/SettingsManager.js @@ -20,7 +20,6 @@ class SettingsManager { } this.data = JSON.parse(fsn.readFileSync(SettingsManager.File, {encoding : "utf-8"})); - ipcMain.handle("SettingsManager::resize", (_, height) => app.windowManager.windows.settings.setSize(800, height, true)); ipcMain.handle("SettingsManager::get", (_, key, defaultValue = null) => this.get(key, defaultValue)); ipcMain.handle("SettingsManager::set", (_, key, value) => this.set(key, value)); ipcMain.handle("SettingsManager::all", () => this.data); diff --git a/src/WindowManager.js b/src/WindowManager.js index dbfefd0..b7df5f1 100644 --- a/src/WindowManager.js +++ b/src/WindowManager.js @@ -19,12 +19,14 @@ class WindowManager { ipcMain.on("WindowManager::openFileDialog", () => this.app.openFile()); ipcMain.on("WindowManager::openFile", (_, path) => this.app.openFile(path)); + ipcMain.handle("WindowManager::resize", (_, height) => this.windows.settings.setSize(800, height + (process.platform === "win32" ? 50 : 0), true)); } init() { this.mainWindow = WindowManager._CreateWindow({ - fullscreen : false, - fullscreenable : true + fullscreen : false, + fullscreenable : true, + autoHideMenuBar : process.platform === "win32" }); this.windows.settings = WindowManager._CreateWindow({ height : 300, @@ -34,6 +36,12 @@ class WindowManager { show : false }, this.mainWindow, false); + // on windows and linux we need to hide the main menu in the settings + // window, because it would look odd. + if (["win32", "linux"].includes(process.platform)) { + this.windows.settings.removeMenu(); + } + this.windows.settings.on("close", event => { event.preventDefault(); this.windows.settings.hide();