mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-03 20:32:07 -04:00
dbar: Refactor to memoize dbar & widget state via json
This commit is contained in:
@@ -152,21 +152,35 @@ Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property string _barLayoutStateJson: {
|
||||||
|
const configs = SettingsData.barConfigs;
|
||||||
|
const mapped = configs.map(c => ({
|
||||||
|
id: c.id,
|
||||||
|
position: c.position,
|
||||||
|
autoHide: c.autoHide,
|
||||||
|
visible: c.visible
|
||||||
|
})).sort((a, b) => {
|
||||||
|
const aVertical = a.position === SettingsData.Position.Left || a.position === SettingsData.Position.Right;
|
||||||
|
const bVertical = b.position === SettingsData.Position.Left || b.position === SettingsData.Position.Right;
|
||||||
|
if (aVertical !== bVertical) {
|
||||||
|
return aVertical - bVertical;
|
||||||
|
}
|
||||||
|
return String(a.id).localeCompare(String(b.id));
|
||||||
|
});
|
||||||
|
return JSON.stringify(mapped);
|
||||||
|
}
|
||||||
|
|
||||||
|
on_BarLayoutStateJsonChanged: {
|
||||||
|
if (typeof dockRecreateDebounce !== "undefined") {
|
||||||
|
dockRecreateDebounce.restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
id: dankBarRepeater
|
id: dankBarRepeater
|
||||||
model: ScriptModel {
|
model: ScriptModel {
|
||||||
id: barRepeaterModel
|
id: barRepeaterModel
|
||||||
values: {
|
values: JSON.parse(root._barLayoutStateJson)
|
||||||
const configs = SettingsData.barConfigs;
|
|
||||||
return configs.map(c => ({
|
|
||||||
id: c.id,
|
|
||||||
position: c.position
|
|
||||||
})).sort((a, b) => {
|
|
||||||
const aVertical = a.position === SettingsData.Position.Left || a.position === SettingsData.Position.Right;
|
|
||||||
const bVertical = b.position === SettingsData.Position.Left || b.position === SettingsData.Position.Right;
|
|
||||||
return aVertical - bVertical;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
property var hyprlandOverviewLoaderRef: hyprlandOverviewLoader
|
property var hyprlandOverviewLoaderRef: hyprlandOverviewLoader
|
||||||
@@ -213,13 +227,6 @@ Item {
|
|||||||
PolkitService.polkitAvailable;
|
PolkitService.polkitAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
|
||||||
target: SettingsData
|
|
||||||
function onBarConfigsChanged() {
|
|
||||||
dockRecreateDebounce.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
id: dockLoader
|
id: dockLoader
|
||||||
active: root.dockEnabled
|
active: root.dockEnabled
|
||||||
|
|||||||
@@ -21,73 +21,82 @@ Item {
|
|||||||
property alias centerWidgetsModel: centerWidgetsModel
|
property alias centerWidgetsModel: centerWidgetsModel
|
||||||
property alias rightWidgetsModel: rightWidgetsModel
|
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 {
|
ScriptModel {
|
||||||
id: leftWidgetsModel
|
id: leftWidgetsModel
|
||||||
values: {
|
values: JSON.parse(root._leftWidgetsJson)
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptModel {
|
ScriptModel {
|
||||||
id: centerWidgetsModel
|
id: centerWidgetsModel
|
||||||
values: {
|
values: JSON.parse(root._centerWidgetsJson)
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptModel {
|
ScriptModel {
|
||||||
id: rightWidgetsModel
|
id: rightWidgetsModel
|
||||||
values: {
|
values: JSON.parse(root._rightWidgetsJson)
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerControlCenterOnFocusedScreen() {
|
function triggerControlCenterOnFocusedScreen() {
|
||||||
|
|||||||
@@ -28,35 +28,6 @@ Item {
|
|||||||
return pos === SettingsData.Position.Left || pos === SettingsData.Position.Right;
|
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() {
|
function createNewBar() {
|
||||||
if (SettingsData.barConfigs.length >= 4)
|
if (SettingsData.barConfigs.length >= 4)
|
||||||
return;
|
return;
|
||||||
@@ -543,9 +514,6 @@ Item {
|
|||||||
SettingsData.updateBarConfig(selectedBarId, {
|
SettingsData.updateBarConfig(selectedBarId, {
|
||||||
position: newPos
|
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, {
|
SettingsData.updateBarConfig(selectedBarId, {
|
||||||
autoHide: toggled
|
autoHide: toggled
|
||||||
});
|
});
|
||||||
notifyHorizontalBarChange();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -631,7 +598,6 @@ Item {
|
|||||||
SettingsData.updateBarConfig(selectedBarId, {
|
SettingsData.updateBarConfig(selectedBarId, {
|
||||||
visible: toggled
|
visible: toggled
|
||||||
});
|
});
|
||||||
notifyHorizontalBarChange();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -923,9 +889,9 @@ Item {
|
|||||||
value: Math.round((selectedBarConfig?.fontScale ?? 1.0) * 100)
|
value: Math.round((selectedBarConfig?.fontScale ?? 1.0) * 100)
|
||||||
unit: "%"
|
unit: "%"
|
||||||
defaultValue: 100
|
defaultValue: 100
|
||||||
onSliderDragFinished: finalValue => {
|
onSliderValueChanged: newValue => {
|
||||||
SettingsData.updateBarConfig(selectedBarId, {
|
SettingsData.updateBarConfig(selectedBarId, {
|
||||||
fontScale: finalValue / 100
|
fontScale: newValue / 100
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -948,9 +914,9 @@ Item {
|
|||||||
value: Math.round((selectedBarConfig?.iconScale ?? 1.0) * 100)
|
value: Math.round((selectedBarConfig?.iconScale ?? 1.0) * 100)
|
||||||
unit: "%"
|
unit: "%"
|
||||||
defaultValue: 100
|
defaultValue: 100
|
||||||
onSliderDragFinished: finalValue => {
|
onSliderValueChanged: newValue => {
|
||||||
SettingsData.updateBarConfig(selectedBarId, {
|
SettingsData.updateBarConfig(selectedBarId, {
|
||||||
iconScale: finalValue / 100
|
iconScale: newValue / 100
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user