Skip to content
This repository has been archived by the owner on Dec 14, 2024. It is now read-only.

Commit

Permalink
♻️ Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
OmegaRogue committed Sep 17, 2023
1 parent 5742f01 commit a7b0f14
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 36 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#file: noinspection SpellCheckingInspection
name: Build and Release
on:
release:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/fork.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#file: noinspection SpellCheckingInspection
name: Merge to fork
on:
push:
Expand Down
3 changes: 2 additions & 1 deletion forge.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// noinspection JSUnusedGlobalSymbols

import type {ForgeConfig} from '@electron-forge/shared-types';
import {MakerSquirrel} from '@electron-forge/maker-squirrel';
import {MakerZIP} from '@electron-forge/maker-zip';
import {MakerDeb} from '@electron-forge/maker-deb';
import {MakerRpm} from '@electron-forge/maker-rpm';
import {MakerFlatpak} from '@electron-forge/maker-flatpak';
import {MakerDMG} from '@electron-forge/maker-dmg';
import {VitePlugin} from '@electron-forge/plugin-vite';

Expand Down
31 changes: 16 additions & 15 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<!DOCTYPE html>
<html>
<!--suppress HtmlFormInputWithoutLabel -->
<html lang="en">

<head>
<meta charset="UTF-8">
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
<title>VTT Desktop Client</title>
<script src="https://kit.fontawesome.com/d9351ab632.js" crossorigin="anonymous"></script>
<!-- <link rel="stylesheet" href="src/style.css">-->
<script crossorigin="anonymous" src="https://kit.fontawesome.com/d9351ab632.js"></script>
<!-- <link rel="stylesheet" href="src/style.css">-->
</head>
<body>
<script>
Expand Down Expand Up @@ -72,25 +73,25 @@
<div class="app-configuration hidden2">
<div class="background-color-field field">
<label for="background-color">Background Color</label>
<input type="color" id="background-color">
<input id="background-color" type="color">
</div>
<div class="text-color-field field">
<label for="text-color">Text Color</label>
<input type="color" id="text-color" class="no-text">
<input class="no-text" id="text-color" type="color">
</div>
<div class="accent-color-field field">
<label for="accent-color">Accent Color</label>
<input type="color" id="accent-color" class="no-text">
<input class="no-text" id="accent-color" type="color">
</div>
<div class="background-image-field">
<input type="text" placeholder="Background Image" id="background-image" value="">
<input id="background-image" placeholder="Background Image" type="text" value="">
</div>
<div class="cache-path-field">
<input type="text" placeholder="Cache Path" id="cache-path" value="">
<input id="cache-path" placeholder="Cache Path" type="text" value="">
</div>
<div class="cache-path-field field">
<label for="clear-cache-on-close">Clear Cache on close</label>
<input id="clear-cache-on-close" class="no-text" type="checkbox">
<input class="no-text" id="clear-cache-on-close" type="checkbox">
</div>
<div class="button-group">
<button id="clear-cache">Clear Cache</button>
Expand All @@ -109,13 +110,13 @@
</div>
<div class="user-configuration hidden">
<div class="user-name-field">
<input type="text" placeholder="User Name" id="user-name" value="">
<input id="user-name" placeholder="User Name" type="text" value="">
</div>
<div class="user-password-field">
<input type="password" placeholder="Password" id="user-password" value="">
<input id="user-password" placeholder="Password" type="password" value="">
</div>
<div class="admin-password-field">
<input type="password" placeholder="Admin Password" id="admin-password" value="">
<input id="admin-password" placeholder="Admin Password" type="password" value="">
</div>

<div class="button-group">
Expand All @@ -127,14 +128,14 @@
</template>
</ul>
<div id="add-game-wrapper">
<input type="text" name="" id="game-name" placeholder="Name">
<input type="text" name="" id="game-url" placeholder="URL">
<input id="game-name" name="" placeholder="Name" type="text">
<input id="game-url" name="" placeholder="URL" type="text">
<button id="add-game">Add Game</button>
</div>
<div id="info">Node.js <span id="node-version"></span>,
Chromium <span id="chrome-version"></span>,
Electron <span id="electron-version"></span></div>
</div>
<script type="module" src="/src/renderer.ts"></script>
<script src="/src/renderer.ts" type="module"></script>
</body>
</html>
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// noinspection ES6MissingAwait,JSIgnoredPromiseFromCall

