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

Commit

Permalink
Merge pull request #15 from OmegaRogue/pull-request-no-injection
Browse files Browse the repository at this point in the history
1.3.10
  • Loading branch information
theripper93 authored Sep 22, 2023
2 parents d51316d + 7191c18 commit e0d7746
Show file tree
Hide file tree
Showing 17 changed files with 5,570 additions and 7,303 deletions.
7 changes: 4 additions & 3 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 Expand Up @@ -128,9 +129,9 @@ jobs:
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: out/win64.zip
asset_name: vtt-desktop-client-windows-x64-${{ github.event.release.tag_name }}.zip
asset_content_type: application/zip
asset_path: out/make/squirrel.windows/x64/vtt-desktop-client-${{ github.event.release.tag_name }} Setup.exe
asset_name: vtt-desktop-client-windows-x64-${{ github.event.release.tag_name }}-setup.exe
asset_content_type: application/vnd.microsoft.portable-executable
- name: Upload Zip to Release 2
uses: shogo82148/actions-upload-release-asset@v1
with:
Expand Down
8 changes: 7 additions & 1 deletion .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 All @@ -16,4 +17,9 @@ jobs:
type: now
from_branch: main
target_branch: pull-request-no-injection
github_token: ${{ secrets.GITHUB_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: create pull request
if: failure()
run: gh pr create -B pull-request-no-injection -H main --title 'Merge main into pull-request-no-injection' --body 'Created by Github action'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .idea/fvtt-player-client.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
14 changes: 11 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<html>
<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">
<!-- <link rel="stylesheet" href="src/style.css">-->
</head>
<body>
<script>
Expand Down Expand Up @@ -68,7 +68,7 @@
</tr>
</table>
</div>

<div class="app-configuration hidden2">
<div class="background-color-field field">
<label for="background-color">Background Color</label>
Expand All @@ -85,7 +85,15 @@
<div class="background-image-field">
<input type="text" placeholder="Background Image" id="background-image" value="">
</div>
<div class="cache-path-field">
<input type="text" placeholder="Cache Path" id="cache-path" 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">
</div>
<div class="button-group">
<button id="clear-cache">Clear Cache</button>
<button id="save-app-config">Save</button>
</div>
</div>
Expand Down
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vtt-desktop-client",
"packageManager": "[email protected]",
"version": "1.3.8",
"version": "1.3.10",
"license": "MIT",
"description": "VTT Desktop Client",
"main": ".vite/build/main.js",
Expand All @@ -19,25 +19,25 @@
}
],
"devDependencies": {
"@electron-forge/cli": "^6.4.1",
"@electron-forge/maker-deb": "^6.4.1",
"@electron-forge/maker-dmg": "^6.4.1",
"@electron-forge/maker-flatpak": "^6.4.1",
"@electron-forge/maker-rpm": "^6.4.1",
"@electron-forge/maker-squirrel": "^6.4.1",
"@electron-forge/maker-zip": "^6.4.1",
"@electron-forge/plugin-auto-unpack-natives": "^6.4.1",
"@electron-forge/plugin-local-electron": "^6.4.1",
"@electron-forge/plugin-vite": "^6.4.1",
"@types/node": "^20.5.9",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"electron": "25.6.0",
"@electron-forge/cli": "^6.4.2",
"@electron-forge/maker-deb": "^6.4.2",
"@electron-forge/maker-dmg": "^6.4.2",
"@electron-forge/maker-flatpak": "^6.4.2",
"@electron-forge/maker-rpm": "^6.4.2",
"@electron-forge/maker-squirrel": "^6.4.2",
"@electron-forge/maker-zip": "^6.4.2",
"@electron-forge/plugin-auto-unpack-natives": "^6.4.2",
"@electron-forge/plugin-local-electron": "^6.4.2",
"@electron-forge/plugin-vite": "^6.4.2",
"@types/node": "^20.6.2",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"electron": "25.8.1",
"electron-builder": "^24.6.4",
"eslint": "^8.0.1",
"eslint": "^8.49.0",
"eslint-plugin-import": "^2.25.0",
"ts-node": "^10.0.0",
"typescript": "~4.5.4"
"typescript": "~5.2.2"
},
"scripts": {
"start": "electron-forge start",
Expand Down
96 changes: 81 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {app, BrowserWindow, ipcMain, safeStorage, shell} from 'electron';
import {app, BrowserWindow, ipcMain, safeStorage,} from 'electron';
import path from 'path';
import fs from 'fs';

Expand All @@ -24,7 +24,18 @@ const createWindow = () => {
webgl: true
},
});
win.webContents.setWindowOpenHandler((e) => {
// Fix Popouts
win.webContents.setUserAgent(win.webContents.getUserAgent().replace("Electron", ""));
win.webContents.on('did-start-loading', () => {
win.setTitle(app.getName() + ' * Loading ....');
win.setProgressBar(2, {mode: 'indeterminate'}) // second parameter optional
});

win.webContents.on('did-finish-load', () => {
win.setTitle(app.getName());
win.setProgressBar(-1);
});
win.webContents.setWindowOpenHandler(() => {
return {
action: 'allow',
overrideBrowserWindowOptions: {
Expand Down Expand Up @@ -61,6 +72,47 @@ app.whenReady().then(() => {
});
win.webContents.on("did-finish-load", () => {
const url = win.webContents.getURL();
if (!url.endsWith("/join") && !url.endsWith("/auth") && !url.endsWith("/setup"))
return;
if (url.endsWith("/setup")) {
win.webContents.executeJavaScript(`
if ($('#server-button').length === 0) {
const serverSelectButton = $('<button type="button" data-action="returnServerSelect" id="server-button" data-tooltip="Return to Server Select"><i class="fas fa-server"></i></button>');
serverSelectButton.on('click', () => {
window.api.send("return-select");
});
setTimeout(() => {
$('nav#setup-menu').append(serverSelectButton)
}, 200);
}
`);
}
if (url.endsWith("/auth")) {
win.webContents.executeJavaScript(`
if ($('#server-button').length === 0) {
const serverSelectButton = $('<button type="button" class="bright" id="server-button"> <i class="fa-solid fa-server"></i>Return to Server Select</button>');
serverSelectButton.on('click', () => {
window.api.send("return-select");
});
setTimeout(() => {
$('.form-footer').append(serverSelectButton)
}, 200);
}
`);
}
if (url.endsWith("/join")) {
win.webContents.executeJavaScript(`
if ($('#server-button').length === 0) {
const serverSelectButton = $('<button type="button" class="bright" id="server-button"> <i class="fa-solid fa-server"></i>Return to Server Select</button>');
serverSelectButton.on('click', () => {
window.api.send("return-select");
});
setTimeout(() => {
$('.form-footer').append(serverSelectButton)
}, 200);
}
`);
}
if (!url.endsWith("/join") && !url.endsWith("/auth"))
return;
const userData = getLoginDetails(gameId);
Expand All @@ -71,6 +123,7 @@ app.whenReady().then(() => {
while (!document.querySelector('select[name="userid"]') && !document.querySelector('input[name="adminPassword"]')) {
await wait(100);
}
console.log("logging in");
login();
}
Expand All @@ -86,12 +139,16 @@ app.whenReady().then(() => {
const password = document.querySelector('input[name="password"]');
if (password)
password.value = "${userData.password}";
const fakeEvent = {
preventDefault: () => {
}, target: document.getElementById("join-game")
}
if ("${autoLogin}" === "true") {
const fakeEvent = {
preventDefault: () => {
}, target: document.getElementById("join-game")
}
ui.join._onSubmit(fakeEvent);
} else {
document.getElementById("join-game").addEventListener("click", () => {
ui.join._onSubmit(fakeEvent);
});
}
}
Expand All @@ -106,9 +163,8 @@ app.whenReady().then(() => {
ipcMain.on("open-game", (_e, gId) => {
gameId = gId;
});

ipcMain.on("open-game", (_e, gId) => {
gameId = gId;
ipcMain.on("clear-cache", async () => {
await win.webContents.session.clearCache();
});
ipcMain.on("return-select", () => {
autoLogin = true;
Expand All @@ -122,13 +178,23 @@ ipcMain.on("return-select", () => {
ipcMain.on("save-user-data", (_e, data: SaveUserData) => {
const {gameId, password, user, adminPassword} = data;
saveUserData(gameId.toString(), {
password: Array.from(safeStorage.encryptString(password)),
password: password.length !== 0 ? Array.from(safeStorage.encryptString(password)) : [],
user,
adminPassword: Array.from(safeStorage.encryptString(adminPassword))
adminPassword: password.length !== 0 ? Array.from(safeStorage.encryptString(adminPassword)) : []
});
});
ipcMain.on("app-version",(event) => {
event.sender.send("app-version", app.getVersion());
ipcMain.handle("get-user-data", (event, gameId: string) => {
return getLoginDetails(gameId);
})

ipcMain.handle("app-version", () => {
return app.getVersion();
})
ipcMain.handle("cache-path", () => {
return app.getPath("sessionData");
})
ipcMain.on("cache-path", (event, path: string) => {
app.setPath("sessionData", path);
});

function getUserData(): UserData {
Expand All @@ -148,8 +214,8 @@ function getLoginDetails(gameId: string): GameUserDataDecrypted {
const adminPassword = new Uint8Array(userData.adminPassword);
return {
user: userData.user,
password: safeStorage.decryptString(Buffer.from(password)),
adminPassword: safeStorage.decryptString(Buffer.from(adminPassword)),
password: password.length !== 0 ? (safeStorage.isEncryptionAvailable() ? safeStorage.decryptString(Buffer.from(password)) : "") : "",
adminPassword: password.length !== 0 ? (safeStorage.isEncryptionAvailable() ? safeStorage.decryptString(Buffer.from(adminPassword)) : "") : "",
};
}

Expand Down
54 changes: 45 additions & 9 deletions src/preload.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: no nodejs in preload
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand All @@ -15,24 +16,59 @@ window.addEventListener("DOMContentLoaded", () => {
});


type SendChannels = "toMain" | "open-game" | "save-user-data" | "return-select" | "app-version";
type ReceiveChannels = "fromMain" | "save-user-data" | "app-version";
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: unknown[]) => void) => void)
type RequestOnChannel = ((channel: RequestChannels, ...args: unknown[]) => Promise<unknown>)

export type ContextBridgeApi = {
send: (channel: SendChannels, data?: number | string | SaveUserData) => void;
receive: (channel: ReceiveChannels, func: (...args: any[]) => void) => void;
send: SendOnChannel;
receive: ReceiveOnChannel;
request: RequestOnChannel;
}
const exposedApi: ContextBridgeApi = {
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");
return ipcRenderer.invoke(channel, args[0] as string) as Promise<GameUserDataDecrypted>;

}
if (channel === "app-version") {
if (args.length != 0)
throw new Error("No arguments allowed for app-version");
return ipcRenderer.invoke(channel) as Promise<string>;

}
if (channel === "cache-path") {
if (args.length != 0)
throw new Error("No arguments allowed for cache-path");
return ipcRenderer.invoke(channel) as Promise<string>;
}
return ipcRenderer.invoke(channel, ...args);
},
receive: (channel: ReceiveChannels, func: (...args: unknown[]) => void) => {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
},
send: (channel: SendChannels, data?: number | string | SaveUserData) => {
if (channel === "save-user-data" && !(data as SaveUserData).user)
throw new Error("Invalid Argument data");
if (channel === "open-game" && !(typeof data === "number" || typeof data === "string"))
throw new Error("Invalid Argument data");
ipcRenderer.send(channel, data);
},
receive: (channel: ReceiveChannels, func: (...args: any[]) => void) => {
// Deliberately strip event as it includes `sender`
ipcRenderer.on(channel, (event, ...args) => func(...args));
},
}


}

contextBridge.exposeInMainWorld("api", exposedApi);
Loading

0 comments on commit e0d7746

Please sign in to comment.