Fixes missing about window and sometimes missing systray entry.

cusax-fix
Damian Minkov 13 years ago
parent 9c89ffe458
commit 4c18b35618

@ -27,9 +27,10 @@
*
* @author Nicolas Chamouard
* @author Lubomir Marinov
* @author Damian Minkov
*/
public class OsDependentActivator
implements BundleActivator
extends AbstractServiceDependentActivator
{
/**
* A currently valid bundle context.
@ -54,13 +55,11 @@ public class OsDependentActivator
/**
* Called when this bundle is started.
*
* @param bc The execution context of the bundle being started.
* @throws Exception If
* @param dependentService the ui service.
*/
public void start(BundleContext bc)
throws Exception
public void start(Object dependentService)
{
bundleContext = bc;
uiService = (UIService)dependentService;
try
{
@ -105,6 +104,25 @@ public void start(BundleContext bc)
}
}
/**
* The class of the service which this activator is interested in.
* @return the class name of the ui service.
*/
public Class getDependentServiceClass()
{
return UIService.class;
}
/**
* Setting context to the activator, as soon as we have one.
*
* @param context the context to set.
*/
public void setBundleContext(BundleContext context)
{
bundleContext = context;
}
/**
* Called when this bundle is stopped so the Framework can perform the
* bundle-specific activities necessary to stop the bundle.
@ -170,15 +188,6 @@ public static ShutdownService getShutdownService()
*/
public static UIService getUIService()
{
if(uiService == null)
{
ServiceReference serviceRef = bundleContext
.getServiceReference(UIService.class.getName());
if (serviceRef != null)
uiService = (UIService) bundleContext.getService(serviceRef);
}
return uiService;
}

@ -37,6 +37,7 @@
* @author Yana Stamcheva
* @author Lyubomir Marinov
* @author Symphorien Wanko
* @author Damian Minkov
*/
public class SystrayServiceJdicImpl
implements SystrayService
@ -152,21 +153,7 @@ public SystrayServiceJdicImpl()
this.systray = systray;
if (this.systray != null)
initSystrayInEventDispatchThread();
}
/**
* Starts initializing systray running in event dispatch thread.
*/
private void initSystrayInEventDispatchThread()
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
initSystray();
}
});
initSystray();
}
/**
@ -176,33 +163,6 @@ private void initSystray()
{
UIService uiService = OsDependentActivator.getUIService();
if (uiService == null)
{
/*
* Delay the call to the #initSystray() method until the UIService
* implementation becomes available.
*/
try
{
OsDependentActivator.bundleContext.addServiceListener(
new DelayedInitSystrayServiceListener(),
'('
+ Constants.OBJECTCLASS
+ '='
+ UIService.class.getName()
+ ')');
}
catch (InvalidSyntaxException ise)
{
/*
* Oh, it should not really happen. Besides, it is not clear at
* the time of this writing what is supposed to happen in the
* case of such an exception here.
*/
}
return;
}
menu = TrayMenuFactory.createTrayMenu(this, systray.isSwing());
boolean isMac = OSUtils.IS_MAC;
@ -418,7 +378,14 @@ public void popupMenuCanceled(PopupMenuEvent e)
if ((activePopupHandler == null) && (pmh != null))
setActivePopupMessageHandler(pmh);
systray.addTrayIcon(trayIcon);
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
systray.addTrayIcon(trayIcon);
}
});
initialized = true;
@ -740,35 +707,4 @@ else if (serviceEvent.getType() == ServiceEvent.UNREGISTERING)
}
}
}
/**
* Implements a <tt>ServiceListener</tt> which waits for an
* <tt>UIService</tt> implementation to become available, invokes
* {@link #initSystray()} and unregisters itself.
*/
private class DelayedInitSystrayServiceListener
implements ServiceListener
{
public void serviceChanged(ServiceEvent serviceEvent)
{
if (serviceEvent.getType() == ServiceEvent.REGISTERED)
{
UIService uiService = OsDependentActivator.getUIService();
if (uiService != null)
{
/*
* This ServiceListener has successfully waited for an
* UIService implementation to become available so it no
* longer need to listen.
*/
OsDependentActivator.bundleContext.removeServiceListener(
this);
if (!initialized)
initSystrayInEventDispatchThread();
}
}
}
}
}

