Skip to content

Commit ffa1e00

Browse files
committed
created electron app launcher
1 parent a9948aa commit ffa1e00

18 files changed

+846
-516
lines changed

bin/codecept-ui.js

+8-12
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ const app = express();
1010
const io = require('socket.io')();
1111
const api = require('../lib/api');
1212
const { events } = require('../lib/model/ws-events');
13-
const snapshotStore = require('../lib/model/snapshot-store');
14-
const scenarioStatusRepository = require('../lib/model/scenario-status-repository');
1513

1614
// Base port
1715
const PORT = getPort();
@@ -42,17 +40,15 @@ io.on('connection', socket => {
4240
}
4341
});
4442

45-
(async function() {
46-
4743

44+
// eslint-disable-next-line no-console
45+
debug(`Listening for websocket connections on port ${PORT}`);
4846

49-
// eslint-disable-next-line no-console
50-
debug(`Listening for websocket connections on port ${PORT}`);
47+
// eslint-disable-next-line no-console
48+
console.log('🌟 CodeceptUI started!');
5149

52-
// eslint-disable-next-line no-console
53-
console.log(`Open http://localhost:${PORT+1} in your web browser!`);
54-
55-
io.listen(PORT);
56-
app.listen(PORT + 1);
57-
})();
50+
// eslint-disable-next-line no-console
51+
console.log(`👉 Open http://localhost:${PORT+1} see CodeceptUI a browser\n\n`);
5852

53+
io.listen(PORT);
54+
app.listen(PORT + 1);

build/icons/1024x1024.png

192 KB
Loading

build/icons/128x128.png

9.36 KB
Loading

build/icons/16x16.png

749 Bytes
Loading

build/icons/24x24.png

1.26 KB
Loading

build/icons/256x256.png

21.8 KB
Loading

build/icons/32x32.png

1.84 KB
Loading

build/icons/48x48.png

2.93 KB
Loading

build/icons/512x512.png

65.3 KB
Loading

build/icons/64x64.png

4.14 KB
Loading

build/icons/icon.icns

385 KB
Binary file not shown.

build/icons/icon.ico

353 KB
Binary file not shown.

lib/app.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const { BrowserWindow, app } = require('electron');
5+
const { getPort } = require('./config/env');
6+
7+
// Keep a global reference of the window object, if you don't, the window will
8+
// be closed automatically when the JavaScript object is garbage collected.
9+
let win;
10+
11+
// Scheme must be registered before the app is ready
12+
// protocol.registerSchemesAsPrivileged([{scheme: 'app', privileges: { secure: true, standard: true } }]);
13+
14+
app.name = 'CodeceptUI';
15+
app.setName('CodeceptUI');
16+
17+
function createWindow () {
18+
const { screen } = require('electron');
19+
const { width: screenWidth, height: screenHeight } = screen.getPrimaryDisplay().size;
20+
21+
const width = Math.floor(screenWidth / 3.5) || 500;
22+
// Create the browser window.
23+
win = new BrowserWindow({
24+
width,
25+
height: screenHeight,
26+
minWidth: 500,
27+
x: screenWidth,
28+
y: 0,
29+
title: 'CodeceptUI',
30+
autoHideMenuBar: true,
31+
icon: path.join(__dirname, '../build/icons/64x64.png'),
32+
webPreferences: {
33+
nodeIntegration: true
34+
},
35+
});
36+
37+
setTimeout(() => {
38+
win.loadURL(`http://localhost:${getPort() + 1}`);
39+
40+
// eslint-disable-next-line no-console
41+
console.log('Application window opened, switch to it to run tests...');
42+
}, 500);
43+
44+
45+
46+
win.on('closed', () => {
47+
win = null;
48+
});
49+
}
50+
51+
// Quit when all windows are closed.
52+
app.on('window-all-closed', () => {
53+
// On macOS 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 macOS 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+
// This method will be called when Electron has finished
69+
// initialization and is ready to create browser windows.
70+
// Some APIs can only be used after this event occurs.
71+
app.on('ready', async () => {
72+
createWindow();
73+
});

lib/commands/electron.js

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const { join } = require('path');
2+
const { spawn } = require('child_process');
3+
4+
const electron =
5+
process.env.ELECTRON_PATH ||
6+
resolve('electron') ||
7+
resolve('electron-prebuilt') ||
8+
resolve('electron', require('which').sync);
9+
10+
if (!electron) {
11+
/* eslint-disable no-console */
12+
console.error('');
13+
console.error(' Can not find `electron` in $PATH and $ELECTRON_PATH is not set.');
14+
console.error(' Please either set $ELECTRON_PATH or `npm install electron`.');
15+
console.error('');
16+
process.exit(1);
17+
}
18+
19+
run(electron);
20+
21+
function resolve (module, resolver) {
22+
try {
23+
return (resolver || require)(module);
24+
} catch (_) {
25+
// ignore
26+
}
27+
}
28+
29+
function run (electron) {
30+
let args = [
31+
join(__dirname, '../app.js'),
32+
...process.argv.slice(2)
33+
];
34+
35+
let child = spawn(electron, args);
36+
37+
// stdio 'inherit' not work reliably in Renderer!
38+
child.stdout.pipe(process.stdout);
39+
child.stderr.pipe(process.stderr);
40+
process.stdin.pipe(child.stdin);
41+
42+
child.on('exit', (code, signal) => {
43+
if (signal) {
44+
process.kill(process.pid, signal);
45+
} else {
46+
process.exit(code);
47+
}
48+
});
49+
50+
process.on('SIGINT', () => {
51+
child.kill('SIGINT');
52+
child.kill('SIGTERM');
53+
});
54+
}

lib/commands/init.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = () => {
77
const program = new commander.Command();
88
program.version(JSON.parse(fs.readFileSync(`${__dirname}/../../package.json`, 'utf8')).version);
99
program
10+
.option('--app', 'launch Electron application')
1011
// codecept-only options
1112
.option('--steps', 'show step-by-step execution')
1213
.option('--debug', 'output additional information')
@@ -18,7 +19,7 @@ module.exports = () => {
1819
.option('-p, --plugins <k=v,k2=v2,...>', 'enable plugins, comma-separated');
1920

2021
program.parse(process.argv);
21-
22+
2223
if (program.config) {
2324
const configFile = program.config;
2425
let configPath = configFile;
@@ -32,6 +33,13 @@ module.exports = () => {
3233
process.chdir(configPath);
3334
codeceptjsFactory.setRootDir(configPath);
3435
}
36+
37+
// console.log(program.opts());
38+
39+
if (program.app) {
40+
// open electron app
41+
require('./electron');
42+
}
3543

3644
codeceptjsFactory.create({}, program.opts());
3745
};

0 commit comments

Comments
 (0)