Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ptma committed Jan 18, 2024
2 parents fac4e44 + b342296 commit 857f0ef
Show file tree
Hide file tree
Showing 28 changed files with 1,043 additions and 816 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ hs_err_pid*
temp/
scripts/
conf/
codecs/
codecs/
logs/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
--
![JDK](https://img.shields.io/badge/JDK-17-blue.svg)
![Apache 2.0](https://img.shields.io/badge/Apache-2.0-blue.svg)
![Release](https://img.shields.io/badge/Release-1.1.0-blue.svg)
![Release](https://img.shields.io/badge/Release-1.1.1-blue.svg)

MqttInsight is an open source cross platform MQTT desktop client.

Expand Down
2 changes: 1 addition & 1 deletion README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
--
![JDK](https://img.shields.io/badge/JDK-17-blue.svg)
![Apache 2.0](https://img.shields.io/badge/Apache-2.0-blue.svg)
![Release](https://img.shields.io/badge/Release-1.1.0-blue.svg)
![Release](https://img.shields.io/badge/Release-1.1.1-blue.svg)

MqttInsight 是开源跨平台的 MQTT 图形客户端.

Expand Down
12 changes: 4 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ import groovy.json.JsonSlurper
import groovy.lang.Closure
import io.github.fvarrui.javapackager.gradle.PackagePluginExtension
import io.github.fvarrui.javapackager.gradle.PackageTask
import io.github.fvarrui.javapackager.model.HeaderType
import io.github.fvarrui.javapackager.model.LinuxConfig
import io.github.fvarrui.javapackager.model.MacConfig
import io.github.fvarrui.javapackager.model.MacStartup
import io.github.fvarrui.javapackager.model.*
import io.github.fvarrui.javapackager.model.Platform
import io.github.fvarrui.javapackager.model.WindowsConfig
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.internal.os.OperatingSystem

Expand Down Expand Up @@ -41,7 +37,7 @@ val organization: String = "ptma@163.com"
val copyright: String = "Copyright 2023 ptma@163.com"
val supportUrl: String = "https://github.com/ptma/mqtt-insight"

val flatlafVersion = "3.2.1"
val flatlafVersion = "3.3"
val javetVersion = "2.2.2"
val fatJar = false

Expand Down Expand Up @@ -83,7 +79,7 @@ dependencies {
implementation("com.intellij:forms_rt:7.0.3") {
exclude(group = "asm", module = "asm-commons")
}
implementation("com.miglayout:miglayout-swing:11.1")
implementation("com.miglayout:miglayout-swing:11.3")

implementation("com.fifesoft:rsyntaxtextarea:3.3.4")
implementation(files("libs/swing-toast-notifications-1.0.1.jar"))
Expand All @@ -100,7 +96,7 @@ dependencies {
implementation("org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5")
implementation("org.eclipse.paho:org.eclipse.paho.mqttv5.client:1.2.5")

if (OperatingSystem.current().isMacOsX()) {
if (OperatingSystem.current().isMacOsX) {
implementation("com.caoccao.javet:javet-macos:${javetVersion}") // Mac OS (x86_64 and arm64)
} else {
implementation("com.caoccao.javet:javet:${javetVersion}") // Linux and Windows (x86_64)
Expand Down
14 changes: 14 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Changelog
--

## 1.1.1 (2024-01-18)

* **优化 🙌**
* Avro 解码增加对 UnionSchema 模式文件的支持
* Protobuf 尝试解码时根据解码命中情况动态调整消息定义的优先级,以减少尝试次数
* 脚本解码器 json、xml 格式化支持
* 记录日志文件
* Flatlaf、MigLayout 包升级
* JsonPath 表达式取值如果是数组的取数组的第一个值
* 优化暗色主题下消息视图文字颜色
* **修复 🐛**
* 修复复制删除消息等操作可能出错的问题
* 修复选项变更保存后重启解析出错的问题

## 1.1.0 (2024-01-09)

* **新增 ✨**
Expand Down
78 changes: 39 additions & 39 deletions src/main/java/com/mqttinsight/MqttInsightApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.fonts.jetbrains_mono.FlatJetBrainsMonoFont;
import com.formdev.flatlaf.util.SystemInfo;
import com.mqttinsight.config.ConfKeys;
import com.mqttinsight.config.Configuration;
import com.mqttinsight.ui.component.TextFieldPopupEventListener;
import com.mqttinsight.ui.frame.MainFrame;
import com.mqttinsight.util.Const;
import com.mqttinsight.util.LangUtil;
import com.mqttinsight.util.ThemeUtil;
import com.mqttinsight.util.Utils;
import org.slf4j.bridge.SLF4JBridgeHandler;

import javax.swing.*;
import java.awt.*;
import java.util.Locale;

/**
* @author ptma
Expand All @@ -24,49 +22,51 @@ public class MqttInsightApplication {
public static MainFrame frame;

public static void main(String[] args) {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
try {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();

if (SystemInfo.isMacOS) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("apple.awt.application.name", Const.APP_NAME);
System.setProperty("apple.awt.application.appearance", "system");
}
if (SystemInfo.isMacOS) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("apple.awt.application.name", Const.APP_NAME);
System.setProperty("apple.awt.application.appearance", "system");
}

if (SystemInfo.isLinux) {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
}
if (SystemInfo.isLinux) {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
}

if (!SystemInfo.isJava_9_orLater && System.getProperty("flatlaf.uiScale") == null) {
System.setProperty("flatlaf.uiScale", "2x");
}
if (!SystemInfo.isJava_9_orLater && System.getProperty("flatlaf.uiScale") == null) {
System.setProperty("flatlaf.uiScale", "2x");
}

SwingUtilities.invokeLater(() -> {
FlatLaf.registerCustomDefaultsSource("com.mqttinsight");
ToolTipManager.sharedInstance().setInitialDelay(300);
ToolTipManager.sharedInstance().setDismissDelay(20000);
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(true);
FlatJetBrainsMonoFont.install();
// FlatInspector.install("ctrl shift alt X");
// FlatUIDefaultsInspector.install("ctrl shift alt Y");
ThemeUtil.setupTheme(args);
String languageTag = Configuration.instance().getString(ConfKeys.LANGUAGE, Locale.getDefault().toLanguageTag());
LangUtil.setLocale(Locale.forLanguageTag(languageTag));
Toolkit toolkit = Toolkit.getDefaultToolkit();
toolkit.addAWTEventListener(new TextFieldPopupEventListener(), AWTEvent.MOUSE_EVENT_MASK);
SwingUtilities.invokeLater(() -> {

frame = new MainFrame();
if (SystemInfo.isMacFullWindowContentSupported) {
frame.getRootPane().putClientProperty("apple.awt.transparentTitleBar", true);
}
FlatLaf.registerCustomDefaultsSource("com.mqttinsight");
ToolTipManager.sharedInstance().setInitialDelay(300);
ToolTipManager.sharedInstance().setDismissDelay(20000);
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(true);
FlatJetBrainsMonoFont.install();
// FlatInspector.install("ctrl shift alt X");
// FlatUIDefaultsInspector.install("ctrl shift alt Y");
ThemeUtil.setupTheme(args);
LangUtil.setupLanguage();
Toolkit toolkit = Toolkit.getDefaultToolkit();
toolkit.addAWTEventListener(new TextFieldPopupEventListener(), AWTEvent.MOUSE_EVENT_MASK);

frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
frame = new MainFrame();
if (SystemInfo.isMacFullWindowContentSupported) {
frame.getRootPane().putClientProperty("apple.awt.transparentTitleBar", true);
}

frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
} catch (Exception e) {
Utils.Message.error(e.getMessage(), e);
}
}


}
6 changes: 5 additions & 1 deletion src/main/java/com/mqttinsight/codec/CodecSupportLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public static void loadCodecs() {
if (codecSupport == null) {
log.error("Cannot find the codec support {}", dynamicCodec.getType());
} else {
CodecSupports.instance().register(codecSupport.newDynamicInstance(dynamicCodec.getName(), dynamicCodec.getSchemaFile()));
if (FileUtil.exist(dynamicCodec.getSchemaFile())) {
CodecSupports.instance().register(codecSupport.newDynamicInstance(dynamicCodec.getName(), dynamicCodec.getSchemaFile()));
} else {
log.warn("The schema file \"{}\" of dynamic codec \"{}\" does not exist.", dynamicCodec.getSchemaFile(), dynamicCodec.getName());
}
}
} catch (Exception ex) {
log.error(ex.getMessage());
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/mqttinsight/codec/ScriptingCodecOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.caoccao.javet.values.reference.V8ValueTypedArray;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;
import java.util.function.Function;
Expand All @@ -11,7 +10,6 @@
* @author ptma
*/
@Getter
@Setter
public class ScriptingCodecOption {

private String format;
Expand All @@ -23,7 +21,8 @@ public class ScriptingCodecOption {
private Function<String, V8ValueTypedArray> encoder;
private Function<String, Void> loadSchema;

private ScriptingCodecOption() {}
private ScriptingCodecOption() {
}

public static ScriptingCodecOption of(Function<byte[], String> decoder,
Function<String, V8ValueTypedArray> encoder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String toString(byte[] payload) {
Hessian2Input h2Input = new Hessian2Input(bis);
return Utils.JSON.toString(h2Input.readObject());
} catch (IOException e) {
log.error(e.getMessage());
log.warn(e.getMessage());
return new String(payload, StandardCharsets.UTF_8);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String toString(byte[] payload) {
HessianInput hInput = new HessianInput(bis);
return Utils.JSON.toString(hInput.readObject());
} catch (IOException e) {
log.error(e.getMessage());
log.warn(e.getMessage());
return new String(payload, StandardCharsets.UTF_8);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public String toString(byte[] payload) {
Object obj = kryo.readClassAndObject(input);
return Utils.JSON.toString(obj);
} catch (Exception e) {
log.error(e.getMessage());
log.warn(e.getMessage());
return new String(payload, StandardCharsets.UTF_8);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public String toString(byte[] payload) {
ObjectNode object = MSGPACK_MAPPER.readValue(payload, ObjectNode.class);
return Utils.JSON.toString(object);
} catch (Exception e) {
log.error(e.getMessage());
log.warn(e.getMessage());
return new String(payload, StandardCharsets.UTF_8);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mqttinsight.codec.impl;

import cn.hutool.core.util.XmlUtil;
import com.caoccao.javet.enums.V8ValueReferenceType;
import com.caoccao.javet.values.reference.V8ValueTypedArray;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand Down Expand Up @@ -46,7 +47,7 @@ public ScriptingCodecSupport newDynamicInstance(String name, String schemaFile)
if (newInstance.options.getLoadSchema() != null) {
newInstance.options.getLoadSchema().apply(schemaFile);
} else if (newInstance.options.isDynamic()) {
throw new CodecException("Cannot load dynamic codec without a schema loader");
throw new CodecException("Cannot initialize a dynamic codec without \"schemaLoader\" function.");
}
newInstance.instantiated = true;
return newInstance;
Expand Down Expand Up @@ -74,8 +75,10 @@ public boolean encodable() {

@Override
public String toPrettyString(String payload) {
if ("text/json".equals(getSyntax())) {
if ("json".equals(options.getFormat())) {
return prettyPrint(payload);
} else if ("xml".equals(options.getFormat())) {
return XmlUtil.format(payload);
} else {
return payload;
}
Expand Down
22 changes: 8 additions & 14 deletions src/main/java/com/mqttinsight/codec/proto/DynamicProtoSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public Map<String, Object> parse(byte[] binary) throws ProtoParseException {
DynamicMessage dynamicMessage = null;
MessageElement messageElement = null;
for (MessageElement type : proto.getMessages()) {
DynamicMessage tempMessage = tryBuildMessage(type.getName(), binary);
if (tempMessage != null) {
dynamicMessage = tempMessage;
messageElement = (MessageElement) type;
try {
dynamicMessage = tryBuildMessage(type.getName(), binary);
messageElement = type;
if (dynamicMessage.getUnknownFields().asMap().isEmpty()) {
messageElement.incrementHitCount();
break;
}
} catch (InvalidProtocolBufferException ignore) {
}
}
if (dynamicMessage == null) {
Expand Down Expand Up @@ -79,16 +79,10 @@ public Map<String, Object> parse(byte[] binary) throws ProtoParseException {
return objectMap;
}

private DynamicMessage tryBuildMessage(String testName, byte[] binary) {
DynamicMessage properBuilder = null;
try {
DynamicMessage.Builder testBuilder = dynamicSchema.newMessageBuilder(testName);
testBuilder.mergeFrom(binary);
properBuilder = testBuilder.build();
} catch (InvalidProtocolBufferException e) {
log.warn(e.getMessage());
}
return properBuilder;
private DynamicMessage tryBuildMessage(String testName, byte[] binary) throws InvalidProtocolBufferException {
DynamicMessage.Builder testBuilder = dynamicSchema.newMessageBuilder(testName);
testBuilder.mergeFrom(binary);
return testBuilder.build();
}

private DynamicSchema getDynamicSchema(Proto proto) throws DescriptorValidationException {
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/mqttinsight/config/ConfKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ public final class ConfKeys {
public static final String MESSAGE_HORIZONTAL_DIVIDER = "messageHorizontalDivider";
public static final String MESSAGE_VERTICAL_DIVIDER = "messageVerticalDivider";

public static final String RECENT_CONNECTIONS = "recentConnections";
public static final String CONNECTIONS = "connections";
public static final String DYNAMIC_CODECS = "dynamicCodecs";

public static final String SCRITP_OPEN_DIALOG_PATH = "scritpOpenDialogPath";
public static final String CERT_OPEN_DIALOG_PATH = "certOpenDialogPath";
public static final String EXPORT_SAVE_DIALOG_PATH = "exportSaveDialogPath";
Expand Down
Loading

0 comments on commit 857f0ef

Please sign in to comment.