Search in sources :

Example 11 with DelayedTask

use of com.biglybt.pif.utils.DelayedTask in project BiglyBT by BiglySoftware.

the class Initializer method run.

@Override
public void run() {
    DelayedTask delayed_task = UtilitiesImpl.addDelayedTask("SWT Initialisation", new Runnable() {

        @Override
        public void run() {
            init_task.reserve();
        }
    });
    delayed_task.queueFirst();
    // initialise the SWT locale util
    long startTime = SystemTime.getCurrentTime();
    new LocaleUtilSWT(core);
    final Display display = Utils.getDisplay();
    new UIMagnetHandler(core);
    if (!STARTUP_UIFIRST) {
        // Ensure colors initialized
        Colors.getInstance();
        UIConfigDefaultsSWT.initialize();
        UIConfigDefaultsSWTv3.initialize(core);
    } else {
        COConfigurationManager.setBooleanDefault("Show Splash", false);
    }
    if (COConfigurationManager.getBooleanParameter("Show Splash")) {
        display.asyncExec(new AERunnable() {

            @Override
            public void runSupport() {
                new SplashWindow(display, Initializer.this);
            }
        });
    }
    System.out.println("Locale Initializing took " + (SystemTime.getCurrentTime() - startTime) + "ms");
    startTime = SystemTime.getCurrentTime();
    core.addLifecycleListener(new CoreLifecycleAdapter() {

        @Override
        public void componentCreated(Core core, CoreComponent component) {
            Initializer.this.reportPercent(curPercent + 1);
            if (component instanceof GlobalManager) {
                reportCurrentTaskByKey("splash.initializePlugins");
                InitialisationFunctions.earlyInitialisation(core);
            } else if (component instanceof PluginInterface) {
                PluginInterface pi = (PluginInterface) component;
                String name = pi.getPluginName();
                String version = pi.getPluginVersion();
                // text says initializing, but it's actually initialized.  close enough
                String s = MessageText.getString("splash.plugin.init") + " " + name + (version == null ? "" : (" v" + version));
                reportCurrentTask(s);
            }
        }

        // @see com.biglybt.core.CoreLifecycleAdapter#started(com.biglybt.core.Core)
        @Override
        public void started(Core core) {
            handleCoreStarted(core);
        }

        @Override
        public void stopping(Core core) {
            Alerts.stopInitiated();
        }

        @Override
        public void stopped(Core core) {
        }

        @Override
        public boolean syncInvokeRequired() {
            return (true);
        }

        @Override
        public boolean requiresPluginInitCompleteBeforeStartedEvent() {
            return (false);
        }

        @Override
        public boolean stopRequested(Core _core) throws CoreException {
            return handleStopRestart(false);
        }

        @Override
        public boolean restartRequested(final Core core) {
            return handleStopRestart(true);
        }
    });
    reportCurrentTaskByKey("splash.initializeCore");
    boolean uiClassic = COConfigurationManager.getStringParameter("ui").equals("az2");
    try {
        new SearchUI();
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
    try {
        subscriptionManagerUI = new SubscriptionManagerUI();
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
    if (!uiClassic) {
        try {
            deviceManagerUI = new DeviceManagerUI(core);
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
    }
    if (core.canStart()) {
        // Other UIs could start the core before us
        if (!core.isStarted()) {
            core.start();
        } else {
            handleCoreStarted(core);
        }
        reportPercent(50);
        System.out.println("Core Initializing took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        reportCurrentTaskByKey("splash.initializeUIElements");
        // Ensure colors initialized
        Colors.getInstance();
        reportPercent(curPercent + 1);
        Alerts.init();
        reportPercent(curPercent + 1);
        ProgressWindow.register(core);
        reportPercent(curPercent + 1);
        new SWTNetworkSelection();
        reportPercent(curPercent + 1);
        new AuthenticatorWindow();
        new CryptoWindow();
        reportPercent(curPercent + 1);
        new CertificateTrustWindow();
        core.getPluginManager().getPluginInstaller().addListener(new PluginInstallerListener() {

            @Override
            public boolean installRequest(final String reason, final InstallablePlugin plugin) throws PluginException {
                if (plugin instanceof StandardPlugin) {
                    Map<Integer, Object> properties = new HashMap<>();
                    properties.put(UpdateCheckInstance.PT_UI_EXTRA_MESSAGE, reason);
                    plugin.install(false, false, false, properties);
                    return (true);
                } else {
                    return (false);
                }
            }
        });
    } else {
        CoreWaiterSWT.startupAbandoned();
        final AESemaphore sem = new AESemaphore("waiter");
        Utils.execSWTThread(new Runnable() {

            @Override
            public void run() {
                MessageBoxShell mb = new MessageBoxShell(MessageText.getString("msgbox.force.close.title"), MessageText.getString("msgbox.force.close.text", new String[] { core.getLockFile().getAbsolutePath() }), new String[] { MessageText.getString("Button.ok") }, 0);
                mb.setIconResource("error");
                mb.setModal(true);
                mb.open(new UserPrompterResultListener() {

                    @Override
                    public void prompterClosed(int result) {
                        sem.releaseForever();
                    }
                });
            }
        });
        sem.reserve();
        SESecurityManager.exitVM(1);
    }
}
Also used : DeviceManagerUI(com.biglybt.ui.swt.devices.DeviceManagerUI) PluginInstallerListener(com.biglybt.pif.installer.PluginInstallerListener) AuthenticatorWindow(com.biglybt.ui.swt.auth.AuthenticatorWindow) SearchUI(com.biglybt.ui.swt.search.SearchUI) CertificateTrustWindow(com.biglybt.ui.swt.auth.CertificateTrustWindow) GlobalManager(com.biglybt.core.global.GlobalManager) DelayedTask(com.biglybt.pif.utils.DelayedTask) SubscriptionManagerUI(com.biglybt.ui.swt.subscriptions.SubscriptionManagerUI) PluginInterface(com.biglybt.pif.PluginInterface) PluginException(com.biglybt.pif.PluginException) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) StandardPlugin(com.biglybt.pif.installer.StandardPlugin) InstallablePlugin(com.biglybt.pif.installer.InstallablePlugin) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) CryptoWindow(com.biglybt.ui.swt.auth.CryptoWindow) SWTNetworkSelection(com.biglybt.ui.swt.networks.SWTNetworkSelection) Map(java.util.Map) HashMap(java.util.HashMap) Display(org.eclipse.swt.widgets.Display)

Aggregations

DelayedTask (com.biglybt.pif.utils.DelayedTask)11 PluginInterface (com.biglybt.pif.PluginInterface)4 ParameterListener (com.biglybt.core.config.ParameterListener)3 LoggerChannelListener (com.biglybt.pif.logging.LoggerChannelListener)3 UIManager (com.biglybt.pif.ui.UIManager)3 BasicPluginConfigModel (com.biglybt.pif.ui.model.BasicPluginConfigModel)3 URL (java.net.URL)3 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 PluginException (com.biglybt.pif.PluginException)2 PluginListener (com.biglybt.pif.PluginListener)2 Torrent (com.biglybt.pif.torrent.Torrent)2 BasicPluginViewModel (com.biglybt.pif.ui.model.BasicPluginViewModel)2 DHT (com.biglybt.core.dht.DHT)1 DHTListener (com.biglybt.core.dht.DHTListener)1 DHTSpeedTester (com.biglybt.core.dht.speed.DHTSpeedTester)1 GlobalManager (com.biglybt.core.global.GlobalManager)1 GlobalManagerAdapter (com.biglybt.core.global.GlobalManagerAdapter)1 LogAlert (com.biglybt.core.logging.LogAlert)1 LogEvent (com.biglybt.core.logging.LogEvent)1 NetworkAdmin (com.biglybt.core.networkmanager.admin.NetworkAdmin)1