mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-29 16:02:51 -05:00
cleanup: Auto theme switcher
This commit is contained in:
@@ -392,15 +392,11 @@ func (m *Manager) recalcSchedule(now time.Time) {
|
|||||||
cond = SunNormal
|
cond = SunNormal
|
||||||
} else {
|
} else {
|
||||||
lat, lon := m.getLocation()
|
lat, lon := m.getLocation()
|
||||||
log.Errorf("@@@ recalcSchedule: lat=%v, lon=%v @@@", lat, lon)
|
|
||||||
if lat == nil || lon == nil {
|
if lat == nil || lon == nil {
|
||||||
log.Errorf("@@@ recalcSchedule: NO LOCATION, setting StateStatic @@@")
|
|
||||||
m.gammaState = StateStatic
|
m.gammaState = StateStatic
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Errorf("@@@ recalcSchedule: calculating sun times for lat=%.4f, lon=%.4f @@@", *lat, *lon)
|
|
||||||
times, cond = CalculateSunTimesWithTwilight(*lat, *lon, now, config.ElevationTwilight, config.ElevationDaylight)
|
times, cond = CalculateSunTimesWithTwilight(*lat, *lon, now, config.ElevationTwilight, config.ElevationDaylight)
|
||||||
log.Errorf("@@@ recalcSchedule: sunrise=%v, sunset=%v @@@", times.Sunrise, times.Sunset)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m.schedule.calcDay = dayStart
|
m.schedule.calcDay = dayStart
|
||||||
@@ -779,21 +775,16 @@ func (m *Manager) updateStateFromSchedule() {
|
|||||||
config := m.config
|
config := m.config
|
||||||
m.configMutex.RUnlock()
|
m.configMutex.RUnlock()
|
||||||
|
|
||||||
log.Errorf("@@@ updateStateFromSchedule: config.Lat=%v, config.Lon=%v @@@", config.Latitude, config.Longitude)
|
|
||||||
|
|
||||||
m.scheduleMutex.RLock()
|
m.scheduleMutex.RLock()
|
||||||
times := m.schedule.times
|
times := m.schedule.times
|
||||||
m.scheduleMutex.RUnlock()
|
m.scheduleMutex.RUnlock()
|
||||||
|
|
||||||
log.Errorf("@@@ updateStateFromSchedule: times.Sunrise=%v, times.Sunset=%v @@@", times.Sunrise, times.Sunset)
|
|
||||||
|
|
||||||
var pos float64
|
var pos float64
|
||||||
var temp int
|
var temp int
|
||||||
var isDay bool
|
var isDay bool
|
||||||
var deadline time.Time
|
var deadline time.Time
|
||||||
|
|
||||||
if times.Sunrise.IsZero() {
|
if times.Sunrise.IsZero() {
|
||||||
log.Errorf("@@@ updateStateFromSchedule: Sunrise is ZERO, defaulting isDay=true @@@")
|
|
||||||
pos = 1.0
|
pos = 1.0
|
||||||
temp = config.HighTemp
|
temp = config.HighTemp
|
||||||
isDay = true
|
isDay = true
|
||||||
@@ -803,7 +794,6 @@ func (m *Manager) updateStateFromSchedule() {
|
|||||||
temp = m.getTempFromPosition(pos)
|
temp = m.getTempFromPosition(pos)
|
||||||
deadline = m.getNextDeadline(now)
|
deadline = m.getNextDeadline(now)
|
||||||
isDay = now.After(times.Sunrise) && now.Before(times.Sunset)
|
isDay = now.After(times.Sunrise) && now.Before(times.Sunset)
|
||||||
log.Errorf("@@@ updateStateFromSchedule: isDay=%v (now=%v, sunrise=%v, sunset=%v) @@@", isDay, now.Format("15:04:05"), times.Sunrise.Format("15:04:05"), times.Sunset.Format("15:04:05"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newState := State{
|
newState := State{
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ Singleton {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
_parseError = true;
|
_parseError = true;
|
||||||
const msg = e.message;
|
const msg = e.message;
|
||||||
console.error("SessionData: Failed to parse session.json - file will not be overwritten. Error:", msg);
|
console.error("SessionData: Failed to parse session.json - file will not be overwritten.");
|
||||||
Qt.callLater(() => ToastService.showError(I18n.tr("Failed to parse session.json"), msg));
|
Qt.callLater(() => ToastService.showError(I18n.tr("Failed to parse session.json"), msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,14 +194,10 @@ Singleton {
|
|||||||
_isReadOnly = !writable;
|
_isReadOnly = !writable;
|
||||||
if (_isReadOnly) {
|
if (_isReadOnly) {
|
||||||
_hasUnsavedChanges = _checkForUnsavedChanges();
|
_hasUnsavedChanges = _checkForUnsavedChanges();
|
||||||
if (!wasReadOnly)
|
|
||||||
console.info("SessionData: session.json is now read-only");
|
|
||||||
} else {
|
} else {
|
||||||
_loadedSessionSnapshot = getCurrentSessionJson();
|
_loadedSessionSnapshot = getCurrentSessionJson();
|
||||||
_hasUnsavedChanges = false;
|
_hasUnsavedChanges = false;
|
||||||
if (wasReadOnly)
|
if (wasReadOnly && _pendingMigration)
|
||||||
console.info("SessionData: session.json is now writable");
|
|
||||||
if (_pendingMigration)
|
|
||||||
settingsFile.setText(JSON.stringify(_pendingMigration, null, 2));
|
settingsFile.setText(JSON.stringify(_pendingMigration, null, 2));
|
||||||
}
|
}
|
||||||
_pendingMigration = null;
|
_pendingMigration = null;
|
||||||
@@ -263,7 +259,7 @@ Singleton {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
_parseError = true;
|
_parseError = true;
|
||||||
const msg = e.message;
|
const msg = e.message;
|
||||||
console.error("SessionData: Failed to parse session.json - file will not be overwritten. Error:", msg);
|
console.error("SessionData: Failed to parse session.json - file will not be overwritten.");
|
||||||
Qt.callLater(() => ToastService.showError(I18n.tr("Failed to parse session.json"), msg));
|
Qt.callLater(() => ToastService.showError(I18n.tr("Failed to parse session.json"), msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,7 +277,6 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function migrateFromUndefinedToV1(settings) {
|
function migrateFromUndefinedToV1(settings) {
|
||||||
console.info("SessionData: Migrating configuration from undefined to version 1");
|
|
||||||
if (typeof SettingsData !== "undefined") {
|
if (typeof SettingsData !== "undefined") {
|
||||||
if (settings.acMonitorTimeout !== undefined) {
|
if (settings.acMonitorTimeout !== undefined) {
|
||||||
SettingsData.set("acMonitorTimeout", settings.acMonitorTimeout);
|
SettingsData.set("acMonitorTimeout", settings.acMonitorTimeout);
|
||||||
@@ -456,7 +451,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!screen) {
|
if (!screen) {
|
||||||
console.warn("SessionData: Screen not found:", screenName);
|
console.warn("SessionData: Screen not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,7 +548,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!screen) {
|
if (!screen) {
|
||||||
console.warn("SessionData: Screen not found:", screenName);
|
console.warn("SessionData: Screen not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,7 +586,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!screen) {
|
if (!screen) {
|
||||||
console.warn("SessionData: Screen not found:", screenName);
|
console.warn("SessionData: Screen not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -629,7 +624,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!screen) {
|
if (!screen) {
|
||||||
console.warn("SessionData: Screen not found:", screenName);
|
console.warn("SessionData: Screen not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -667,7 +662,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!screen) {
|
if (!screen) {
|
||||||
console.warn("SessionData: Screen not found:", screenName);
|
console.warn("SessionData: Screen not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -710,7 +705,6 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setNightModeAutoEnabled(enabled) {
|
function setNightModeAutoEnabled(enabled) {
|
||||||
console.log("SessionData: Setting nightModeAutoEnabled to", enabled);
|
|
||||||
nightModeAutoEnabled = enabled;
|
nightModeAutoEnabled = enabled;
|
||||||
saveSettings();
|
saveSettings();
|
||||||
}
|
}
|
||||||
@@ -746,13 +740,11 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setLatitude(lat) {
|
function setLatitude(lat) {
|
||||||
console.log("SessionData: Setting latitude to", lat);
|
|
||||||
latitude = lat;
|
latitude = lat;
|
||||||
saveSettings();
|
saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLongitude(lng) {
|
function setLongitude(lng) {
|
||||||
console.log("SessionData: Setting longitude to", lng);
|
|
||||||
longitude = lng;
|
longitude = lng;
|
||||||
saveSettings();
|
saveSettings();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,10 +94,7 @@ Singleton {
|
|||||||
property var matugenColors: ({})
|
property var matugenColors: ({})
|
||||||
property var _pendingGenerateParams: null
|
property var _pendingGenerateParams: null
|
||||||
|
|
||||||
// Theme automation
|
|
||||||
property bool themeModeAutomationActive: false
|
property bool themeModeAutomationActive: false
|
||||||
|
|
||||||
// Watch for DMSService connection to retry location setup
|
|
||||||
property bool dmsServiceWasDisconnected: true
|
property bool dmsServiceWasDisconnected: true
|
||||||
|
|
||||||
readonly property var dank16: {
|
readonly property var dank16: {
|
||||||
@@ -131,8 +128,6 @@ Singleton {
|
|||||||
readonly property string currentThemeId: customThemeRawData?.id || ""
|
readonly property string currentThemeId: customThemeRawData?.id || ""
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
console.warn("THEME AUTOMATION DEBUG: Component.onCompleted STARTING");
|
|
||||||
console.error("THEME AUTOMATION DEBUG: This is an error test");
|
|
||||||
Quickshell.execDetached(["mkdir", "-p", stateDir]);
|
Quickshell.execDetached(["mkdir", "-p", stateDir]);
|
||||||
Proc.runCommand("matugenCheck", ["which", "matugen"], (output, code) => {
|
Proc.runCommand("matugenCheck", ["which", "matugen"], (output, code) => {
|
||||||
matugenAvailable = (code === 0) && !envDisableMatugen;
|
matugenAvailable = (code === 0) && !envDisableMatugen;
|
||||||
@@ -186,17 +181,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof SessionData !== "undefined" && SessionData.themeModeAutoEnabled) {
|
if (typeof SessionData !== "undefined" && SessionData.themeModeAutoEnabled) {
|
||||||
console.error("*** THEME STARTUP: themeModeAutoEnabled = true, starting automation ***");
|
|
||||||
console.error("*** THEME STARTUP: themeModeAutoMode =", SessionData.themeModeAutoMode);
|
|
||||||
console.error("*** THEME STARTUP: current isLightMode =", root.isLightMode);
|
|
||||||
console.error("*** THEME STARTUP: DisplayService.gammaIsDay =", DisplayService?.gammaIsDay);
|
|
||||||
startThemeModeAutomation();
|
startThemeModeAutomation();
|
||||||
console.error("*** THEME STARTUP: automation started ***");
|
|
||||||
} else {
|
|
||||||
console.error("*** THEME STARTUP: automation NOT enabled ***");
|
|
||||||
if (typeof SessionData !== "undefined") {
|
|
||||||
console.error("*** THEME STARTUP: themeModeAutoEnabled =", SessionData.themeModeAutoEnabled);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +271,6 @@ Singleton {
|
|||||||
|
|
||||||
function onLatitudeChanged() {
|
function onLatitudeChanged() {
|
||||||
if (root.themeModeAutomationActive && SessionData.themeModeAutoMode === "location") {
|
if (root.themeModeAutomationActive && SessionData.themeModeAutoMode === "location") {
|
||||||
// Update backend with new coordinates
|
|
||||||
if (!SessionData.nightModeUseIPLocation &&
|
if (!SessionData.nightModeUseIPLocation &&
|
||||||
SessionData.latitude !== 0.0 &&
|
SessionData.latitude !== 0.0 &&
|
||||||
SessionData.longitude !== 0.0 &&
|
SessionData.longitude !== 0.0 &&
|
||||||
@@ -303,7 +287,6 @@ Singleton {
|
|||||||
|
|
||||||
function onLongitudeChanged() {
|
function onLongitudeChanged() {
|
||||||
if (root.themeModeAutomationActive && SessionData.themeModeAutoMode === "location") {
|
if (root.themeModeAutomationActive && SessionData.themeModeAutoMode === "location") {
|
||||||
// Update backend with new coordinates
|
|
||||||
if (!SessionData.nightModeUseIPLocation &&
|
if (!SessionData.nightModeUseIPLocation &&
|
||||||
SessionData.latitude !== 0.0 &&
|
SessionData.latitude !== 0.0 &&
|
||||||
SessionData.longitude !== 0.0 &&
|
SessionData.longitude !== 0.0 &&
|
||||||
@@ -320,14 +303,12 @@ Singleton {
|
|||||||
|
|
||||||
function onNightModeUseIPLocationChanged() {
|
function onNightModeUseIPLocationChanged() {
|
||||||
if (root.themeModeAutomationActive && SessionData.themeModeAutoMode === "location") {
|
if (root.themeModeAutomationActive && SessionData.themeModeAutoMode === "location") {
|
||||||
// Update backend with IP location preference
|
|
||||||
if (typeof DMSService !== "undefined") {
|
if (typeof DMSService !== "undefined") {
|
||||||
DMSService.sendRequest("wayland.gamma.setUseIPLocation", {
|
DMSService.sendRequest("wayland.gamma.setUseIPLocation", {
|
||||||
"use": SessionData.nightModeUseIPLocation
|
"use": SessionData.nightModeUseIPLocation
|
||||||
}, response => {
|
}, response => {
|
||||||
if (!response.error && !SessionData.nightModeUseIPLocation &&
|
if (!response.error && !SessionData.nightModeUseIPLocation &&
|
||||||
SessionData.latitude !== 0.0 && SessionData.longitude !== 0.0) {
|
SessionData.latitude !== 0.0 && SessionData.longitude !== 0.0) {
|
||||||
// If switching from IP to manual, send coordinates
|
|
||||||
DMSService.sendRequest("wayland.gamma.setLocation", {
|
DMSService.sendRequest("wayland.gamma.setLocation", {
|
||||||
"latitude": SessionData.latitude,
|
"latitude": SessionData.latitude,
|
||||||
"longitude": SessionData.longitude
|
"longitude": SessionData.longitude
|
||||||
@@ -342,9 +323,6 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// React to gamma backend's isDay state changes for location-based mode
|
// React to gamma backend's isDay state changes for location-based mode
|
||||||
// Note: gamma backend calculates isDay independently from whether
|
|
||||||
// gamma control is enabled for display adjustments
|
|
||||||
// Use gammaIsDay property instead of gammaState object for proper change notifications
|
|
||||||
Connections {
|
Connections {
|
||||||
target: DisplayService
|
target: DisplayService
|
||||||
enabled: typeof DisplayService !== "undefined" &&
|
enabled: typeof DisplayService !== "undefined" &&
|
||||||
@@ -354,12 +332,7 @@ Singleton {
|
|||||||
!themeAutoBackendAvailable()
|
!themeAutoBackendAvailable()
|
||||||
|
|
||||||
function onGammaIsDayChanged() {
|
function onGammaIsDayChanged() {
|
||||||
console.error("!!! onGammaIsDayChanged FIRED !!!");
|
|
||||||
console.error("!!! gammaIsDay =", DisplayService.gammaIsDay);
|
|
||||||
console.error("!!! current isLightMode =", root.isLightMode);
|
|
||||||
console.error("!!! Will switch?", root.isLightMode !== DisplayService.gammaIsDay);
|
|
||||||
if (root.isLightMode !== DisplayService.gammaIsDay) {
|
if (root.isLightMode !== DisplayService.gammaIsDay) {
|
||||||
console.error("!!! CALLING setLightMode from onGammaIsDayChanged");
|
|
||||||
root.setLightMode(DisplayService.gammaIsDay, true, true);
|
root.setLightMode(DisplayService.gammaIsDay, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -370,12 +343,7 @@ Singleton {
|
|||||||
enabled: typeof DMSService !== "undefined" && typeof SessionData !== "undefined"
|
enabled: typeof DMSService !== "undefined" && typeof SessionData !== "undefined"
|
||||||
|
|
||||||
function onLoginctlEvent(event) {
|
function onLoginctlEvent(event) {
|
||||||
console.error("### onLoginctlEvent FIRED:", event.event, "###");
|
|
||||||
// Only handle if automation is enabled
|
|
||||||
if (!SessionData.themeModeAutoEnabled) return;
|
if (!SessionData.themeModeAutoEnabled) return;
|
||||||
|
|
||||||
// Re-evaluate theme mode when system wakes up or unlocks
|
|
||||||
// This ensures time-based and location-based (non-shared) modes stay accurate
|
|
||||||
if (event.event === "unlock" || event.event === "resume") {
|
if (event.event === "unlock" || event.event === "resume") {
|
||||||
if (!themeAutoBackendAvailable()) {
|
if (!themeAutoBackendAvailable()) {
|
||||||
root.evaluateThemeMode();
|
root.evaluateThemeMode();
|
||||||
@@ -393,13 +361,6 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onConnectionStateChanged() {
|
function onConnectionStateChanged() {
|
||||||
console.error("@@@ onConnectionStateChanged FIRED @@@");
|
|
||||||
console.error("@@@ DMSService.isConnected =", DMSService.isConnected);
|
|
||||||
console.error("@@@ SessionData.themeModeAutoEnabled =", SessionData.themeModeAutoEnabled);
|
|
||||||
console.error("@@@ SessionData.themeModeAutoMode =", SessionData.themeModeAutoMode);
|
|
||||||
console.error("@@@ SessionData.latitude =", SessionData.latitude);
|
|
||||||
console.error("@@@ SessionData.longitude =", SessionData.longitude);
|
|
||||||
|
|
||||||
if (DMSService.isConnected && SessionData.themeModeAutoMode === "time") {
|
if (DMSService.isConnected && SessionData.themeModeAutoMode === "time") {
|
||||||
root.syncTimeThemeSchedule();
|
root.syncTimeThemeSchedule();
|
||||||
}
|
}
|
||||||
@@ -416,42 +377,36 @@ Singleton {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only handle if automation is enabled
|
|
||||||
if (!SessionData.themeModeAutoEnabled) {
|
if (!SessionData.themeModeAutoEnabled) {
|
||||||
console.error("@@@ Automation not enabled, skipping @@@");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When DMSService connects, retry location initialization if in location mode
|
|
||||||
if (DMSService.isConnected && SessionData.themeModeAutoMode === "location") {
|
if (DMSService.isConnected && SessionData.themeModeAutoMode === "location") {
|
||||||
console.error("@@@ RETRYING location setup @@@");
|
|
||||||
if (SessionData.nightModeUseIPLocation) {
|
if (SessionData.nightModeUseIPLocation) {
|
||||||
console.error("@@@ Using IP location @@@");
|
|
||||||
DMSService.sendRequest("wayland.gamma.setUseIPLocation", {
|
DMSService.sendRequest("wayland.gamma.setUseIPLocation", {
|
||||||
"use": true
|
"use": true
|
||||||
}, response => {
|
}, response => {
|
||||||
if (!response.error) {
|
if (!response.error) {
|
||||||
console.log("Theme automation: IP location enabled after connection");
|
console.info("Theme automation: IP location enabled after connection");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (SessionData.latitude !== 0.0 && SessionData.longitude !== 0.0) {
|
} else if (SessionData.latitude !== 0.0 && SessionData.longitude !== 0.0) {
|
||||||
console.error("@@@ Using manual coordinates:", SessionData.latitude, SessionData.longitude, "@@@");
|
|
||||||
DMSService.sendRequest("wayland.gamma.setUseIPLocation", {
|
DMSService.sendRequest("wayland.gamma.setUseIPLocation", {
|
||||||
"use": false
|
"use": false
|
||||||
}, response => {
|
}, response => {
|
||||||
console.error("@@@ setUseIPLocation(false) response:", JSON.stringify(response), "@@@");
|
|
||||||
if (!response.error) {
|
if (!response.error) {
|
||||||
console.error("@@@ Sending setLocation request @@@");
|
|
||||||
DMSService.sendRequest("wayland.gamma.setLocation", {
|
DMSService.sendRequest("wayland.gamma.setLocation", {
|
||||||
"latitude": SessionData.latitude,
|
"latitude": SessionData.latitude,
|
||||||
"longitude": SessionData.longitude
|
"longitude": SessionData.longitude
|
||||||
}, locationResponse => {
|
}, locationResponse => {
|
||||||
console.error("@@@ setLocation response:", JSON.stringify(locationResponse), "@@@");
|
if (locationResponse?.error) {
|
||||||
|
console.warn("Theme automation: Failed to set location", locationResponse.error);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.error("@@@ No location configured - nightModeUseIPLocation:", SessionData.nightModeUseIPLocation, "@@@");
|
console.warn("Theme automation: No location configured");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -770,7 +725,9 @@ Singleton {
|
|||||||
property real popupTransparency: typeof SettingsData !== "undefined" && SettingsData.popupTransparency !== undefined ? SettingsData.popupTransparency : 1.0
|
property real popupTransparency: typeof SettingsData !== "undefined" && SettingsData.popupTransparency !== undefined ? SettingsData.popupTransparency : 1.0
|
||||||
|
|
||||||
function screenTransition() {
|
function screenTransition() {
|
||||||
CompositorService.isNiri && NiriService.doScreenTransition();
|
if (CompositorService.isNiri) {
|
||||||
|
NiriService.doScreenTransition();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchTheme(themeName, savePrefs = true, enableTransition = true) {
|
function switchTheme(themeName, savePrefs = true, enableTransition = true) {
|
||||||
@@ -813,25 +770,17 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setLightMode(light, savePrefs = true, enableTransition = false) {
|
function setLightMode(light, savePrefs = true, enableTransition = false) {
|
||||||
console.error(">>> setLightMode CALLED: light =", light, ", savePrefs =", savePrefs, ", enableTransition =", enableTransition);
|
|
||||||
console.error(">>> BEFORE: root.isLightMode =", root.isLightMode);
|
|
||||||
|
|
||||||
if (enableTransition) {
|
if (enableTransition) {
|
||||||
screenTransition();
|
screenTransition();
|
||||||
lightModeTransitionTimer.lightMode = light;
|
lightModeTransitionTimer.lightMode = light;
|
||||||
lightModeTransitionTimer.savePrefs = savePrefs;
|
lightModeTransitionTimer.savePrefs = savePrefs;
|
||||||
lightModeTransitionTimer.restart();
|
lightModeTransitionTimer.restart();
|
||||||
console.error(">>> setLightMode: Starting transition timer");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isGreeterMode = (typeof SessionData !== "undefined" && SessionData.isGreeterMode);
|
const isGreeterMode = (typeof SessionData !== "undefined" && SessionData.isGreeterMode);
|
||||||
console.error(">>> setLightMode: isGreeterMode =", isGreeterMode, ", will save =", savePrefs && typeof SessionData !== "undefined" && !isGreeterMode);
|
|
||||||
|
|
||||||
if (savePrefs && typeof SessionData !== "undefined" && !isGreeterMode) {
|
if (savePrefs && typeof SessionData !== "undefined" && !isGreeterMode) {
|
||||||
console.error(">>> setLightMode: Calling SessionData.setLightMode(", light, ")");
|
|
||||||
SessionData.setLightMode(light);
|
SessionData.setLightMode(light);
|
||||||
console.error(">>> setLightMode: AFTER SessionData.setLightMode - root.isLightMode =", root.isLightMode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isGreeterMode) {
|
if (!isGreeterMode) {
|
||||||
@@ -842,7 +791,6 @@ Singleton {
|
|||||||
generateSystemThemesFromCurrentTheme();
|
generateSystemThemesFromCurrentTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error(">>> setLightMode DONE: root.isLightMode =", root.isLightMode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleLightMode(savePrefs = true) {
|
function toggleLightMode(savePrefs = true) {
|
||||||
@@ -1524,7 +1472,7 @@ Singleton {
|
|||||||
return `#${invR}${invG}${invB}`;
|
return `#${invR}${invG}${invB}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
property string baseLogoColor: {
|
property var baseLogoColor: {
|
||||||
if (typeof SettingsData === "undefined")
|
if (typeof SettingsData === "undefined")
|
||||||
return "";
|
return "";
|
||||||
const colorOverride = SettingsData.launcherLogoColorOverride;
|
const colorOverride = SettingsData.launcherLogoColorOverride;
|
||||||
@@ -1537,7 +1485,7 @@ Singleton {
|
|||||||
return colorOverride;
|
return colorOverride;
|
||||||
}
|
}
|
||||||
|
|
||||||
property string effectiveLogoColor: {
|
property var effectiveLogoColor: {
|
||||||
if (typeof SettingsData === "undefined")
|
if (typeof SettingsData === "undefined")
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
@@ -1852,46 +1800,22 @@ Singleton {
|
|||||||
|
|
||||||
const mode = SessionData.themeModeAutoMode;
|
const mode = SessionData.themeModeAutoMode;
|
||||||
|
|
||||||
// Location mode uses gamma backend or JavaScript fallback
|
|
||||||
// The Connections block also handles real-time gamma state updates
|
|
||||||
if (mode === "location") {
|
if (mode === "location") {
|
||||||
evaluateLocationBasedThemeMode();
|
evaluateLocationBasedThemeMode();
|
||||||
} else {
|
} else {
|
||||||
// Time-based mode
|
|
||||||
evaluateTimeBasedThemeMode();
|
evaluateTimeBasedThemeMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function evaluateLocationBasedThemeMode() {
|
function evaluateLocationBasedThemeMode() {
|
||||||
console.error("=== THEME AUTOMATION DEBUG: evaluateLocationBasedThemeMode START ===");
|
|
||||||
console.error("THEME AUTO: DisplayService exists?", typeof DisplayService !== "undefined");
|
|
||||||
console.error("THEME AUTO: gammaState =", JSON.stringify(DisplayService?.gammaState || {}));
|
|
||||||
console.error("THEME AUTO: gammaIsDay =", DisplayService?.gammaIsDay);
|
|
||||||
console.error("THEME AUTO: current Theme.isLightMode =", root.isLightMode);
|
|
||||||
|
|
||||||
// When using IP location or manual coordinates, the gamma backend
|
|
||||||
// can calculate sun position and isDay independently from whether
|
|
||||||
// gamma control is enabled for display adjustments
|
|
||||||
|
|
||||||
// Try to use gamma backend's isDay state (works with both IP and manual location)
|
|
||||||
// Use gammaIsDay property for reliable value access
|
|
||||||
if (typeof DisplayService !== "undefined") {
|
if (typeof DisplayService !== "undefined") {
|
||||||
const shouldBeLight = DisplayService.gammaIsDay;
|
const shouldBeLight = DisplayService.gammaIsDay;
|
||||||
console.error("THEME AUTO: shouldBeLight =", shouldBeLight);
|
|
||||||
console.error("THEME AUTO: Will switch?", root.isLightMode !== shouldBeLight);
|
|
||||||
if (root.isLightMode !== shouldBeLight) {
|
if (root.isLightMode !== shouldBeLight) {
|
||||||
console.error("THEME AUTO: CALLING setLightMode(", shouldBeLight, ", true, true)");
|
|
||||||
root.setLightMode(shouldBeLight, true, true);
|
root.setLightMode(shouldBeLight, true, true);
|
||||||
console.error("THEME AUTO: AFTER setLightMode - isLightMode =", root.isLightMode);
|
|
||||||
} else {
|
|
||||||
console.error("THEME AUTO: No change needed - already in correct mode");
|
|
||||||
}
|
}
|
||||||
console.error("=== THEME AUTOMATION DEBUG: evaluateLocationBasedThemeMode END ===");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback: Use JavaScript sun calculation with manual coordinates
|
|
||||||
// This is less accurate but works if backend isn't available
|
|
||||||
if (!SessionData.nightModeUseIPLocation &&
|
if (!SessionData.nightModeUseIPLocation &&
|
||||||
SessionData.latitude !== 0.0 &&
|
SessionData.latitude !== 0.0 &&
|
||||||
SessionData.longitude !== 0.0) {
|
SessionData.longitude !== 0.0) {
|
||||||
@@ -1905,7 +1829,6 @@ Singleton {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warn about missing configuration
|
|
||||||
if (root.themeModeAutomationActive) {
|
if (root.themeModeAutomationActive) {
|
||||||
if (SessionData.nightModeUseIPLocation) {
|
if (SessionData.nightModeUseIPLocation) {
|
||||||
console.warn("Theme automation: Waiting for IP location from backend");
|
console.warn("Theme automation: Waiting for IP location from backend");
|
||||||
@@ -1918,7 +1841,6 @@ Singleton {
|
|||||||
function evaluateTimeBasedThemeMode() {
|
function evaluateTimeBasedThemeMode() {
|
||||||
const shareSettings = SessionData.themeModeShareGammaSettings;
|
const shareSettings = SessionData.themeModeShareGammaSettings;
|
||||||
|
|
||||||
// Get time settings (shared or independent)
|
|
||||||
const startHour = shareSettings ?
|
const startHour = shareSettings ?
|
||||||
SessionData.nightModeStartHour : SessionData.themeModeStartHour;
|
SessionData.nightModeStartHour : SessionData.themeModeStartHour;
|
||||||
const startMinute = shareSettings ?
|
const startMinute = shareSettings ?
|
||||||
@@ -1933,13 +1855,10 @@ Singleton {
|
|||||||
const startMinutes = startHour * 60 + startMinute;
|
const startMinutes = startHour * 60 + startMinute;
|
||||||
const endMinutes = endHour * 60 + endMinute;
|
const endMinutes = endHour * 60 + endMinute;
|
||||||
|
|
||||||
// Light mode is OUTSIDE the dark period
|
|
||||||
let shouldBeLight;
|
let shouldBeLight;
|
||||||
if (startMinutes < endMinutes) {
|
if (startMinutes < endMinutes) {
|
||||||
// Normal case: dark period within same day (e.g., 01:00-05:00)
|
|
||||||
shouldBeLight = currentMinutes < startMinutes || currentMinutes >= endMinutes;
|
shouldBeLight = currentMinutes < startMinutes || currentMinutes >= endMinutes;
|
||||||
} else {
|
} else {
|
||||||
// Overnight case: dark period crosses midnight (e.g., 18:00-06:00)
|
|
||||||
shouldBeLight = currentMinutes >= endMinutes && currentMinutes < startMinutes;
|
shouldBeLight = currentMinutes >= endMinutes && currentMinutes < startMinutes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1955,14 +1874,11 @@ Singleton {
|
|||||||
const dayOfYear = Math.floor(diff / 86400000);
|
const dayOfYear = Math.floor(diff / 86400000);
|
||||||
const latRad = lat * Math.PI / 180;
|
const latRad = lat * Math.PI / 180;
|
||||||
|
|
||||||
// Solar declination approximation
|
|
||||||
const declination = 23.45 * Math.sin((360/365) * (dayOfYear - 81) * Math.PI / 180);
|
const declination = 23.45 * Math.sin((360/365) * (dayOfYear - 81) * Math.PI / 180);
|
||||||
const declinationRad = declination * Math.PI / 180;
|
const declinationRad = declination * Math.PI / 180;
|
||||||
|
|
||||||
// Hour angle at sunrise/sunset
|
|
||||||
const cosHourAngle = -Math.tan(latRad) * Math.tan(declinationRad);
|
const cosHourAngle = -Math.tan(latRad) * Math.tan(declinationRad);
|
||||||
|
|
||||||
// Handle polar conditions
|
|
||||||
if (cosHourAngle > 1) {
|
if (cosHourAngle > 1) {
|
||||||
return false; // Polar night
|
return false; // Polar night
|
||||||
}
|
}
|
||||||
@@ -1973,18 +1889,15 @@ Singleton {
|
|||||||
const hourAngle = Math.acos(cosHourAngle);
|
const hourAngle = Math.acos(cosHourAngle);
|
||||||
const hourAngleDeg = hourAngle * 180 / Math.PI;
|
const hourAngleDeg = hourAngle * 180 / Math.PI;
|
||||||
|
|
||||||
// Sunrise/sunset in decimal hours (solar noon ± hour angle)
|
|
||||||
const sunriseHour = 12 - hourAngleDeg / 15;
|
const sunriseHour = 12 - hourAngleDeg / 15;
|
||||||
const sunsetHour = 12 + hourAngleDeg / 15;
|
const sunsetHour = 12 + hourAngleDeg / 15;
|
||||||
|
|
||||||
// Adjust for longitude (rough approximation)
|
|
||||||
const timeZoneOffset = now.getTimezoneOffset() / 60;
|
const timeZoneOffset = now.getTimezoneOffset() / 60;
|
||||||
const localSunrise = sunriseHour - lng / 15 - timeZoneOffset;
|
const localSunrise = sunriseHour - lng / 15 - timeZoneOffset;
|
||||||
const localSunset = sunsetHour - lng / 15 - timeZoneOffset;
|
const localSunset = sunsetHour - lng / 15 - timeZoneOffset;
|
||||||
|
|
||||||
const currentHour = now.getHours() + now.getMinutes() / 60;
|
const currentHour = now.getHours() + now.getMinutes() / 60;
|
||||||
|
|
||||||
// Normalize hours to 0-24 range
|
|
||||||
const normalizeSunrise = ((localSunrise % 24) + 24) % 24;
|
const normalizeSunrise = ((localSunrise % 24) + 24) % 24;
|
||||||
const normalizeSunset = ((localSunset % 24) + 24) % 24;
|
const normalizeSunset = ((localSunset % 24) + 24) % 24;
|
||||||
|
|
||||||
@@ -1994,39 +1907,35 @@ Singleton {
|
|||||||
// Helper function to send location to backend
|
// Helper function to send location to backend
|
||||||
function sendLocationToBackend() {
|
function sendLocationToBackend() {
|
||||||
if (typeof SessionData === "undefined" || typeof DMSService === "undefined") {
|
if (typeof SessionData === "undefined" || typeof DMSService === "undefined") {
|
||||||
console.error("$$$ sendLocationToBackend: SessionData or DMSService unavailable $$$");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DMSService.isConnected) {
|
if (!DMSService.isConnected) {
|
||||||
console.error("$$$ sendLocationToBackend: DMSService not connected yet $$$");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error("$$$ sendLocationToBackend: SENDING location to backend $$$");
|
|
||||||
|
|
||||||
if (SessionData.nightModeUseIPLocation) {
|
if (SessionData.nightModeUseIPLocation) {
|
||||||
console.error("$$$ Using IP location $$$");
|
|
||||||
DMSService.sendRequest("wayland.gamma.setUseIPLocation", {"use": true}, response => {
|
DMSService.sendRequest("wayland.gamma.setUseIPLocation", {"use": true}, response => {
|
||||||
console.error("$$$ IP location response:", JSON.stringify(response), "$$$");
|
if (response?.error) {
|
||||||
|
console.warn("Theme automation: Failed to enable IP location", response.error);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
} else if (SessionData.latitude !== 0.0 && SessionData.longitude !== 0.0) {
|
} else if (SessionData.latitude !== 0.0 && SessionData.longitude !== 0.0) {
|
||||||
console.error("$$$ Using manual coords:", SessionData.latitude, SessionData.longitude, "$$$");
|
|
||||||
DMSService.sendRequest("wayland.gamma.setUseIPLocation", {"use": false}, response => {
|
DMSService.sendRequest("wayland.gamma.setUseIPLocation", {"use": false}, response => {
|
||||||
if (!response.error) {
|
if (!response.error) {
|
||||||
DMSService.sendRequest("wayland.gamma.setLocation", {
|
DMSService.sendRequest("wayland.gamma.setLocation", {
|
||||||
"latitude": SessionData.latitude,
|
"latitude": SessionData.latitude,
|
||||||
"longitude": SessionData.longitude
|
"longitude": SessionData.longitude
|
||||||
}, locResp => {
|
}, locResp => {
|
||||||
console.error("$$$ setLocation response:", JSON.stringify(locResp), "$$$");
|
if (locResp?.error) {
|
||||||
|
console.warn("Theme automation: Failed to set location", locResp.error);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error("$$$ sendLocationToBackend: No location configured $$$");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2038,16 +1947,13 @@ Singleton {
|
|||||||
property int retryCount: 0
|
property int retryCount: 0
|
||||||
|
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
console.error("$$$ locationRetryTimer triggered, attempt", retryCount + 1, "$$$");
|
|
||||||
if (root.sendLocationToBackend()) {
|
if (root.sendLocationToBackend()) {
|
||||||
console.error("$$$ Location sent successfully, stopping retry timer $$$");
|
|
||||||
stop();
|
stop();
|
||||||
retryCount = 0;
|
retryCount = 0;
|
||||||
root.evaluateThemeMode();
|
root.evaluateThemeMode();
|
||||||
} else {
|
} else {
|
||||||
retryCount++;
|
retryCount++;
|
||||||
if (retryCount >= 10) {
|
if (retryCount >= 10) {
|
||||||
console.error("$$$ Giving up after 10 retries $$$");
|
|
||||||
stop();
|
stop();
|
||||||
retryCount = 0;
|
retryCount = 0;
|
||||||
}
|
}
|
||||||
@@ -2056,23 +1962,16 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function startThemeModeAutomation() {
|
function startThemeModeAutomation() {
|
||||||
console.error("XYZABC NEW startThemeModeAutomation VERSION XYZABC");
|
|
||||||
root.themeModeAutomationActive = true;
|
root.themeModeAutomationActive = true;
|
||||||
|
|
||||||
root.syncTimeThemeSchedule();
|
root.syncTimeThemeSchedule();
|
||||||
root.syncLocationThemeSchedule();
|
root.syncLocationThemeSchedule();
|
||||||
|
|
||||||
// Try to send location immediately
|
|
||||||
const sent = root.sendLocationToBackend();
|
const sent = root.sendLocationToBackend();
|
||||||
console.error("XYZABC sendLocationToBackend returned:", sent, "XYZABC");
|
|
||||||
|
|
||||||
// If it failed (likely because DMSService not connected), retry
|
|
||||||
if (!sent && typeof SessionData !== "undefined" && SessionData.themeModeAutoMode === "location") {
|
if (!sent && typeof SessionData !== "undefined" && SessionData.themeModeAutoMode === "location") {
|
||||||
console.error("XYZABC Starting retry timer XYZABC");
|
|
||||||
locationRetryTimer.start();
|
locationRetryTimer.start();
|
||||||
} else {
|
} else {
|
||||||
console.error("XYZABC Calling evaluateThemeMode XYZABC");
|
|
||||||
// Evaluate theme mode immediately
|
|
||||||
root.evaluateThemeMode();
|
root.evaluateThemeMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,7 +152,6 @@ Item {
|
|||||||
}
|
}
|
||||||
themeColorsTab.templateDetection = detection;
|
themeColorsTab.templateDetection = detection;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("ThemeColorsTab: Failed to parse template check:", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user