Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions console/atest-desktop/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
<input name="download-timeout" id="download-timeout" type="text"/>
</td>
</tr>
<tr>
<td>
<label for="bin-location">Bin Location</label>
</td>
<td>
<input name="bin-location" id="bin-location" type="text"/>
</td>
</tr>
<tr>
<td>Log</td>
<td>
Expand Down Expand Up @@ -118,10 +126,16 @@
window.electronAPI.setDownloadTimeout(downloadTimeout.value)
});

const binLocation = document.getElementById('bin-location');
binLocation.addEventListener("input", function(e) {
window.electronAPI.setBinLocation(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()

document.getElementById('address').innerText = await window.electronAPI.getHomePage();
})();
Expand Down
67 changes: 47 additions & 20 deletions console/atest-desktop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ let serverProcess;
let serverPort = 7788;
let extensionRegistry = "ghcr.io";
let downloadTimeout = "1m";
let mainProcessLocation = "built-in";

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
Expand Down Expand Up @@ -156,6 +157,12 @@ app.whenReady().then(() => {
})
ipcMain.handle('getHomePage', server.getHomePage)
ipcMain.handle('getHealthzUrl', server.getHealthzUrl)
ipcMain.handle('getMainProcessLocation', () => {
return mainProcessLocation
})
ipcMain.handle('setMainProcessLocation', (e, location) => {
mainProcessLocation = location
})

startServer()
createWindow()
Expand All @@ -178,28 +185,21 @@ const startServer = () => {
recursive: true
})

// try to find the atest file first
const serverFile = process.platform === "win32" ? "atest.exe" : "atest"
const atestFromHome = path.join(homeBin, serverFile)
const atestFromPkg = path.join(__dirname, serverFile)

const data = fs.readFileSync(atestFromPkg)
log.info('start to write file with length', data.length)

try {
if (process.platform === "win32") {
const file = fs.openSync(atestFromHome, 'w');
fs.writeSync(file, data, 0, data.length, 0);
fs.closeSync(file);
}else{
fs.writeFileSync(atestFromHome, data);
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;
}
} catch (e) {
log.error('Error Code:', e.code);
}
fs.chmodSync(atestFromHome, 0o755);

serverProcess = spawn(atestFromHome, [
serverProcess = spawn(atestBinPath, [
"server",
`--http-port=${serverPort}`,
"--port=0",
Expand All @@ -223,6 +223,33 @@ const startServer = () => {
log.info(serverProcess.spawnargs)
}

const locateBinPath = (overwrite = true) => {
// try to find the atest file first
const serverFile = process.platform === "win32" ? "atest.exe" : "atest"
const atestFromHome = path.join(homeBin, serverFile)
if (!overwrite) {
return atestFromHome
}

const atestFromPkg = path.join(__dirname, serverFile)
const data = fs.readFileSync(atestFromPkg)
log.info('start to write file with length', data.length)

try {
if (process.platform === "win32") {
const file = fs.openSync(atestFromHome, 'w');
fs.writeSync(file, data, 0, data.length, 0);
fs.closeSync(file);
}else{
fs.writeFileSync(atestFromHome, data);
}
} catch (e) {
log.error('Error Code:', e.code);
}
fs.chmodSync(atestFromHome, 0o755);
return atestFromHome
}

const stopServer = () => {
if (serverProcess) {
serverProcess.kill()
Expand Down
6 changes: 4 additions & 2 deletions console/atest-desktop/preload.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2024 API Testing Authors.
Copyright 2024-2025 API Testing Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,6 +41,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
setExtensionRegistry: (registry) => ipcRenderer.invoke('setExtensionRegistry', registry),
getExtensionRegistry: () => ipcRenderer.invoke('getExtensionRegistry'),
getDownloadTimeout: () => ipcRenderer.invoke('getDownloadTimeout'),
setDownloadTimeout: (timeout) => ipcRenderer.invoke('setDownloadTimeout', timeout),
setDownloadTimeout: (e) => ipcRenderer.invoke('setDownloadTimeout', e),
getMainProcessLocation: () => ipcRenderer.invoke('getMainProcessLocation'),
setMainProcessLocation: (e) => ipcRenderer.invoke('setMainProcessLocation', e),
getHealthzUrl: () => ipcRenderer.invoke('getHealthzUrl'),
})
Loading