Skip to content

Commit 661c95c

Browse files
author
waffles-dev
committed
Chore: Address Sonar quality warnings
1 parent 890926c commit 661c95c

File tree

20 files changed

+163
-169
lines changed

20 files changed

+163
-169
lines changed

src/main/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,6 @@ app.on("second-instance", _ => {
146146
}
147147
});
148148

149-
ipcMain.on("message", (event, message) => {
149+
ipcMain.on("message", (_event, message) => {
150150
console.log(message);
151151
});

src/renderer/App.vue

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,7 @@ import { WinboatConfig } from "./lib/config";
159159
import { USBManager } from "./lib/usbmanager";
160160
import { GUEST_NOVNC_PORT } from "./lib/constants";
161161
const { BrowserWindow }: typeof import("@electron/remote") = require("@electron/remote");
162-
const os: typeof import("os") = require("os");
163-
const path: typeof import("path") = require("path");
164-
const remote: typeof import("@electron/remote") = require("@electron/remote");
162+
const os: typeof import("os") = require("node:os");
165163
166164
const $router = useRouter();
167165
const appVer = import.meta.env.VITE_APP_VERSION;
@@ -178,14 +176,14 @@ const novncURL = ref("");
178176
179177
onMounted(async () => {
180178
const winboatInstalled = await isInstalled();
181-
if (!winboatInstalled) {
179+
if (winboatInstalled) {
180+
winboat = Winboat.getInstance(); // Instantiate singleton class
181+
wbConfig = WinboatConfig.getInstance(); // Instantiate singleton class
182+
USBManager.getInstance(); // Instantiate singleton class
183+
$router.push("/home");
184+
} else {
182185
console.log("Not installed, redirecting to setup...");
183186
$router.push("/setup");
184-
} else {
185-
winboat = new Winboat(); // Instantiate singleton class
186-
wbConfig = new WinboatConfig(); // Instantiate singleton class
187-
new USBManager(); // Instantiate singleton class
188-
$router.push("/home");
189187
}
190188
191189
// Watch for guest server updates and show dialog

src/renderer/components/WBContextMenu.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</template>
2323

2424
<script setup lang="ts">
25-
import { ref, computed, onMounted, onUnmounted, nextTick } from "vue";
25+
import { ref, computed, onUnmounted, nextTick } from "vue";
2626
2727
interface Props {
2828
trigger?: "contextmenu" | "click" | "none";
@@ -37,7 +37,6 @@ const emit = defineEmits<{
3737
hide: [];
3838
}>();
3939
40-
const contextMenuRef = ref<HTMLElement>();
4140
const triggerRef = ref<HTMLElement>();
4241
const menuRef = ref<HTMLElement>();
4342

src/renderer/lib/config.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const fs: typeof import("fs") = require("fs");
2-
const path: typeof import("path") = require("path");
1+
const fs: typeof import("fs") = require("node:fs");
2+
const path: typeof import("path") = require("node:path");
33
import { type WinApp } from "../../types";
44
import { WINBOAT_DIR } from "./constants";
55
import { type PTSerializableDeviceInfo } from "./usbmanager";
@@ -37,15 +37,18 @@ const defaultConfig: WinboatConfigObj = {
3737
};
3838

3939
export class WinboatConfig {
40-
private static instance: WinboatConfig;
41-
#configPath: string = path.join(WINBOAT_DIR, "winboat.config.json");
40+
private static instance: WinboatConfig | null = null;
41+
readonly #configPath: string = path.join(WINBOAT_DIR, "winboat.config.json");
4242
#configData: WinboatConfigObj = { ...defaultConfig };
4343

44-
constructor() {
45-
if (WinboatConfig.instance) return WinboatConfig.instance;
44+
static getInstance() {
45+
WinboatConfig.instance ??= new WinboatConfig();
46+
return WinboatConfig.instance;
47+
}
48+
49+
private constructor() {
4650
this.#configData = this.readConfig();
4751
console.log("Reading current config", this.#configData);
48-
WinboatConfig.instance = this;
4952
}
5053

5154
get config(): WinboatConfigObj {

src/renderer/lib/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const os: typeof import("os") = require("os");
2-
const path: typeof import("path") = require("path");
1+
const os: typeof import("os") = require("node:os");
2+
const path: typeof import("path") = require("node:path");
33

44
// Should be {home}/.winboat
55
export const WINBOAT_DIR = path.join(os.homedir(), ".winboat");

src/renderer/lib/install.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import { createLogger } from "../utils/log";
66
import { createNanoEvents, type Emitter } from "nanoevents";
77
import { PortManager } from "../utils/port";
88
import { Winboat } from "./winboat";
9-
const fs: typeof import("fs") = require("fs");
10-
const { exec }: typeof import("child_process") = require("child_process");
11-
const path: typeof import("path") = require("path");
12-
const { promisify }: typeof import("util") = require("util");
9+
const fs: typeof import("fs") = require("node:fs");
10+
const { exec }: typeof import("child_process") = require("node:child_process");
11+
const path: typeof import("path") = require("node:path");
12+
const { promisify }: typeof import("util") = require("node:util");
1313
const nodeFetch: typeof import("node-fetch").default = require("node-fetch");
1414
const remote: typeof import("@electron/remote") = require("@electron/remote");
1515

@@ -145,21 +145,21 @@ export class InstallManager {
145145

146146
// Storage folder mapping
147147
const storageFolderIdx = composeContent.services.windows.volumes.findIndex(vol => vol.includes("/storage"));
148-
if (storageFolderIdx !== -1) {
149-
composeContent.services.windows.volumes[storageFolderIdx] = `${this.conf.installFolder}:/storage`;
150-
} else {
148+
if (storageFolderIdx === -1) {
151149
logger.warn("No /storage volume found in compose template, adding one...");
152150
composeContent.services.windows.volumes.push(`${this.conf.installFolder}:/storage`);
151+
} else {
152+
composeContent.services.windows.volumes[storageFolderIdx] = `${this.conf.installFolder}:/storage`;
153153
}
154154

155155
// Home folder mapping
156156
if (!this.conf.shareHomeFolder) {
157157
const sharedFolderIdx = composeContent.services.windows.volumes.findIndex(vol => vol.includes("/shared"));
158-
if (sharedFolderIdx !== -1) {
158+
if (sharedFolderIdx === -1) {
159+
logger.info("No home folder sharing volume found, nothing to remove");
160+
} else {
159161
composeContent.services.windows.volumes.splice(sharedFolderIdx, 1);
160162
logger.info("Removed home folder sharing as per user configuration");
161-
} else {
162-
logger.info("No home folder sharing volume found, nothing to remove");
163163
}
164164
}
165165

@@ -242,8 +242,7 @@ export class InstallManager {
242242

243243
// Start the container
244244
try {
245-
// execSync(`docker compose -f ${composeFilePath} up -d`, { stdio: 'inherit' });
246-
const { stdout, stderr } = await execAsync(`docker compose -f ${composeFilePath} up -d`);
245+
const { stderr } = await execAsync(`docker compose -f ${composeFilePath} up -d`);
247246
if (stderr) {
248247
logger.error(stderr);
249248
}
@@ -263,6 +262,7 @@ export class InstallManager {
263262
this.changeState(InstallStates.MONITORING_PREINSTALL);
264263
logger.info("Starting preinstall monitoring...");
265264

265+
const re = new RegExp(/>([^<]+)</);
266266
while (true) {
267267
try {
268268
const vncHostPort = this.portMgr.value!.getHostPort(GUEST_NOVNC_PORT);
@@ -272,8 +272,7 @@ export class InstallManager {
272272
return; // Exit the method when we get 404
273273
}
274274
const message = await response.text();
275-
const re = />([^<]+)</;
276-
const messageFormatted = message.match(re)?.[1] || message;
275+
const messageFormatted = re.exec(message)?.[1] || message;
277276
this.setPreinstallMsg(messageFormatted);
278277
} catch (error) {
279278
if (error instanceof Error && error.message.includes("404")) {
@@ -304,7 +303,7 @@ export class InstallManager {
304303
logger.info("WinBoat Guest Server is up and healthy!");
305304
this.changeState(InstallStates.COMPLETED);
306305

307-
const winboat = new Winboat();
306+
const winboat = Winboat.getInstance();
308307
const config = winboat.parseCompose();
309308
const filteredVolumes = config.services.windows.volumes.filter(
310309
volume => !volume.endsWith("/boot.iso"),
@@ -325,7 +324,7 @@ export class InstallManager {
325324
} minutes...`,
326325
);
327326
}
328-
} catch (error) {
327+
} catch {
329328
// Log every 60 seconds for errors too
330329
if (attempts % 12 === 0) {
331330
logger.info(`API not responding yet, still waiting after ${(attempts * 5) / 60} minutes...`);

src/renderer/lib/qmp.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { WINBOAT_DIR } from "./constants";
22
import { createLogger } from "../utils/log";
3-
const path: typeof import("path") = require("path");
3+
const path: typeof import("path") = require("node:path");
44
import { type Socket } from "net";
55
import { assert } from "@vueuse/core";
6-
const { createConnection }: typeof import("net") = require("net");
6+
const { createConnection }: typeof import("net") = require("node:net");
77

88
const logger = createLogger(path.join(WINBOAT_DIR, "qmp.log"));
99

@@ -110,7 +110,7 @@ export type QMPResponse<T extends QMPCommand> = QMPReturn<
110110
>;
111111

112112
export class QMPManager {
113-
private static IS_ALIVE_TIMEOUT = 2000;
113+
private static readonly IS_ALIVE_TIMEOUT = 2000;
114114
qmpSocket: Socket;
115115

116116
/**

src/renderer/lib/specs.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { getFreeRDP } from "../utils/getFreeRDP";
2-
const fs: typeof import("fs") = require("fs");
3-
const os: typeof import("os") = require("os");
4-
const { exec }: typeof import("child_process") = require("child_process");
5-
const { promisify }: typeof import("util") = require("util");
2+
const fs: typeof import("fs") = require("node:fs");
3+
const os: typeof import("os") = require("node:os");
4+
const { exec }: typeof import("child_process") = require("node:child_process");
5+
const { promisify }: typeof import("util") = require("node:util");
66
const execAsync = promisify(exec);
77

88
export function satisfiesPrequisites(specs: Specs) {
@@ -35,7 +35,7 @@ export async function getSpecs() {
3535
// Physical CPU cores check
3636
try {
3737
const res = (await execAsync('lscpu -p | egrep -v "^#" | sort -u -t, -k 2,4 | wc -l')).stdout;
38-
specs.cpuCores = parseInt(res.trim(), 10);
38+
specs.cpuCores = Number.parseInt(res.trim(), 10);
3939
} catch (e) {
4040
console.error("Error getting CPU cores:", e);
4141
}
@@ -73,9 +73,9 @@ export async function getSpecs() {
7373
if (dockerComposeOutput) {
7474
// Example output: "Docker Compose version v2.35.1"
7575
// Example output 2: "Docker Compose version 2.36.2"
76-
const versionMatch = dockerComposeOutput.match(/(\d+\.\d+\.\d+)/);
76+
const versionMatch = new RegExp(/(\d+\.\d+\.\d+)/).exec(dockerComposeOutput);
7777
if (versionMatch) {
78-
const majorVersion = parseInt(versionMatch[1].split(".")[0], 10);
78+
const majorVersion = Number.parseInt(versionMatch[1].split(".")[0], 10);
7979
specs.dockerComposeInstalled = majorVersion >= 2;
8080
} else {
8181
specs.dockerComposeInstalled = false; // No valid version found
@@ -130,11 +130,12 @@ export async function getMemoryInfo() {
130130
const totalMemLine = memInfo.split("\n").find(line => line.startsWith("MemTotal"));
131131
const availableMemLine = memInfo.split("\n").find(line => line.startsWith("MemAvailable"));
132132
if (totalMemLine) {
133-
memoryInfo.totalGB = Math.round((parseInt(totalMemLine.split(/\s+/)[1]) / 1024 / 1024) * 100) / 100;
133+
memoryInfo.totalGB = Math.round((Number.parseInt(totalMemLine.split(/\s+/)[1]) / 1024 / 1024) * 100) / 100;
134134
}
135135

136136
if (availableMemLine) {
137-
memoryInfo.availableGB = Math.round((parseInt(availableMemLine.split(/\s+/)[1]) / 1024 / 1024) * 100) / 100;
137+
memoryInfo.availableGB =
138+
Math.round((Number.parseInt(availableMemLine.split(/\s+/)[1]) / 1024 / 1024) * 100) / 100;
138139
}
139140

140141
return memoryInfo;

0 commit comments

Comments
 (0)