[FEATURE] Support icon in notifications

This commit is contained in:
Gravita 2021-04-30 00:20:10 +07:00
parent a34b2c206b
commit d522976f0b
2 changed files with 20 additions and 2 deletions

View file

@ -13,7 +13,7 @@ public NotifyCommand(LaunchServer server) {
@Override
public String getArgsDescription() {
return "[head] [message]";
return "[head] [message] (icon)";
}
@Override
@ -24,7 +24,12 @@ public String getUsageDescription() {
@Override
public void invoke(String... args) throws Exception {
verifyArgs(args, 2);
NotificationEvent event = new NotificationEvent(args[0], args[1]);
NotificationEvent event;
if(args.length < 3) {
event = new NotificationEvent(args[0], args[1]);
} else {
event = new NotificationEvent(args[0], args[1], Enum.valueOf(NotificationEvent.NotificationType.class, args[2]));
}
WebSocketService service = server.nettyServerSocketHandler.nettyServer.service;
service.sendObjectAll(event, WebSocketEvent.class);
}

View file

@ -8,14 +8,27 @@ public class NotificationEvent implements WebSocketEvent {
public final String head;
@LauncherNetworkAPI
public final String message;
@LauncherNetworkAPI
public final NotificationType icon;
public NotificationEvent(String head, String message) {
this.head = head;
this.message = message;
this.icon = NotificationType.INFO;
}
public NotificationEvent(String head, String message, NotificationType icon) {
this.head = head;
this.message = message;
this.icon = icon;
}
@Override
public String getType() {
return "notification";
}
public enum NotificationType {
INFO, WARN, ERROR, OTHER
}
}