|
|
|
@ -10,6 +10,7 @@ import com.fr.design.mainframe.DesignerContext;
|
|
|
|
|
import com.fr.design.ui.util.UIUtil; |
|
|
|
|
import com.fr.env.detect.base.DetectorBridge; |
|
|
|
|
import com.fr.env.detect.base.DetectorUtil; |
|
|
|
|
import com.fr.env.detect.base.EnvDetectorConfig; |
|
|
|
|
import com.fr.env.detect.bean.DetectorResult; |
|
|
|
|
import com.fr.env.detect.bean.DetectorStatus; |
|
|
|
|
import com.fr.event.Event; |
|
|
|
@ -36,6 +37,43 @@ import java.util.stream.Stream;
|
|
|
|
|
**/ |
|
|
|
|
public class EnvDetectorCenter { |
|
|
|
|
|
|
|
|
|
private final Listener<Null> AFTER_START_LISTENER = new Listener<Null>() { |
|
|
|
|
@Override |
|
|
|
|
public void on(Event event, Null param) { |
|
|
|
|
if (isSameProcess(DetectorProcess.SERVER_LAUNCH)) { |
|
|
|
|
stop(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
private final Listener<Null> BEFORE_START_LISTENER = new Listener<Null>() { |
|
|
|
|
@Override |
|
|
|
|
public void on(Event event, Null param) { |
|
|
|
|
PROCESS.set(DetectorProcess.SERVER_LAUNCH); |
|
|
|
|
start(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Listener<Null> START_UP_COMPLETE_LISTENER = new Listener<Null>() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void on(Event event, Null param) { |
|
|
|
|
if (isSameProcess(DetectorProcess.DESIGN_LAUNCH)) { |
|
|
|
|
stop(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
private final Listener<Workspace> AFTER_SWITCH_LISTENER = new Listener<Workspace>() { |
|
|
|
|
@Override |
|
|
|
|
public void on(Event event, Workspace param) { |
|
|
|
|
if (isSameProcess(DetectorProcess.DESIGN_LAUNCH)) { |
|
|
|
|
stop(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
private final AtomicReference<DetectorProcess> PROCESS = new AtomicReference<>(); |
|
|
|
|
|
|
|
|
|
public static EnvDetectorCenter getInstance() { |
|
|
|
|
return EnvDetectorCenterHolder.INSTANCE; |
|
|
|
|
} |
|
|
|
@ -44,54 +82,36 @@ public class EnvDetectorCenter {
|
|
|
|
|
private static final EnvDetectorCenter INSTANCE = new EnvDetectorCenter(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private final AtomicReference<DetectorProcess> PROCESS = new AtomicReference<>(); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 初始化 |
|
|
|
|
*/ |
|
|
|
|
public void init() { |
|
|
|
|
|
|
|
|
|
// 如果已经启动了,则不再启动
|
|
|
|
|
if (PROCESS.get() != null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
start(); |
|
|
|
|
// 默认是启动
|
|
|
|
|
PROCESS.set(DetectorProcess.DESIGN_LAUNCH); |
|
|
|
|
start(); |
|
|
|
|
|
|
|
|
|
// 添加启动完成监听
|
|
|
|
|
EventDispatcher.listen(DesignerLaunchStatus.STARTUP_COMPLETE, new Listener<Null>() { |
|
|
|
|
@Override |
|
|
|
|
public void on(Event event, Null param) { |
|
|
|
|
if (isSameProcess(DetectorProcess.DESIGN_LAUNCH)) { |
|
|
|
|
stop(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// 切换完成后的监听
|
|
|
|
|
EventDispatcher.listen(WorkspaceEvent.AfterSwitch, new Listener<Workspace>() { |
|
|
|
|
@Override |
|
|
|
|
public void on(Event event, Workspace param) { |
|
|
|
|
if (isSameProcess(DetectorProcess.DESIGN_LAUNCH)) { |
|
|
|
|
stop(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// 打开内置服务器
|
|
|
|
|
EventDispatcher.listen(EmbedServerEvent.BeforeStart, new Listener<Null>() { |
|
|
|
|
@Override |
|
|
|
|
public void on(Event event, Null param) { |
|
|
|
|
PROCESS.set(DetectorProcess.SERVER_LAUNCH); |
|
|
|
|
start(); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
EventDispatcher.listen(EmbedServerEvent.AfterStart, new Listener<Null>() { |
|
|
|
|
@Override |
|
|
|
|
public void on(Event event, Null param) { |
|
|
|
|
if (isSameProcess(DetectorProcess.SERVER_LAUNCH)) { |
|
|
|
|
stop(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
listen(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 销毁,一般用在模块关闭中 |
|
|
|
|
*/ |
|
|
|
|
public void destroy() { |
|
|
|
|
|
|
|
|
|
stopListen(); |
|
|
|
|
// 重置内容
|
|
|
|
|
DetectorBridge.getInstance().reset(); |
|
|
|
|
// 关闭逻辑
|
|
|
|
|
DetectorBridge.getInstance().stop(); |
|
|
|
|
|
|
|
|
|
PROCESS.set(null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -121,13 +141,17 @@ public class EnvDetectorCenter {
|
|
|
|
|
*/ |
|
|
|
|
public void stop() { |
|
|
|
|
|
|
|
|
|
// 一分钟后执行
|
|
|
|
|
// 结束
|
|
|
|
|
DetectorBridge.getInstance().stop(); |
|
|
|
|
|
|
|
|
|
// 30s后执行
|
|
|
|
|
DelayHelper.delayCall(EnvDetectorCenter.class.getName(), () -> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果当前没开启,则直接返回
|
|
|
|
|
if (!EnvDetectorConfig.getInstance().isEnabled()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Stream<DetectorResult> resultStream = DetectorBridge.getInstance().detect(); |
|
|
|
|
|
|
|
|
|
// 结束
|
|
|
|
|
DetectorBridge.getInstance().stop(); |
|
|
|
|
|
|
|
|
|
// 展示效果
|
|
|
|
|
NotificationDialogProperties properties = new NotificationDialogProperties(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Detect_Notification_Title")); |
|
|
|
@ -162,6 +186,28 @@ public class EnvDetectorCenter {
|
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void listen() { |
|
|
|
|
|
|
|
|
|
// 添加启动完成监听
|
|
|
|
|
EventDispatcher.listen(DesignerLaunchStatus.STARTUP_COMPLETE, START_UP_COMPLETE_LISTENER); |
|
|
|
|
|
|
|
|
|
// 切换完成后的监听
|
|
|
|
|
EventDispatcher.listen(WorkspaceEvent.AfterSwitch, AFTER_SWITCH_LISTENER); |
|
|
|
|
|
|
|
|
|
// 内置服务器监听
|
|
|
|
|
EventDispatcher.listen(EmbedServerEvent.BeforeStart, BEFORE_START_LISTENER); |
|
|
|
|
EventDispatcher.listen(EmbedServerEvent.AfterStart, AFTER_START_LISTENER); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void stopListen() { |
|
|
|
|
|
|
|
|
|
EventDispatcher.stopListen(START_UP_COMPLETE_LISTENER); |
|
|
|
|
EventDispatcher.stopListen(AFTER_SWITCH_LISTENER); |
|
|
|
|
EventDispatcher.stopListen(BEFORE_START_LISTENER); |
|
|
|
|
EventDispatcher.stopListen(AFTER_START_LISTENER); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private enum DetectorProcess { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|