Esempio n. 1
0
  /**
   * Attempts to find and activate a service which provides a UI that we can use.
   *
   * @param pm The plugin manager to use to load plugins
   * @param cm The config manager to use to retrieve settings
   */
  protected static void loadUI(final PluginManager pm, final ConfigManager cm) {
    final List<Service> uis = pm.getServicesByType("ui");
    final String desired = cm.getOption("general", "ui");

    // First try: go for our desired service type
    for (Service service : uis) {
      if (service.getName().equals(desired) && service.activate()) {
        return;
      }
    }

    // Second try: go for any service type
    for (Service service : uis) {
      if (service.activate()) {
        return;
      }
    }

    if (!GraphicsEnvironment.isHeadless()) {
      // Show a dialog informing the user that no UI was found.
      NoUIDialog.displayBlocking();
      return;
    }

    // Can't find any
    throw new IllegalStateException("No UIs could be loaded");
  }
Esempio n. 2
0
  /**
   * Initialises the client.
   *
   * @param args The command line arguments
   */
  private static void init(final String[] args) {
    Thread.setDefaultUncaughtExceptionHandler(new DMDircExceptionHandler());

    for (Handler handler : java.util.logging.Logger.getLogger("").getHandlers()) {
      handler.setLevel(Level.OFF); // Needs to be changed to enable debugging
    }

    // Enable finer debugging for specific components like so:
    // java.util.logging.Logger.getLogger("com.dmdirc.plugins").setLevel(Level.ALL);

    IdentityManager.loadVersion();

    final CommandLineParser clp = new CommandLineParser(args);

    IdentityManager.load();

    final PluginManager pm = PluginManager.getPluginManager();

    ThemeManager.loadThemes();

    clp.applySettings();

    CommandManager.initCommands();

    for (String service : new String[] {"ui", "tabcompletion"}) {
      ensureExists(pm, service);
    }

    loadUI(pm, IdentityManager.getGlobalConfig());

    doFirstRun();

    ActionManager.init();

    pm.doAutoLoad();

    ActionManager.loadActions();

    getUI().getMainWindow();

    ActionManager.processEvent(CoreActionType.CLIENT_OPENED, null);

    UpdateChecker.init();

    clp.processArguments();

    GlobalWindow.init();

    Runtime.getRuntime()
        .addShutdownHook(
            new Thread(
                new Runnable() {
                  /** {@inheritDoc} */
                  @Override
                  public void run() {
                    ActionManager.processEvent(CoreActionType.CLIENT_CLOSED, null);
                    ServerManager.getServerManager().disconnectAll("Unexpected shutdown");
                    IdentityManager.save();
                  }
                },
                "Shutdown thread"));
  }
Esempio n. 3
0
 /**
  * Ensures that there is at least one provider of the specified service type by extracting
  * matching core plugins. Plugins must be named so that their file name starts with the service
  * type, and then an underscore.
  *
  * @param pm The plugin manager to use to access services
  * @param serviceType The type of service that should exist
  */
 public static void ensureExists(final PluginManager pm, final String serviceType) {
   if (pm.getServicesByType(serviceType).isEmpty()) {
     extractCorePlugins(serviceType + "_");
     pm.getPossiblePluginInfos(true);
   }
 }