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 os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|
||||||
# 条件判断函数类型
|
# 条件判断函数类型
|
||||||
@@ -86,6 +87,11 @@ class BuiltinConditions:
|
|||||||
_check.__name__ = f"HAS_INSTALLED({app_name!r})"
|
_check.__name__ = f"HAS_INSTALLED({app_name!r})"
|
||||||
return _check
|
return _check
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def DIR_EXISTS(dir: Path) -> Condition:
|
||||||
|
"""路径是否存在."""
|
||||||
|
return dir.exists
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ENV_VAR_EXISTS(var_name: str) -> Condition:
|
def ENV_VAR_EXISTS(var_name: str) -> Condition:
|
||||||
"""检查环境变量是否存在.
|
"""检查环境变量是否存在.
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import pyflowx as px
|
import pyflowx as px
|
||||||
|
from pyflowx import BuiltinConditions
|
||||||
from pyflowx.conditions import Constants
|
from pyflowx.conditions import Constants
|
||||||
|
|
||||||
|
|
||||||
@@ -34,6 +36,7 @@ def reset_icon_cache() -> list[px.TaskSpec]:
|
|||||||
px.TaskSpec(
|
px.TaskSpec(
|
||||||
"delete_icon_cache",
|
"delete_icon_cache",
|
||||||
fn=lambda: subprocess.run(["del", "/a", "/q", r"%localappdata%\IconCache.db"], check=False),
|
fn=lambda: subprocess.run(["del", "/a", "/q", r"%localappdata%\IconCache.db"], check=False),
|
||||||
|
conditions=(BuiltinConditions.DIR_EXISTS(Path(r"%localappdata%\IconCache.db")),),
|
||||||
verbose=True,
|
verbose=True,
|
||||||
),
|
),
|
||||||
px.TaskSpec(
|
px.TaskSpec(
|
||||||
@@ -41,11 +44,13 @@ def reset_icon_cache() -> list[px.TaskSpec]:
|
|||||||
fn=lambda: subprocess.run(
|
fn=lambda: subprocess.run(
|
||||||
["del", "/a", "/q", r"%localappdata%\Microsoft\Windows\Explorer\iconcache*"], check=False
|
["del", "/a", "/q", r"%localappdata%\Microsoft\Windows\Explorer\iconcache*"], check=False
|
||||||
),
|
),
|
||||||
|
conditions=(BuiltinConditions.DIR_EXISTS(Path(r"%localappdata%\Microsoft\Windows\Explorer")),),
|
||||||
verbose=True,
|
verbose=True,
|
||||||
),
|
),
|
||||||
px.TaskSpec(
|
px.TaskSpec(
|
||||||
"restart_explorer",
|
"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,
|
verbose=True,
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user