diff --git a/electron-builder.json b/electron-builder.json index 1a9c6e8..f952916 100644 --- a/electron-builder.json +++ b/electron-builder.json @@ -20,12 +20,15 @@ "!**/{npm-debug.log,yarn.lock,.yarn-integrity,.yarn-metadata.json}" ], "linux": { + "icon": "dist/build/static/icons/icon.png", "target": ["AppImage"] }, "mac": { + "icon": "dist/build/static/icons/icon.png", "target": ["dmg"] }, "win": { + "icon": "dist/build/static/icons/icon.png", "target": ["NSIS"] } } diff --git a/electron-webpack.json b/electron-webpack.json index 52e8c81..947daa7 100644 --- a/electron-webpack.json +++ b/electron-webpack.json @@ -1,4 +1,5 @@ { + "staticSourceDirectory": "src/static", "main": { "extraEntries": ["@/preload.js"], "sourceDirectory": "dist/electron" diff --git a/package.json b/package.json index a3ebbe2..a437e94 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "e2e": "yarn ng:e2e && yarn electron:e2e", "start": "del -f dist && npm-run-all -p ng:serve electron:serve", "build:dist": "del -f dist && yarn ng:build && yarn electron:build", - "build:copy": "cpy package.json dist/main/* dist/angular/* dist/build", + "build:copy": "cpy package.json dist/main/* dist/angular/* dist/build && cpy static ../dist/build --cwd=src --parents", "build": "yarn build:dist && yarn build:copy && cd dist/build && yarn --prod", "package": "yarn build && electron-builder" }, diff --git a/src/electron/components/window.ts b/src/electron/components/window.ts index ac94861..751298f 100644 --- a/src/electron/components/window.ts +++ b/src/electron/components/window.ts @@ -1,9 +1,11 @@ -import { app, BrowserWindow, ipcMain } from 'electron'; +import { app, BrowserWindow, ipcMain, nativeImage } from 'electron'; import * as path from 'path'; import * as url from 'url'; import { AbstractService } from '../services/abstract-service'; import { MultiplesService } from '../services/multiples-service'; +declare const __static: string; + export class Window { private _window: BrowserWindow | any; private _dev: boolean; @@ -14,7 +16,7 @@ export class Window { this._e2e = process.env.X_NODE_ENV === 'e2e-test'; this.createWindow(); - this.loadRender(); + this.loadRenderer(); this.registerService(MultiplesService); } @@ -23,6 +25,7 @@ export class Window { width: 800, height: 600, backgroundColor: '#FFFFFF', + icon: this._dev ? this.loadIcon() : null, webPreferences: { // Default behavior in Electron since 5, that // limits the powers granted to remote content @@ -40,7 +43,18 @@ export class Window { }); } - private loadRender(): void { + private loadIcon(): Electron.NativeImage { + const iconPath = path.join(__static, 'icons/icon.png'); + console.debug('Icon Path ', iconPath); + const iconObj = nativeImage.createFromPath(iconPath); + // Change dock icon on MacOS + if (iconObj && process.platform === 'darwin') { + app.dock.setIcon(iconObj); + } + return iconObj; + } + + private loadRenderer(): void { if (this._dev) { // Dev mode, take advantage of the live reload by loading local URL this.window.loadURL(`http://localhost:4200`); @@ -55,7 +69,7 @@ export class Window { this.window.loadURL(indexPath); } - // Delete current reference when the window is closed + // Delete current reference when the window is closed` this._window.on('closed', () => { delete this._window; }); diff --git a/src/static/icons/icon.png b/src/static/icons/icon.png new file mode 100644 index 0000000..a630df7 Binary files /dev/null and b/src/static/icons/icon.png differ