Skip to content

Commit 1af90f0

Browse files
authored
Merge pull request slgobinath#722 from deltragon/cli-gtk-actions
port cli handling and uniqueness to gtk
2 parents b32bcda + c5d3957 commit 1af90f0

File tree

56 files changed

+177
-1018
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+177
-1018
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ Ensure to meet the following dependencies:
122122
- python3-babel
123123
- python3-croniter
124124
- python3-gi
125-
- python3-psutil
126125
- python3-packaging
127126
- python3-xlib
128127
- python3-pywayland (optional for KDE/other wayland)
@@ -191,7 +190,6 @@ This method has the same caveats about icons/window icons as running from source
191190
- Smart pause if system is idle
192191
- Multi-screen support
193192
- Customizable user interface
194-
- RPC API to control externally
195193
- Command-line arguments to control the running instance
196194
- Customizable using plug-ins
197195

debian/control

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Depends: ${misc:Depends}, ${python3:Depends},
1616
x11-utils,
1717
xprintidle,
1818
alsa-utils,
19-
python3-psutil,
2019
python3-croniter,
2120
python3-packaging,
2221
gir1.2-notify-0.7,

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ dependencies = [
2424
"pywayland",
2525
"PyGObject",
2626
"babel",
27-
"psutil",
2827
"packaging",
2928
"python-xlib",
3029
]
@@ -65,7 +64,6 @@ types = [
6564
"mypy==1.15.0",
6665
"PyGObject-stubs==2.13.0",
6766
"types-croniter==5.0.1.20250322",
68-
"types-psutil==7.0.0.20250218",
6967
"types-python-xlib==0.33.0.20240407",
7068
{include-group = "tests"},
7169
]

safeeyes/__main__.py