import {app, BrowserWindow, ipcMain, safeStorage,} from 'electron';
import path from 'path';
import fs from 'fs';
Expand Down Expand Up @@ -33,7 +35,7 @@ const createWindow = () => {
win.setTitle(app.getName());
win.setProgressBar(-1);
});
win.webContents.setWindowOpenHandler((e) => {
win.webContents.setWindowOpenHandler(() => {
return {
action: 'allow',
overrideBrowserWindowOptions: {
Expand Down
22 changes: 15 additions & 7 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// @ts-ignore: no nodejs in preload
// eslint-disable-next-line @typescript-eslint/no-var-requires
import {contextBridge, ipcRenderer} from 'electron';
import {versions} from 'node:process';

window.addEventListener("DOMContentLoaded", () => {
const replaceText = (selector: string, text: string) => {
Expand All @@ -10,25 +11,32 @@ window.addEventListener("DOMContentLoaded", () => {
};

for (const dependency of ["chrome", "node", "electron"]) {
replaceText(`${dependency}-version`, process.versions[dependency]);
replaceText(`${dependency}-version`, versions[dependency]);
}
});


type SendChannels = "toMain" | "open-game" | "save-user-data" | "return-select" | "app-version" | "cache-path" | "clear-cache";
type SendChannels =
"toMain"
| "open-game"
| "save-user-data"
| "return-select"
| "app-version"
| "cache-path"
| "clear-cache";
type ReceiveChannels = "fromMain" | "save-user-data" | "app-version" | "cache-path";
type RequestChannels = "app-version" | "cache-path" | "get-user-data";
type SendOnChannel = (channel: SendChannels, data?: number | string | SaveUserData) => void;
type ReceiveOnChannel = ((channel: ReceiveChannels, func: (...args: any[]) => void) => void)
type RequestOnChannel = ((channel: RequestChannels, ...args: any[]) => Promise<any>)
type ReceiveOnChannel = ((channel: ReceiveChannels, func: (...args: unknown[]) => void) => void)
type RequestOnChannel = ((channel: RequestChannels, ...args: unknown[]) => Promise<unknown>)

export type ContextBridgeApi = {
send: SendOnChannel;
receive: ReceiveOnChannel;
request: RequestOnChannel;
}
const exposedApi: ContextBridgeApi = {
request: (channel: RequestChannels, ...args: any[]): Promise<any> => {
request: (channel: RequestChannels, ...args: unknown[]): Promise<unknown> => {
if (channel === "get-user-data") {
if (args.length !== 1 || typeof args[0] !== "string")
throw new Error("Invalid arguments for get-user-data");
Expand All @@ -46,9 +54,9 @@ const exposedApi: ContextBridgeApi = {
throw new Error("No arguments allowed for cache-path");
return ipcRenderer.invoke(channel) as Promise<string>;
}
return ipcRenderer.invoke(channel, ...args);
return ipcRenderer.invoke(channel, ...args);
},
receive: (channel: ReceiveChannels, func: (...args: any[]) => void) => {
receive: (channel: ReceiveChannels, func: (...args: unknown[]) => void) => {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
},
Expand Down
2 changes: 2 additions & 0 deletions src/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// noinspection JSIgnoredPromiseFromCall

import './style.css';

let appVersion: string;
Expand Down
14 changes: 7 additions & 7 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ input[type=checkbox]:after {
display: block;
width: 30px;
height: 30px;
border: solid #FFCB9A;
border-width: 0 0px 0px 0;
border: 0 solid #FFCB9A;
}

input[type=checkbox]:checked:after {
Expand Down Expand Up @@ -194,7 +193,7 @@ table, th, td {
border-collapse: collapse;
}

.menu-container{
.menu-container {
display: flex;
align-items: center;
justify-content: center;
Expand All @@ -206,7 +205,7 @@ table, th, td {
gap: 1rem;
}

.field{
.field {
display: flex;
justify-content: space-between;
}
Expand All @@ -217,7 +216,7 @@ table, th, td {
box-shadow: 0 0 5px black;
}

.help td{
.help td {
padding: 0.3rem 0.5rem;
}

Expand All @@ -226,6 +225,7 @@ table, th, td {
top: 2rem;
right: 2rem;
}

.app-configuration {
box-shadow: 0 0 5px black;
display: flex;
Expand All @@ -237,13 +237,13 @@ table, th, td {
pointer-events: all;
}

.update-available{
.update-available {
position: absolute;
bottom: 0;
left: 0;
}

.update-available a{
.update-available a {
font-size: 1rem;
color: var(--color-accent);
}
Expand Down
4 changes: 3 additions & 1 deletion src/window.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { ContextBridgeApi } from './preload'
// noinspection JSUnusedGlobalSymbols

import type {ContextBridgeApi} from './preload'

declare global {
interface Window {
Expand Down
5 changes: 3 additions & 2 deletions vite.main.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { defineConfig } from 'vite';
// noinspection JSUnusedGlobalSymbols

import {defineConfig} from 'vite';

// https://vitejs.dev/config
export default defineConfig({
resolve: {
// Some libs that can run in both Web and Node.js, such as `axios`, we need to tell Vite to build them in Node.js.
browserField: false,
mainFields: ['module', 'jsnext:main', 'jsnext'],
},
});
4 changes: 3 additions & 1 deletion vite.preload.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { defineConfig } from 'vite';
// noinspection JSUnusedGlobalSymbols

import {defineConfig} from 'vite';

// https://vitejs.dev/config
export default defineConfig({});
4 changes: 3 additions & 1 deletion vite.renderer.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { defineConfig } from 'vite';
// noinspection JSUnusedGlobalSymbols

import {defineConfig} from 'vite';

// https://vitejs.dev/config
export default defineConfig({});

0 comments on commit a7b0f14

Please sign in to comment.