Skip to content

Commit 6650d88

Browse files
committed
feat: Add option for auto-starting the container to Configuration
chore: Minor refactors
1 parent a4090e1 commit 6650d88

3 files changed

Lines changed: 72 additions & 22 deletions

File tree

src/renderer/lib/constants.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,10 @@ export const USB_INTERFACE_MTP = 5;
6666
export const USB_VID_BLACKLIST = [
6767
// Linux Foundation VID
6868
"1d6b:"
69-
];
69+
];
70+
71+
// Docker Restart Policies
72+
export const RESTART_UNLESS_STOPPED = "unless-stopped";
73+
export const RESTART_ON_FAILURE = "on-failure";
74+
export const RESTART_ALWAYS = "always";
75+
export const RESTART_NO = "no";

src/renderer/lib/install.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type ComposeConfig, type InstallConfiguration } from "../../types";
2-
import { WINBOAT_DIR, WINBOAT_GUEST_API } from "./constants";
2+
import { RESTART_ON_FAILURE, WINBOAT_DIR, WINBOAT_GUEST_API } from "./constants";
33
import YAML from "json-to-pretty-yaml";
44
import { createLogger } from "../utils/log";
55
import { createNanoEvents, type Emitter } from "nanoevents";
@@ -47,7 +47,7 @@ export const DefaultCompose: ComposeConfig = {
4747
"3389:3389/udp" // RDP
4848
],
4949
"stop_grace_period": "120s",
50-
"restart": "on-failure",
50+
"restart": RESTART_ON_FAILURE,
5151
"volumes": [
5252
"data:/storage",
5353
"${HOME}:/shared",

src/renderer/views/Config.vue

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<template>
22
<div class="flex flex-col gap-10 overflow-x-hidden" :class="{ 'hidden': !maxNumCores }">
33
<div>
4-
<x-label class="mb-4 text-neutral-300">Resources</x-label>
4+
<x-label class="mb-4 text-neutral-300">Container</x-label>
55
<div class="flex flex-col gap-4">
6+
<!-- RAM Allocation -->
67
<x-card
78
class="flex flex-row justify-between items-center p-2 py-3 my-0 w-full backdrop-blur-xl backdrop-brightness-150 bg-neutral-800/20">
89
<div>
@@ -28,6 +29,8 @@
2829
<p class="text-neutral-100">GB</p>
2930
</div>
3031
</x-card>
32+
33+
<!-- CPU Cores -->
3134
<x-card
3235
class="flex flex-row justify-between items-center p-2 py-3 my-0 w-full backdrop-blur-xl backdrop-brightness-150 bg-neutral-800/20">
3336
<div>
@@ -53,6 +56,8 @@
5356
<p class="text-neutral-100">Cores</p>
5457
</div>
5558
</x-card>
59+
60+
<!-- Shared Home Folder -->
5661
<x-card class="flex relative z-20 flex-row justify-between items-center p-2 py-3 my-0 w-full backdrop-blur-xl backdrop-brightness-150 bg-neutral-800/20">
5762
<div>
5863
<div class="flex flex-row items-center gap-2 mb-2">
@@ -74,6 +79,30 @@
7479
></x-switch>
7580
</div>
7681
</x-card>
82+
83+
<!-- Auto Start Container -->
84+
<x-card class="flex relative z-20 flex-row justify-between items-center p-2 py-3 my-0 w-full backdrop-blur-xl backdrop-brightness-150 bg-neutral-800/20">
85+
<div>
86+
<div class="flex flex-row items-center gap-2 mb-2">
87+
<Icon class="text-violet-400 inline-flex size-8" icon="clarity:power-solid"></Icon>
88+
<h1 class="text-lg my-0 font-semibold">
89+
Auto Start Container
90+
</h1>
91+
</div>
92+
<p class="text-neutral-400 text-[0.9rem] !pt-0 !mt-0">
93+
If enabled, the Windows container will automatically be started when the system boots up
94+
</p>
95+
</div>
96+
<div class="flex flex-row justify-center items-center gap-2">
97+
<x-switch
98+
:toggled="autoStartContainer"
99+
@toggle="(_: any) => autoStartContainer = !autoStartContainer"
100+
size="large"
101+
></x-switch>
102+
</div>
103+
</x-card>
104+
105+
<!-- FreeRDP Port -->
77106
<x-card
78107
class="flex items-center p-2 flex-row justify-between w-full py-3 my-0 bg-neutral-800/20 backdrop-brightness-150 backdrop-blur-xl">
79108
<div>
@@ -105,7 +134,7 @@
105134
</div>
106135
<x-button
107136
:disabled="saveButtonDisabled || isUpdatingUSBPrerequisites"
108-
@click="applyChanges()"
137+
@click="saveDockerCompose()"
109138
class="w-24"
110139
>
111140
<span v-if="!isApplyingChanges || isUpdatingUSBPrerequisites">Save</span>
@@ -116,6 +145,7 @@
116145
<div v-show="wbConfig.config.experimentalFeatures" :key="rerenderExperimental">
117146
<x-label class="mb-4 text-neutral-300">Devices</x-label>
118147
<div class="flex flex-col gap-4">
148+
<!-- USB Passthrough -->
119149
<x-card class="flex relative z-20 flex-row justify-between items-center p-2 py-3 my-0 w-full backdrop-blur-xl backdrop-brightness-150 bg-neutral-800/20">
120150
<div class="w-full">
121151
<div class="flex flex-row gap-2 items-center mb-2">
@@ -227,6 +257,7 @@
227257
<div>
228258
<x-label class="mb-4 text-neutral-300">General</x-label>
229259
<div class="flex flex-col gap-4">
260+
<!-- Display Scaling -->
230261
<x-card
231262
class="flex relative z-10 flex-row justify-between items-center p-2 py-3 my-0 w-full backdrop-blur-xl backdrop-brightness-150 bg-neutral-800/20">
232263
<div>
@@ -258,6 +289,8 @@
258289
</x-select>
259290
</div>
260291
</x-card>
292+
293+
<!-- Smartcard Passthrough -->
261294
<x-card
262295
class="flex flex-row justify-between items-center p-2 py-3 my-0 w-full backdrop-blur-xl backdrop-brightness-150 bg-neutral-800/20">
263296
<div>
@@ -279,6 +312,8 @@
279312
></x-switch>
280313
</div>
281314
</x-card>
315+
316+
<!-- RDP Monitoring -->
282317
<x-card
283318
class="flex flex-row justify-between items-center p-2 py-3 my-0 w-full backdrop-blur-xl backdrop-brightness-150 bg-neutral-800/20">
284319
<div>
@@ -305,6 +340,8 @@
305340

306341
<div>
307342
<x-label class="mb-4 text-neutral-300">WinBoat</x-label>
343+
344+
<!-- Experimental Features -->
308345
<x-card
309346
class="flex items-center p-2 flex-row justify-between w-full py-3 my-0 bg-neutral-800/20 backdrop-brightness-150 backdrop-blur-xl">
310347
<div>
@@ -367,7 +404,9 @@ import { type Device } from "usb";
367404
import {
368405
RDP_PORT,
369406
PORT_MAX,
370-
USB_VID_BLACKLIST
407+
USB_VID_BLACKLIST,
408+
RESTART_ON_FAILURE,
409+
RESTART_NO
371410
} from '../lib/constants';
372411
const { app }: typeof import('@electron/remote') = require('@electron/remote');
373412
@@ -393,6 +432,8 @@ const origRamGB = ref(0);
393432
const maxRamGB = ref(0);
394433
const origShareHomeFolder = ref(false);
395434
const shareHomeFolder = ref(false);
435+
const origAutoStartContainer = ref(false);
436+
const autoStartContainer = ref(false);
396437
const freerdpPort = ref(0);
397438
const origFreerdpPort = ref(0);
398439
const isApplyingChanges = ref(false);
@@ -413,6 +454,10 @@ onMounted(async () => {
413454
await assignValues();
414455
});
415456
457+
/**
458+
* Assigns the initial values from the Docker Compose file to the reactive refs
459+
* so we can display them and track when a change has been made
460+
*/
416461
async function assignValues() {
417462
compose.value = winboat.parseCompose();
418463
@@ -425,6 +470,9 @@ async function assignValues() {
425470
shareHomeFolder.value = compose.value.services.windows.volumes.includes(HOMEFOLDER_SHARE_STR);
426471
origShareHomeFolder.value = shareHomeFolder.value;
427472
473+
autoStartContainer.value = compose.value.services.windows.restart === RESTART_ON_FAILURE;
474+
origAutoStartContainer.value = autoStartContainer.value;
475+
428476
const rdpEntry = compose.value.services.windows.ports.find(x => x.includes(`:${RDP_PORT}`))
429477
freerdpPort.value = Number(rdpEntry?.split(":")?.at(0) ?? RDP_PORT);
430478
origFreerdpPort.value = freerdpPort.value;
@@ -436,6 +484,10 @@ async function assignValues() {
436484
refreshAvailableDevices();
437485
}
438486
487+
/**
488+
* Saves the currently specified values to the Docker Compose file
489+
* and then re-assigns the initial values to the reactive refs
490+
*/
439491
async function saveDockerCompose() {
440492
compose.value!.services.windows.environment.RAM_SIZE = `${ramGB.value}G`;
441493
compose.value!.services.windows.environment.CPU_CORES = `${numCores.value}`;
@@ -448,6 +500,8 @@ async function saveDockerCompose() {
448500
compose.value!.services.windows.volumes = compose.value!.services.windows.volumes.filter(v => v !== HOMEFOLDER_SHARE_STR);
449501
}
450502
503+
compose.value!.services.windows.restart = autoStartContainer.value ? RESTART_ON_FAILURE : RESTART_NO;
504+
451505
const newPortEntries = compose.value!.services.windows.ports.filter(x => !x.includes(`:${RDP_PORT}`));
452506
453507
newPortEntries.push(`${freerdpPort.value}:${RDP_PORT}/tcp`);
@@ -466,21 +520,10 @@ async function saveDockerCompose() {
466520
}
467521
}
468522
469-
async function applyChanges() {
470-
compose.value!.services.windows.environment.RAM_SIZE = `${ramGB.value}G`;
471-
compose.value!.services.windows.environment.CPU_CORES = `${numCores.value}`;
472-
473-
const composeHasHomefolderShare = compose.value!.services.windows.volumes.includes(HOMEFOLDER_SHARE_STR);
474-
475-
if (shareHomeFolder.value && !composeHasHomefolderShare) {
476-
compose.value!.services.windows.volumes.push(HOMEFOLDER_SHARE_STR);
477-
} else if (!shareHomeFolder.value && composeHasHomefolderShare) {
478-
compose.value!.services.windows.volumes = compose.value!.services.windows.volumes.filter(v => v !== HOMEFOLDER_SHARE_STR);
479-
}
480-
481-
await saveDockerCompose();
482-
}
483-
523+
/**
524+
* Adds the required fields for USB passthrough to work
525+
* to the Docker Compose file if they don't already exist
526+
*/
484527
async function addRequiredComposeFieldsUSB() {
485528
if (!usbPassthroughDisabled.value) {
486529
return;
@@ -551,7 +594,8 @@ const saveButtonDisabled = computed(() => {
551594
origNumCores.value !== numCores.value ||
552595
origRamGB.value !== ramGB.value ||
553596
shareHomeFolder.value !== origShareHomeFolder.value ||
554-
freerdpPort.value !== origFreerdpPort.value;
597+
freerdpPort.value !== origFreerdpPort.value ||
598+
autoStartContainer.value !== origAutoStartContainer.value;
555599
556600
const shouldBeDisabled =
557601
errors.value.length ||

0 commit comments

Comments
 (0)