Skip to content

Commit

Permalink
Allow overriding slimevr server/port to search on
Browse files Browse the repository at this point in the history
idk why i didn't have this before, lol

thanks @ButterscotchV
  • Loading branch information
JovannMC committed Dec 18, 2024
1 parent c384f6e commit 58a7cbe
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
"autoStart": "Start connection on open",
"autoOff": "Turn off trackers on exit",
"trackerVisualizationFPS": "Tracker visualization FPS",
"heartbeat": "Tracker heartbeat interval"
"heartbeat": "Tracker heartbeat interval",
"serverAddress": "SlimeVR server address",
"serverPort": "SlimeVR server port"
},
"updates": {
"title": "Update checking",
Expand Down
24 changes: 22 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ let firstLaunch = false;
let isClosing = false;
let hasInitializedLogDir = false;
let foundSlimeVR = false;
let serverAddress = "255.255.255.255";
let serverPort = 6969;

let canLogToFile = true;
let loggingMode = 1;
Expand Down Expand Up @@ -86,6 +88,9 @@ try {
updateChannel = config.global?.updates?.updateChannel ?? "stable";
heartbeatInterval = config.global?.trackers?.heartbeatInterval ?? 2000;
loggingMode = config.global?.debug?.loggingMode ?? 1;

serverAddress = config.global?.serverAddress ?? "255.255.255.255";
serverPort = config.global?.serverPort ?? 6969;
} catch (err) {
// If the config file doesn't exist or is empty, create it
log("First launch, creating config file and showing onboarding screen (after load)");
Expand Down Expand Up @@ -637,6 +642,16 @@ ipcMain.on("set-auto-off", (_event, arg) => {
log(`Auto-off set to: ${arg}`, "settings");
});

ipcMain.on("set-server-address", (_event, arg) => {
serverAddress = arg;
log(`Server address set to: ${arg}`, "settings");
});

ipcMain.on("set-server-port", (_event, arg) => {
serverPort = arg;
log(`Server port set to: ${arg}`, "settings");
});

ipcMain.on("open-support-page", async () => {
await shell.openExternal("https://github.com/OCSYT/SlimeTora/wiki/FAQ#i-found-an-issuebug");
});
Expand Down Expand Up @@ -1194,7 +1209,9 @@ async function processQueue() {
`SlimeTora v${app.getVersion()}`,
new FirmwareFeatureFlags(new Map([])),
BoardType.HARITORA,
MCUType.HARITORA
MCUType.HARITORA,
serverAddress,
serverPort
);

await newTracker.init();
Expand Down Expand Up @@ -1650,11 +1667,14 @@ const heartbeatTracker = new EmulatedTracker(
`SlimeTora v${app.getVersion()} heartbeat`,
new FirmwareFeatureFlags(new Map([])),
BoardType.HARITORA,
MCUType.HARITORA
MCUType.HARITORA,
serverAddress,
serverPort
);

setupTrackerEvents(heartbeatTracker, true);
await heartbeatTracker.init();
log(`Looking for SlimeVR server on: ${serverAddress}:${serverPort}`, "connection");

/*
* Logging
Expand Down
38 changes: 38 additions & 0 deletions src/static/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,43 @@ <h3 class="title is-4 is-spaced" data-i18n="programSettings.other.title">Other s
</div>
</div>
</div>
<br />
<div class="columns is-centered">
<div class="column is-two-fifths is-centered">
<div class="input-container">
<label
for="server-address"
class="label has-text-warning"
data-i18n="programSettings.other.serverAddress"
>SlimeVR server address</label
>
<input
type="text"
id="server-address"
placeholder="255.255.255.255"
class="input"
style="max-width: 100%"
/>
</div>
</div>
<div class="column is-two-fifths is-centered">
<div class="input-container">
<label
for="server-port"
class="label has-text-warning"
data-i18n="programSettings.other.serverPort"
>SlimeVR server port</label
>
<input
type="text"
id="server-port"
placeholder="6969"
class="input"
style="max-width: 100%"
/>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -728,6 +765,7 @@ <h2 class="subtitle has-text-centered" data-i18n="debugging.text">
</div>
</div>
<br />
<br />
<div class="buttons is-centered">
<button class="button is-primary" onclick="openSupport()" data-i18n="debugging.openSupportPage">
Open support page
Expand Down
38 changes: 37 additions & 1 deletion src/static/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ let autoOff = false;
let trackerVisualizationFPS = 10;
let trackerHeartbeatInterval = 2000;

let serverAddress = "255.255.255.255";
let serverPort = 6969;

let appUpdatesEnabled = true;
let translationsUpdatesEnabled = true;
let updateChannel = "stable";
Expand Down Expand Up @@ -145,6 +148,8 @@ document.addEventListener("DOMContentLoaded", async function () {
canLogToFile = settings.global?.debug?.canLogToFile ?? true;
loggingMode = settings.global?.debug?.loggingMode ?? 1;
bypassCOMPortLimit = settings.global?.debug?.bypassCOMPortLimit ?? false;
serverAddress = settings.global?.serverAddress ?? "255.255.255.255";
serverPort = settings.global?.serverPort ?? 6969;

// Set switch states based on settings
setSwitchState("compact-view-switch", compactView);
Expand Down Expand Up @@ -178,6 +183,12 @@ document.addEventListener("DOMContentLoaded", async function () {
const trackerHeartbeatIntervalInput = document.getElementById("tracker-heartbeat-interval") as HTMLInputElement;
trackerHeartbeatIntervalInput.value = trackerHeartbeatInterval.toString();

const serverAddressInput = document.getElementById("server-address") as HTMLInputElement;
serverAddressInput.value = serverAddress;

const serverPortInput = document.getElementById("server-port") as HTMLInputElement;
serverPortInput.value = serverPort.toString();

// Set the selected COM ports
const comPortsSwitches = Array.from(document.getElementById("com-ports").querySelectorAll("input"));
const selectedPorts: string[] = settings.global?.connectionMode?.comPorts ?? [];
Expand Down Expand Up @@ -1234,6 +1245,30 @@ function addEventListeners() {
window.ipc.send("set-tracker-heartbeat-interval", heartbeatInterval);
});

document.getElementById("server-address").addEventListener("change", async function () {
serverAddress = (document.getElementById("server-address") as HTMLInputElement).value;
window.log(`Changed server address to: ${serverAddress}`);
window.ipc.send("save-setting", {
global: {
serverAddress: serverAddress,
},
});

window.ipc.send("set-server-address", serverAddress);
});

document.getElementById("server-port").addEventListener("change", async function () {
serverPort = parseInt((document.getElementById("server-port") as HTMLInputElement).value);
window.log(`Changed server port to: ${serverPort}`);
window.ipc.send("save-setting", {
global: {
serverPort: serverPort,
},
});

window.ipc.send("set-server-port", serverPort);
});

document.getElementById("language-select").addEventListener("change", async function () {
const language: string = (document.getElementById("language-select") as HTMLSelectElement).value;
selectLanguage(language);
Expand Down Expand Up @@ -1544,4 +1579,5 @@ window.openSupport = () => {
window.ipc.send("open-support-page", null);
};

export {};
export { };

0 comments on commit 58a7cbe

Please sign in to comment.