(): print('demo tray action', randint(999, 99999))if __name__ == "__main__": app = QApplication (sys.argv) app.setQuitOnLastWindowClosed(False) tray = QSystemTrayIcon() tray.setIcon(QIcon( '/xxxxxx/ubuntu-plain-icon.svg')) tray.setVisible(True) tray.setToolTip('a tray app with ubuntu ) menu.addAction(action) tray_quit = QAction('TrayAppQuit') tray_quit.triggered.connect(app.quit ) menu.addAction(tray_quit) tray.setContextMenu(menu) app.exec()运行效果
::create_tray(handle)? ,需要配置tauri.conf.json参数 "bundle": {"resources": ["tray"]} res.setIcon('tray/msg.png = await TrayIcon.getById("tray") tray.setIcon('icons/icon.png') } }</script>托盘右键菜单 ,需要配置tauri.conf.json参数 "bundle": {"resources": ["tray"]} res.setIcon('tray/msg.png = await TrayIcon.getById("tray") tray.setIcon('icons/icon.png') } }</script><template
SystemTray tray = SystemTray.getSystemTray(); TrayIcon trayIcon = new TrayIcon(image, "Tray Demo"); tray.add (trayIcon); // 这里可能抛出 AWTException 在上述场景中,如果系统托盘不可用或者资源被其他进程占用,tray.add(trayIcon)会抛出AWTException。 SystemTray.isSupported()) { throw new AWTException("System tray is not supported"); } SystemTray tray = SystemTray.getSystemTray(); TrayIcon trayIcon = new TrayIcon(image, "Tray Demo" SystemTray.isSupported()) { System.out.println("System tray is not supported on this platform
new("quit".to_string(), "关闭窗口"); let hide = CustomMenuItem::new("hide".to_string(), "隐藏窗口"); let tray_menu add_item(quit) .add_native_item(SystemTrayMenuItem::Separator) .add_item(hide); let system_tray = SystemTray::new().with_menu(tray_menu); tauri::Builder::default() .system_tray(system_tray) .on_system_tray_event(|app, event| menu_handle(app, event)) .run(tauri::generate_context! => {} }, _ => {} } } 核心都在menu_handle函数中 参考文章: https://tauri.app/v1/guides/features/system-tray
别担心,今天要介绍的 Twinkle Tray,就是专为解决这些问题而生的开源利器! 项目简介 Twinkle Tray 是一款专为 Windows 设计的开源工具,它通过系统托盘图标提供多显示器亮度统一调控功能,弥补了 Windows 原生功能对外接显示器支持的不足。 install extras/twinkle-tray #### 2. \Twinkle Tray.exe" --All --Set=50 总结 Twinkle Tray 的亮点在于:完全免费开源(MIT 协议),无广告、无捆绑;轻量高效,仅占用约 15MB 内存,后台运行无负担 立即尝试 Twinkle Tray,告别手动调光的繁琐吧! 项目地址:https://github.com/xanderfrangos/twinkle-tray
= QSystemTrayIcon(self) self.tray_icon.setIcon(QIcon('resources/app_tray.ico')) # 这里需要一个名为icon.png 的图标文件,可以替换为真实路径 self.tray_icon.activated.connect(self.tray_icon_activated) # 创建托盘菜单 (sys.exit) tray_menu.addAction(show_action) tray_menu.addAction(quit_action) self.tray_icon.setContextMenu(tray_menu) # 从托盘菜单点击显示窗口 deftray_menu_show_main(self): : self.tray_icon.show() self.is_tray_icon_visible = True ifnotself.is_floating_ball_visible
const electron = require('electron'); const { app, BrowserWindow, Menu, ipcMain, Tray let appIcon = new Tray(iconPath); const contextMenu = Menu.buildFromTemplate([{ label: '移除', click: function() { event.sender.send('tray-removed'); } }, { type: 'separator' }, { /img/tray/tray_icon_2.png')); } else { appIcon.setImage(path.join(__dirname, '.. /img/tray/tray_icon.png')); } }, 400); 上面两个功能并不复杂,主要是对API方法的调用。
Electron托盘图标 添加引用 const {app, Menu, Tray} = require("electron"); const path = require("path"); 设置托盘图标及菜单 let tray = null tray = new Tray(path.join(__dirname, 'app.ico')); const contextMenu = Menu.buildFromTemplate ([ { label: '退出', click: () => { app.quit(); } }, ]) tray.setToolTip ('直播') tray.setContextMenu(contextMenu) tray.on('click', () => { //我们这里模拟桌面程序点击通知区图标实现打开关闭应用的功能
在 Electron 中,借助 Tray 模块实现。 //app 模块,控制整个应用程序的事件生命周期。 //BrowserWindow 模块,它创建和管理程序的窗口。 const { app, BrowserWindow, Tray, Menu } = require("electron"); const path = require("path"); const /src/img/logo.png"); //应用运行时的标题栏图标 let mainWindow, tray; //在 Electron 中,只有在 app 模块的 ready 事件被激发后才能创建浏览器窗口 /src/main.html"); // 系统托盘 tray = new Tray(iconPath); //实例化一个tray对象,构造函数的唯一参数是需要在托盘中显示的图标url tray.setToolTip ("Tasky"); //鼠标移到托盘中应用程序的图标上时,显示的文本 tray.on("click", () => { //点击图标的响应事件,这里是切换主窗口的显示和隐藏 if
>
}// 取消拖拽.vu__undrag {-webkit-app-region: no-drag;}tauri2自定义托盘闪烁|托盘右键菜单/** * 自定义托盘图标 */use tauri::{ tray ("TAURI-WINCHAT") .icon(app.default_window_icon().unwrap().clone()) .on_tray_icon_event(|tray, ("点击右键"); tray.app_handle().emit("tray_contextmenu", position).unwrap(); } _ = ("鼠标滑过托盘"); tray.app_handle().emit("tray_mouseenter", position).unwrap(); } TrayIconEvent ("鼠标离开托盘"); tray.app_handle().emit("tray_mouseleave", position).unwrap(); } _ => {}
electron-localshortcut:本地快捷键 electron-store:本地存储 下面是main.js 加载页面的代码 const { app, BrowserWindow,Tray }) win.loadURL('https://gofly.v1kf.com/main') //隐藏顶部菜单 win.setMenu(null); //托盘图标 let tray = new Tray(path.join(__dirname, 'favicon.ico')) //点击托盘图标显示窗口 tray.on('click', () => { win.show () }) //设置托盘提示 tray.setToolTip('客服系统') const { Menu } = require('electron') //设置托盘菜单 const contextMenu = Menu.buildFromTemplate([ { label: '退出', click: () => { app.exit() } } ]) tray.setContextMenu
================ 下面是代码部分: ======================================================================== /tray /src/com/b510/tray托盘/DesktopCapture.java 1 package com.b510.tray托盘; 2 3 import java.awt.event.ActionEvent serialVersionUID = 1L; 18 // JButton confirm; 19 // BufferedImage desktopImg; 20 MyTray tray } 75 76 @Override 77 public void actionPerformed(ActionEvent e) { 78 79 } 80 81 } /tray /src/com/b510/tray托盘/MyTray.java 1 package com.b510.tray托盘; 2 3 import java.awt.AWTException; 4
= judge_tray_cube(camera_data_b) return cube_data, tray_data每个物体的表面都有贴有STag码,可以通过标记码来精准的获得物体的坐标参数 def put_up_tray(tray_data): ml.set_gripper_value(60, 10) mr.set_gripper_value(60, 10) time.sleep (1) for tray in tray_data: offset, fact_bcl = get_obj_coords(tray["corners"], tray["ids"], tray["cur_coords"], tray['arm']) point = fact_bcl.copy() px, py, pz = point[0], point[1 ], point[2] if tray["ids"] == [4] and tray['arm'] == "left": af = (offset + 90) * pi
root_window = display.XDefaultRootWindow(display.XOpenDisplay(None)) # Create a window for the tray icon tray_window = display.XCreateSimpleWindow(display.XOpenDisplay(None), root_window, 0, 0, 1, 1, 0, 0, 0) # Set the tray icon display.XSetIconName(display.XOpenDisplay(None), tray_window, " icon.png") # Show the tray icon display.XMapWindow(display.XOpenDisplay(None), tray_window) # Create a menu for the tray icon menu = gtk.Menu() menu_item = gtk.MenuItem("Show Window")
BrowserWindow对象创建窗体,electron-vue构建项目后,主进程入口页面是src/main/index.js import { BrowserWindow, app, ipcMain, Tray __static = require('path').join(__dirname, '/static').replace(/\\/g, '\\\\') } let mainWin let tray (menu) tray.setToolTip('electron-vchat v1.0.0') // 托盘点击事件 tray.on('click', () => { (trayIco1) } }, // 销毁托盘图标 destroyTray() { this.flashTray(false) tray.destroy() tray = null } } renderer渲染进程里面的页面写法和vue一样,这里不作过多介绍了。
style: FontStyle = FontStyle.Normal ): Font = ResourceFont(resource, weight, style) 如此一来,卡顿问题便得到了解决 Tray 但是需要注意的是,sendNotification 有一个限制: /** * Send notification to tray. If [TrayState] is attached to [Tray], notification will be sent to * the platform. application { val isShowTray = remember { mutableStateOf(false) } if (isShowTray.value) { Tray 这实际上是当我们发送 Notification 时,此时 trayState 还未被 attach 到我们的 Tray 上,导致了这个问题。
2.1.1markdown解析:flutter_markdown_plus^1.0.7环境变量配置:flutter_dotenv^6.0.0窗口管理:window_manager^0.5.1托盘管理:system_tray });flutter3自定义系统托盘// 初始化系统托盘Future<void> initSystemTray() async { String trayIco = 'assets/images/tray.ico SystemTray systemTray = SystemTray(); // 初始化系统托盘 await systemTray.initSystemTray( title: 'system-tray Menu menu = Menu(); await menu.buildFrom([ MenuItemLabel(label: '打开主界面', image: 'assets/images/tray.ico ', onClicked: (menuItem) => {}), MenuItemLabel(label: '关闭程序并退出', image: 'assets/images/tray.ico',
技术栈技术框架:flutter3.32.0+dart3.8.0对话大模型:deepseek-v3流请求:dio^5.8.0+1窗口管理:window_manager^0.5.0托盘管理:system_tray shirne_dialog/shirne_dialog.dart';import 'package:flutter_dotenv/flutter_dotenv.dart';import 'package:system_tray /system_tray.dart';import 'package:window_manager/window_manager.dart';import 'controller/app.dart';import SystemTray systemTray = SystemTray(); // 初始化系统托盘 await systemTray.initSystemTray( title: 'system-tray ', onClicked: (menuItem) => {}), MenuItemLabel(label: '关闭程序并退出', image: 'assets/images/tray.ico',
image.png // 创建系统托盘图标 let tray = null let flashTimer = null let trayIco1 = path.join(__dirname, '.. /static/tray.ico') let trayIco2 = path.join(__dirname, '.. = new Tray(this.trayIco1) this.tray.setContextMenu(trayMenu) this.tray.setToolTip(app.name) this.tray.on('double-click', () => { // ... }) } // 托盘图标闪烁 flashTray(flash) { let this.tray = null } 注意:加载本地ico,主进程__dirname会默认指向dist_electron目录。