Search in sources :

Example 1 with Rendezvous

use of ch.cyberduck.core.bonjour.Rendezvous in project cyberduck by iterate-ch.

the class MainController method applicationDidFinishLaunching.

/**
 * Sent by the default notification center after the application has been launched and initialized but before it has
 * received its first event. aNotification is always an ApplicationDidFinishLaunchingNotification. You can retrieve
 * the NSApplication object in question by sending object to aNotification. The delegate can implement this method
 * to perform further initialization. If the user started up the application by double-clicking a file, the delegate
 * receives the applicationOpenFile message before receiving applicationDidFinishLaunching.
 * (applicationWillFinishLaunching is sent before applicationOpenFile.)
 */
@Override
public void applicationDidFinishLaunching(NSNotification notification) {
    // Opt-in of automatic window tabbing
    NSWindow.setAllowsAutomaticWindowTabbing(true);
    // Load main menu
    this.loadBundle();
    // Open default windows
    if (preferences.getBoolean("browser.open.untitled")) {
        final BrowserController c = newDocument();
        c.window().makeKeyAndOrderFront(null);
    }
    if (preferences.getBoolean("queue.window.open.default")) {
        TransferController c = TransferControllerFactory.get();
        c.window().makeKeyAndOrderFront(null);
    }
    if (preferences.getBoolean("browser.serialize")) {
        this.background(new AbstractBackgroundAction<Void>() {

            @Override
            public Void run() throws BackgroundException {
                sessions.load();
                return null;
            }

            @Override
            public void cleanup() {
                for (Host host : sessions) {
                    if (log.isInfoEnabled()) {
                        log.info(String.format("New browser for saved session %s", host));
                    }
                    final BrowserController browser = newDocument(true, host.getUuid());
                    browser.mount(host);
                }
                sessions.clear();
            }
        });
    }
    final AbstractHostCollection bookmarks = BookmarkCollection.defaultCollection();
    // Load all bookmarks in background
    this.background(new AbstractBackgroundAction<Void>() {

        @Override
        public Void run() throws BackgroundException {
            bookmarks.load();
            bookmarksSemaphore.countDown();
            return null;
        }

        @Override
        public void cleanup() {
            if (preferences.getBoolean("browser.open.untitled")) {
                if (preferences.getProperty("browser.open.bookmark.default") != null) {
                    openDefaultBookmark(newDocument());
                }
            }
            // Set delegate for NSService
            NSApplication.sharedApplication().setServicesProvider(MainController.this.id());
        }
    });
    this.background(new AbstractBackgroundAction<Void>() {

        @Override
        public Void run() throws BackgroundException {
            final HistoryCollection history = HistoryCollection.defaultCollection();
            history.load();
            return null;
        }
    });
    this.background(new AbstractBackgroundAction<Void>() {

        @Override
        public Void run() throws BackgroundException {
            final TransferCollection transfers = TransferCollection.defaultCollection();
            transfers.load();
            return null;
        }
    });
    final Rendezvous bonjour = RendezvousFactory.instance();
    bonjour.addListener(new NotificationRendezvousListener(bonjour));
    if (preferences.getBoolean("defaulthandler.reminder") && preferences.getInteger("uses") > 0) {
        if (!SchemeHandlerFactory.get().isDefaultHandler(Arrays.asList(Scheme.ftp.name(), Scheme.ftps.name(), Scheme.sftp.name()), new Application(preferences.getProperty("application.identifier")))) {
            final NSAlert alert = NSAlert.alert(LocaleFactory.localizedString("Set Cyberduck as default application for FTP and SFTP locations?", "Configuration"), LocaleFactory.localizedString("As the default application, Cyberduck will open when you click on FTP or SFTP links " + "in other applications, such as your web browser. You can change this setting in the Preferences later.", "Configuration"), // default
            LocaleFactory.localizedString("Change", "Configuration"), // other
            null, LocaleFactory.localizedString("Cancel", "Configuration"));
            alert.setAlertStyle(NSAlert.NSInformationalAlertStyle);
            alert.setShowsSuppressionButton(true);
            alert.suppressionButton().setTitle(LocaleFactory.localizedString("Don't ask again", "Configuration"));
            int choice = new AlertSheetReturnCodeMapper().getOption(alert.runModal());
            if (alert.suppressionButton().state() == NSCell.NSOnState) {
                // Never show again.
                preferences.setProperty("defaulthandler.reminder", false);
            }
            if (choice == SheetCallback.DEFAULT_OPTION) {
                SchemeHandlerFactory.get().setDefaultHandler(new Application(preferences.getProperty("application.identifier")), Arrays.asList(Scheme.ftp.name(), Scheme.ftps.name(), Scheme.sftp.name()));
            }
        }
    }
    // NSWorkspace notifications are posted to a notification center provided by
    // the NSWorkspace object, instead of going through the application’s default
    // notification center as most notifications do. To receive NSWorkspace notifications,
    // your application must register an observer with the NSWorkspace notification center.
    workspace.notificationCenter().addObserver(this.id(), Foundation.selector("workspaceWillPowerOff:"), NSWorkspace.WorkspaceWillPowerOffNotification, null);
    workspace.notificationCenter().addObserver(this.id(), Foundation.selector("workspaceWillLogout:"), NSWorkspace.WorkspaceSessionDidResignActiveNotification, null);
    workspace.notificationCenter().addObserver(this.id(), Foundation.selector("workspaceWillSleep:"), NSWorkspace.WorkspaceWillSleepNotification, null);
    NSNotificationCenter.defaultCenter().addObserver(this.id(), Foundation.selector("applicationWillRestartAfterUpdate:"), "SUUpdaterWillRestartNotificationName", null);
    this.background(new AbstractBackgroundAction<Void>() {

        @Override
        public Void run() {
            bonjour.init();
            return null;
        }
    });
    // Import thirdparty bookmarks.
    this.background(new ImporterBackgroundAction(bookmarks, bookmarksSemaphore));
    final CrashReporter reporter = CrashReporter.create();
    if (log.isInfoEnabled()) {
        log.info("Check for crash report");
    }
    reporter.checkForCrash(preferences.getProperty("website.crash"));
    if (updater.hasUpdatePrivileges()) {
        if (preferences.getBoolean("update.check")) {
            final long next = preferences.getLong("update.check.timestamp") + preferences.getLong("update.check.interval") * 1000;
            if (next < System.currentTimeMillis()) {
                updater.check(true);
            }
            updater.register();
        }
    }
    if (preferences.getBoolean("profiles.discovery.updater.enable")) {
        // Synchronize and register timer
        profiles.register();
    }
    // Register OAuth handler
    final String handler = preferences.getProperty("oauth.handler.scheme");
    if (log.isInfoEnabled()) {
        log.info(String.format("Register OAuth handler %s", handler));
    }
    SchemeHandlerFactory.get().setDefaultHandler(new Application(preferences.getProperty("application.identifier")), Collections.singletonList(handler));
    NSAppleEventManager.sharedAppleEventManager().setEventHandler_andSelector_forEventClass_andEventID(this.id(), Foundation.selector("handleGetURLEvent:withReplyEvent:"), kInternetEventClass, kAEGetURL);
}
Also used : Rendezvous(ch.cyberduck.core.bonjour.Rendezvous) NotificationRendezvousListener(ch.cyberduck.core.bonjour.NotificationRendezvousListener) NSAttributedString(ch.cyberduck.binding.foundation.NSAttributedString) NSAlert(ch.cyberduck.binding.application.NSAlert) Application(ch.cyberduck.core.local.Application) NSApplication(ch.cyberduck.binding.application.NSApplication) AlertSheetReturnCodeMapper(ch.cyberduck.binding.application.AlertSheetReturnCodeMapper) BackgroundException(ch.cyberduck.core.exception.BackgroundException)

Aggregations

AlertSheetReturnCodeMapper (ch.cyberduck.binding.application.AlertSheetReturnCodeMapper)1 NSAlert (ch.cyberduck.binding.application.NSAlert)1 NSApplication (ch.cyberduck.binding.application.NSApplication)1 NSAttributedString (ch.cyberduck.binding.foundation.NSAttributedString)1 NotificationRendezvousListener (ch.cyberduck.core.bonjour.NotificationRendezvousListener)1 Rendezvous (ch.cyberduck.core.bonjour.Rendezvous)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 Application (ch.cyberduck.core.local.Application)1