Skip to content

Commit e66fd4a

Browse files
authored
feat: support set the atest server arguments (#750)
* feat: support to set the server arguments on desktop * test pass for setting extension registry * support to open server on the external broswer --------- Co-authored-by: rick <[email protected]>
1 parent 59e3ce9 commit e66fd4a

File tree

5 files changed

+119
-18
lines changed

5 files changed

+119
-18
lines changed

console/atest-desktop/index.html

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,51 @@
99
</head>
1010
<body>
1111

12-
<div style="margin: 5px">
12+
<div style="margin: 5px; display: flex; justify-content: center">
1313
<div>
1414
<div>Server Status</div>
15-
<button type="button" id="action">Start</button>
16-
<button type="button" id="open-server-page">Open Server Page</button>
17-
<div>
18-
<span>Port:</span><input name="port" id="port" type="text"/>
19-
</div>
20-
</div>
21-
22-
<div>
23-
<div>Log</div>
24-
<button type="button" id="open-log-file">Open Log File</button>
15+
<div id="address"></div>
16+
<table>
17+
<tr>
18+
<td>
19+
<label for="port">Port</label>
20+
</td>
21+
<td>
22+
<input name="port" id="port" type="text"/>
23+
</td>
24+
</tr>
25+
<tr>
26+
<td>
27+
<label for="extension-registry">Extension Registry</label>
28+
</td>
29+
<td>
30+
<input name="extension-registry" id="extension-registry" type="text"/>
31+
</td>
32+
</tr>
33+
<tr>
34+
<td>
35+
<label for="download-timeout">Download timeout</label>
36+
</td>
37+
<td>
38+
<input name="download-timeout" id="download-timeout" type="text"/>
39+
</td>
40+
</tr>
41+
<tr>
42+
<td>Log</td>
43+
<td>
44+
<button type="button" id="open-log-file">Open Log File</button>
45+
</td>
46+
</tr>
47+
<tr>
48+
<td>
49+
<button type="button" id="action">Start</button>
50+
</td>
51+
<td>
52+
<button type="button" id="open-server-page">Open Server Page</button>
53+
<button type="button" id="open-from-browser">Open from Browser</button>
54+
</td>
55+
</tr>
56+
</table>
2557
</div>
2658
</div>
2759

@@ -39,6 +71,15 @@
3971
}
4072
})
4173

