Add session to cache with both hostname and address.
[cyberduck.git] / source / ch / cyberduck / core / preferences / ServiceManagementApplicationLoginRegistry.java
blobb071fcb908f5c2c345ca91fe163d3cb112cf8270
1 package ch.cyberduck.core.preferences;
3 /*
4 * Copyright (c) 2002-2015 David Kocher. All rights reserved.
5 * http://cyberduck.ch/
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to feedback@cyberduck.ch
20 import ch.cyberduck.binding.foundation.ServiceManagementLibrary;
21 import ch.cyberduck.core.Local;
22 import ch.cyberduck.core.LocalFactory;
23 import ch.cyberduck.core.local.Application;
24 import ch.cyberduck.core.local.LaunchServicesApplicationFinder;
26 import org.apache.log4j.Logger;
28 /**
29 * @version $Id$
31 public class ServiceManagementApplicationLoginRegistry implements ApplicationLoginRegistry {
32 private static Logger log = Logger.getLogger(ServiceManagementApplicationLoginRegistry.class);
34 private LaunchServicesApplicationFinder finder
35 = new LaunchServicesApplicationFinder();
37 /**
38 * This function works only with executables stored in the
39 * <code>Contents/Library/LoginItems</code> directory of the bundle.
41 @Override
42 public boolean register(final Application application) {
43 final Local helper = LocalFactory.get(new BundleApplicationResourcesFinder().find().getParent(),
44 String.format("Library/LoginItems/%s.app", application.getName()));
45 if(!finder.register(helper)) {
46 log.warn(String.format("Failed to register %s (%s) with launch services", helper,
47 finder.getDescription(application.getIdentifier())));
49 if(!ServiceManagementLibrary.SMLoginItemSetEnabled(application.getIdentifier(), true)) {
50 log.warn(String.format("Failed to register %s as login item", application));
51 return false;
53 return true;
56 @Override
57 public boolean unregister(final Application application) {
58 if(!ServiceManagementLibrary.SMLoginItemSetEnabled(application.getIdentifier(), false)) {
59 log.warn(String.format("Failed to remove %s as login item", application));
60 return false;
62 return true;