mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-22 09:52:50 +00:00
feat: profile support
This commit is contained in:
@@ -48,10 +48,14 @@
|
||||
$syncStatus = "uploading";
|
||||
|
||||
const layoutChanges = $overlay.layout.reduce(
|
||||
(acc, layer) => acc + layer.size,
|
||||
(acc, profile) =>
|
||||
acc + profile.reduce((acc, layer) => acc + layer.size, 0),
|
||||
0,
|
||||
);
|
||||
const settingChanges = $overlay.settings.reduce(
|
||||
(acc, profile) => acc + profile.size,
|
||||
0,
|
||||
);
|
||||
const settingChanges = $overlay.settings.size;
|
||||
const chordChanges = $overlay.chords.size;
|
||||
const needsCommit = settingChanges > 0 || layoutChanges > 0;
|
||||
const progressMax = layoutChanges + settingChanges + chordChanges;
|
||||
@@ -63,6 +67,8 @@
|
||||
current: progressCurrent,
|
||||
});
|
||||
|
||||
console.log($overlay);
|
||||
|
||||
for (const [id, chord] of $overlay.chords) {
|
||||
if (!chord.deleted) {
|
||||
if (id !== JSON.stringify(chord.actions)) {
|
||||
@@ -105,9 +111,26 @@
|
||||
});
|
||||
}
|
||||
|
||||
for (const [layer, actions] of $overlay.layout.entries()) {
|
||||
for (const [id, action] of actions) {
|
||||
await port.setLayoutKey(layer + 1, id, action);
|
||||
for (const [profile, layout] of $overlay.layout.entries()) {
|
||||
if (layout === undefined) continue;
|
||||
for (const [layer, actions] of layout.entries()) {
|
||||
if (actions === undefined) continue;
|
||||
for (const [id, action] of actions) {
|
||||
if (action === undefined) continue;
|
||||
await port.setLayoutKey(profile, layer + 1, id, action);
|
||||
syncProgress.set({
|
||||
max: progressMax,
|
||||
current: progressCurrent++,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const [profile, settings] of $overlay.settings.entries()) {
|
||||
if (settings === undefined) continue;
|
||||
for (const [id, setting] of settings.entries()) {
|
||||
if (setting === undefined) continue;
|
||||
await port.setSetting(profile, id, setting);
|
||||
syncProgress.set({
|
||||
max: progressMax,
|
||||
current: progressCurrent++,
|
||||
@@ -115,14 +138,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
for (const [id, setting] of $overlay.settings) {
|
||||
await port.setSetting(id, setting);
|
||||
syncProgress.set({
|
||||
max: progressMax,
|
||||
current: progressCurrent++,
|
||||
});
|
||||
}
|
||||
|
||||
// Yes, this is a completely arbitrary and unnecessary delay.
|
||||
// The only purpose of it is to create a sense of weight,
|
||||
// aka make it more "energy intensive" to click.
|
||||
@@ -134,13 +149,15 @@
|
||||
await port.commit();
|
||||
}
|
||||
|
||||
$deviceLayout = $layout.map((layer) =>
|
||||
layer.map<number>(({ action }) => action),
|
||||
) as [number[], number[], number[]];
|
||||
$deviceLayout = $layout.map((profile) =>
|
||||
profile.map((layer) => layer.map<number>(({ action }) => action)),
|
||||
);
|
||||
$deviceChords = $chords
|
||||
.filter(({ deleted }) => !deleted)
|
||||
.map(({ actions, phrase }) => ({ actions, phrase }));
|
||||
$deviceSettings = $settings.map(({ value }) => value);
|
||||
$deviceSettings = $settings.map((profile) =>
|
||||
profile.map(({ value }) => value),
|
||||
);
|
||||
$changes = [];
|
||||
} catch (e) {
|
||||
alert(e);
|
||||
|
||||
Reference in New Issue
Block a user