Skip to content

Commit

Permalink
Start pairing window
Browse files Browse the repository at this point in the history
and optimize browserwindow creation
  • Loading branch information
JovannMC committed Sep 13, 2024
1 parent c35ac03 commit fdf87da
Show file tree
Hide file tree
Showing 9 changed files with 322 additions and 79 deletions.
24 changes: 23 additions & 1 deletion src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
"other": {
"title": "Other settings",
"tooltip": "Other settings for the program that don't fit in the other categories.",
"trackerVisualizationFPS": "Tracker visualization FPS"
"trackerVisualizationFPS": "Tracker visualization FPS",
"pairing": "Manage GX(6/2) pairing"
},
"updates": {
"title": "Update checking",
Expand Down Expand Up @@ -215,6 +216,27 @@
}
}
},
"pairing": {
"title": "GX(6/2) Tracker Pairing",
"text": "Manage the pairing of your trackers connected with the GX(6/2) communication dongles.",
"card": {
"title": "COM port:",
"id": {
"title": {
"0": "Port ID 0",
"1": "Port ID 1"
},
"status": {
"title": "Status:",
"paired": "Paired",
"unpaired": "Unpaired"
},
"tracker": "Tracker:",
"manage": "Pair/Unpair"
},
"manage": "Pair/Unpair all"
}
},
"dialogs": {
"connectionFailed": {
"title": "Connection failed",
Expand Down
123 changes: 54 additions & 69 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@

import { app, BrowserWindow, ipcMain, shell, dialog, Menu } from "electron";
// @ts-ignore (for development)
import { HaritoraX, TrackerModel, SensorMode, FPSMode, SensorAutoCorrection, MagStatus } from "haritorax-interpreter";
import {
HaritoraX,
TrackerModel,
SensorMode,
FPSMode,
SensorAutoCorrection,
MagStatus,
} from "haritorax-interpreter;

Check failure on line 14 in src/main.ts

View workflow job for this annotation

GitHub Actions / build

Unterminated string literal.

Check failure on line 14 in src/main.ts

View workflow job for this annotation

GitHub Actions / build

Unterminated string literal.
import { autoDetect } from "@serialport/bindings-cpp";
const Binding = autoDetect();
import fs, { PathLike } from "fs";
Expand Down Expand Up @@ -305,28 +312,7 @@ const createWindow = async () => {
await fs.promises.writeFile(configPath, "{}");
firstLaunch = true;
}
mainWindow = new BrowserWindow({
title: "SlimeTora: Main",
autoHideMenuBar: true,
width: 900,
height: 700,
webPreferences: {
contextIsolation: true,
nodeIntegration: true,
preload: path.join(__dirname, "preload.mjs"),
spellcheck: false,
sandbox: false, // fixes startup crashes due to GPU process, shouldn't be too large of a security risk as we're not loading any external content/connect to internet
},
icon: path.join(__dirname, "static/images/icon.ico"),
});

mainWindow.loadURL(
format({
pathname: path.join(__dirname, "static/html/index.html"),
protocol: "file:",
slashes: true,
})
);
mainWindow = createBrowserWindow("SlimeTora: Main", "index.html", "en", null, 900, 700);

mainWindow.webContents.on("did-finish-load", async () => {
mainWindow.webContents.send("localize", resources);
Expand All @@ -346,11 +332,6 @@ const createWindow = async () => {
if (appUpdatesEnabled) await checkForAppUpdates();
if (translationsUpdatesEnabled) await checkForTranslationUpdates();
});

mainWindow.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: "deny" };
});
};

