mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-07 22:15:38 -05:00
Initial commit for nightMode automation
This commit is contained in:
@@ -762,9 +762,9 @@ DankPopout {
|
||||
implicitHeight: {
|
||||
let height = Theme.spacingL
|
||||
|
||||
if (BrightnessService.brightnessAvailable) {
|
||||
if (DisplayService.brightnessAvailable) {
|
||||
height += 80
|
||||
if (BrightnessService.devices.length > 1) {
|
||||
if (DisplayService.devices.length > 1) {
|
||||
height += 40
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,9 @@ Item {
|
||||
width: parent.width
|
||||
sourceComponent: settingsComponent
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Component {
|
||||
@@ -43,7 +45,7 @@ Item {
|
||||
Column {
|
||||
width: parent.width
|
||||
spacing: Theme.spacingS
|
||||
visible: BrightnessService.brightnessAvailable
|
||||
visible: DisplayService.brightnessAvailable
|
||||
|
||||
StyledText {
|
||||
text: "Brightness"
|
||||
@@ -54,102 +56,105 @@ Item {
|
||||
|
||||
DankDropdown {
|
||||
id: deviceDropdown
|
||||
|
||||
width: parent.width
|
||||
height: 40
|
||||
visible: BrightnessService.devices.length > 1
|
||||
visible: DisplayService.devices.length > 1
|
||||
text: "Device"
|
||||
description: {
|
||||
const deviceInfo = BrightnessService.getCurrentDeviceInfo()
|
||||
if (deviceInfo && deviceInfo.class === "ddc") {
|
||||
return "DDC changes can be slow and unreliable"
|
||||
}
|
||||
return ""
|
||||
const deviceInfo = DisplayService.getCurrentDeviceInfo();
|
||||
if (deviceInfo && deviceInfo.class === "ddc")
|
||||
return "DDC changes can be slow and unreliable";
|
||||
|
||||
return "";
|
||||
}
|
||||
currentValue: BrightnessService.currentDevice
|
||||
options: BrightnessService.devices.map(function (d) {
|
||||
return d.name
|
||||
currentValue: DisplayService.currentDevice
|
||||
options: DisplayService.devices.map(function(d) {
|
||||
return d.name;
|
||||
})
|
||||
optionIcons: BrightnessService.devices.map(function (d) {
|
||||
optionIcons: DisplayService.devices.map(function(d) {
|
||||
if (d.class === "backlight")
|
||||
return "desktop_windows"
|
||||
return "desktop_windows";
|
||||
|
||||
if (d.class === "ddc")
|
||||
return "tv"
|
||||
return "tv";
|
||||
|
||||
if (d.name.includes("kbd"))
|
||||
return "keyboard"
|
||||
return "keyboard";
|
||||
|
||||
return "lightbulb"
|
||||
return "lightbulb";
|
||||
})
|
||||
onValueChanged: function (value) {
|
||||
BrightnessService.setCurrentDevice(value, true)
|
||||
onValueChanged: function(value) {
|
||||
DisplayService.setCurrentDevice(value, true);
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: BrightnessService
|
||||
function onDevicesChanged() {
|
||||
if (BrightnessService.currentDevice) {
|
||||
deviceDropdown.currentValue = BrightnessService.currentDevice
|
||||
}
|
||||
if (DisplayService.currentDevice)
|
||||
deviceDropdown.currentValue = DisplayService.currentDevice;
|
||||
|
||||
// Check if saved device is now available
|
||||
const lastDevice = SessionData.lastBrightnessDevice
|
||||
|| ""
|
||||
const lastDevice = SessionData.lastBrightnessDevice || "";
|
||||
if (lastDevice) {
|
||||
const deviceExists = BrightnessService.devices.some(
|
||||
d => d.name === lastDevice)
|
||||
if (deviceExists
|
||||
&& (!BrightnessService.currentDevice
|
||||
|| BrightnessService.currentDevice !== lastDevice)) {
|
||||
BrightnessService.setCurrentDevice(lastDevice,
|
||||
false)
|
||||
}
|
||||
const deviceExists = DisplayService.devices.some((d) => {
|
||||
return d.name === lastDevice;
|
||||
});
|
||||
if (deviceExists && (!DisplayService.currentDevice || DisplayService.currentDevice !== lastDevice))
|
||||
DisplayService.setCurrentDevice(lastDevice, false);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function onDeviceSwitched() {
|
||||
// Force update the description when device switches
|
||||
deviceDropdown.description = Qt.binding(function () {
|
||||
const deviceInfo = BrightnessService.getCurrentDeviceInfo()
|
||||
if (deviceInfo && deviceInfo.class === "ddc") {
|
||||
return "DDC changes can be slow and unreliable"
|
||||
}
|
||||
return ""
|
||||
})
|
||||
deviceDropdown.description = Qt.binding(function() {
|
||||
const deviceInfo = DisplayService.getCurrentDeviceInfo();
|
||||
if (deviceInfo && deviceInfo.class === "ddc")
|
||||
return "DDC changes can be slow and unreliable";
|
||||
|
||||
return "";
|
||||
});
|
||||
}
|
||||
|
||||
target: DisplayService
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DankSlider {
|
||||
id: brightnessSlider
|
||||
|
||||
width: parent.width
|
||||
value: BrightnessService.brightnessLevel
|
||||
value: DisplayService.brightnessLevel
|
||||
leftIcon: "brightness_low"
|
||||
rightIcon: "brightness_high"
|
||||
enabled: BrightnessService.brightnessAvailable
|
||||
&& BrightnessService.isCurrentDeviceReady()
|
||||
opacity: BrightnessService.isCurrentDeviceReady() ? 1.0 : 0.5
|
||||
onSliderValueChanged: function (newValue) {
|
||||
brightnessDebounceTimer.pendingValue = newValue
|
||||
brightnessDebounceTimer.restart()
|
||||
enabled: DisplayService.brightnessAvailable && DisplayService.isCurrentDeviceReady()
|
||||
opacity: DisplayService.isCurrentDeviceReady() ? 1 : 0.5
|
||||
onSliderValueChanged: function(newValue) {
|
||||
brightnessDebounceTimer.pendingValue = newValue;
|
||||
brightnessDebounceTimer.restart();
|
||||
}
|
||||
onSliderDragFinished: function (finalValue) {
|
||||
brightnessDebounceTimer.stop()
|
||||
BrightnessService.setBrightnessInternal(
|
||||
finalValue, BrightnessService.currentDevice)
|
||||
onSliderDragFinished: function(finalValue) {
|
||||
brightnessDebounceTimer.stop();
|
||||
DisplayService.setBrightnessInternal(finalValue, DisplayService.currentDevice);
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: BrightnessService
|
||||
function onBrightnessChanged() {
|
||||
brightnessSlider.value = BrightnessService.brightnessLevel
|
||||
brightnessSlider.value = DisplayService.brightnessLevel;
|
||||
}
|
||||
|
||||
function onDeviceSwitched() {
|
||||
brightnessSlider.value = BrightnessService.brightnessLevel
|
||||
brightnessSlider.value = DisplayService.brightnessLevel;
|
||||
}
|
||||
|
||||
target: DisplayService
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Component {
|
||||
@@ -174,32 +179,40 @@ Item {
|
||||
width: (parent.width - Theme.spacingM) / 2
|
||||
height: 80
|
||||
radius: Theme.cornerRadius
|
||||
color: BrightnessService.nightModeActive ? Qt.rgba(
|
||||
Theme.primary.r,
|
||||
Theme.primary.g,
|
||||
Theme.primary.b,
|
||||
0.12) : (nightModeToggle.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08))
|
||||
border.color: BrightnessService.nightModeActive ? Theme.primary : "transparent"
|
||||
border.width: BrightnessService.nightModeActive ? 1 : 0
|
||||
color: DisplayService.nightModeActive ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : (nightModeToggle.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08))
|
||||
border.color: DisplayService.nightModeActive ? Theme.primary : "transparent"
|
||||
border.width: DisplayService.nightModeActive ? 1 : 0
|
||||
opacity: SessionData.nightModeAutoEnabled ? 0.6 : 1
|
||||
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
spacing: Theme.spacingS
|
||||
|
||||
DankIcon {
|
||||
name: BrightnessService.nightModeActive ? "nightlight" : "dark_mode"
|
||||
name: DisplayService.nightModeActive ? "nightlight" : "dark_mode"
|
||||
size: Theme.iconSizeLarge
|
||||
color: BrightnessService.nightModeActive ? Theme.primary : Theme.surfaceText
|
||||
color: DisplayService.nightModeActive ? Theme.primary : Theme.surfaceText
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: "Night Mode"
|
||||
text: SessionData.nightModeAutoEnabled ? "Night Mode (Auto)" : "Night Mode"
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: BrightnessService.nightModeActive ? Theme.primary : Theme.surfaceText
|
||||
color: DisplayService.nightModeActive ? Theme.primary : Theme.surfaceText
|
||||
font.weight: Font.Medium
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DankIcon {
|
||||
name: "schedule"
|
||||
size: 16
|
||||
color: Theme.primary
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
anchors.margins: Theme.spacingS
|
||||
visible: SessionData.nightModeAutoEnabled
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
@@ -209,20 +222,17 @@ Item {
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
BrightnessService.toggleNightMode()
|
||||
DisplayService.toggleNightMode();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
width: (parent.width - Theme.spacingM) / 2
|
||||
height: 80
|
||||
radius: Theme.cornerRadius
|
||||
color: SessionData.isLightMode ? Qt.rgba(
|
||||
Theme.primary.r,
|
||||
Theme.primary.g,
|
||||
Theme.primary.b,
|
||||
0.12) : (lightModeToggle.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08))
|
||||
color: SessionData.isLightMode ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.12) : (lightModeToggle.containsMouse ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.08) : Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.08))
|
||||
border.color: SessionData.isLightMode ? Theme.primary : "transparent"
|
||||
border.width: SessionData.isLightMode ? 1 : 0
|
||||
|
||||
@@ -244,6 +254,7 @@ Item {
|
||||
font.weight: Font.Medium
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
@@ -253,7 +264,7 @@ Item {
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
Theme.toggleLightMode()
|
||||
Theme.toggleLightMode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,10 +273,15 @@ Item {
|
||||
duration: Theme.shortDuration
|
||||
easing.type: Theme.standardEasing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
brightnessDebounceTimer: Timer {
|
||||
@@ -273,13 +289,13 @@ Item {
|
||||
|
||||
interval: {
|
||||
// Use longer interval for DDC devices since ddcutil is slow
|
||||
const deviceInfo = BrightnessService.getCurrentDeviceInfo()
|
||||
return (deviceInfo && deviceInfo.class === "ddc") ? 100 : 50
|
||||
const deviceInfo = DisplayService.getCurrentDeviceInfo();
|
||||
return (deviceInfo && deviceInfo.class === "ddc") ? 100 : 50;
|
||||
}
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
BrightnessService.setBrightnessInternal(
|
||||
pendingValue, BrightnessService.currentDevice)
|
||||
DisplayService.setBrightnessInternal(pendingValue, DisplayService.currentDevice);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user