使用iFlow CLI通过hook添加任务完成通知(定制你的个性化通知) Windows版

作者: @遥控小飞机

前言

之前看过大佬分享的添加hook发送通知的教程,奈何要么是Mac环境的,要么执行sh脚本在我这里一直无法执行触发,今天试了下,通过第三方的BurnToastNotification,执行python脚本的方式可以触发了,定制一个属于你的iflow弹出通知。

首先需要一个能够调用windows系统通知中心的插件,我这里选择了BurnToastNotification,Github地址:Windos/BurntToast: Module for creating and displaying Toast Notifications on Microsoft Windows 10.

好处是

  • 安装简单,一行命令即可安装成功
bash 复制代码
Install-Module -Name BurntToast
  • 定制化强,可以定制你的通知的标题,内容,属性文字,图标,声音,甚至是添加延迟提醒等交互操作。

具体步骤:

  1. 先按照官方说明,在命令行安装好BurnToastNotification。
  2. 然后配置你的通知提醒的python脚本,代码我用AI生成的
python 复制代码
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Stop hook脚本-任务完成通知

import subprocess
import os

def send_notification():
    """发送任务完成通知"""
    try:
        # 构建PowerShell命令,我这里加了个图标文件,配置了通知的标题,内容和属性文字,通过powsershell命令调用BurnToastNotification来发送弹出通知
        ps_command = (
            "New-BurntToastNotification -AppLogo ~/.iflow/hooks/iflow.png "
            "-Text 'Mission Complete!','iflow任务完成' -Attribution 'Powered by Samael'"
        )
        
        # 执行PowerShell命令[6,7,8](@ref)
        result = subprocess.run(
            ["powershell", "-Command", ps_command],
            capture_output=True,
            text=True,
            timeout=30
        )
        
        if result.returncode == 0:
            print("通知发送成功")
        else:
            print(f"通知发送失败: {result.stderr}")
            
    except subprocess.TimeoutExpired:
        print("PowerShell命令执行超时")
    except FileNotFoundError:
        print("未找到powershell命令,请确保在Windows系统中运行")
    except Exception as e:
        print(f"执行过程中发生错误: {e}")

def main():
    """主函数"""
    send_notification()

if __name__ == "__main__":
    main()

上边的python脚本中,我在powershell命令调用burnToastNotification发送系统通知时,加了个图标文件(如果你不改图标文件的话,BurnToast会用它默认的一个图标),也放到python文件同一个目录下了,就是~/.iflow/hooks/目录,如下图:

3.最后一步,在你的iFlow的settings.json中,添加hook配置,我这里用~/.iflow/目录不生效(命名py中能用不知道为啥),所以我就改成完整路径了,小伙伴们可以根据你的情况来修改路径。

python 复制代码
"hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "python c:/Users/26933/.iflow/hooks/stop.py"
          }
        ]
      }
    ],
    "Notification": [
      {
        "matcher": ".*permission.*",
        "hooks": [
          {
            "type": "command",
            "command": "python c:/Users/26933/.iflow/hooks/notification.py"
          }
        ]
      }
    ]
  }

最后的实际效果是这样

在通知中心中也会有记录:

欢迎大家试用~

原文链接:https://vibex.iflow.cn/t/topic/

相关推荐
qq_3692243314 天前
Windows全系通用!ntdll.dll文件丢失、报错、闪退问题的完整排查与修复教程
windows·dll·dll修复·dll丢失·dll错误
阿米亚波14 天前
【Windows】QEMU 启动 openEuler aarch64/arm64 架构系统 + 离线软件源
linux·windows·经验分享·笔记·架构·arm
caimouse14 天前
Reactos 第 10 章 网络操作 — 10.3.1 NIC驱动
网络·windows
初圣魔门首席弟子14 天前
Node.js 详细介绍(知识库版)
windows·qt·node.js·知识库
CHENG-JustDoIt15 天前
AI工具 | 爆火开源项目Odysseus AI 工作台:从项目介绍、部署情况及其使用等多方位分析指南(含详细步骤)
大数据·人工智能·windows·python·ai·开源·github
kingbal15 天前
Windows:flutter环境搭建
windows·flutter
未若君雅裁15 天前
Python 数据容器详解,list、tuple、str、set、dict 到底怎么选
windows·python·list
CodeKwang15 天前
Windows 环境 OCCT 8.0 编译构建及与 Qt6 项目集成
windows·qt·opencascade
我是伪码农15 天前
小兔鲜1-25
linux·服务器·windows
vx-Biye_Design15 天前
springboot安阳地区研学旅游服务小程序-计算机毕业设计源码12785
java·vue.js·windows·spring boot·tomcat·maven·mybatis