Skip to content

Commit 92b52e0

Browse files
committed
fix: progress bar is broken
fixes #175
1 parent 4192210 commit 92b52e0

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

src/routes/(app)/SyncOverlay.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@
5454
5555
progress::-webkit-progress-value {
5656
background: var(--md-sys-color-primary);
57+
transition: width 2s ease;
5758
}
5859
</style>

src/routes/(app)/config/EditActions.svelte

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@
4747
if (!port) return;
4848
$syncStatus = "uploading";
4949
50+
const layoutChanges = $overlay.layout.reduce(
51+
(acc, layer) => acc + layer.size,
52+
0,
53+
);
54+
const settingChanges = $overlay.settings.size;
55+
const chordChanges = $overlay.chords.size;
56+
const needsCommit = settingChanges > 0 && layoutChanges > 0;
57+
const progressMax = layoutChanges + settingChanges + chordChanges;
58+
59+
let progressCurrent = 0;
60+
61+
syncProgress.set({
62+
max: progressMax,
63+
current: progressCurrent,
64+
});
65+
5066
for (const [id, chord] of $overlay.chords) {
5167
if (!chord.deleted) {
5268
if (id !== JSON.stringify(chord.actions)) {
@@ -83,16 +99,28 @@
8399
} else {
84100
await port.deleteChord({ actions: chord.actions });
85101
}
102+
syncProgress.set({
103+
max: progressMax,
104+
current: progressCurrent++,
105+
});
86106
}
87107
88108
for (const [layer, actions] of $overlay.layout.entries()) {
89109
for (const [id, action] of actions) {
90110
await port.setLayoutKey(layer + 1, id, action);
111+
syncProgress.set({
112+
max: progressMax,
113+
current: progressCurrent++,
114+
});
91115
}
92116
}
93117
94118
for (const [id, setting] of $overlay.settings) {
95119
await port.setSetting(id, setting);
120+
syncProgress.set({
121+
max: progressMax,
122+
current: progressCurrent++,
123+
});
96124
}
97125
98126
// Yes, this is a completely arbitrary and unnecessary delay.
@@ -102,24 +130,9 @@
102130
// would be if they click it every time they change a setting.
103131
// Because of that, we don't need to show a fearmongering message such as
104132
// "Your device will break after you click this 10,000 times!"
105-
const virtualWriteTime = 1000;
106-
const startStamp = performance.now();
107-
await new Promise<void>((resolve) => {
108-
function animate() {
109-
const delta = performance.now() - startStamp;
110-
syncProgress.set({
111-
max: virtualWriteTime,
112-
current: delta,
113-
});
114-
if (delta >= virtualWriteTime) {
115-
resolve();
116-
} else {
117-
requestAnimationFrame(animate);
118-
}
119-
}
120-
requestAnimationFrame(animate);
121-
});
122-
await port.commit();
133+
if (needsCommit) {
134+
await port.commit();
135+
}
123136
124137
$deviceLayout = $layout.map((layer) =>
125138
layer.map<number>(({ action }) => action),

0 commit comments

Comments
 (0)