mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-04 04:42:05 -04:00
dbar: Refactor to memoize dbar & widget state via json
This commit is contained in:
@@ -21,73 +21,82 @@ Item {
|
||||
property alias centerWidgetsModel: centerWidgetsModel
|
||||
property alias rightWidgetsModel: rightWidgetsModel
|
||||
|
||||
property string _leftWidgetsJson: {
|
||||
root.barConfig;
|
||||
const leftWidgets = root.barConfig?.leftWidgets || [];
|
||||
const mapped = leftWidgets.map((w, index) => {
|
||||
if (typeof w === "string") {
|
||||
return {
|
||||
widgetId: w,
|
||||
id: w + "_" + index,
|
||||
enabled: true
|
||||
};
|
||||
} else {
|
||||
const obj = Object.assign({}, w);
|
||||
obj.widgetId = w.id || w.widgetId;
|
||||
obj.id = (w.id || w.widgetId) + "_" + index;
|
||||
obj.enabled = w.enabled !== false;
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
return JSON.stringify(mapped);
|
||||
}
|
||||
|
||||
property string _centerWidgetsJson: {
|
||||
root.barConfig;
|
||||
const centerWidgets = root.barConfig?.centerWidgets || [];
|
||||
const mapped = centerWidgets.map((w, index) => {
|
||||
if (typeof w === "string") {
|
||||
return {
|
||||
widgetId: w,
|
||||
id: w + "_" + index,
|
||||
enabled: true
|
||||
};
|
||||
} else {
|
||||
const obj = Object.assign({}, w);
|
||||
obj.widgetId = w.id || w.widgetId;
|
||||
obj.id = (w.id || w.widgetId) + "_" + index;
|
||||
obj.enabled = w.enabled !== false;
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
return JSON.stringify(mapped);
|
||||
}
|
||||
|
||||
property string _rightWidgetsJson: {
|
||||
root.barConfig;
|
||||
const rightWidgets = root.barConfig?.rightWidgets || [];
|
||||
const mapped = rightWidgets.map((w, index) => {
|
||||
if (typeof w === "string") {
|
||||
return {
|
||||
widgetId: w,
|
||||
id: w + "_" + index,
|
||||
enabled: true
|
||||
};
|
||||
} else {
|
||||
const obj = Object.assign({}, w);
|
||||
obj.widgetId = w.id || w.widgetId;
|
||||
obj.id = (w.id || w.widgetId) + "_" + index;
|
||||
obj.enabled = w.enabled !== false;
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
return JSON.stringify(mapped);
|
||||
}
|
||||
|
||||
ScriptModel {
|
||||
id: leftWidgetsModel
|
||||
values: {
|
||||
root.barConfig;
|
||||
const leftWidgets = root.barConfig?.leftWidgets || [];
|
||||
return leftWidgets.map((w, index) => {
|
||||
if (typeof w === "string") {
|
||||
return {
|
||||
widgetId: w,
|
||||
id: w + "_" + index,
|
||||
enabled: true
|
||||
};
|
||||
} else {
|
||||
const obj = Object.assign({}, w);
|
||||
obj.widgetId = w.id || w.widgetId;
|
||||
obj.id = (w.id || w.widgetId) + "_" + index;
|
||||
obj.enabled = w.enabled !== false;
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
}
|
||||
values: JSON.parse(root._leftWidgetsJson)
|
||||
}
|
||||
|
||||
ScriptModel {
|
||||
id: centerWidgetsModel
|
||||
values: {
|
||||
root.barConfig;
|
||||
const centerWidgets = root.barConfig?.centerWidgets || [];
|
||||
return centerWidgets.map((w, index) => {
|
||||
if (typeof w === "string") {
|
||||
return {
|
||||
widgetId: w,
|
||||
id: w + "_" + index,
|
||||
enabled: true
|
||||
};
|
||||
} else {
|
||||
const obj = Object.assign({}, w);
|
||||
obj.widgetId = w.id || w.widgetId;
|
||||
obj.id = (w.id || w.widgetId) + "_" + index;
|
||||
obj.enabled = w.enabled !== false;
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
}
|
||||
values: JSON.parse(root._centerWidgetsJson)
|
||||
}
|
||||
|
||||
ScriptModel {
|
||||
id: rightWidgetsModel
|
||||
values: {
|
||||
root.barConfig;
|
||||
const rightWidgets = root.barConfig?.rightWidgets || [];
|
||||
return rightWidgets.map((w, index) => {
|
||||
if (typeof w === "string") {
|
||||
return {
|
||||
widgetId: w,
|
||||
id: w + "_" + index,
|
||||
enabled: true
|
||||
};
|
||||
} else {
|
||||
const obj = Object.assign({}, w);
|
||||
obj.widgetId = w.id || w.widgetId;
|
||||
obj.id = (w.id || w.widgetId) + "_" + index;
|
||||
obj.enabled = w.enabled !== false;
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
}
|
||||
values: JSON.parse(root._rightWidgetsJson)
|
||||
}
|
||||
|
||||
function triggerControlCenterOnFocusedScreen() {
|
||||
|
||||
@@ -28,35 +28,6 @@ Item {
|
||||
return pos === SettingsData.Position.Left || pos === SettingsData.Position.Right;
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: horizontalBarChangeDebounce
|
||||
interval: 500
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
const verticalBars = SettingsData.barConfigs.filter(cfg => {
|
||||
const pos = cfg.position ?? SettingsData.Position.Top;
|
||||
return pos === SettingsData.Position.Left || pos === SettingsData.Position.Right;
|
||||
});
|
||||
|
||||
verticalBars.forEach(bar => {
|
||||
if (!bar.enabled)
|
||||
return;
|
||||
SettingsData.updateBarConfig(bar.id, {
|
||||
enabled: false
|
||||
});
|
||||
Qt.callLater(() => SettingsData.updateBarConfig(bar.id, {
|
||||
enabled: true
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function notifyHorizontalBarChange() {
|
||||
if (selectedBarIsVertical)
|
||||
return;
|
||||
horizontalBarChangeDebounce.restart();
|
||||
}
|
||||
|
||||
function createNewBar() {
|
||||
if (SettingsData.barConfigs.length >= 4)
|
||||
return;
|
||||
@@ -543,9 +514,6 @@ Item {
|
||||
SettingsData.updateBarConfig(selectedBarId, {
|
||||
position: newPos
|
||||
});
|
||||
const isVertical = newPos === SettingsData.Position.Left || newPos === SettingsData.Position.Right;
|
||||
if (wasVertical !== isVertical || !isVertical)
|
||||
notifyHorizontalBarChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -564,7 +532,6 @@ Item {
|
||||
SettingsData.updateBarConfig(selectedBarId, {
|
||||
autoHide: toggled
|
||||
});
|
||||
notifyHorizontalBarChange();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -631,7 +598,6 @@ Item {
|
||||
SettingsData.updateBarConfig(selectedBarId, {
|
||||
visible: toggled
|
||||
});
|
||||
notifyHorizontalBarChange();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -923,9 +889,9 @@ Item {
|
||||
value: Math.round((selectedBarConfig?.fontScale ?? 1.0) * 100)
|
||||
unit: "%"
|
||||
defaultValue: 100
|
||||
onSliderDragFinished: finalValue => {
|
||||
onSliderValueChanged: newValue => {
|
||||
SettingsData.updateBarConfig(selectedBarId, {
|
||||
fontScale: finalValue / 100
|
||||
fontScale: newValue / 100
|
||||
});
|
||||
}
|
||||
|
||||
@@ -948,9 +914,9 @@ Item {
|
||||
value: Math.round((selectedBarConfig?.iconScale ?? 1.0) * 100)
|
||||
unit: "%"
|
||||
defaultValue: 100
|
||||
onSliderDragFinished: finalValue => {
|
||||
onSliderValueChanged: newValue => {
|
||||
SettingsData.updateBarConfig(selectedBarId, {
|
||||
iconScale: finalValue / 100
|
||||
iconScale: newValue / 100
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user