Skip to content

Commit

Permalink
Remove need to restart connection for some settings
Browse files Browse the repository at this point in the history
  • Loading branch information
JovannMC committed Aug 14, 2024
1 parent ada0c90 commit 5930886
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ function startDeviceListeners() {
}
trackerTimeouts[trackerName] = setTimeout(() => {
device.emit("disconnect", trackerName);
log(`Tracker ${trackerName} assumed disconnected due to inactivity.`);
log(`Tracker ${trackerName} assumed disconnected due to inactivity.`, "tracker");
}, 5000);
};

Expand Down
5 changes: 2 additions & 3 deletions src/static/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ <h3 class="title is-2 is-spaced" data-i18n="trackerInfo.title">Tracker informati
<input type="checkbox" id="compact-view-switch" />
<label for="compact-view-switch" class="slider round"></label>
</div>
<label for="compact-view-switch" class="has-text-warning" data-i18n="trackerInfo.compactView"
<label for="compact-view-switch" data-i18n="trackerInfo.compactView"
>Compact view</label
>
</div>
Expand All @@ -120,7 +120,6 @@ <h3 class="title is-2 is-spaced" data-i18n="trackerInfo.title">Tracker informati
</div>
<label
for="visualization-switch"
class="has-text-warning"
data-i18n="trackerInfo.trackerVisualization"
>Tracker visualization</label
>
Expand Down Expand Up @@ -344,7 +343,7 @@ <h3 class="title is-4 is-spaced" data-i18n="programSettings.updates.title">
<div class="input-container is-centered has-text-centered">
<label
for="update-channel-select"
class="label has-text-warning"
class="label"
data-i18n="programSettings.updates.channel.title"
>Update channel</label
>
Expand Down
23 changes: 22 additions & 1 deletion src/static/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

let isActive = false;
let refreshingDeviceList = false;

let bluetoothEnabled = false;
let comEnabled = false;
Expand Down Expand Up @@ -625,7 +626,7 @@ window.ipc.on("device-connected-to-server", (_event, deviceID) => {
window.ipc.on("device-data", async (_event: any, arg) => {
const { trackerName, rotation, gravity, rawRotation, rawGravity } = arg;

if (!isActive) return;
if (!isActive || refreshingDeviceList) return;

const trackerElement = document.getElementById(trackerName);
if (!trackerElement) {
Expand Down Expand Up @@ -964,6 +965,22 @@ window.ipc.on("set-status", (_event, msg) => {
});

function addEventListeners() {
function refreshDeviceList() {
refreshingDeviceList = true;

document.getElementById("device-list").textContent = "";
deviceQueue.length = 0;

const devices = document.querySelectorAll(".card");
devices.forEach((device) => {
deviceQueue.push(device.id);
});

processQueue().then(() => {
refreshingDeviceList = false;
});
}

/*
* "Tracker info" event listeners
*/
Expand All @@ -976,6 +993,8 @@ function addEventListeners() {
compactView: compactView,
},
});

refreshDeviceList();
});

document.getElementById("censor-serial-switch").addEventListener("change", function () {
Expand Down Expand Up @@ -1038,6 +1057,8 @@ function addEventListeners() {
trackerVisualization: trackerVisualization,
},
});

refreshDeviceList();
});

/*
Expand Down

0 comments on commit 5930886

Please sign in to comment.