use of ch.cyberduck.core.local.Application in project cyberduck by iterate-ch.
the class LaunchServicesSchemeHandler method getAllHandlers.
@Override
public List<Application> getAllHandlers(final String scheme) {
final List<Application> handlers = new ArrayList<Application>();
final NSArray applications = LaunchServicesLibrary.library.LSCopyApplicationURLsForURL(NSURL.URLWithString(String.format("%s:/", scheme)), LaunchServicesLibrary.kLSRolesAll);
NSEnumerator ordered = applications.objectEnumerator();
NSObject next;
while (((next = ordered.nextObject()) != null)) {
final NSURL url = Rococoa.cast(next, NSURL.class);
final NSBundle bundle = NSBundle.bundleWithPath(url.path());
if (null == bundle) {
log.warn(String.format("Failure loading bundle for path %s", url.path()));
continue;
}
final Application application = applicationFinder.getDescription(bundle.bundleIdentifier());
if (applicationFinder.isInstalled(application)) {
handlers.add(application);
}
}
return handlers;
}
use of ch.cyberduck.core.local.Application in project cyberduck by iterate-ch.
the class LaunchServicesSchemeHandler method getDefaultHandler.
/**
* See ApplicationServices/ApplicationServices.h#LSCopyDefaultHandlerForURLScheme
*
* @param scheme The protocol identifier
* @return The bundle identifier for the application registered as the default handler for this scheme
*/
@Override
public Application getDefaultHandler(final String scheme) {
final ObjCObjectByReference error = new ObjCObjectByReference();
final NSURL url = LaunchServicesLibrary.library.LSCopyDefaultApplicationURLForURL(NSURL.URLWithString(String.format("%s:/", scheme)), LaunchServicesLibrary.kLSRolesAll, error);
if (url != null) {
final NSBundle bundle = NSBundle.bundleWithPath(url.path());
if (null == bundle) {
log.warn(String.format("Failure loading bundle for path %s", url.path()));
return Application.notfound;
}
final Application application = applicationFinder.getDescription(bundle.bundleIdentifier());
if (applicationFinder.isInstalled(application)) {
return application;
}
}
return Application.notfound;
}
use of ch.cyberduck.core.local.Application in project cyberduck by iterate-ch.
the class EditorFactory method getEditors.
/**
* @param filename File type
* @return Installed applications suitable to edit the given file type. Does always include the default editor set
* in the Preferences
*/
public static List<Application> getEditors(final String filename) {
if (log.isDebugEnabled()) {
log.debug(String.format("Find installed editors for file %s", filename));
}
final List<Application> editors = new ArrayList<>(finder.findAll(filename));
// Add the application set as the default editor in the Preferences to be always
// included in the list of available editors.
final Application defaultEditor = getDefaultEditor();
if (finder.isInstalled(defaultEditor)) {
if (!editors.contains(defaultEditor)) {
editors.add(defaultEditor);
}
}
return editors;
}
use of ch.cyberduck.core.local.Application in project cyberduck by iterate-ch.
the class DefaultWatchEditorTest method testNotfound.
@Test(expected = NoSuchFileException.class)
public void testNotfound() throws Exception {
final DefaultWatchEditor editor = new DefaultWatchEditor(new Host(new TestProtocol()), new Path("/remote", EnumSet.of(Path.Type.file)), new DisabledListProgressListener());
editor.watch(new Application("com.app"), new Local(System.getProperty("java.io.tmpdir") + "/notfound", UUID.randomUUID().toString()), new DisabledFileWatcherListener(), new DisabledApplicationQuitCallback());
}
use of ch.cyberduck.core.local.Application 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);
}
Aggregations