Skip to content

Commit

Permalink
优化:修改了静默启动的指令,新增了隐藏主窗的指令
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroi-sora committed Mar 6, 2023
1 parent b9e37ea commit 02f00e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 3 additions & 2 deletions ui/win_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ def onCanvasMouseWheel(event): # 绑定画布中滚轮滚动事件
SysTray.start()
self.win.wm_protocol( # 注册窗口关闭事件
'WM_DELETE_WINDOW', self.onCloseWin)
if not flags['no_win']: # 非静默模式
if not flags['hide']: # 非静默模式
self.gotoTop() # 恢复主窗显示
else: # 无托盘,强制显示主窗
self.gotoTop()
Expand Down Expand Up @@ -1084,7 +1084,8 @@ def updateFrameHeight(self): # 刷新设置页框架高度

def gotoTop(self, isForce=False): # 主窗置顶
flag = Config.get('WindowTopMode')
if flag == WindowTopModeFlag.never and not isForce: # 模式:从不置顶
# 模式:从不置顶
if flag == WindowTopModeFlag.never and not isForce and Config.get('isTray'):
self.win.attributes('-topmost', 0)
return
if self.win.state() == 'iconic': # 窗口最小化状态下
Expand Down
13 changes: 10 additions & 3 deletions utils/command_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
# ======================= 参数解析 ===================================

Flags = gflags.FLAGS
gflags.DEFINE_bool('no_win', False, 'true时关闭窗口,最小化到托盘')
gflags.DEFINE_bool('no_win', False, '(已过时,请用-hide)true时隐藏窗口,最小化到托盘') # 兼容旧版
gflags.DEFINE_bool('hide', False, 'true时隐藏窗口,最小化到托盘') # 兼容旧版
gflags.DEFINE_bool('show', False, 'true时将主窗口显示到最前(不锁定)。')
gflags.DEFINE_string('img', '', '传入本地图片路径。含空格的路径用引号""括起来。多个路径可用逗号,连接。')
gflags.DEFINE_bool('exit', False, 'true时进行一次截屏识图。')
gflags.DEFINE_bool('clipboard', False, 'true时读取一次剪贴板进行识图。')
gflags.DEFINE_bool('screenshot', False, 'true时进行一次截屏识图。')
gflags.DEFINE_bool('exit', False, 'true时进行一次截屏识图。')
gflags.DEFINE_string('img', '', '传入本地图片路径。含空格的路径用引号""括起来。多个路径可用逗号,连接。')


DictDefault = Flags.FlagValuesDict() # 生成默认值字典
Expand All @@ -37,6 +38,8 @@ def Parse(args): # 解析参数。传入参数列表,返回解析后的字典
f['img'] = f['img'].split(',')
else: # 单个地址包装
f['img'] = [f['img']]
if f['no_win']: # 兼容旧版
f['hide'] = True
return f
except Exception as e:
return {'error': f'参数解析失败。\n参数:{args}\n错误:{e}', **DictDefault}
Expand All @@ -51,6 +54,10 @@ def Mission(flags):
return
if flags['show']: # 显示主窗
Config.main.gotoTop(isForce=True)
elif flags['hide']: # 隐藏主窗
if not Config.get('isBackground'): # 非后台模式
Config.set('isBackground', True) # 开启后台模式
Config.main.onCloseWin() # 关闭窗口

# 任务
if not Config.main.isMsnReady():
Expand Down
2 changes: 1 addition & 1 deletion utils/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def switch(action, path, configItem):
try:
arguments = ''
if ShortcutApi.askStartupNoWin(action):
arguments = '--no_win=1'
arguments = '-hide'
ShortcutApi.add(path, name, arguments)
tk.messagebox.showinfo('成功', f'{name} 已添加到{action}')
except Exception as e:
Expand Down

0 comments on commit 02f00e5

Please sign in to comment.