Commit ca0e857
authored
Patch chromium flag endpoint (#77)
Here's a PR description for your changes:
---
## Add Dynamic Chromium Flags API & Refactor Restart Logic
This PR adds the ability to dynamically update Chromium launch flags at
runtime and consolidates duplicate code across the codebase.
### Changes
**New Feature:**
- Added `PATCH /chromium/flags` endpoint to update Chromium flags
dynamically without container restart
- Updated `run-docker.sh` to make flags file writable (removed `ro`
mount option)
- Set default to `--kiosk` mode for better fullscreen experience
**Code Refactoring:**
- Created `mergeAndWriteChromiumFlags()` helper to consolidate flag
merging logic (eliminates 52 lines of duplication)
- Created `restartChromiumAndWait()` helper to consolidate Chromium
restart logic (eliminates 62 lines of duplication)
- Removed duplicate `restartChromium()` function from `display.go`
- Updated display resolution handlers to use shared restart helper
**Benefits:**
- Single source of truth for Chromium restart and flag management
- Better logging with operation-specific context
- Consistent error handling across all Chromium operations
- ~100 lines of code reduction through DRY principles
### Testing
**E2E Tests:**
- Ran `TestExtensionUploadAndActivation` in `e2e_chromium_test.go` to
verify extension endpoint still works correctly
**Manual Testing:**
- Started Docker container with the updated image
- Called the new flags endpoint to enable kiosk mode:
```bash
curl -X PATCH http://localhost:444/chromium/flags \
-H "Content-Type: application/json" \
-d '{"flags": ["--kiosk"]}'
```
- Verified kiosk mode was successfully applied and Chromium restarted
with new flags
<img width="1512" height="860" alt="image"
src="https://github.com/user-attachments/assets/786f158a-4c79-4ae6-b7b8-102468ffd863"
/>
**Unit Tests:**
- Added `TestApiService_PatchChromiumFlags` to verify flag validation
and merging logic
- All existing tests pass
---
<!-- CURSOR_SUMMARY -->
> [!NOTE]
> Introduces a new PATCH /chromium/flags API and consolidates Chromium
flag merging and restart logic into shared helpers, updating extension
upload and display flows, with OpenAPI/client generation and a unit
test.
>
> - **API/OpenAPI**:
> - Add `PATCH /chromium/flags` endpoint (request: `{ flags: string[]
}`; responses: `200/400/500`).
> - Regenerate `oapi` client/server types, routing, and swagger spec for
the new endpoint.
> - **Backend**:
> - Implement `ApiService.PatchChromiumFlags` to validate, merge, write
flags, restart Chromium, and wait for DevTools.
> - Refactor into helpers: `mergeAndWriteChromiumFlags()` and
`restartChromiumAndWait()`.
> - Update `UploadExtensionsAndRestart` to use the new helpers and
improved logging.
> - Remove old `restartChromium()` from `display.go` and replace calls
with `restartChromiumAndWait()`.
> - **Tests**:
> - Add `TestApiService_PatchChromiumFlags` covering flag
validation/flow.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
ee0c0f3. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent a730519 commit ca0e857
File tree
5 files changed
+508
-142
lines changed- server
- cmd/api/api
- lib/oapi
5 files changed
+508
-142
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
173 | 201 | | |
| 202 | + | |
| 203 | + | |
174 | 204 | | |
175 | 205 | | |
176 | 206 | | |
177 | | - | |
| 207 | + | |
178 | 208 | | |
179 | 209 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
| 210 | + | |
185 | 211 | | |
186 | | - | |
| 212 | + | |
187 | 213 | | |
188 | 214 | | |
| 215 | + | |
189 | 216 | | |
190 | 217 | | |
191 | | - | |
| 218 | + | |
192 | 219 | | |
| 220 | + | |
193 | 221 | | |
194 | 222 | | |
195 | | - | |
196 | | - | |
| 223 | + | |
| 224 | + | |
197 | 225 | | |
198 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
199 | 237 | | |
200 | 238 | | |
201 | 239 | | |
202 | 240 | | |
203 | 241 | | |
204 | 242 | | |
205 | 243 | | |
206 | | - | |
| 244 | + | |
207 | 245 | | |
208 | 246 | | |
209 | 247 | | |
| |||
219 | 257 | | |
220 | 258 | | |
221 | 259 | | |
222 | | - | |
223 | | - | |
| 260 | + | |
| 261 | + | |
224 | 262 | | |
225 | | - | |
| 263 | + | |
226 | 264 | | |
227 | | - | |
228 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
229 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
230 | 316 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
| |||
99 | 98 | | |
100 | 99 | | |
101 | 100 | | |
102 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
| |||
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | 149 | | |
185 | 150 | | |
186 | 151 | | |
| |||
287 | 252 | | |
288 | 253 | | |
289 | 254 | | |
290 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
291 | 258 | | |
292 | 259 | | |
293 | 260 | | |
| |||
0 commit comments