const closeApp = () => {
Expand All @@ -375,16 +356,21 @@ app.on("window-all-closed", closeApp);
* Renderer handlers
*/

function onboarding(language: string) {
log("Showing onboarding screen");

let onboardingWindow = new BrowserWindow({
title: "SlimeTora: Onboarding",
function createBrowserWindow(
title: string,
htmlFile: string,
query: string | ParsedUrlQueryInput,
parent: BrowserWindow,
width: number = 950,
height: number = 750
): BrowserWindow {
let window = new BrowserWindow({
title: title,
autoHideMenuBar: true,
width: 950,
height: 750,
width: width,
height: height,
modal: true, // prevent interaction with "parent" window until closed
parent: mainWindow,
parent: parent,
webPreferences: {
contextIsolation: true,
nodeIntegration: true,
Expand All @@ -395,19 +381,31 @@ function onboarding(language: string) {
icon: path.join(__dirname, "static/images/icon.ico"),
});

onboardingWindow.loadURL(
window.loadURL(
format({
pathname: path.join(__dirname, "static/html/onboarding.html"),
pathname: path.join(__dirname, `static/html/${htmlFile}`),
protocol: "file:",
slashes: true,
query: { language: language },
query: query,
})
);

onboardingWindow.webContents.setWindowOpenHandler(({ url }) => {
window.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: "deny" };
});

return window;
}

function onboarding(language: string) {
log("Showing onboarding screen");
createBrowserWindow("SlimeTora: Onboarding", "onboarding.html", { language: language }, mainWindow);
}

function pairing() {
log("Showing pairing screen");
createBrowserWindow("SlimeTora: Pairing", "pairing.html", null, mainWindow);
}

async function showMessage(
Expand Down Expand Up @@ -472,6 +470,10 @@ ipcMain.on("show-onboarding", (_event, language) => {
onboarding(language);
});

ipcMain.on("show-pairing", () => {
pairing();
});

ipcMain.handle("translate", async (_event, arg: string) => {
return await translate(arg);
});
Expand Down Expand Up @@ -548,30 +550,13 @@ ipcMain.on("open-logs-folder", async () => {
});

ipcMain.on("open-tracker-settings", (_event, arg: string) => {
let trackerSettingsWindow = new BrowserWindow({
title: `SlimeTora: ${arg} settings`,
autoHideMenuBar: true,
width: 850,
height: 650,
modal: true, // prevent interaction with "parent" window until closed
parent: mainWindow,
webPreferences: {
contextIsolation: true,
nodeIntegration: true,
preload: path.join(__dirname, "preload.mjs"),
spellcheck: false,
sandbox: false, // fixes startup crashes due to GPU process, shouldn't be too large of a security risk as we're not loading any external content/connect to internet
},
icon: path.join(__dirname, "static/images/icon.ico"),
});

trackerSettingsWindow.loadURL(
format({
pathname: path.join(__dirname, "static/html/settings.html"),
protocol: "file:",
slashes: true,
query: { trackerName: arg },
})
let trackerSettingsWindow = createBrowserWindow(
`SlimeTora: ${arg} settings`,
"settings.html",
{ trackerName: arg },
mainWindow,
850,
650
);

trackerSettingsWindow.webContents.on("did-finish-load", () => {
Expand Down Expand Up @@ -704,7 +689,7 @@ function shouldInitializeNewDevice(): boolean {
}

function initializeDevice(forceDisableLogging: boolean = false) {
const trackerType = wiredTrackerEnabled ? TrackerModel.Wired: TrackerModel.Wireless;
const trackerType = wiredTrackerEnabled ? TrackerModel.Wired : TrackerModel.Wireless;
const effectiveLoggingMode = forceDisableLogging ? 1 : loggingMode;
log(`Creating new HaritoraX ${trackerType} instance with logging mode ${effectiveLoggingMode}...`, "connection");
const loggingOptions = {
Expand All @@ -721,7 +706,7 @@ function initializeDevice(forceDisableLogging: boolean = false) {
async function notifyConnectedDevices(): Promise<void> {
const activeTrackers = Array.from(new Set(device.getActiveTrackers()));
if (activeTrackers.length === 0) return;
for (const trackerName of activeTrackers) await addTracker(trackerName);
for (const trackerName of activeTrackers) await addTracker(trackerName as string);
log("Connected devices: " + JSON.stringify(activeTrackers), "connection");
}

Expand Down Expand Up @@ -921,6 +906,7 @@ import {
} from "@slimevr/firmware-protocol";
import { EmulatedTracker } from "@slimevr/tracker-emulation";
import BetterQuaternion from "quaternion";
import { ParsedUrlQueryInput } from "querystring";

// For haritorax-interpreter
// Used to handle errors coming from haritorax-interpreter and display them to the user if wanted
Expand Down Expand Up @@ -1037,9 +1023,8 @@ async function processQueue() {
const trackerTimeouts: { [key: string]: NodeJS.Timeout } = {};

const resetTrackerTimeout = (trackerName: string) => {
if (trackerTimeouts[trackerName]) {
clearTimeout(trackerTimeouts[trackerName]);
}
if (trackerTimeouts[trackerName]) clearTimeout(trackerTimeouts[trackerName]);

trackerTimeouts[trackerName] = setTimeout(() => {
device.emit("disconnect", trackerName);
log(`Tracker "${trackerName}" assumed disconnected due to inactivity.`, "tracker");
Expand Down
1 change: 1 addition & 0 deletions src/preload.mts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ declare global {
startConnection: () => void;
stopConnection: () => void;
showOnboarding: () => void;
showPairing: () => void;
openLogsFolder: () => void;
openSupport: () => void;
saveSettings: () => void;
Expand Down
2 changes: 1 addition & 1 deletion src/static/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -21850,7 +21850,7 @@ br {
flex-wrap: wrap;
}

.card-header-title {
.card-header-title.with-padding {
padding-right: 0.4rem;
}

Expand Down
2 changes: 1 addition & 1 deletion src/static/css/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ br {
flex-wrap: wrap;
}

.card-header-title {
.card-header-title.with-padding {
padding-right: 0.4rem;
}

Expand Down
69 changes: 69 additions & 0 deletions src/static/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,17 @@ <h3 class="title is-4 is-spaced" data-i18n="programSettings.other.title">Other s
style="max-width: 30%"
/>
</div>
<br />
<div class="buttons is-centered">
<button
class="button is-info"
id="onboarding-button"
onclick="showPairing()"
data-i18n="programSettings.other.pairing"
>
Manage GX(6/2) pairing
</button>
</div>
</div>

<div class="column is-12">
Expand Down Expand Up @@ -510,6 +521,64 @@ <h3 class="title is-4 is-spaced" data-i18n="trackerSettings.sensorCorrection.tit
</div>
</div>
</div>

<!-- Ankle settings -->
<div class="column is-6">
<div class="with-tooltip">
<h3 class="title is-4 is-spaced" data-i18n="settings.ankle.title">Virtual feet trackers</h3>
<div class="tooltip-container">
<div class="icon">
<img src="../images/help.svg" alt="Help icon" />
</div>
<span
class="tooltip-text subtitle is-6 has-text-weight-normal"
data-i18n="settings.ankle.tooltip"
>This enables the use of the trackers' ankle motion detection (ToF/distance sensors)
to create virtual feet trackers for use in SlimeVR.</span
>
</div>
</div>
<div class="settings-container">
<div class="switch-container">
<div class="switch">
<input type="checkbox" id="ankle-switch" />
<label for="ankle-switch" class="slider round"></label>
</div>
<label for="ankle-switch" data-i18n="settings.ankle.ankle"
>Feet trackers (w/ ankle data)</label
>
</div>
<br />
<div class="columns">
<div class="column">
<div class="input-container">
<label for="left-ankle-id" class="label" data-i18n="settings.ankle.leftAnkle"
>Left Ankle</label
>
<input
type="text"
id="left-ankle-id"
placeholder="Enter device ID"
class="input"
/>
</div>
</div>
<div class="column">
<div class="input-container">
<label for="right-ankle-id" class="label" data-i18n="settings.ankle.rightAnkle"
>Right Ankle</label
>
<input
type="text"
id="right-ankle-id"
placeholder="Enter device ID"
class="input"
/>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit fdf87da

Please sign in to comment.