White-Tiger / T-Clock

Highly configurable Windows taskbar clock
1.73k stars 169 forks source link

Clock doesn't respect dark/light modes #217

Open caulmseh opened 4 years ago

caulmseh commented 4 years ago

I use Auto Dark Mode from another developer and the clock gets left on white when the system automatically switches to light mode

ArthurWolfhound commented 4 years ago

@White-Tiger - I believe that this article will provide you with information how to extract current theme status from Windows registry to implement asked functionality.

Kind regards, Friendly contributor to this issue madness

benjamin051000 commented 3 years ago

Related to this issue

francesco-plt commented 3 years ago

I solved the issue by creating this python script and associating it to a task into the task scheduler. Inside the task I setted it to run the script two times, one at morning and one at night. At each execution the clock color gets changed and t-clock is closed and opened again to update the color. This is the code:

import os, subprocess, winreg
from time import sleep
import logging.config

TCLOCK_PATH = "Path\\to\\tclock\\executable.exe"

# Logging Configuration
logging.basicConfig(
    level=logging.INFO,
    format="[%(asctime)s] [PID %(process)d] [Thread %(thread)d] [%(levelname)s] %(message)s",
    handlers=[
        logging.StreamHandler()
    ]
)
LOGGER = logging.getLogger()

# accessing the registry
registry = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER)
text_color_key = winreg.OpenKey(registry, "SOFTWARE\\Stoic Joker's\\T-Clock 2010\\Clock", 0, winreg.KEY_ALL_ACCESS | winreg.KEY_WOW64_64KEY)

# changing registry value associated with clock text color
cur_value = winreg.QueryValueEx(text_color_key, "ForeColor")
if int(cur_value[0]) == 0:
    winreg.SetValueEx(text_color_key, "ForeColor", 0, winreg.REG_DWORD, 16777215)
    LOGGER.info("switched to dark mode")
elif int(cur_value[0]) == 16777215:
    winreg.SetValueEx(text_color_key, "ForeColor", 0, winreg.REG_DWORD, 0)
    LOGGER.info("switched to light mode")

# restarting t-clock
os.system(TCLOCK_PATH + " /exit")
sleep(0.2)
try:
    subprocess.Popen(TCLOCK_PATH, creationflags=subprocess.DETACHED_PROCESS, close_fds=True)
except E:
    LOGGER.exception(E)
quit()
samwzlim commented 3 years ago

@plt-francesco how do i do that? image Do I just do what I did in the picture above? I pasted the code that you provided in a notepad file and linked that in task scheduler

Edit: I followed this guide and there is no effect upon running the task in task scheduler. Can you explain in detail how you got it to work?

francesco-plt commented 3 years ago

@plt-francesco how do i do that? image Do I just do what I did in the picture above? I pasted the code that you provided in a notepad file and linked that in task scheduler

Edit: I followed this guide and there is no effect upon running the task in task scheduler. Can you explain in detail how you got it to work?

Since this is a python script, you need to install python to get this working.It is quite easy, since it is like installing any other program. You can download it from here. After that you have to setup task scheduler to get it working. Import this task, by first changing the path to the path in which you have saved your script (remember to give it a .py extension: in the screenshot I see .txt):

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2021-01-01T20:00:11.3402576</Date>
    <Author>DESKTOP-APOHRK4\frapa</Author>
    <URI>\tclock dark mode</URI>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2021-01-02T18:00:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
    <CalendarTrigger>
      <StartBoundary>2021-01-02T07:00:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId></UserId>
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>StopExisting</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>cmd</Command>
      <Arguments>"/c python PATH_TO_SCRIPT_IN_YOUR_SYSTEM_GOES_HERE"</Arguments>
    </Exec>
  </Actions>
</Task>

And it should work.

samwzlim commented 3 years ago

@plt-francesco, I made some changes to the python script that you sent, can you please help me check if it's valid in the code below? Also, I did everything as you said, but I am getting this prompt everytime the script runs: image

Is there anyway to get rid of the prompt upon execution of the script? I have already made sure the file extension is .py. Also, after selecting Python to run the program, a command prompt opens and then closes briefly later but no changes were made to T-clock's font.

`<?xml version="1.0" encoding="UTF-16"?>

2021-01-01T20:00:11.3402576 DESKTOP-APOHRK4\frapa \tclock dark mode 2021-01-02T19:00:00 true 1 2021-01-02T07:15:00 true 1 InteractiveToken LeastPrivilege StopExisting false true true false false true false true true false false false PT1H 7 cmd "/c python C:\Tweaks\T-Clock font color according to lightdark mode\T-Clock font color according to lightdark mode.py" ` ![image](https://user-images.githubusercontent.com/74489037/105176191-e233d300-5b5f-11eb-82c9-cfb8224b36f6.png) ![image](https://user-images.githubusercontent.com/74489037/105176211-e829b400-5b5f-11eb-8d29-7205046753d1.png) ![image](https://user-images.githubusercontent.com/74489037/105176231-f2e44900-5b5f-11eb-8b24-ef10fe468945.png) fyi, i chose the python script above for start program ![image](https://user-images.githubusercontent.com/74489037/105176245-f7106680-5b5f-11eb-829a-dc070f246f6a.png) ![image](https://user-images.githubusercontent.com/74489037/105176262-fe377480-5b5f-11eb-84ce-3688ec9efbad.png)
debiedowner commented 3 years ago

In case it helps anybody, I did the same thing as @plt-francesco on AutoHotkey:

#F3::
  RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize, SystemUsesLightTheme, 0
  RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize, AppsUseLightTheme, 0
  RegWrite, REG_DWORD, HKEY_CURRENT_USER\SOFTWARE\Stoic Joker's\T-Clock 2010\Clock, ForeColor, 16777215
  return
#F4::
  RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize, SystemUsesLightTheme, 1
  RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize, AppsUseLightTheme, 1
  RegWrite, REG_DWORD, HKEY_CURRENT_USER\SOFTWARE\Stoic Joker's\T-Clock 2010\Clock, ForeColor, 4210884306
  return

So Windows Logo Key + F3 for dark mode, Windows Logo Key + F4 for light mode. The first two lines changes the Windows mode, and the third lines change T-Clock color. If any other programs need similar special treatment, they can be added here as well. Two things to note: