Skip to content

Commit 835d32b

Browse files
committed
ref/ electron main from js to ts
1 parent 93dcc52 commit 835d32b

File tree

4 files changed

+78
-88
lines changed

4 files changed

+78
-88
lines changed

main.js

Lines changed: 0 additions & 81 deletions
This file was deleted.

main.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { app, BrowserWindow, screen } from 'electron';
2+
import * as path from 'path';
3+
4+
5+
let win, serve;
6+
const args = process.argv.slice(1);
7+
serve = args.some(val => val === "--serve");
8+
9+
if (serve) {
10+
require('electron-reload')(__dirname, {
11+
});
12+
}
13+
14+
function createWindow() {
15+
16+
let electronScreen = screen;
17+
let size = electronScreen.getPrimaryDisplay().workAreaSize;
18+
19+
// Create the browser window.
20+
win = new BrowserWindow({
21+
x: 0,
22+
y: 0,
23+
width: size.width,
24+
height: size.height
25+
});
26+
27+
// and load the index.html of the app.
28+
win.loadURL('file://' + __dirname + '/index.html');
29+
30+
// Open the DevTools.
31+
if (serve) {
32+
win.webContents.openDevTools();
33+
}
34+
35+
// Emitted when the window is closed.
36+
win.on('closed', () => {
37+
// Dereference the window object, usually you would store window
38+
// in an array if your app supports multi windows, this is the time
39+
// when you should delete the corresponding element.
40+
win = null;
41+
});
42+
}
43+
44+
try {
45+
46+
// This method will be called when Electron has finished
47+
// initialization and is ready to create browser windows.
48+
// Some APIs can only be used after this event occurs.
49+
app.on('ready', createWindow);
50+
51+
// Quit when all windows are closed.
52+
app.on('window-all-closed', () => {
53+
// On OS X it is common for applications and their menu bar
54+
// to stay active until the user quits explicitly with Cmd + Q
55+
if (process.platform !== 'darwin') {
56+
app.quit();
57+
}
58+
});
59+
60+
app.on('activate', () => {
61+
// On OS X it's common to re-create a window in the app when the
62+
// dock icon is clicked and there are no other windows open.
63+
if (win === null) {
64+
createWindow();
65+
}
66+
});
67+
68+
} catch (e) {
69+
// Catch Error
70+
//throw e;
71+
}

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@
1919
"ng": "ng",
2020
"lint": "ng lint",
2121
"start": "webpack --watch",
22-
"start:web": "webpack-dev-server . --port 4200",
23-
"build": "webpack --display-error-details && copyfiles main.js package.json dist",
24-
"dependencies:prod": "cd ./dist && npm install --only=prod && cd ..",
22+
"start:web": "webpack-dev-server --content-base . --port 4200 --inline",
23+
"build:electron:main": "tsc main.ts --outDir dist && copyfiles package.json dist",
24+
"build": "webpack --display-error-details && npm run build:electron:main",
2525
"build:prod": "cross-env NODE_ENV='production' npm run build",
26-
"electron:serve": "electron . --serve",
26+
"electron:serve": "npm run build:electron:main && electron ./dist --serve",
2727
"electron:test": "electron ./dist",
2828
"electron:dev": "npm run build && electron dist/main.js",
2929
"electron:prod": "npm run build:prod && electron dist/main.js",
3030
"electron:linux": "npm run build:prod && node package.js --asar --platform=linux --arch=x64",
3131
"electron:windows": "npm run build:prod && node package.js --asar --platform=win32 --arch=ia32",
3232
"electron:mac": "npm run build:prod && node package.js --asar --platform=darwin --arch=x64",
3333
"test": "karma start ./karma.conf.js",
34-
"e2e": "protractor ./protractor.conf.js",
35-
"pree2e": "webdriver-manager update --standalone false --gecko false --quiet"
34+
"pree2e": "webdriver-manager update --standalone false --gecko false --quiet && npm run build",
35+
"e2e": "protractor ./protractor.conf.js"
3636
},
3737
"dependencies": {
3838
"@angular/common": "4.0.2",

protractor.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ exports.config = {
1212
'browserName': 'chrome',
1313
chromeOptions: {
1414
binary: './node_modules/electron/dist/electron.exe',
15-
args: ['--test-type=webdriver', 'app=main.js']
15+
args: ['--test-type=webdriver', 'app=dist/main.js']
1616
}
1717
},
1818
directConnect: true,

0 commit comments

Comments
 (0)