Skip to content

Commit 077e726

Browse files
committed
Added "Go to Rules", "File Properties" and "Service Properties" items to the context menu of the process list, as well as refactoring, QoL improvement and bug fixes.
1 parent 382fa95 commit 077e726

25 files changed

Lines changed: 444 additions & 193 deletions

resources/UI/file-properties.png

2.24 KB
Loading

resources/UI/go-to-rule.png

2.03 KB
Loading

resources/UI/open-folder.png

394 Bytes
Loading
2.48 KB
Loading

src/constants/app_info.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
from util.utils import is_portable
66

7-
APP_NAME: Final[str] = "Process Governor"
8-
APP_VERSION: Final[str] = "1.2.2"
97
APP_AUTHOR: Final[str] = "System X - Files"
8+
APP_NAME: Final[str] = "Process Governor"
9+
APP_VERSION: Final[str] = "2.0.0"
1010
APP_PROCESSES = {f"{APP_NAME}.exe", "python.exe"}
1111

1212
CURRENT_TAG: Final[str] = f"v{APP_VERSION}"
1313
APP_NAME_WITH_VERSION: Final[str] = f"{APP_NAME} {CURRENT_TAG}"
14+
APP_TITLE = f"{APP_NAME_WITH_VERSION} by {APP_AUTHOR}"
1415
TITLE_ERROR: Final[str] = f"Error Detected - {APP_NAME_WITH_VERSION}"
1516

1617
if is_portable():

src/constants/resources.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
UI_SERVICE: Final[str] = f"{APP_PATH}/resources/UI/service.png"
2727
UI_PROCESS: Final[str] = f"{APP_PATH}/resources/UI/process.png"
2828
UI_OPEN_FOLDER: Final[str] = f"{APP_PATH}/resources/UI/open-folder.png"
29+
UI_OPEN_FILE_PROPERTIES: Final[str] = f"{APP_PATH}/resources/UI/file-properties.png"
30+
UI_OPEN_SERVICE_PROPERTIES: Final[str] = f"{APP_PATH}/resources/UI/service-properties.png"
31+
UI_GO_TO_RULE: Final[str] = f"{APP_PATH}/resources/UI/go-to-rule.png"
2932

3033
UI_INFO_TOOLTIP: Final[str] = f"{APP_PATH}/resources/UI/info-tooltip.png"
3134
UI_WARN_TOOLTIP: Final[str] = f"{APP_PATH}/resources/UI/warn-tooltip.png"

src/constants/threads.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
THREAD_TRAY = "tray"
33
THREAD_PROCESS_LIST_DATA = "process_list_data"
44
THREAD_PROCESS_LIST_ICONS = "process_list_icons"
5+
THREAD_PROCESS_LIST_OPEN_SERVICE_PROPERTIES = "process_list_open_service_properties"

src/constants/ui.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
OPEN_CONFIG_LABEL = "Open config file"
1717
OPEN_LOG_LABEL = "Open log file"
1818

19-
CMENU_ADD_PROCESS_RULE_LABEL = " Add Process Rule"
20-
CMENU_ADD_SERVICE_RULE_LABEL = " Add Service Rule"
21-
CMENU_COPY_LABEL = " Copy Special"
22-
CMENU_OPEN_PROCESS_FOLDER = " Open process folder"
23-
2419

2520
class ActionEvents:
2621
ADD: Final[str] = "<<Add>>"

src/model/service.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Service:
66
"""
77
The Service class represents information about a Windows service.
88
9-
It includes attributes such as service process ID (pid), name and current status.
9+
It includes attributes such as service process ID (pid), name, display name and current status.
1010
"""
1111

1212
pid: int
@@ -19,6 +19,11 @@ class Service:
1919
The name of the Windows service.
2020
"""
2121

22+
display_name: str
23+
"""
24+
The display name of the Windows service.
25+
"""
26+
2227
status: str
2328
"""
2429
The current status of the Windows service.

src/service/rules_service.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __handle_processes(cls, config: Config, processes: dict[int, Process], only_
6666
continue
6767

6868
if rule.delay > 0:
69-
TaskScheduler.schedule_task(process, cls.__handle_process, rule.delay, process, rule)
69+
TaskScheduler.schedule_task(process, cls.__handle_process, process, rule, delay=rule.delay)
7070
else:
7171
cls.__handle_process(process, rule)
7272

@@ -127,22 +127,48 @@ def __first_rule_by_process(cls, config: Config, process: Process) -> Optional[P
127127
return rule
128128

129129
for rule in config.processRules:
130-
if rule.selectorBy == SelectorType.NAME:
131-
value = process.process_name
132-
elif rule.selectorBy == SelectorType.PATH:
133-
value = process.bin_path
134-
elif rule.selectorBy == SelectorType.CMDLINE:
135-
value = process.cmd_line
136-
else:
137-
message = f"Unknown selector type: {rule.selectorBy}"
138-
LOG.error(message)
139-
raise ValueError(message)
130+
value = cls._get_value_for_matching(process, rule)
140131

141132
if path_match(rule.selector, value):
142133
return rule
143134

144135
return None
145136

137+
@classmethod
138+
def find_rules_ids_by_process(
139+
cls,
140+
process: Process,
141+
process_rules: dict[str, ProcessRule],
142+
service_rules: dict[str, ServiceRule],
143+
) -> list[tuple[str, ProcessRule | ServiceRule]]:
144+
result = []
145+
146+
if process.service:
147+
for row_id, rule in service_rules.items():
148+
if path_match(rule.selector, process.service_name):
149+
result.append((row_id, rule))
150+
151+
for row_id, rule in process_rules.items():
152+
value = cls._get_value_for_matching(process, rule)
153+
154+
if path_match(rule.selector, value):
155+
result.append((row_id, rule))
156+
157+
return result
158+
159+
@classmethod
160+
def _get_value_for_matching(cls, process, rule):
161+
if rule.selectorBy == SelectorType.NAME:
162+
return process.process_name
163+
elif rule.selectorBy == SelectorType.PATH:
164+
return process.bin_path
165+
elif rule.selectorBy == SelectorType.CMDLINE:
166+
return process.cmd_line
167+
168+
message = f"Unknown selector type: {rule.selectorBy}"
169+
LOG.error(message)
170+
raise ValueError(message)
171+
146172
@classmethod
147173
@cached(5) # Workaround to ensure the procedure runs only once every 5 seconds
148174
def __light_gc_ignored_process_parameters(cls) -> None:

0 commit comments

Comments
 (0)