Skip to content

Commit 63287e5

Browse files
waffles-devwaffles-dev
andauthored
Chore: fix sonar warnings (#385)
* Chore: Fix odd prettier formatting * Chore: Address Sonar quality warnings * Add alt text and move comment to line above --------- Co-authored-by: waffles-dev <[email protected]>
1 parent 2feb539 commit 63287e5

File tree

20 files changed

+207
-210
lines changed

20 files changed

+207
-210
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: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
<ol class="mt-2 list-decimal list-inside">
3838
<li>
3939
Use VNC over at
40-
<a @click="openAnchorLink" :href="novncURL" target="_blank" rel="noopener noreferrer">{{
41-
novncURL
42-
}}</a>
40+
<a @click="openAnchorLink" :href="novncURL" target="_blank" rel="noopener noreferrer">
41+
{{ novncURL }}
42+
</a>
4343
to access Windows
4444
</li>
4545
<li>Press Win + R or search for <code>Run</code>, type in <code>services.msc</code></li>
@@ -51,8 +51,10 @@
5151
href="https://github.com/TibixDev/winboat/releases"
5252
target="_blank"
5353
rel="noopener noreferrer"
54-
>https://github.com/TibixDev/winboat/releases</a
55-
>, you should pick version <strong>{{ appVer }}</strong>
54+
>
55+
https://github.com/TibixDev/winboat/releases
56+
</a>
57+
, you should pick version <strong>{{ appVer }}</strong>
5658
</li>
5759
<li>Navigate to <code>C:\Program Files\WinBoat</code> and delete the contents</li>
5860
<li>Extract the freshly downloaded zip into the same folder</li>
@@ -158,9 +160,7 @@ import { USBManager } from "./lib/usbmanager";
158160
import { GUEST_NOVNC_PORT } from "./lib/constants";
159161
import { setIntervalImmediately } from "./utils/interval";
160162
const { BrowserWindow }: typeof import("@electron/remote") = require("@electron/remote");
161-
const os: typeof import("os") = require("os");
162-
const path: typeof import("path") = require("path");
163-
const remote: typeof import("@electron/remote") = require("@electron/remote");
163+
const os: typeof import("os") = require("node:os");
164164
165165
const $router = useRouter();
166166
const appVer = import.meta.env.VITE_APP_VERSION;
@@ -172,20 +172,21 @@ let updateTimeout: NodeJS.Timeout | null = null;
172172
const manualUpdateRequired = ref(false);
173173
const MANUAL_UPDATE_TIMEOUT = 60000; // 60 seconds
174174
const updateDialog = useTemplateRef("updateDialog");
175-
const rerenderCounter = ref(0); // TODO: Hack for non-reactive data
175+
// TODO: Hack for non-reactive data
176+
const rerenderCounter = ref(0);
176177
const novncURL = ref("");
177178
let animationCheckInterval: NodeJS.Timeout | null = null;
178179
179180
onMounted(async () => {
180181
const winboatInstalled = await isInstalled();
181-
if (!winboatInstalled) {
182+
if (winboatInstalled) {
183+
winboat = Winboat.getInstance(); // Instantiate singleton class
184+
wbConfig = WinboatConfig.getInstance(); // Instantiate singleton class
185+
USBManager.getInstance(); // Instantiate singleton class
186+
$router.push("/home");
187+
} else {
182188
console.log("Not installed, redirecting to setup...");
183189
$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");
189190
}
190191
191192
// Apply or remove disable-animations class based on config

src/renderer/components/WBContextMenu.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</template>
2020

2121
<script setup lang="ts">
22-
import { ref, computed, onMounted, onUnmounted, nextTick } from "vue";
22+
import { ref, computed, onUnmounted, nextTick } from "vue";
2323
2424
interface Props {
2525
trigger?: "contextmenu" | "click" | "none";
@@ -34,7 +34,6 @@ const emit = defineEmits<{
3434
hide: [];
3535
}>();
3636
37-
const contextMenuRef = ref<HTMLElement>();
3837
const triggerRef = ref<HTMLElement>();
3938
const menuRef = ref<HTMLElement>();
4039

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";
@@ -39,15 +39,18 @@ const defaultConfig: WinboatConfigObj = {
3939
};
4040

4141
export class WinboatConfig {
42-
private static instance: WinboatConfig;
43-
#configPath: string = path.join(WINBOAT_DIR, "winboat.config.json");
42+
private static instance: WinboatConfig | null = null;
43+
readonly #configPath: string = path.join(WINBOAT_DIR, "winboat.config.json");
4444
#configData: WinboatConfigObj = { ...defaultConfig };
4545

46-
constructor() {
47-
if (WinboatConfig.instance) return WinboatConfig.instance;
46+
static getInstance() {
47+
WinboatConfig.instance ??= new WinboatConfig();
48+
return WinboatConfig.instance;
49+
}
50+
51+
private constructor() {
4852
this.#configData = this.readConfig();
4953
console.log("Reading current config", this.#configData);
50-
WinboatConfig.instance = this;
5154
}
5255

5356
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)