Skip to content

Commit 0542e3a

Browse files
committed
chore: Make 'readConfig' and 'parseCompose' static
chore: Naming change 'readConfig' -> 'readConfigObject' chore: Naming change 'parseCompose' -> 'readCompose' fix: Add spacing between 'Experimental Features' and 'Advanced Settings'
1 parent 0728f4b commit 0542e3a

File tree

6 files changed

+73
-70
lines changed

6 files changed

+73
-70
lines changed

src/renderer/lib/config.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ const defaultConfig: WinboatConfigObj = {
4242
};
4343

4444
export class WinboatConfig {
45+
private static readonly configPath: string = path.join(WINBOAT_DIR, "winboat.config.json");
4546
private static instance: WinboatConfig | null = null;
46-
readonly #configPath: string = path.join(WINBOAT_DIR, "winboat.config.json");
4747
#configData: WinboatConfigObj = { ...defaultConfig };
4848

4949
static getInstance() {
5050
WinboatConfig.instance ??= new WinboatConfig();
5151
return WinboatConfig.instance;
5252
}
5353

54-
constructor() {
55-
this.#configData = this.readConfig()!;
54+
private constructor() {
55+
this.#configData = WinboatConfig.readConfigObject()!;
5656
console.log("Reading current config", this.#configData);
5757
}
5858

@@ -63,7 +63,7 @@ export class WinboatConfig {
6363
set: (target, key, value) => {
6464
// @ts-expect-error This is valid
6565
target[key as keyof WinboatConfigObj] = value;
66-
this.writeConfig();
66+
WinboatConfig.writeConfigObject(target);
6767
console.info("Wrote modified config to disk");
6868
return true;
6969
},
@@ -72,29 +72,29 @@ export class WinboatConfig {
7272

7373
set config(newConfig: WinboatConfigObj) {
7474
this.#configData = { ...newConfig };
75-
this.writeConfig();
75+
WinboatConfig.writeConfigObject(newConfig);
7676
console.info("Wrote modified config to disk");
7777
}
7878

79-
writeConfig(): void {
80-
console.log("writing data: ", this.#configData);
81-
fs.writeFileSync(this.#configPath, JSON.stringify(this.#configData, null, 4), "utf-8");
79+
static writeConfigObject(configObj: WinboatConfigObj): void {
80+
console.log("writing data: ", configObj);
81+
fs.writeFileSync(WinboatConfig.configPath, JSON.stringify(configObj, null, 4), "utf-8");
8282
}
8383

84-
readConfig(writeDefault = true): WinboatConfigObj | null {
85-
if (!fs.existsSync(this.#configPath)) {
84+
static readConfigObject(writeDefault = true): WinboatConfigObj | null {
85+
if (!fs.existsSync(WinboatConfig.configPath)) {
8686
if (!writeDefault) return null;
8787
// Also the create the directory because we're not guaranteed to have it
8888
if (!fs.existsSync(WINBOAT_DIR)) {
8989
fs.mkdirSync(WINBOAT_DIR);
9090
}
9191

92-
fs.writeFileSync(this.#configPath, JSON.stringify(defaultConfig, null, 4), "utf-8");
92+
fs.writeFileSync(WinboatConfig.configPath, JSON.stringify(defaultConfig, null, 4), "utf-8");
9393
return { ...defaultConfig };
9494
}
9595

9696
try {
97-
const rawConfig = fs.readFileSync(this.#configPath, "utf-8");
97+
const rawConfig = fs.readFileSync(WinboatConfig.configPath, "utf-8");
9898
const configObj = JSON.parse(rawConfig) as WinboatConfigObj;
9999
console.log("Successfully read the config file");
100100

@@ -115,7 +115,7 @@ export class WinboatConfig {
115115
// If we have any missing keys, we should just write the config back to disk so those new keys are saved
116116
// We cannot use this.writeConfig() here since #configData is not populated yet
117117
if (hasMissing) {
118-
fs.writeFileSync(this.#configPath, JSON.stringify(configObj, null, 4), "utf-8");
118+
fs.writeFileSync(WinboatConfig.configPath, JSON.stringify(configObj, null, 4), "utf-8");
119119
console.log("Wrote updated config with missing keys to disk");
120120
}
121121
}

src/renderer/lib/install.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,14 @@ export class InstallManager {
259259
logger.info("WinBoat Guest Server is up and healthy!");
260260
this.changeState(InstallStates.COMPLETED);
261261

262-
const winboat = Winboat.getInstance();
263-
const config = winboat.parseCompose();
264-
const filteredVolumes = config.services.windows.volumes.filter(
262+
const compose = Winboat.readCompose(this.container.composeFilePath);
263+
const filteredVolumes = compose.services.windows.volumes.filter(
265264
volume => !volume.endsWith("/boot.iso"),
266265
);
267266

268-
if (config.services.windows.volumes.length !== filteredVolumes.length) {
269-
config.services.windows.volumes = filteredVolumes;
270-
await winboat.replaceCompose(config, false);
267+
if (compose.services.windows.volumes.length !== filteredVolumes.length) {
268+
compose.services.windows.volumes = filteredVolumes;
269+
await this.container.writeCompose(compose);
271270
}
272271

273272
return;
@@ -311,8 +310,7 @@ export class InstallManager {
311310

312311
export async function isInstalled(): Promise<boolean> {
313312
// Check if a winboat container exists
314-
const configInstance = new WinboatConfig();
315-
const config = configInstance.readConfig();
313+
const config = WinboatConfig.readConfigObject();
316314

317315
if (!config) return false;
318316

src/renderer/lib/winboat.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,14 @@ export class Winboat {
426426
return status.rdpConnected;
427427
}
428428

429-
parseCompose() {
430-
const composeFile = fs.readFileSync(this.containerMgr!.composeFilePath, "utf-8");
429+
static readCompose(composePath: string): ComposeConfig {
430+
const composeFile = fs.readFileSync(composePath, "utf-8");
431431
const composeContents = YAML.parse(composeFile) as ComposeConfig;
432432
return composeContents;
433433
}
434434

435435
getCredentials() {
436-
const compose = this.parseCompose();
436+
const compose = Winboat.readCompose(this.containerMgr!.composeFilePath);
437437
return {
438438
username: compose.services.windows.environment.USERNAME,
439439
password: compose.services.windows.environment.PASSWORD,
@@ -572,7 +572,7 @@ export class Winboat {
572572
console.info("Removed container");
573573

574574
// 3. Remove the container volume or folder
575-
const compose = this.parseCompose();
575+
const compose = Winboat.readCompose(this.containerMgr!.composeFilePath);
576576
const storage = compose.services.windows.volumes.find(vol => vol.includes("/storage"));
577577
if (storage?.startsWith("data:")) {
578578
if (this.#wbConfig?.config.containerRuntime !== ContainerRuntimes.DOCKER) {

src/renderer/views/Config.vue

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@
390390
</div>
391391
</x-card>
392392

393+
<!-- Application Scaling -->
393394
<x-card
394395
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"
395396
>
@@ -544,51 +545,55 @@
544545
<div>
545546
<x-label class="mb-4 text-neutral-300">WinBoat</x-label>
546547

547-
<!-- Experimental Features -->
548-
<x-card
549-
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"
550-
>
551-
<div>
552-
<div class="flex flex-row items-center gap-2 mb-2">
553-
<Icon
554-
class="text-violet-400 inline-flex size-8"
555-
icon="streamline-ultimate:lab-tube-experiment"
548+
<div class="flex flex-col gap-4">
549+
<!-- Experimental Features -->
550+
<x-card
551+
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"
552+
>
553+
<div>
554+
<div class="flex flex-row items-center gap-2 mb-2">
555+
<Icon
556+
class="text-violet-400 inline-flex size-8"
557+
icon="streamline-ultimate:lab-tube-experiment"
558+
/>
559+
<h1 class="text-lg my-0 font-semibold">Experimental Features</h1>
560+
</div>
561+
<p class="text-neutral-400 text-[0.9rem] !pt-0 !mt-0">
562+
If enabled, you'll have access to experimental features that may not be stable or complete
563+
</p>
564+
</div>
565+
<div class="flex flex-row justify-center items-center gap-2">
566+
<x-switch
567+
:toggled="wbConfig.config.experimentalFeatures"
568+
@toggle="toggleExperimentalFeatures"
569+
size="large"
556570
/>
557-
<h1 class="text-lg my-0 font-semibold">Experimental Features</h1>
558571
</div>
559-
<p class="text-neutral-400 text-[0.9rem] !pt-0 !mt-0">
560-
If enabled, you'll have access to experimental features that may not be stable or complete
561-
</p>
562-
</div>
563-
<div class="flex flex-row justify-center items-center gap-2">
564-
<x-switch
565-
:toggled="wbConfig.config.experimentalFeatures"
566-
@toggle="toggleExperimentalFeatures"
567-
size="large"
568-
/>
569-
</div>
570-
</x-card>
571-
<x-card
572-
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"
573-
>
574-
<div>
575-
<div class="flex flex-row items-center gap-2 mb-2">
576-
<Icon class="text-violet-400 inline-flex size-8" icon="mdi:administrator"> </Icon>
577-
<h1 class="text-lg my-0 font-semibold">Advanced Settings</h1>
572+
</x-card>
573+
574+
<!-- Advanced Settings -->
575+
<x-card
576+
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"
577+
>
578+
<div>
579+
<div class="flex flex-row items-center gap-2 mb-2">
580+
<Icon class="text-violet-400 inline-flex size-8" icon="mdi:administrator"> </Icon>
581+
<h1 class="text-lg my-0 font-semibold">Advanced Settings</h1>
582+
</div>
583+
<p class="text-neutral-400 text-[0.9rem] !pt-0 !mt-0">
584+
If enabled, you'll have access to advanced settings that may prevent WinBoat from working if
585+
misconfigured
586+
</p>
578587
</div>
579-
<p class="text-neutral-400 text-[0.9rem] !pt-0 !mt-0">
580-
If enabled, you'll have access to advanced settings that may prevent WinBoat from working if
581-
misconfigured
582-
</p>
583-
</div>
584-
<div class="flex flex-row justify-center items-center gap-2">
585-
<x-switch
586-
:toggled="wbConfig.config.advancedFeatures"
587-
@toggle="toggleAdvancedFeatures"
588-
size="large"
589-
/>
590-
</div>
591-
</x-card>
588+
<div class="flex flex-row justify-center items-center gap-2">
589+
<x-switch
590+
:toggled="wbConfig.config.advancedFeatures"
591+
@toggle="toggleAdvancedFeatures"
592+
size="large"
593+
/>
594+
</div>
595+
</x-card>
596+
</div>
592597
</div>
593598

594599
<div>
@@ -722,7 +727,7 @@ function updateApplicationScale(value: string | number) {
722727
* so we can display them and track when a change has been made
723728
*/
724729
async function assignValues() {
725-
compose.value = winboat.parseCompose();
730+
compose.value = Winboat.readCompose(winboat.containerMgr!.composeFilePath);
726731
portMapper.value = new ComposePortMapper(compose.value);
727732
728733
numCores.value = Number(compose.value.services.windows.environment.CPU_CORES);

src/renderer/views/Home.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const compose = ref<ComposeConfig | null>(null);
191191
const wallpaper = ref("");
192192
193193
onMounted(async () => {
194-
compose.value = winboat.parseCompose();
194+
compose.value = Winboat.readCompose(winboat.containerMgr!.composeFilePath);
195195
wallpaper.value = compose.value?.services.windows.environment.VERSION.includes("11")
196196
? "./img/wallpaper/win11.webp"
197197
: "./img/wallpaper/win10.webp";

src/renderer/views/SetupUI.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ function install() {
10661066
container: createContainer(containerRuntime.value), // Hardcdde for now
10671067
};
10681068
1069-
const wbConfig = new WinboatConfig(); // Create winboat config.
1069+
const wbConfig = WinboatConfig.getInstance(); // Create winboat config.
10701070
wbConfig.config.containerRuntime = containerRuntime.value; // Save which runtime to use.
10711071
10721072
installManager = new InstallManager(installConfig);

0 commit comments

Comments
 (0)