diff --git a/console/atest-desktop/index.html b/console/atest-desktop/index.html
index 40fcdba3..2fe195ee 100644
--- a/console/atest-desktop/index.html
+++ b/console/atest-desktop/index.html
@@ -43,7 +43,11 @@
-
+
|
@@ -128,14 +132,14 @@
const binLocation = document.getElementById('bin-location');
binLocation.addEventListener("input", function(e) {
- window.electronAPI.setBinLocation(binLocation.value)
+ window.electronAPI.setMainProcessLocation(binLocation.value)
});
(async function() {
portInput.value = await window.electronAPI.getPort()
extensionRegistry.value = await window.electronAPI.getExtensionRegistry()
downloadTimeout.value = await window.electronAPI.getDownloadTimeout()
- binLocation.value = await window.electronAPI.getBinLocation()
+ binLocation.value = await window.electronAPI.getMainProcessLocation()
document.getElementById('address').innerText = await window.electronAPI.getHomePage();
})();
diff --git a/console/atest-desktop/main.js b/console/atest-desktop/main.js
index 7f83a05e..9bd7c9df 100644
--- a/console/atest-desktop/main.js
+++ b/console/atest-desktop/main.js
@@ -29,89 +29,89 @@ log.initialize();
log.transports.file.level = getLogLevel()
log.transports.file.resolvePathFn = () => server.getLogfile()
-if (process.platform === 'darwin'){
- app.dock.setIcon(path.join(__dirname, "api-testing.png"))
+if (process.platform === 'darwin') {
+ app.dock.setIcon(path.join(__dirname, "api-testing.png"))
}
const windowOptions = {
- width: 1024,
- height: 600,
- frame: true,
- webPreferences: {
- preload: path.join(__dirname, 'preload.js'),
- nodeIntegration: true,
- contextIsolation: true,
- enableRemoteModule: true
- },
- icon: path.join(__dirname, '/api-testing.ico'),
+ width: 1024,
+ height: 600,
+ frame: true,
+ webPreferences: {
+ preload: path.join(__dirname, 'preload.js'),
+ nodeIntegration: true,
+ contextIsolation: true,
+ enableRemoteModule: true
+ },
+ icon: path.join(__dirname, '/api-testing.ico'),
}
const createWindow = () => {
- var width = storage.getSync('window.width')
- if (!isNaN(width)) {
- windowOptions.width = width
- }
- var height = storage.getSync('window.height')
- if (!isNaN(height)) {
- windowOptions.height = height
- }
+ var width = storage.getSync('window.width')
+ if (!isNaN(width)) {
+ windowOptions.width = width
+ }
+ var height = storage.getSync('window.height')
+ if (!isNaN(height)) {
+ windowOptions.height = height
+ }
- // Create the browser window.
- const mainWindow = new BrowserWindow(windowOptions)
+ // Create the browser window.
+ const mainWindow = new BrowserWindow(windowOptions)
- if (!isNaN(serverProcess.pid)) {
- // server process started by app
- mainWindow.loadURL(server.getHomePage())
- } else {
- server.control(() => {
- mainWindow.loadURL(server.getHomePage())
- }, () => {
- // and load the index.html of the app.
- mainWindow.loadFile('index.html')
- })
- }
+ if (!isNaN(serverProcess.pid)) {
+ // server process started by app
+ mainWindow.loadURL(server.getHomePage())
+ } else {
+ server.control(() => {
+ mainWindow.loadURL(server.getHomePage())
+ }, () => {
+ // and load the index.html of the app.
+ mainWindow.loadFile('index.html')
+ })
+ }
- mainWindow.on('resize', () => {
- const size = mainWindow.getSize();
- storage.set('window.width', size[0])
- storage.set('window.height', size[1])
- })
+ mainWindow.on('resize', () => {
+ const size = mainWindow.getSize();
+ storage.set('window.width', size[0])
+ storage.set('window.height', size[1])
+ })
}
const menu = new Menu()
menu.append(new MenuItem({
- label: 'Window',
- submenu: [{
- label: 'Console',
- accelerator: process.platform === 'darwin' ? 'Alt+Cmd+C' : 'Alt+Shift+C',
- click: () => {
- BrowserWindow.getFocusedWindow().loadFile('index.html');
- }
- }, {
- label: 'Server',
- accelerator: process.platform === 'darwin' ? 'Alt+Cmd+S' : 'Alt+Shift+S',
- click: () => {
- BrowserWindow.getFocusedWindow().loadURL(server.getHomePage());
- }
- }, {
- label: 'Reload',
- accelerator: process.platform === 'darwin' ? 'Cmd+R' : 'F5',
- click: () => {
- BrowserWindow.getFocusedWindow().reload()
- }
- }, {
- label: 'Developer Mode',
- accelerator: process.platform === 'darwin' ? 'Alt+Cmd+D' : 'F12',
- click: () => {
- BrowserWindow.getFocusedWindow().webContents.openDevTools();
- }
- }, {
- label: 'Quit',
- accelerator: process.platform === 'darwin' ? 'Cmd+Q' : 'Alt+Shift+Q',
- click: () => {
- app.quit()
- }
- }]
+ label: 'Window',
+ submenu: [{
+ label: 'Console',
+ accelerator: process.platform === 'darwin' ? 'Alt+Cmd+C' : 'Alt+Shift+C',
+ click: () => {
+ BrowserWindow.getFocusedWindow().loadFile('index.html');
+ }
+ }, {
+ label: 'Server',
+ accelerator: process.platform === 'darwin' ? 'Alt+Cmd+S' : 'Alt+Shift+S',
+ click: () => {
+ BrowserWindow.getFocusedWindow().loadURL(server.getHomePage());
+ }
+ }, {
+ label: 'Reload',
+ accelerator: process.platform === 'darwin' ? 'Cmd+R' : 'F5',
+ click: () => {
+ BrowserWindow.getFocusedWindow().reload()
+ }
+ }, {
+ label: 'Developer Mode',
+ accelerator: process.platform === 'darwin' ? 'Alt+Cmd+D' : 'F12',
+ click: () => {
+ BrowserWindow.getFocusedWindow().webContents.openDevTools();
+ }
+ }, {
+ label: 'Quit',
+ accelerator: process.platform === 'darwin' ? 'Cmd+Q' : 'Alt+Shift+Q',
+ click: () => {
+ app.quit()
+ }
+ }]
}))
Menu.setApplicationMenu(menu)
@@ -126,37 +126,37 @@ let mainProcessLocation = "built-in";
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
- ipcMain.on('openLogDir', () => {
- shell.openExternal('file://' + server.getLogfile())
- })
- ipcMain.handle('openWithExternalBrowser', (e, address) => {
- shell.openExternal(address)
- })
- ipcMain.on('startServer', startServer)
- ipcMain.on('stopServer', stopServer)
- ipcMain.on('control', (e, okCallback, errCallback) => {
- server.control(okCallback, errCallback)
- })
- ipcMain.handle('getPort', () => {
- return serverPort
- })
- ipcMain.handle('setPort', (e, port) => {
- serverPort = port;
- })
- ipcMain.handle('getExtensionRegistry', () => {
- return extensionRegistry
- })
- ipcMain.handle('setExtensionRegistry', (e, registry) => {
- extensionRegistry = registry
- })
- ipcMain.handle('getDownloadTimeout', () => {
- return downloadTimeout
- })
- ipcMain.handle('setDownloadTimeout', (e, timeout) => {
- downloadTimeout = timeout
- })
- ipcMain.handle('getHomePage', server.getHomePage)
- ipcMain.handle('getHealthzUrl', server.getHealthzUrl)
+ ipcMain.on('openLogDir', () => {
+ shell.openExternal('file://' + server.getLogfile())
+ })
+ ipcMain.handle('openWithExternalBrowser', (e, address) => {
+ shell.openExternal(address)
+ })
+ ipcMain.on('startServer', startServer)
+ ipcMain.on('stopServer', stopServer)
+ ipcMain.on('control', (e, okCallback, errCallback) => {
+ server.control(okCallback, errCallback)
+ })
+ ipcMain.handle('getPort', () => {
+ return serverPort
+ })
+ ipcMain.handle('setPort', (e, port) => {
+ serverPort = port;
+ })
+ ipcMain.handle('getExtensionRegistry', () => {
+ return extensionRegistry
+ })
+ ipcMain.handle('setExtensionRegistry', (e, registry) => {
+ extensionRegistry = registry
+ })
+ ipcMain.handle('getDownloadTimeout', () => {
+ return downloadTimeout
+ })
+ ipcMain.handle('setDownloadTimeout', (e, timeout) => {
+ downloadTimeout = timeout
+ })
+ ipcMain.handle('getHomePage', server.getHomePage)
+ ipcMain.handle('getHealthzUrl', server.getHealthzUrl)
ipcMain.handle('getMainProcessLocation', () => {
return mainProcessLocation
})
@@ -164,66 +164,67 @@ app.whenReady().then(() => {
mainProcessLocation = location
})
- startServer()
- createWindow()
+ startServer()
+ createWindow()
- app.on('activate', () => {
- // On macOS 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 (BrowserWindow.getAllWindows().length === 0) createWindow()
- })
+ app.on('activate', () => {
+ // On macOS 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 (BrowserWindow.getAllWindows().length === 0) createWindow()
+ })
})
const startServer = () => {
- const homeData = path.join(atestHome, 'data')
- const homeBin = path.join(atestHome, 'bin')
-
- fs.mkdirSync(homeData, {
- recursive: true
- })
- fs.mkdirSync(homeBin, {
- recursive: true
- })
+ const homeData = path.join(atestHome, 'data')
+ fs.mkdirSync(homeData, {
+ recursive: true
+ })
- let atestBinPath
+ let atestBinPath
switch (mainProcessLocation) {
- case "built-in":
- atestBinPath = locateBinPath()
- break;
- case "system-path":
- const which = require('which');
- atestBinPath = process.platform === "win32" ? which.sync('atest.exe') : which.sync('atest')
- break;
- case "home-path":
- atestBinPath = locateBinPath(false)
- break;
+ case "built-in":
+ atestBinPath = locateBinPath()
+ break;
+ case "system-path":
+ const which = require('which');
+ atestBinPath = process.platform === "win32" ? which.sync('atest.exe') : which.sync('atest')
+ break;
+ case "home-path":
+ atestBinPath = locateBinPath(false)
+ break;
}
- serverProcess = spawn(atestBinPath, [
- "server",
- `--http-port=${serverPort}`,
- "--port=0",
- `--download-timeout=${downloadTimeout}`,
- `--extension-registry=${extensionRegistry}`,
- "--local-storage", path.join(homeData, "*.yaml")
- ])
- serverProcess.stdout.on('data', (data) => {
- log.info(data.toString())
- if (data.toString().indexOf('Server is running') != -1) {
- BrowserWindow.getFocusedWindow().loadURL(server.getHomePage())
- }
- })
- serverProcess.stderr.on('data', (data) => {
- log.error(data.toString())
- })
- serverProcess.on('close', (code) => {
- log.log(`child process exited with code ${code}`);
- })
- log.info('start atest server as pid:', serverProcess.pid)
- log.info(serverProcess.spawnargs)
+ serverProcess = spawn(atestBinPath, [
+ "server",
+ `--http-port=${serverPort}`,
+ "--port=0",
+ `--download-timeout=${downloadTimeout}`,
+ `--extension-registry=${extensionRegistry}`,
+ "--local-storage", path.join(homeData, "*.yaml")
+ ])
+ serverProcess.stdout.on('data', (data) => {
+ log.info(data.toString())
+ if (data.toString().indexOf('Server is running') != -1) {
+ BrowserWindow.getFocusedWindow().loadURL(server.getHomePage())
+ }
+ })
+ serverProcess.stderr.on('data', (data) => {
+ log.error(data.toString())
+ })
+ serverProcess.on('close', (code) => {
+ log.log(`child process exited with code ${code}`);
+ })
+ log.info('start atest server as pid:', serverProcess.pid)
+ log.info(serverProcess.spawnargs)
}
-const locateBinPath = (overwrite = true) => {
+const locateBinPath = (overwrite = true) => {
+ const homeBin = path.join(atestHome, 'bin')
+
+ fs.mkdirSync(homeBin, {
+ recursive: true
+ })
+
// try to find the atest file first
const serverFile = process.platform === "win32" ? "atest.exe" : "atest"
const atestFromHome = path.join(homeBin, serverFile)
@@ -240,7 +241,7 @@ const locateBinPath = (overwrite = true) => {
const file = fs.openSync(atestFromHome, 'w');
fs.writeSync(file, data, 0, data.length, 0);
fs.closeSync(file);
- }else{
+ } else {
fs.writeFileSync(atestFromHome, data);
}
} catch (e) {
@@ -251,25 +252,25 @@ const locateBinPath = (overwrite = true) => {
}
const stopServer = () => {
- if (serverProcess) {
- serverProcess.kill()
- }
+ if (serverProcess) {
+ serverProcess.kill()
+ }
}
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
- if (process.platform !== 'darwin') {
- app.quit()
+ if (process.platform !== 'darwin') {
+ app.quit()
- stopServer()
- }
+ stopServer()
+ }
})
app.on('before-quit', stopServer)
function getLogLevel() {
- return 'info'
+ return 'info'
}
// In this file you can include the rest of your app's specific main process