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
83 changes: 71 additions & 12 deletions console/atest-desktop/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,51 @@
</head>
<body>

<div style="margin: 5px">
<div style="margin: 5px; display: flex; justify-content: center">
<div>
<div>Server Status</div>
<button type="button" id="action">Start</button>
<button type="button" id="open-server-page">Open Server Page</button>
<div>
<span>Port:</span><input name="port" id="port" type="text"/>
</div>
</div>

<div>
<div>Log</div>
<button type="button" id="open-log-file">Open Log File</button>
<div id="address"></div>
<table>
<tr>
<td>
<label for="port">Port</label>
</td>
<td>
<input name="port" id="port" type="text"/>
</td>
</tr>
<tr>
<td>
<label for="extension-registry">Extension Registry</label>
</td>
<td>
<input name="extension-registry" id="extension-registry" type="text"/>
</td>
</tr>
<tr>
<td>
<label for="download-timeout">Download timeout</label>
</td>
<td>
<input name="download-timeout" id="download-timeout" type="text"/>
</td>
</tr>
<tr>
<td>Log</td>
<td>
<button type="button" id="open-log-file">Open Log File</button>
</td>
</tr>
<tr>
<td>
<button type="button" id="action">Start</button>
</td>
<td>
<button type="button" id="open-server-page">Open Server Page</button>
<button type="button" id="open-from-browser">Open from Browser</button>
</td>
</tr>
</table>
</div>
</div>

Expand All @@ -39,6 +71,15 @@
}
})

document.getElementById('open-from-browser').addEventListener('click', async (e) => {
const address = await window.electronAPI.getHomePage();
if (address) {
await window.electronAPI.openWithExternalBrowser(address);
} else {
alert('Please start the server first!');
}
})

const openServerBut = document.getElementById('open-server-page');
openServerBut.addEventListener('click', async (e) => {
window.location = await window.electronAPI.getHomePage()
Expand All @@ -63,9 +104,27 @@
window.setInterval(loadServerStatus, 2000)

const portInput = document.getElementById('port');
portInput.addEventListener("input", function(e) {
window.electronAPI.setPort(portInput.value)
});

const extensionRegistry = document.getElementById('extension-registry');
extensionRegistry.addEventListener("input", function(e) {
window.electronAPI.setExtensionRegistry(extensionRegistry.value)
});

const downloadTimeout = document.getElementById('download-timeout');
downloadTimeout.addEventListener("input", function(e) {
window.electronAPI.setDownloadTimeout(downloadTimeout.value)
});

(async function() {
portInput.value = await window.electronAPI.getPort()
extensionRegistry.value = await window.electronAPI.getExtensionRegistry()
downloadTimeout.value = await window.electronAPI.getDownloadTimeout()

document.getElementById('address').innerText = await window.electronAPI.getHomePage();
})();
</script>
</body>
</html>
</html>
34 changes: 29 additions & 5 deletions console/atest-desktop/main.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 @@ -117,22 +117,44 @@ menu.append(new MenuItem({
Menu.setApplicationMenu(menu)

let serverProcess;
let serverPort = 7788;
let extensionRegistry = "ghcr.io";
let downloadTimeout = "1m";

// 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.
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('getHomePage', server.getHomePage)
ipcMain.handle('getPort', () => {
return server.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)

startServer()
Expand Down Expand Up @@ -179,8 +201,10 @@ const startServer = () => {

serverProcess = spawn(atestFromHome, [
"server",
"--http-port", server.getPort(),
`--http-port=${serverPort}`,
"--port=0",
`--download-timeout=${downloadTimeout}`,
`--extension-registry=${extensionRegistry}`,
"--local-storage", path.join(homeData, "*.yaml")
])
serverProcess.stdout.on('data', (data) => {
Expand Down Expand Up @@ -222,4 +246,4 @@ function getLogLevel() {
}

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
// code. You can also put them in separate files and require them here.
6 changes: 6 additions & 0 deletions console/atest-desktop/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ window.addEventListener('DOMContentLoaded', () => {

contextBridge.exposeInMainWorld('electronAPI', {
openLogDir: () => ipcRenderer.send('openLogDir'),
openWithExternalBrowser: (address) => ipcRenderer.invoke('openWithExternalBrowser', address),
startServer: () => ipcRenderer.send('startServer'),
stopServer: () => ipcRenderer.send('stopServer'),
control: (okCallback, errCallback) => ipcRenderer.send('control', okCallback, errCallback),
getHomePage: () => ipcRenderer.invoke('getHomePage'),
getPort: () => ipcRenderer.invoke('getPort'),
setPort: (port) => ipcRenderer.invoke('setPort', port),
setExtensionRegistry: (registry) => ipcRenderer.invoke('setExtensionRegistry', registry),
getExtensionRegistry: () => ipcRenderer.invoke('getExtensionRegistry'),
getDownloadTimeout: () => ipcRenderer.invoke('getDownloadTimeout'),
setDownloadTimeout: (timeout) => ipcRenderer.invoke('setDownloadTimeout', timeout),
getHealthzUrl: () => ipcRenderer.invoke('getHealthzUrl'),
})
13 changes: 12 additions & 1 deletion pkg/server/store_ext_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,24 @@ func (s *storeExtManager) StopAll() error {
serverLogger.Info("stop", "extensions", len(s.processs))
for _, p := range s.processs {
if p != nil {
p.Signal(syscall.SIGTERM)
// Use Kill on Windows, Signal on other platforms
if isWindows() {
p.Kill()
} else {
p.Signal(syscall.SIGTERM)
}
}
}
s.stopSingal <- struct{}{}
return nil
}

// isWindows returns true if the program is running on Windows OS.
func isWindows() bool {
return strings.Contains(strings.ToLower(os.Getenv("OS")), "windows") ||
(strings.Contains(strings.ToLower(os.Getenv("GOOS")), "windows"))
}

func (s *storeExtManager) WithDownloader(ociDownloader downloader.PlatformAwareOCIDownloader) {
s.ociDownloader = ociDownloader
}
Expand Down
1 change: 1 addition & 0 deletions pkg/server/store_ext_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestStoreExtManager(t *testing.T) {
err = mgr.Start("go", "")
assert.NoError(t, err)

time.Sleep(time.Microsecond * 100)
err = mgr.StopAll()
assert.NoError(t, err)
})
Expand Down
Loading