22
22
just_fix_windows_console ()
23
23
24
24
YASB_VERSION = BUILD_VERSION
25
- YASB_CLI_VERSION = "1.0.8 "
25
+ YASB_CLI_VERSION = "1.0.9 "
26
26
27
27
OS_STARTUP_FOLDER = os .path .join (os .environ ['APPDATA' ], r'Microsoft\Windows\Start Menu\Programs\Startup' )
28
28
INSTALLATION_PATH = os .path .abspath (os .path .join (__file__ , "../../.." ))
@@ -36,7 +36,7 @@ def is_process_running(process_name):
36
36
if proc .info ['name' ] == process_name :
37
37
return True
38
38
return False
39
-
39
+
40
40
class Format :
41
41
end = '\033 [0m'
42
42
underline = '\033 [4m'
@@ -119,7 +119,7 @@ def _enable_startup():
119
119
except Exception as e :
120
120
logging .error (f"Failed to create startup shortcut: { e } " )
121
121
print (f"Failed to create startup shortcut: { e } " )
122
-
122
+
123
123
def _disable_startup ():
124
124
shortcut_path = os .path .join (OS_STARTUP_FOLDER , SHORTCUT_FILENAME )
125
125
if os .path .exists (shortcut_path ):
@@ -130,55 +130,64 @@ def _disable_startup():
130
130
except Exception as e :
131
131
logging .error (f"Failed to remove startup shortcut: { e } " )
132
132
print (f"Failed to remove startup shortcut: { e } " )
133
-
134
-
133
+
134
+
135
135
def parse_arguments ():
136
136
parser = CustomArgumentParser (description = "The command-line interface for YASB Reborn." , add_help = False )
137
137
subparsers = parser .add_subparsers (dest = 'command' , help = 'Commands' )
138
138
139
- subparsers .add_parser ('start' , help = 'Start the application' )
140
- subparsers .add_parser ('stop' , help = 'Stop the application' )
141
- subparsers .add_parser ('reload' , help = 'Reload the application' )
139
+ start_parser = subparsers .add_parser ('start' , help = 'Start the application' )
140
+ start_parser .add_argument ('-s' , '--silent' , action = 'store_true' , help = 'Silence print messages' )
141
+
142
+ stop_parser = subparsers .add_parser ('stop' , help = 'Stop the application' )
143
+ stop_parser .add_argument ('-s' , '--silent' , action = 'store_true' , help = 'Silence print messages' )
144
+
145
+ reload_parser = subparsers .add_parser ('reload' , help = 'Reload the application' )
146
+ reload_parser .add_argument ('-s' , '--silent' , action = 'store_true' , help = 'Silence print messages' )
147
+
142
148
subparsers .add_parser ('update' , help = 'Update the application' )
143
-
149
+
144
150
enable_autostart_parser = subparsers .add_parser ('enable-autostart' , help = 'Enable autostart on system boot' )
145
151
enable_autostart_parser .add_argument ('--task' , action = 'store_true' , help = 'Enable autostart as a scheduled task' )
146
-
152
+
147
153
disable_autostart_parser = subparsers .add_parser ('disable-autostart' , help = 'Disable autostart on system boot' )
148
154
disable_autostart_parser .add_argument ('--task' , action = 'store_true' , help = 'Disable autostart as a scheduled task' )
149
-
155
+
150
156
subparsers .add_parser ('help' , help = 'Show help message' )
151
157
subparsers .add_parser ('log' , help = 'Tail yasb process logs (cancel with Ctrl-C)' )
152
158
parser .add_argument ('-v' , '--version' , action = 'store_true' , help = "Show program's version number and exit." )
153
159
parser .add_argument ('-h' , '--help' , action = 'store_true' , help = 'Show help message' )
154
160
args = parser .parse_args ()
155
-
161
+
156
162
if args .command == 'start' :
157
- print (f"Start YASB Reborn v{ YASB_VERSION } in background." )
158
- print ("\n # Community" )
159
- print ("* Join the Discord https://discord.gg/qkeunvBFgX - Chat, ask questions, share your desktops and more..." )
160
- print ("* GitHub discussions https://github.com/amnweb/yasb/discussions - Ask questions, share your ideas and more..." )
161
- print ("\n # Documentation" )
162
- print ("* Read the docs https://github.com/amnweb/yasb/wiki - how to configure and use YASB" )
163
+ if not args .silent :
164
+ print (f"Start YASB Reborn v{ YASB_VERSION } in background." )
165
+ print ("\n # Community" )
166
+ print ("* Join the Discord https://discord.gg/qkeunvBFgX - Chat, ask questions, share your desktops and more..." )
167
+ print ("* GitHub discussions https://github.com/amnweb/yasb/discussions - Ask questions, share your ideas and more..." )
168
+ print ("\n # Documentation" )
169
+ print ("* Read the docs https://github.com/amnweb/yasb/wiki - how to configure and use YASB" )
163
170
subprocess .Popen (["yasb.exe" ])
164
171
sys .exit (0 )
165
-
172
+
166
173
elif args .command == 'stop' :
167
- print ("Stop YASB..." )
174
+ if not args .silent :
175
+ print ("Stop YASB..." )
168
176
CLIHandler .stop_or_reload_application ()
169
177
sys .exit (0 )
170
-
178
+
171
179
elif args .command == 'reload' :
172
180
if is_process_running ("yasb.exe" ):
173
- print ("Reload YASB..." )
181
+ if not args .silent :
182
+ print ("Reload YASB..." )
174
183
CLIHandler .stop_or_reload_application (reload = True )
175
184
else :
176
185
print ("YASB is not running. Reload aborted." )
177
186
sys .exit (0 )
178
187
elif args .command == 'update' :
179
188
CLIUpdateHandler .update_yasb (YASB_VERSION )
180
189
sys .exit (0 )
181
-
190
+
182
191
elif args .command == 'enable-autostart' :
183
192
if args .task :
184
193
if not CLITaskHandler .is_admin ():
@@ -188,7 +197,7 @@ def parse_arguments():
188
197
else :
189
198
CLIHandler ._enable_startup ()
190
199
sys .exit (0 )
191
-
200
+
192
201
elif args .command == 'disable-autostart' :
193
202
if args .task :
194
203
if not CLITaskHandler .is_admin ():
@@ -197,8 +206,8 @@ def parse_arguments():
197
206
CLITaskHandler .delete_task ()
198
207
else :
199
208
CLIHandler ._disable_startup ()
200
- sys .exit (0 )
201
-
209
+ sys .exit (0 )
210
+
202
211
elif args .command == 'log' :
203
212
config_home = os .getenv ('YASB_CONFIG_HOME' ) if os .getenv ('YASB_CONFIG_HOME' ) else os .path .join (os .path .expanduser ("~" ), ".config" , "yasb" )
204
213
log_file = os .path .join (config_home , "yasb.log" )
@@ -218,7 +227,7 @@ def parse_arguments():
218
227
except KeyboardInterrupt :
219
228
pass
220
229
sys .exit (0 )
221
-
230
+
222
231
elif args .command == 'help' or args .help :
223
232
print ("The command-line interface for YASB Reborn." )
224
233
print ('\n ' + Format .underline + 'Usage' + Format .end + ': yasbc <COMMAND>' )
@@ -235,7 +244,7 @@ def parse_arguments():
235
244
print ("-v, --version Print version" )
236
245
print ("-h, --help Print this message" )
237
246
sys .exit (0 )
238
-
247
+
239
248
elif args .version :
240
249
version_message = f"YASB Reborn v{ YASB_VERSION } \n YASB-CLI v{ YASB_CLI_VERSION } "
241
250
print (version_message )
@@ -246,7 +255,7 @@ def parse_arguments():
246
255
247
256
248
257
class CLITaskHandler :
249
-
258
+
250
259
def is_admin ():
251
260
try :
252
261
return ctypes .windll .shell32 .IsUserAnAdmin ()
@@ -259,7 +268,7 @@ def get_current_user_sid():
259
268
user , domain , type = win32security .LookupAccountName (None , username )
260
269
sid = win32security .ConvertSidToStringSid (user )
261
270
return sid
262
-
271
+
263
272
def create_task ():
264
273
scheduler = win32com .client .Dispatch ('Schedule.Service' )
265
274
scheduler .Connect ()
@@ -308,7 +317,7 @@ def create_task():
308
317
print (f"Task YASB Reborn created successfully." )
309
318
except Exception as e :
310
319
print (f"Failed to create task YASB Reborn. Error: { e } " )
311
-
320
+
312
321
def delete_task ():
313
322
scheduler = win32com .client .Dispatch ('Schedule.Service' )
314
323
scheduler .Connect ()
@@ -318,7 +327,7 @@ def delete_task():
318
327
print (f"Task YASB Reborn deleted successfully." )
319
328
except Exception :
320
329
print (f"Failed to delete task YASB or task does not exist." )
321
-
330
+
322
331
class CLIUpdateHandler ():
323
332
324
333
def get_installed_product_code ():
@@ -335,7 +344,7 @@ def get_installed_product_code():
335
344
return product_code .value
336
345
index += 1
337
346
return None
338
-
347
+
339
348
def update_yasb (YASB_VERSION ):
340
349
# Fetch the latest tag from the GitHub API
341
350
api_url = f"https://api.github.com/repos/amnweb/yasb/releases/latest"
@@ -376,7 +385,7 @@ def update_yasb(YASB_VERSION):
376
385
except KeyboardInterrupt :
377
386
print ("\n Download interrupted by user." )
378
387
sys .exit (0 )
379
-
388
+
380
389
# Verify the downloaded file size
381
390
downloaded_size = os .path .getsize (msi_path )
382
391
if downloaded_size != total_length :
@@ -394,7 +403,7 @@ def update_yasb(YASB_VERSION):
394
403
# uninstall_command = f'msiexec /x {product_code} /passive'
395
404
# else:
396
405
# uninstall_command = ""
397
-
406
+
398
407
# Construct the install command as a string
399
408
install_command = f'msiexec /i "{ os .path .abspath (msi_path )} " /passive /norestart'
400
409
run_after_command = f'"{ EXE_PATH } "'
@@ -403,7 +412,7 @@ def update_yasb(YASB_VERSION):
403
412
# Finally run update and restart the application
404
413
subprocess .Popen (combined_command , shell = True )
405
414
sys .exit (0 )
406
-
415
+
407
416
if __name__ == "__main__" :
408
417
CLIHandler .parse_arguments ()
409
- sys .exit (0 )
418
+ sys .exit (0 )
0 commit comments