mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-13 00:42:49 -05:00
ControlCenter: Implement edit mode for customizing widgets
This commit is contained in:
75
Modules/ControlCenter/utils/widgets.js
Normal file
75
Modules/ControlCenter/utils/widgets.js
Normal file
@@ -0,0 +1,75 @@
|
||||
function getWidgetForId(baseWidgetDefinitions, widgetId) {
|
||||
return baseWidgetDefinitions.find(w => w.id === widgetId)
|
||||
}
|
||||
|
||||
function addWidget(widgetId) {
|
||||
var widgets = SettingsData.controlCenterWidgets.slice()
|
||||
var widget = {
|
||||
"id": widgetId,
|
||||
"enabled": true,
|
||||
"width": 50
|
||||
}
|
||||
widgets.push(widget)
|
||||
SettingsData.setControlCenterWidgets(widgets)
|
||||
}
|
||||
|
||||
function removeWidget(index) {
|
||||
var widgets = SettingsData.controlCenterWidgets.slice()
|
||||
if (index >= 0 && index < widgets.length) {
|
||||
widgets.splice(index, 1)
|
||||
SettingsData.setControlCenterWidgets(widgets)
|
||||
}
|
||||
}
|
||||
|
||||
function toggleWidgetSize(index) {
|
||||
var widgets = SettingsData.controlCenterWidgets.slice()
|
||||
if (index >= 0 && index < widgets.length) {
|
||||
const currentWidth = widgets[index].width || 50
|
||||
const id = widgets[index].id || ""
|
||||
|
||||
if (id === "wifi" || id === "bluetooth" || id === "audioOutput" || id === "audioInput") {
|
||||
widgets[index].width = currentWidth <= 50 ? 100 : 50
|
||||
} else {
|
||||
if (currentWidth <= 25) {
|
||||
widgets[index].width = 50
|
||||
} else if (currentWidth <= 50) {
|
||||
widgets[index].width = 100
|
||||
} else {
|
||||
widgets[index].width = 25
|
||||
}
|
||||
}
|
||||
|
||||
SettingsData.setControlCenterWidgets(widgets)
|
||||
}
|
||||
}
|
||||
|
||||
function reorderWidgets(newOrder) {
|
||||
SettingsData.setControlCenterWidgets(newOrder)
|
||||
}
|
||||
|
||||
function moveWidget(fromIndex, toIndex) {
|
||||
let widgets = [...(SettingsData.controlCenterWidgets || [])]
|
||||
if (fromIndex >= 0 && fromIndex < widgets.length && toIndex >= 0 && toIndex < widgets.length) {
|
||||
const movedWidget = widgets.splice(fromIndex, 1)[0]
|
||||
widgets.splice(toIndex, 0, movedWidget)
|
||||
SettingsData.setControlCenterWidgets(widgets)
|
||||
}
|
||||
}
|
||||
|
||||
function resetToDefault() {
|
||||
const defaultWidgets = [
|
||||
{"id": "volumeSlider", "enabled": true, "width": 50},
|
||||
{"id": "brightnessSlider", "enabled": true, "width": 50},
|
||||
{"id": "wifi", "enabled": true, "width": 50},
|
||||
{"id": "bluetooth", "enabled": true, "width": 50},
|
||||
{"id": "audioOutput", "enabled": true, "width": 50},
|
||||
{"id": "audioInput", "enabled": true, "width": 50},
|
||||
{"id": "nightMode", "enabled": true, "width": 50},
|
||||
{"id": "darkMode", "enabled": true, "width": 50}
|
||||
]
|
||||
SettingsData.setControlCenterWidgets(defaultWidgets)
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
SettingsData.setControlCenterWidgets([])
|
||||
}
|
||||
Reference in New Issue
Block a user