ref/ electron builder two packages build
This commit is contained in:
90
app/main.ts
Normal file
90
app/main.ts
Normal file
@@ -0,0 +1,90 @@
|
||||
import { app, BrowserWindow, screen } from 'electron';
|
||||
import * as path from 'path';
|
||||
import * as url from 'url';
|
||||
|
||||
const pad = require('pad');
|
||||
|
||||
console.log(pad('pad', 5));
|
||||
|
||||
// Initialize remote module
|
||||
require('@electron/remote/main').initialize();
|
||||
|
||||
let win: BrowserWindow = null;
|
||||
const args = process.argv.slice(1),
|
||||
serve = args.some(val => val === '--serve');
|
||||
|
||||
function createWindow(): BrowserWindow {
|
||||
|
||||
const electronScreen = screen;
|
||||
const size = electronScreen.getPrimaryDisplay().workAreaSize;
|
||||
|
||||
// Create the browser window.
|
||||
win = new BrowserWindow({
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
allowRunningInsecureContent: (serve) ? true : false,
|
||||
contextIsolation: false, // false if you want to run 2e2 test with Spectron
|
||||
enableRemoteModule : true // true if you want to run 2e2 test with Spectron or use remote module in renderer context (ie. Angular)
|
||||
},
|
||||
});
|
||||
|
||||
if (serve) {
|
||||
|
||||
win.webContents.openDevTools();
|
||||
|
||||
require('electron-reload')(__dirname, {
|
||||
electron: require(`${__dirname}/../node_modules/electron`)
|
||||
});
|
||||
win.loadURL('http://localhost:4200');
|
||||
|
||||
} else {
|
||||
win.loadURL(url.format({
|
||||
pathname: path.join(__dirname, '../dist/index.html'),
|
||||
protocol: 'file:',
|
||||
slashes: true
|
||||
}));
|
||||
}
|
||||
|
||||
// Emitted when the window is closed.
|
||||
win.on('closed', () => {
|
||||
// Dereference the window object, usually you would store window
|
||||
// in an array if your app supports multi windows, this is the time
|
||||
// when you should delete the corresponding element.
|
||||
win = null;
|
||||
});
|
||||
|
||||
return win;
|
||||
}
|
||||
|
||||
try {
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
// Added 400 ms to fix the black background issue while using transparent window. More detais at https://github.com/electron/electron/issues/15947
|
||||
app.on('ready', () => setTimeout(createWindow, 400));
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', () => {
|
||||
// On OS X it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('activate', () => {
|
||||
// On OS X it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (win === null) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
// Catch Error
|
||||
// throw e;
|
||||
}
|
||||
42
app/package-lock.json
generated
Normal file
42
app/package-lock.json
generated
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "angular-electron",
|
||||
"version": "8.0.6",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"@electron/remote": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@electron/remote/-/remote-1.0.4.tgz",
|
||||
"integrity": "sha512-kguDJRhL3ZynHrkbX8Tr7xoAzGsNgh4eqXkycXb6cgXbOgehGqkBVe+MnjSVMXz3QJykerGKPy28gqcM7AFGYw=="
|
||||
},
|
||||
"clone": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz",
|
||||
"integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4="
|
||||
},
|
||||
"defaults": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz",
|
||||
"integrity": "sha1-xlYFHpgX2f8I7YgUd/P+QBnz730=",
|
||||
"requires": {
|
||||
"clone": "^1.0.2"
|
||||
}
|
||||
},
|
||||
"pad": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/pad/-/pad-3.2.0.tgz",
|
||||
"integrity": "sha512-2u0TrjcGbOjBTJpyewEl4hBO3OeX5wWue7eIFPzQTg6wFSvoaHcBTTUY5m+n0hd04gmTCPuY0kCpVIVuw5etwg==",
|
||||
"requires": {
|
||||
"wcwidth": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"wcwidth": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz",
|
||||
"integrity": "sha1-8LDc+RW8X/FSivrbLA4XtTLaL+g=",
|
||||
"requires": {
|
||||
"defaults": "^1.0.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
10
app/package.json
Normal file
10
app/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "angular-electron",
|
||||
"version": "10.0.0",
|
||||
"main": "main.js",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@electron/remote": "1.0.4",
|
||||
"pad": "3.2.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user