74+
document.getElementById('open-from-browser').addEventListener('click', async (e) => {
75+
const address = await window.electronAPI.getHomePage();
76+
if (address) {
77+
await window.electronAPI.openWithExternalBrowser(address);
78+
} else {
79+
alert('Please start the server first!');
80+
}
81+
})
82+
4283
const openServerBut = document.getElementById('open-server-page');
4384
openServerBut.addEventListener('click', async (e) => {
4485
window.location = await window.electronAPI.getHomePage()
@@ -63,9 +104,27 @@
63104
window.setInterval(loadServerStatus, 2000)
64105

65106
const portInput = document.getElementById('port');
107+
portInput.addEventListener("input", function(e) {
108+
window.electronAPI.setPort(portInput.value)
109+
});
110+
111+
const extensionRegistry = document.getElementById('extension-registry');
112+
extensionRegistry.addEventListener("input", function(e) {
113+
window.electronAPI.setExtensionRegistry(extensionRegistry.value)
114+
});
115+
116+
const downloadTimeout = document.getElementById('download-timeout');
117+
downloadTimeout.addEventListener("input", function(e) {
118+
window.electronAPI.setDownloadTimeout(downloadTimeout.value)
119+
});
120+
66121
(async function() {
67122
portInput.value = await window.electronAPI.getPort()
123+
extensionRegistry.value = await window.electronAPI.getExtensionRegistry()
124+
downloadTimeout.value = await window.electronAPI.getDownloadTimeout()
125+
126+
document.getElementById('address').innerText = await window.electronAPI.getHomePage();
68127
})();
69128
</script>
70129
</body>
71-
</html>
130+
</html>

console/atest-desktop/main.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2024 API Testing Authors.
2+
Copyright 2024-2025 API Testing Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -117,22 +117,44 @@ menu.append(new MenuItem({
117117
Menu.setApplicationMenu(menu)
118118

119119
let serverProcess;
120+
let serverPort = 7788;
121+
let extensionRegistry = "ghcr.io";
122+
let downloadTimeout = "1m";
123+
120124
// This method will be called when Electron has finished
121125
// initialization and is ready to create browser windows.
122126
// Some APIs can only be used after this event occurs.
123127
app.whenReady().then(() => {
124128
ipcMain.on('openLogDir', () => {
125129
shell.openExternal('file://' + server.getLogfile())
126130
})
131+
ipcMain.handle('openWithExternalBrowser', (e, address) => {
132+
shell.openExternal(address)
133+
})
127134
ipcMain.on('startServer', startServer)
128135
ipcMain.on('stopServer', stopServer)
129136
ipcMain.on('control', (e, okCallback, errCallback) => {
130137
server.control(okCallback, errCallback)
131138
})
132-
ipcMain.handle('getHomePage', server.getHomePage)
133139
ipcMain.handle('getPort', () => {
134-
return server.getPort()
140+
return serverPort
141+
})
142+
ipcMain.handle('setPort', (e, port) => {
143+
serverPort = port;
144+
})
145+
ipcMain.handle('getExtensionRegistry', () => {
146+
return extensionRegistry
135147
})
148+
ipcMain.handle('setExtensionRegistry', (e, registry) => {
149+
extensionRegistry = registry
150+
})
151+
ipcMain.handle('getDownloadTimeout', () => {
152+
return downloadTimeout
153+
})
154+
ipcMain.handle('setDownloadTimeout', (e, timeout) => {
155+
downloadTimeout = timeout
156+
})
157+
ipcMain.handle('getHomePage', server.getHomePage)
136158
ipcMain.handle('getHealthzUrl', server.getHealthzUrl)
137159

138160
startServer()
@@ -179,8 +201,10 @@ const startServer = () => {
179201

180202
serverProcess = spawn(atestFromHome, [
181203
"server",
182-
"--http-port", server.getPort(),
204+
`--http-port=${serverPort}`,
183205
"--port=0",
206+
`--download-timeout=${downloadTimeout}`,
207+
`--extension-registry=${extensionRegistry}`,
184208
"--local-storage", path.join(homeData, "*.yaml")
185209
])
186210
serverProcess.stdout.on('data', (data) => {
@@ -222,4 +246,4 @@ function getLogLevel() {
222246
}
223247

224248
// In this file you can include the rest of your app's specific main process
225-
// code. You can also put them in separate files and require them here.
249+
// code. You can also put them in separate files and require them here.

console/atest-desktop/preload.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,16 @@ window.addEventListener('DOMContentLoaded', () => {
3131

3232
contextBridge.exposeInMainWorld('electronAPI', {
3333
openLogDir: () => ipcRenderer.send('openLogDir'),
34+
openWithExternalBrowser: (address) => ipcRenderer.invoke('openWithExternalBrowser', address),
3435
startServer: () => ipcRenderer.send('startServer'),
3536
stopServer: () => ipcRenderer.send('stopServer'),
3637
control: (okCallback, errCallback) => ipcRenderer.send('control', okCallback, errCallback),
3738
getHomePage: () => ipcRenderer.invoke('getHomePage'),
3839
getPort: () => ipcRenderer.invoke('getPort'),
40+
setPort: (port) => ipcRenderer.invoke('setPort', port),
41+
setExtensionRegistry: (registry) => ipcRenderer.invoke('setExtensionRegistry', registry),
42+
getExtensionRegistry: () => ipcRenderer.invoke('getExtensionRegistry'),
43+
getDownloadTimeout: () => ipcRenderer.invoke('getDownloadTimeout'),
44+
setDownloadTimeout: (timeout) => ipcRenderer.invoke('setDownloadTimeout', timeout),
3945
getHealthzUrl: () => ipcRenderer.invoke('getHealthzUrl'),
4046
})

pkg/server/store_ext_manager.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,24 @@ func (s *storeExtManager) StopAll() error {
160160
serverLogger.Info("stop", "extensions", len(s.processs))
161161
for _, p := range s.processs {
162162
if p != nil {
163-
p.Signal(syscall.SIGTERM)
163+
// Use Kill on Windows, Signal on other platforms
164+
if isWindows() {
165+
p.Kill()
166+
} else {
167+
p.Signal(syscall.SIGTERM)
168+
}
164169
}
165170
}
166171
s.stopSingal <- struct{}{}
167172
return nil
168173
}
169174

175+
// isWindows returns true if the program is running on Windows OS.
176+
func isWindows() bool {
177+
return strings.Contains(strings.ToLower(os.Getenv("OS")), "windows") ||
178+
(strings.Contains(strings.ToLower(os.Getenv("GOOS")), "windows"))
179+
}
180+
170181
func (s *storeExtManager) WithDownloader(ociDownloader downloader.PlatformAwareOCIDownloader) {
171182
s.ociDownloader = ociDownloader
172183
}

pkg/server/store_ext_manager_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func TestStoreExtManager(t *testing.T) {
4444
err = mgr.Start("go", "")
4545
assert.NoError(t, err)
4646

47+
time.Sleep(time.Microsecond * 100)
4748
err = mgr.StopAll()
4849
assert.NoError(t, err)
4950
})

0 commit comments

Comments
 (0)