@ -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 ) { }
}
if ( supported ) {
ListenerHandler mHandler = new ListenerHandler ( listener ) ;
StartupNotification . registerStartupListener ( new StartupNotification . Listener ( ) {
Object listenerCallbackInstance = Proxy . newProxyInstance ( this . getClass ( ) . getClassLoader ( ) , new Class [ ] { StartupNotificationListenerClass } , mHandler ) ;
@Override
Reflect . on ( "com.install4j.api.launcher.StartupNotification" ) . call ( "registerStartupListener" , listenerCallbackInstance ) ;
public void startupPerformed ( String parameters ) {
}
listener . startupPerformed ( parameters ) ;
}
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 ;
}
}
}
}
}
}