Skip to content

Commit 759e376

Browse files
authored
Merge pull request #4 from Nieznany237/DEV
Dev
2 parents 0552ce2 + 9a10041 commit 759e376

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

Images/1.png

-5.2 KB
Binary file not shown.

Images/2.png

2.89 KB
Loading

Main.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
This application automatically puts the system into hibernation after a specified countdown.'''
33
# pylint: disable = W0718
44
# pylint: disable = C0103
5-
from logging import config
5+
import logging
66
import time
77
import tkinter as tk
88
from tkinter import ttk, messagebox
@@ -11,12 +11,11 @@
1111
import logging
1212
import os
1313
import json
14-
from getpass import getuser
1514
from hPyT import maximize_minimize_button # https://pypi.org/project/hPyT/
1615
from modules.b64assets import APP_ICON
1716

18-
VERSION = "1.9"
19-
RELEASE_DATE = "28.06.2025"
17+
VERSION = "1.10.0"
18+
RELEASE_DATE = "04.07.2025"
2019

2120
# Global cache
2221
DEBUG_MODE = False
@@ -50,18 +49,20 @@
5049
BUTTON_STYLE = "raised"
5150
FRAME_STYLE = "groove"
5251

53-
# Load config: overrides defaults if present, creates config file if missing
52+
# Load config: overrides defaults if present, creates config file if missing or invalid
5453
def load_config_from_file():
55-
'''Load HIBERNATION_TIME and TARGET_FPS from config.json, create file/folder if missing or invalid. Returns the loaded or default values.'''
54+
'''Load HIBERNATION_TIME, TARGET_FPS, and SHOW_DECIMAL_SECONDS from config.json, create file/folder if missing or invalid. Returns the loaded or default values.'''
5655
config_dir = os.path.join(os.path.expanduser("~"), "NiezPrograms", "AutoHibernate")
5756
config_file = os.path.join(config_dir, "config.json")
5857
logging.debug("Config directory: %s", config_file)
5958
defaults = {
6059
'HIBERNATION_TIME': HIBERNATION_TIME,
61-
'TARGET_FPS': TARGET_FPS
60+
'TARGET_FPS': TARGET_FPS,
61+
'SHOW_DECIMAL_SECONDS': False,
6262
}
6363
hib_time = defaults['HIBERNATION_TIME']
6464
target_fps = defaults['TARGET_FPS']
65+
show_decimal_seconds = defaults['SHOW_DECIMAL_SECONDS']
6566

6667
if not os.path.exists(config_dir):
6768
os.makedirs(config_dir, exist_ok=True)
@@ -76,13 +77,15 @@ def load_config_from_file():
7677
data = json.load(f)
7778
hib_time = data.get('HIBERNATION_TIME', hib_time)
7879
target_fps = data.get('TARGET_FPS', target_fps)
80+
show_decimal_seconds = data.get('SHOW_DECIMAL_SECONDS', show_decimal_seconds)
7981
except Exception as e:
8082
logging.warning("Failed to load config.json, using defaults. Error: %s", e)
8183
with open(config_file, 'w', encoding='utf-8') as f:
8284
json.dump(defaults, f, indent=4)
8385
logging.info("Recreated config file with defaults: %s", config_file)
8486
hib_time = defaults['HIBERNATION_TIME']
8587
target_fps = defaults['TARGET_FPS']
88+
show_decimal_seconds = defaults['SHOW_DECIMAL_SECONDS']
8689

8790
# Validate hib_time
8891
if hib_time is None or not isinstance(hib_time, int) or hib_time <= 0:
@@ -94,9 +97,15 @@ def load_config_from_file():
9497
logging.warning("TARGET_FPS is set to %s, which is invalid. Using default value of %d.", target_fps, defaults['TARGET_FPS'])
9598
target_fps = defaults['TARGET_FPS']
9699

100+
# Validate show_decimal_seconds
101+
if not isinstance(show_decimal_seconds, bool):
102+
logging.warning("SHOW_DECIMAL_SECONDS is set to %s, which is invalid. Using default value of %s.", show_decimal_seconds, defaults['SHOW_DECIMAL_SECONDS'])
103+
show_decimal_seconds = defaults['SHOW_DECIMAL_SECONDS']
104+
97105
logging.info("Loaded HIBERNATION_TIME from config: %s", hib_time)
98106
logging.info("Loaded TARGET_FPS from config: %s", target_fps)
99-
return hib_time, target_fps
107+
logging.info("Loaded SHOW_DECIMAL_SECONDS from config: %s", show_decimal_seconds)
108+
return hib_time, target_fps, show_decimal_seconds
100109

101110
# Global variable for caching hibernation support result
102111
_hibernate_support_cache = None
@@ -149,6 +158,7 @@ def hibernate_system_call():
149158
time_label.config(text="Hibernating...\n")
150159
logging.info("Calling system hibernation")
151160
if DISABLE_HIBERNATION_CALL:
161+
terminate_countdown()
152162
logging.info("| Hibernation call is disabled (DISABLE_HIBERNATION_CALL=True). Skipping system call. |")
153163
messagebox.showinfo("Info", "Hibernation is disabled (test mode). The system will not hibernate.")
154164
root.destroy()
@@ -207,10 +217,13 @@ def update_time():
207217
remaining_time = max(total_time - time_elapsed, 0)
208218
remaining_seconds = int(remaining_time)
209219

210-
# Update text only when seconds change
211-
if remaining_seconds != last_displayed_time:
212-
label.config(text=f"System will hibernate in\n{remaining_seconds} seconds")
213-
last_displayed_time = remaining_seconds
220+
# Update text only when seconds change (or always if decimals enabled)
221+
if SHOW_DECIMAL_SECONDS:
222+
label.config(text=f"System will hibernate in\n{remaining_time:.1f} seconds")
223+
else:
224+
if remaining_seconds != last_displayed_time:
225+
label.config(text=f"System will hibernate in\n{int(remaining_seconds)} seconds")
226+
last_displayed_time = remaining_seconds
214227

215228
# Progressbar updated every frame (for smoothness)
216229
progress["value"] = (time_elapsed / total_time) * 100
@@ -255,7 +268,7 @@ def load_base64_image(base64_data: str):
255268
root.attributes("-topmost", True)
256269
if current_os() == "Windows":
257270
maximize_minimize_button.hide(root)
258-
HIBERNATION_TIME, TARGET_FPS = load_config_from_file()
271+
HIBERNATION_TIME, TARGET_FPS, SHOW_DECIMAL_SECONDS = load_config_from_file()
259272
root.protocol("WM_DELETE_WINDOW", on_closing)
260273

261274
root.after(100, root.focus_force) # Force focus after a short delay

0 commit comments

Comments
 (0)