Making desktop-like apps with IDesktopApp and AppUI
From BUG Wiki
Contents |
Overview
| By default, BUG apps lack any centralized GUI for application launching or control. This is because OSGi applications exist primarily within an always-running OSGi framework instance. Due to this apps are always, in effect, launched. This is unlike traditional desktop applications where the user controls, via an application launcher of some sort, the lifecycle of the application.
A new service introduced in R1.4.1 (currently unreleased) called IDesktopApp aims to provide a path for BUGapps (OSGi bundles) to present themselves as traditional icons and to receive events that can allow them to behave (to the user) like traditional applications. An application that utilizes this interface on the server side is AppUI. It is a BUGapp that presents a standard icon view for applications. A BUGapp on BUGNet, BUG_Desktop_App, fully exersizes the IDesktopApp interface and can be referred to as a good example implementation. AppUI interface is inspired by the Concierge GUI written by Jan Rellermeyer. The AppUI implementation was aided by Switch's port of Concierge GUI to BUG. |
com.buglabs.application.IDesktopApp
Essentially clients need to implement and register this interface:
public interface IDesktopApp {
public void click();
public URL getIcon(int width, int height, int depth);
public String[] getMenuItems();
public void menuSelected(String item);
}
In BUG_Desktop_app the two critical lines are the interface implementation:
public class Activator implements BundleActivator, IDesktopApp {
And the service registration code:
public void start(BundleContext context) throws Exception {
this.context = context;
reg = context.registerService(IDesktopApp.class.getName(), this, null);
selectionLabel = new Label("<No menu item selected>");
}
In addition, only OSGi bundles with a specific manifest header are rendered. This is Bug-Bundle-Type: Application. Note by default the SDK generates this line in your manifest so this should just work. In the example app you'll see this in the manifest:
Manifest-Version: 1.0 Bundle-Name: BUG_Desktop_app Bundle-Activator: bugapp.Activator Bundle-SymbolicName: BUG_Desktop_app Bundle-Version: 1.0.0 Bundle-Vendor: kgilmer Bug-Bundle-Type: Application Import-Package: com.buglabs.application
IDesktopApp.click()
This method, which the client application will implement in code, gets called when the user clicks on the application. Typically, when this happens the client application should create or show the primary user interface.
IDesktopApp.getIcon()
This optional method will allow the client application to specific it's own icon. The physical parameters for the image URL are passed it. Currently, AppUI only renders 32x32 sized icons, and the depth is ignored. Future versions of AppUI (or other applications) could specify different sizes for icons. Currently the image format that the URL should point to should be PNG.
IDesktopApp.getMenuItems()
This optional method will allow a client application to present a configurable menu to the user. The menu selections are essentially a flat list. While it's up to the client application to determine if and how menus are used, sticking with the common GUI metaphor only stateless actions should be exposed.
IDesktopApp.menuSelected()
This methow will be called when a user selects a menu item as presented in getMenuItems(). The client application should not block this method, and should utilize a concurrency pattern if expensive operations need to be performed.
AppUI
AppUI is a BUG application that is the "server" to IDesktopApp. Currently it is not installed by default on BUG and will have to be installed from BUGnet. Other implementations could exist that present other "views" of the OSGi bundle state and IDesktopApp control mechanism. AppUI is simply one implementation.
Icon Types
There are these basic types of icons rendered in AppUI:
- Default App Bundles - These apps do not implement IDesktopApp and therefor cannot be "clicked".
- IDesktopApp App Bundles - These apps can be clicked and user menus may be available.
- Stopped App Bundle
- Custom App Icons
Default Actions
In the context menu for an application the following options are always available, although at times some will be disabled:
- start
- stop
- uninstall
These items relate specifically to the OSGi bundle state, and are analagous to start|stop|uninstall commands in the Concierge shell.
Triggering the Menu
The app menu is triggered by "pressing" a given icon for a specific time threashold. Currently that threshold is 800 milliseconds. If the icon is "released" before this time, a "click" is performed. If longer, then click is not performed and the app menu is displayed.

