feat(conditions): add DIR_EXISTS builtin condition, update system tasks
- add Path type import and DIR_EXISTS condition method - update reset_icon_cache tasks to add directory existence checks - simplify explorer restart command and add installation check
This commit is contained in:
@@ -9,6 +9,7 @@ from __future__ import annotations
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
# 条件判断函数类型
|
||||
@@ -86,6 +87,11 @@ class BuiltinConditions:
|
||||
_check.__name__ = f"HAS_INSTALLED({app_name!r})"
|
||||
return _check
|
||||
|
||||
@staticmethod
|
||||
def DIR_EXISTS(dir: Path) -> Condition:
|
||||
"""路径是否存在."""
|
||||
return dir.exists
|
||||
|
||||
@staticmethod
|
||||
def ENV_VAR_EXISTS(var_name: str) -> Condition:
|
||||
"""检查环境变量是否存在.
|
||||
|
||||
@@ -8,8 +8,10 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import pyflowx as px
|
||||
from pyflowx import BuiltinConditions
|
||||
from pyflowx.conditions import Constants
|
||||
|
||||
|
||||
@@ -34,6 +36,7 @@ def reset_icon_cache() -> list[px.TaskSpec]:
|
||||
px.TaskSpec(
|
||||
"delete_icon_cache",
|
||||
fn=lambda: subprocess.run(["del", "/a", "/q", r"%localappdata%\IconCache.db"], check=False),
|
||||
conditions=(BuiltinConditions.DIR_EXISTS(Path(r"%localappdata%\IconCache.db")),),
|
||||
verbose=True,
|
||||
),
|
||||
px.TaskSpec(
|
||||
@@ -41,11 +44,13 @@ def reset_icon_cache() -> list[px.TaskSpec]:
|
||||
fn=lambda: subprocess.run(
|
||||
["del", "/a", "/q", r"%localappdata%\Microsoft\Windows\Explorer\iconcache*"], check=False
|
||||
),
|
||||
conditions=(BuiltinConditions.DIR_EXISTS(Path(r"%localappdata%\Microsoft\Windows\Explorer")),),
|
||||
verbose=True,
|
||||
),
|
||||
px.TaskSpec(
|
||||
"restart_explorer",
|
||||
fn=lambda: subprocess.run(["cmd", "/c", "start", "explorer.exe"], check=False),
|
||||
fn=lambda: subprocess.run(["explorer.exe"], check=False),
|
||||
conditions=(BuiltinConditions.HAS_INSTALLED("explorer.exe"),),
|
||||
verbose=True,
|
||||
),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user