|
|
@ -1,6 +1,10 @@ |
|
|
|
package com.fr.design.startup; |
|
|
|
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 |
|
|
|
* @author Starryi |
|
|
@ -18,18 +22,30 @@ public class Install4jStartupNotificationProvider implements FineStartupNotifica |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void registerStartupListener(Listener listener) { |
|
|
|
public void registerStartupListener(Listener listener) { |
|
|
|
boolean supported = false; |
|
|
|
Class<?> StartupNotificationListenerClass = Reflect.on("com.install4j.api.launcher.StartupNotification$Listener").type(); |
|
|
|
try { |
|
|
|
if (StartupNotificationListenerClass == null) { |
|
|
|
supported = Class.forName("com.install4j.api.launcher.StartupNotification") != null; |
|
|
|
return; |
|
|
|
} catch (Throwable ignored) {} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (supported) { |
|
|
|
|
|
|
|
StartupNotification.registerStartupListener(new StartupNotification.Listener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void startupPerformed(String parameters) { |
|
|
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { |
|
|
|
|
|
|
|
if (args[0] instanceof String) { |
|
|
|
|
|
|
|
String parameters = (String) args[0]; |
|
|
|
listener.startupPerformed(parameters); |
|
|
|
listener.startupPerformed(parameters); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|