feat(RegisterTray): 重构并添加新功能
- 重构了 RegisterTray.dll 的核心逻辑,使用更现代的 Windows API - 添加了自定义弹出菜单功能,支持鼠标悬停和点击事件 - 优化了托盘图标的创建和销毁流程 -改进了错误处理和资源管理- 新增 registerEx 方法,支持描述信息
This commit is contained in:
Binary file not shown.
@@ -7,12 +7,21 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Class: com_axis_innovators_box_tools_RegisterTray
|
||||
* Method: register
|
||||
* Signature: (Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Ljava/lang/String;Lcom/axis/innovators/box/tools/RegisterTray/Event;)J
|
||||
* Signature: (Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Lcom/axis/innovators/box/tools/RegisterTray/Event;)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_com_axis_innovators_box_tools_RegisterTray_register
|
||||
(JNIEnv*, jclass, jstring, jobject, jstring, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_axis_innovators_box_tools_RegisterTray
|
||||
* Method: registerEx
|
||||
* Signature: (Ljava/lang/String;Ljava/util/List;Ljava/lang/String;Ljava/lang/String;Lcom/axis/innovators/box/tools/RegisterTray/Event;)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_com_axis_innovators_box_tools_RegisterTray_registerEx
|
||||
(JNIEnv*, jclass, jstring, jobject, jstring, jstring, jobject);
|
||||
|
||||
/*
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -79,7 +79,7 @@ public class Main {
|
||||
if (!acquireLock()) {
|
||||
return;
|
||||
}
|
||||
AxisInnovatorsBox.run(args, true);
|
||||
AxisInnovatorsBox.run(args, debugWindowEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,6 +14,7 @@ public class RegisterTray {
|
||||
|
||||
static {
|
||||
LibraryLoad.loadLibrary("RegisterTray");
|
||||
//System.load("C:\\Users\\Administrator\\source\\repos\\RegisterTray\\x64\\Release\\RegisterTray.dll");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,39 +27,28 @@ public class RegisterTray {
|
||||
* 添加菜单项
|
||||
* @param id 菜单项唯一标识符(需大于0)
|
||||
* @param label 菜单显示文本
|
||||
* @param onClick 点击事件处理器
|
||||
* @param onClick 点击事件处理器(接收 itemId)
|
||||
* @return 当前构建器实例
|
||||
*/
|
||||
public MenuBuilder addItem(int id, String label, MenuItemClickListener onClick) {
|
||||
items.add(new Item(
|
||||
id,
|
||||
label,
|
||||
"", "", "",
|
||||
(Event) combinedId -> {
|
||||
int itemId = (int)(combinedId >> 32);
|
||||
onClick.onClick(itemId);
|
||||
// 为每一项创建一个 Event 回调对象(native 端会在点击时回调此 Event.onClick(long))
|
||||
// 这里我们忽略 native 传回的 trayId,只把 itemId 传给上层的 MenuItemClickListener
|
||||
Event ev = new Event() {
|
||||
@Override
|
||||
public void onClick(long trayId) {
|
||||
try {
|
||||
onClick.onClick(id);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 添加菜单项
|
||||
* @param id 菜单项唯一标识符(需大于0)
|
||||
* @param label 菜单显示文本
|
||||
* @param onClick 点击事件处理器
|
||||
* @return 当前构建器实例
|
||||
*/
|
||||
public MenuBuilder addItem(MenuBuilder builder,int id, String label, MenuItemClickListener onClick) {
|
||||
this.items = builder.items;
|
||||
items.add(new Item(
|
||||
id,
|
||||
label,
|
||||
"", "", "",
|
||||
(Event) combinedId -> {
|
||||
int itemId = (int)(combinedId >> 32);
|
||||
onClick.onClick(itemId);
|
||||
}
|
||||
ev
|
||||
));
|
||||
return this;
|
||||
}
|
||||
@@ -72,6 +62,7 @@ public class RegisterTray {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 托盘配置器(流畅接口)
|
||||
*/
|
||||
@@ -143,7 +134,6 @@ public class RegisterTray {
|
||||
title,
|
||||
menuItems,
|
||||
iconPath,
|
||||
tooltip,
|
||||
clickListener::onClick
|
||||
);
|
||||
} catch (Exception e) {
|
||||
@@ -185,8 +175,13 @@ public class RegisterTray {
|
||||
}
|
||||
}
|
||||
|
||||
public static native long register(String name, List<Item> value,
|
||||
String icon, String description, Event event);
|
||||
public static native long register(String name, List<Item> items, String icon, Event event);
|
||||
|
||||
/**
|
||||
* 更强的变体:允许提供 description(可以用于 tooltip 或弹出顶部信息)。
|
||||
* 推荐使用 registerEx 来获取现代化圆角弹出菜单。
|
||||
*/
|
||||
public static native long registerEx(String name, List<Item> items, String icon, String description, Event event);
|
||||
public static native void unregister(long id);
|
||||
|
||||
public interface Event {
|
||||
|
||||
@@ -60,22 +60,17 @@ public class Tray {
|
||||
* @throws RegisterTray.TrayException 抛出错误
|
||||
*/
|
||||
public static void load(TrayLabels trayLabels) throws RegisterTray.TrayException {
|
||||
if (trayLabels == null || trayLabelsList.contains(trayLabels)){
|
||||
if (trayLabels == null || trayLabelsList.contains(trayLabels)) {
|
||||
System.err.println("trayLabels is null or trayLabelsList contains trayLabels");
|
||||
return;
|
||||
}
|
||||
trayLabelsList.add(trayLabels);
|
||||
|
||||
if (menuBuilders == null) {
|
||||
RegisterTray.MenuBuilder menuBuilder = new RegisterTray.MenuBuilder()
|
||||
.addItem(trayLabels.id, trayLabels.name, itemId -> trayLabels.action.run());
|
||||
menuBuilders = menuBuilder;
|
||||
menuItems = menuBuilder.build();
|
||||
} else {
|
||||
menuBuilders = new RegisterTray.MenuBuilder()
|
||||
.addItem(menuBuilders, trayLabels.id, trayLabels.name, itemId -> trayLabels.action.run());
|
||||
menuItems = menuBuilders.build();
|
||||
menuBuilders = new RegisterTray.MenuBuilder();
|
||||
}
|
||||
menuBuilders.addItem(trayLabels.id, trayLabels.name, itemId -> trayLabels.action.run());
|
||||
menuItems = menuBuilders.build();
|
||||
}
|
||||
|
||||
public static void addAction(Runnable action){
|
||||
|
||||
Reference in New Issue
Block a user