added windows build and minor tweaks for `win32` platform

master
Michael Ochmann 3 years ago
parent 38cb3e3295
commit 9b8da8be9e
  1. 1
      .gitignore
  2. 2
      contextAPI.js
  3. 18
      package.json
  4. 18
      src/Ation.js
  5. 1
      src/SettingsManager.js
  6. 12
      src/WindowManager.js

1
.gitignore vendored

@ -6,4 +6,5 @@ node_modules
dist dist
assets/*.png assets/*.png
assets/*.icns assets/*.icns
assets/*.ico
!assets/dmg_background.png !assets/dmg_background.png

@ -26,7 +26,7 @@ contextBridge.exposeInMainWorld("api", {
clearCache : () => webFrame.clearCache(), clearCache : () => webFrame.clearCache(),
appVersion : async () => await ipcRenderer.invoke("Ation::appVersion"), appVersion : async () => await ipcRenderer.invoke("Ation::appVersion"),
fonts : async () => await ipcRenderer.invoke("FontManager::fonts"), fonts : async () => await ipcRenderer.invoke("FontManager::fonts"),
resize : size => ipcRenderer.invoke("SettingsManager::resize", size) resize : size => ipcRenderer.invoke("WindowManager::resize", size)
}); });
contextBridge.exposeInMainWorld("appSettings", { contextBridge.exposeInMainWorld("appSettings", {

@ -8,9 +8,9 @@
"dev": "concurrently \"cd src/ui && cross-env BROWSER=none npm start\" \"wait-on tcp:3000 && electron .\"", "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": "npm i && npm run build:assets && npm run build:react",
"build:react": "cd src/ui && npm i && npm run build", "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", "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 -m", "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" "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 <miko@massivedynamic.eu>", "author": "Michael Ochmann <miko@massivedynamic.eu>",
"license": "MIT", "license": "MIT",
@ -30,10 +30,20 @@
"assets/*.svg", "assets/*.svg",
"package.json" "package.json"
], ],
"win": {
"target": "nsis",
"icon": "assets/appIcon.ico"
},
"mac": { "mac": {
"category": "public.app-category.productivity", "category": "public.app-category.productivity",
"target": [ "target": [
"dmg" {
"target": "dmg",
"arch": [
"x64",
"arm64"
]
}
], ],
"icon": "assets/app.icns", "icon": "assets/app.icns",
"darkModeSupport": true, "darkModeSupport": true,

@ -20,10 +20,12 @@ class Ation {
mainMenu; mainMenu;
watcher; watcher;
currentFile; currentFile;
fileToOpen;
constructor() { constructor() {
if (Ation.Instances > 0) if (Ation.Instances > 0)
throw new Error("Only one Instance of Ation possible"); throw new Error("Only one Instance of Ation possible");
this.fileToOpen = null;
this.currentFile = ""; this.currentFile = "";
this.watcher = null; this.watcher = null;
this.windowManager = new WindowManager(this); this.windowManager = new WindowManager(this);
@ -31,16 +33,24 @@ class Ation {
this.settingsManager = new SettingsManager(this); this.settingsManager = new SettingsManager(this);
this.mainMenu = new MainMenu(this); this.mainMenu = new MainMenu(this);
ipcMain.handle("Ation::appVersion", () => AppInfo.version);
ipcMain.on("Ation::closeFile", () => this.closeFile());
app.on("open-file", (_, path) => { app.on("open-file", (_, path) => {
this.fileToOpen = path; this.fileToOpen = path;
}); });
ipcMain.handle("Ation::appVersion", () => AppInfo.version);
ipcMain.on("Ation::closeFile", () => this.closeFile());
app.whenReady().then(async () => { app.whenReady().then(async () => {
this.settingsManager.change(); 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) if (this.fileToOpen)
this.openFile(this.fileToOpen); this.openFile(this.fileToOpen);
protocol.registerFileProtocol("slideimg", (request, callback) => { protocol.registerFileProtocol("slideimg", (request, callback) => {
@ -64,7 +74,7 @@ class Ation {
filters : [ filters : [
{ {
name : "Markdown files", name : "Markdown files",
extensions : [".md"] extensions : ["md"]
} }
] ]
}); });

@ -20,7 +20,6 @@ class SettingsManager {
} }
this.data = JSON.parse(fsn.readFileSync(SettingsManager.File, {encoding : "utf-8"})); 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::get", (_, key, defaultValue = null) => this.get(key, defaultValue));
ipcMain.handle("SettingsManager::set", (_, key, value) => this.set(key, value)); ipcMain.handle("SettingsManager::set", (_, key, value) => this.set(key, value));
ipcMain.handle("SettingsManager::all", () => this.data); ipcMain.handle("SettingsManager::all", () => this.data);

@ -19,12 +19,14 @@ class WindowManager {
ipcMain.on("WindowManager::openFileDialog", () => this.app.openFile()); ipcMain.on("WindowManager::openFileDialog", () => this.app.openFile());
ipcMain.on("WindowManager::openFile", (_, path) => this.app.openFile(path)); 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() { init() {
this.mainWindow = WindowManager._CreateWindow({ this.mainWindow = WindowManager._CreateWindow({
fullscreen : false, fullscreen : false,
fullscreenable : true fullscreenable : true,
autoHideMenuBar : process.platform === "win32"
}); });
this.windows.settings = WindowManager._CreateWindow({ this.windows.settings = WindowManager._CreateWindow({
height : 300, height : 300,
@ -34,6 +36,12 @@ class WindowManager {
show : false show : false
}, this.mainWindow, 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 => { this.windows.settings.on("close", event => {
event.preventDefault(); event.preventDefault();
this.windows.settings.hide(); this.windows.settings.hide();

Loading…
Cancel
Save