Lines changed: 3 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -20,140 +20,22 @@
2020
your eyes from eye strain.
2121
"""
2222

23-
import argparse
24-
import logging
2523
import signal
2624
import sys
2725

28-
import psutil
29-
from safeeyes import utility, translations
30-
from safeeyes.translations import translate as _
26+
from safeeyes import translations
3127
from safeeyes.model import Config
3228
from safeeyes.safeeyes import SafeEyes
33-
from safeeyes.safeeyes import SAFE_EYES_VERSION
34-
from safeeyes.rpc import RPCClient
35-
36-
37-
def __running():
38-
"""Check if SafeEyes is already running."""
39-
process_count = 0
40-
current_user = psutil.Process().username()
41-
for proc in psutil.process_iter():
42-
if not proc.cmdline:
43-
continue
44-
try:
45-
# Check if safeeyes is in process arguments
46-
if callable(proc.cmdline):
47-
# Latest psutil has cmdline function
48-
cmd_line = proc.cmdline()
49-
else:
50-
# In older versions cmdline was a list object
51-
cmd_line = proc.cmdline
52-
if ("python3" in cmd_line[0] or "python" in cmd_line[0]) and (
53-
"safeeyes" in cmd_line[1] or "safeeyes" in cmd_line
54-
):
55-
if proc.username() == current_user:
56-
process_count += 1
57-
if process_count > 1:
58-
return True
59-
60-
# Ignore if process does not exist or does not have command line args
61-
except (IndexError, psutil.NoSuchProcess):
62-
pass
63-
return False
6429

6530

6631
def main():
6732
"""Start the Safe Eyes."""
6833
system_locale = translations.setup()
6934

70-
parser = argparse.ArgumentParser(prog="safeeyes")
71-
group = parser.add_mutually_exclusive_group()
72-
group.add_argument(
73-
"-a", "--about", help=_("show the about dialog"), action="store_true"
74-
)
75-
group.add_argument(
76-
"-d",
77-
"--disable",
78-
help=_("disable the currently running safeeyes instance"),
79-
action="store_true",
80-
)
81-
group.add_argument(
82-
"-e",
83-
"--enable",
84-
help=_("enable the currently running safeeyes instance"),
85-
action="store_true",
86-
)
87-
group.add_argument(
88-
"-q",
89-
"--quit",
90-
help=_("quit the running safeeyes instance and exit"),
91-
action="store_true",
92-
)
93-
group.add_argument(
94-
"-s", "--settings", help=_("show the settings dialog"), action="store_true"
95-
)
96-
group.add_argument(
97-
"-t", "--take-break", help=_("Take a break now").lower(), action="store_true"
98-
)
99-
parser.add_argument(
100-
"--debug", help=_("start safeeyes in debug mode"), action="store_true"
101-
)
102-
parser.add_argument(
103-
"--status",
104-
help=_("print the status of running safeeyes instance and exit"),
105-
action="store_true",
106-
)
107-
parser.add_argument(
108-
"--version", action="version", version="%(prog)s " + SAFE_EYES_VERSION
109-
)
110-
args = parser.parse_args()
111-
112-
# Initialize the logging
113-
utility.initialize_logging(args.debug)
114-
utility.initialize_platform()
11535
config = Config.load()
116-
utility.cleanup_old_user_stylesheet()
11736

118-
if __running():
119-
logging.info("Safe Eyes is already running")
120-
if not config.get("use_rpc_server", True):
121-
# RPC sever is disabled
122-
print(
123-
_(
124-
"Safe Eyes is running without an RPC server. Turn it on to use"
125-
" command-line arguments."
126-
)
127-
)
128-
sys.exit(0)
129-
return
130-
rpc_client = RPCClient(config.get("rpc_port"))
131-
if args.about:
132-
rpc_client.show_about()
133-
elif args.disable:
134-
rpc_client.disable_safeeyes()
135-
elif args.enable:
136-
rpc_client.enable_safeeyes()
137-
elif args.settings:
138-
rpc_client.show_settings()
139-
elif args.take_break:
140-
rpc_client.take_break()
141-
elif args.status:
142-
print(rpc_client.status())
143-
elif args.quit:
144-
rpc_client.quit()
145-
else:
146-
# Default behavior is opening settings
147-
rpc_client.show_settings()
148-
sys.exit(0)
149-
else:
150-
if args.status:
151-
print(_("Safe Eyes is not running"))
152-
sys.exit(0)
153-
elif not args.quit:
154-
logging.info("Starting Safe Eyes")
155-
safe_eyes = SafeEyes(system_locale, config, args)
156-
safe_eyes.start()
37+
safe_eyes = SafeEyes(system_locale, config)
38+
safe_eyes.run(sys.argv)
15739

15840

15941
if __name__ == "__main__":

safeeyes/config/locale/ar/LC_MESSAGES/safeeyes.po

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,6 @@ msgstr "أظهر حالة برنامج safeeyes المشتغل حاليا و أ
8787
msgid "Safe Eyes is not running"
8888
msgstr "SafeEyes لا يعمل"
8989

90-
# RPC not enabled message
91-
msgid ""
92-
"Safe Eyes is running without an RPC server. Turn it on to use command-line "
93-
"arguments."
94-
msgstr "يعمل Safe Eyes الآن دون خادوم RPC. شغِّله لكي تستعمل معطيات سطر الأوامر."
95-
9690
# About dialog
9791
msgid "Close"
9892
msgstr "أغلق"
@@ -160,14 +154,6 @@ msgstr "مكّن تأخير الاستراحات"
160154
msgid "Persist the internal state"
161155
msgstr "ثبّت الحالة الداخلية"
162156

163-
# Settings dialog
164-
msgid "Use RPC server to receive runtime commands"
165-
msgstr "استعمل خادوم RPC لاستقبال الأوامر في وقت التشغيل"
166-
167-
# Settings dialog
168-
msgid "Without the RPC server, command-line commands may not work"
169-
msgstr "قد لا تعمل أوامر سطر الأوامر من غير خادوم RPC"
170-
171157
# Settings dialog
172158
msgid "Long break interval must be a multiple of short break interval"
173159
msgstr "الاستراحات الطويلة يجب أن تكون من مضاعفات مدة الاستراحات القصيرة"

safeeyes/config/locale/bg/LC_MESSAGES/safeeyes.po

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ msgstr ""
8585
msgid "Safe Eyes is not running"
8686
msgstr ""
8787

88-
# RPC not enabled message
89-
msgid ""
90-
"Safe Eyes is running without an RPC server. Turn it on to use command-line "
91-
"arguments."
92-
msgstr ""
93-
9488
# About dialog
9589
msgid "Close"
9690
msgstr "Затваряне"
@@ -158,14 +152,6 @@ msgstr ""
158152
msgid "Persist the internal state"
159153
msgstr ""
160154

161-
# Settings dialog
162-
msgid "Use RPC server to receive runtime commands"
163-
msgstr ""
164-
165-
# Settings dialog
166-
msgid "Without the RPC server, command-line commands may not work"
167-
msgstr ""
168-
169155
# Settings dialog
170156
msgid "Long break interval must be a multiple of short break interval"
171157
msgstr ""

safeeyes/config/locale/bn/LC_MESSAGES/safeeyes.po

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ msgstr ""
8585
msgid "Safe Eyes is not running"
8686
msgstr "Safe Eyes চলছে না"
8787

88-
# RPC not enabled message
89-
msgid ""
90-
"Safe Eyes is running without an RPC server. Turn it on to use command-line "
91-
"arguments."
92-
msgstr ""
93-
9488
# About dialog
9589
msgid "Close"
9690
msgstr ""
@@ -158,14 +152,6 @@ msgstr ""
158152
msgid "Persist the internal state"
159153
msgstr ""
160154

161-
# Settings dialog
162-
msgid "Use RPC server to receive runtime commands"
163-
msgstr ""
164-
165-
# Settings dialog
166-
msgid "Without the RPC server, command-line commands may not work"
167-
msgstr ""
168-
169155
# Settings dialog
170156
msgid "Long break interval must be a multiple of short break interval"
171157
msgstr ""

safeeyes/config/locale/ca/LC_MESSAGES/safeeyes.po

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,6 @@ msgstr "Mostra l'estat de la instància de safeeyes en funcionament i surt"
8585
msgid "Safe Eyes is not running"
8686
msgstr "Safe Eyes no s'està executant"
8787

88-
# RPC not enabled message
89-
msgid ""
90-
"Safe Eyes is running without an RPC server. Turn it on to use command-line "
91-
"arguments."
92-
msgstr ""
93-
"Safe Eyes s'està executant sense un servidor RPC. Engegueu-lo per usar els "
94-
"arguments de la línia d'ordres."
95-
9688
# About dialog
9789
msgid "Close"
9890
msgstr "Tanca"
@@ -163,17 +155,6 @@ msgstr "Permet posposar les pauses"
163155
msgid "Persist the internal state"
164156
msgstr "Persisteix l'estat intern"
165157

166-
# Settings dialog
167-
msgid "Use RPC server to receive runtime commands"
168-
msgstr ""
169-
"Empra el servidor RPC per a rebre els comandaments del temps d'execució"
170-
171-
# Settings dialog
172-
msgid "Without the RPC server, command-line commands may not work"
173-
msgstr ""
174-
"Sense el servidor RPC, és possible que les ordres a la línia d'ordres no "
175-
"funcionin"
176-
177158
# Settings dialog
178159
msgid "Long break interval must be a multiple of short break interval"
179160
msgstr ""

safeeyes/config/locale/cs/LC_MESSAGES/safeeyes.po

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,6 @@ msgstr "Popis argumentu příkazového řádku"
8585
msgid "Safe Eyes is not running"
8686
msgstr "Stavová zpráva"
8787

88-
# RPC not enabled message
89-
msgid ""
90-
"Safe Eyes is running without an RPC server. Turn it on to use command-line "
91-
"arguments."
92-
msgstr ""
93-
"Safe Eyes je spuštěné s tím, že RPC server je vypnutý. Aby bylo možné "
94-
"používat argumenty příkazového řádku, je třeba RPC server zapnout."
95-
9688
# About dialog
9789
msgid "Close"
9890
msgstr "Zavřít"
@@ -162,14 +154,6 @@ msgstr "Umožnit přeskakování přestávek"
162154
msgid "Persist the internal state"
163155
msgstr "Zachovat vnitřní stav"
164156

165-
# Settings dialog
166-
msgid "Use RPC server to receive runtime commands"
167-
msgstr "Použít RPC server pro obdržení příkazů za chodu"
168-
169-
# Settings dialog
170-
msgid "Without the RPC server, command-line commands may not work"
171-
msgstr "Bez RPC serveru, argumenty na příkazovém řádku nemusí fungovat"
172-
173157
# Settings dialog
174158
msgid "Long break interval must be a multiple of short break interval"
175159
msgstr "Je třeba, aby dlouhé přestávky byly násobkem krátkých přestávek"

safeeyes/config/locale/da/LC_MESSAGES/safeeyes.po

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,6 @@ msgstr "print status for at køre Safe Eyes instans og afslut"
8585
msgid "Safe Eyes is not running"
8686
msgstr "Safe Eyes kører ikke"
8787

88-
# RPC not enabled message
89-
msgid ""
90-
"Safe Eyes is running without an RPC server. Turn it on to use command-line "
91-
"arguments."
92-
msgstr ""
93-
"Safe Eyes kører med RPC-server deaktiveret. Aktivér RPC-serveren for at "
94-
"bruge kommandolinjeargumenter."
95-
9688
# About dialog
9789
msgid "Close"
9890
msgstr "Luk"
@@ -160,14 +152,6 @@ msgstr "Tillad at udskyde pauser"
160152
msgid "Persist the internal state"
161153
msgstr "Fortsætter i interntilstand"
162154

163-
# Settings dialog
164-
msgid "Use RPC server to receive runtime commands"
165-
msgstr "Brug RPC-server til at modtage runtime-kommandoer"
166-
167-
# Settings dialog
168-
msgid "Without the RPC server, command-line commands may not work"
169-
msgstr "Uden RPC-serveren fungerer kommandolinjekommandoer muligvis ikke"
170-
171155
# Settings dialog
172156
msgid "Long break interval must be a multiple of short break interval"
173157
msgstr ""

0 commit comments

Comments
 (0)