@ -21,7 +21,8 @@
* Branding bundle activator.
*/
public class BrandingActivator
implements BundleActivator
extends AbstractServiceDependentActivator
implements BundleListener
{
private final Logger logger = Logger.getLogger(BrandingActivator.class);
@ -37,9 +38,14 @@ public class BrandingActivator
private static ResourceManagementService resourcesService;
/**
* The welcome window.
*/
private WelcomeWindow welcomeWindow;
public void start(BundleContext bc) throws Exception
{
bundleContext = bc;
super.start(bc);
ConfigurationService config = getConfigurationService();
boolean showSplashScreen
@ -59,7 +65,6 @@ public void start(BundleContext bc) throws Exception
* as a final variable used inside a BundleListener which never gets
* removed).
*/
final WelcomeWindow welcomeWindow;
if (showSplashScreen)
{
welcomeWindow = new WelcomeWindow();
@ -73,58 +78,20 @@ public void start(BundleContext bc) throws Exception
"service.gui.APPLICATION_NAME").equals("SIP Communicator"))
new JitsiWarningWindow(null).setVisible(true);
bundleContext.addBundleListener(new BundleListener()
{
/**
* The indicator which determines whether the job of this listener
* is done and no other <tt>BundleEvent</tt>s should be handled.
* <p>
* After
* {@link BrandingActivator#bundleChanged(BundleEvent, WelcomeWindow)}
* reports it's done, it's not enough to remove this listener from
* the notifying <tt>BundleContext</tt> in order to not handle more
* <tt>BundleEvent</tt>s because the notifications get triggered on
* packs of events without consulting the currently registered
* <tt>BundleListener</tt> and, if an event in the pack concludes
* the job of this listener, the subsequent events from the same
* pack will still be handled without the indicator.
* </p>
*/
private boolean done;
public void bundleChanged(BundleEvent evt)
{
if (!done
&& !BrandingActivator
.this.bundleChanged(evt, welcomeWindow))
{
/*
* Don't let bundleContext retain a reference to this
* listener because it'll retain a reference to
* welcomeWindow. Besides, we're no longer interested in
* handling events so it doesn't make sense to even retain
* this listener.
*/
bundleContext.removeBundleListener(this);
done = true;
}
}
});
}
public void stop(BundleContext arg0) throws Exception
{
bundleContext.addBundleListener(this);
}
private boolean bundleChanged(BundleEvent evt, WelcomeWindow welcomeWindow)
/**
* Bundle has been started if welcome window is available and visible
* update it to show the bundle activity.
* @param evt
*/
public synchronized void bundleChanged(BundleEvent evt)
{
if ((welcomeWindow != null)
&& welcomeWindow.isShowing()
&& (evt.getType() == BundleEvent.STARTED))
if (welcomeWindow != null
&& welcomeWindow.isShowing()
&& (evt.getType() == BundleEvent.STARTED))
{
/*
* The IBM JRE on GNU/Linux reports the Bundle-Name as null while
* the SUN JRE reports it as non-null. Just prevent the throwing of
@ -136,36 +103,67 @@ private boolean bundleChanged(BundleEvent evt, WelcomeWindow welcomeWindow)
welcomeWindow.setBundle(
(bundleName == null) ? null : bundleName.toString());
}
}
ServiceReference uiServiceRef =
bundleContext.getServiceReference(UIService.class.getName());
if ((uiServiceRef != null)
&& (Bundle.ACTIVE == uiServiceRef.getBundle().getState()))
{
// UI-Service started.
/**
* Setting context to the activator, as soon as we have one.
*
* @param context the context to set.
*/
public void setBundleContext(BundleContext context)
{
bundleContext = context;
}
// register the about dialog menu entry
registerMenuEntry(uiServiceRef);
/**
* This activator depends on UIService.
* @return the class name of uiService.
*/
public Class getDependentServiceClass()
{
return UIService.class;
}
if (welcomeWindow != null)
welcomeWindow.close();
/**
* The dependent service is available and the bundle will start.
* @param dependentService the UIService this activator is waiting.
*/
public void start(Object dependentService)
{
// UI-Service started.
/*
* We've just closed the WelcomeWindow so there'll be no other
* updates to it and we should stop listening to events which
* trigger them.
*/
return false;
}
/*
* Don't let bundleContext retain a reference to this
* listener because it'll retain a reference to
* welcomeWindow. Besides, we're no longer interested in
* handling events so it doesn't make sense to even retain
* this listener.
*/
bundleContext.removeBundleListener(this);
return true;
// register the about dialog menu entry
registerMenuEntry((UIService)dependentService);
if (welcomeWindow != null)
{
synchronized(this)
{
welcomeWindow.close();
welcomeWindow = null;
}
}
}
private void registerMenuEntry(ServiceReference uiServiceRef)
public void stop(BundleContext arg0) throws Exception
{
UIService uiService
= (UIService) bundleContext.getService(uiServiceRef);
}
/**
* Register the about menu entry.
* @param uiService
*/
private void registerMenuEntry(UIService uiService)
{
if ((uiService == null)
|| !uiService.useMacOSXScreenMenuBar()
|| !registerMenuEntryMacOSX(uiService))

Loading…
Cancel
Save