|
|
|
@ -1,6 +1,10 @@
|
|
|
|
|
package com.fr.design.startup; |
|
|
|
|
|
|
|
|
|
import com.install4j.api.launcher.StartupNotification; |
|
|
|
|
import com.fr.invoke.Reflect; |
|
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationHandler; |
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
import java.lang.reflect.Proxy; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author Starryi |
|
|
|
@ -18,18 +22,30 @@ public class Install4jStartupNotificationProvider implements FineStartupNotifica
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void registerStartupListener(Listener listener) { |
|
|
|
|
boolean supported = false; |
|
|
|
|
try { |
|
|
|
|
supported = Class.forName("com.install4j.api.launcher.StartupNotification") != null; |
|
|
|
|
} catch (Throwable ignored) {} |
|
|
|
|
|
|
|
|
|
if (supported) { |
|
|
|
|
StartupNotification.registerStartupListener(new StartupNotification.Listener() { |
|
|
|
|
@Override |
|
|
|
|
public void startupPerformed(String parameters) { |
|
|
|
|
listener.startupPerformed(parameters); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
Class<?> StartupNotificationListenerClass = Reflect.on("com.install4j.api.launcher.StartupNotification$Listener").type(); |
|
|
|
|
if (StartupNotificationListenerClass == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ListenerHandler mHandler = new ListenerHandler(listener); |
|
|
|
|
Object listenerCallbackInstance = Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { StartupNotificationListenerClass }, mHandler); |
|
|
|
|
Reflect.on("com.install4j.api.launcher.StartupNotification").call("registerStartupListener", listenerCallbackInstance); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static class ListenerHandler implements InvocationHandler { |
|
|
|
|
private final Listener listener; |
|
|
|
|
|
|
|
|
|
public ListenerHandler(Listener listener) { |
|
|
|
|
this.listener = listener; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { |
|
|
|
|
if (args[0] instanceof String) { |
|
|
|
|
String parameters = (String) args[0]; |
|
|
|
|
listener.startupPerformed(parameters); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|