use of ch.cyberduck.binding.ProxyController in project cyberduck by iterate-ch.
the class ProxyControllerTest method testInvokeWait.
@Test
public void testInvokeWait() throws Exception {
final CountDownLatch entry = new CountDownLatch(1);
final AtomicBoolean c = new AtomicBoolean();
final ProxyController controller = new ProxyController() {
@Override
public void invoke(final MainAction runnable, final boolean wait) {
assertTrue(wait);
super.invoke(runnable, wait);
entry.countDown();
}
};
new Thread(() -> controller.invoke(new DefaultMainAction() {
@Override
public void run() {
c.set(true);
}
}, true)).start();
entry.await(1, TimeUnit.SECONDS);
assertTrue(c.get());
}
use of ch.cyberduck.binding.ProxyController in project cyberduck by iterate-ch.
the class MainController method application_openFile.
@Override
public boolean application_openFile(final NSApplication app, final String filename) {
if (log.isDebugEnabled()) {
log.debug(String.format("Open file %s", filename));
}
final Local f = LocalFactory.get(filename);
if (f.exists()) {
if ("duck".equals(f.getExtension())) {
final Host bookmark;
try {
newDocument().mount(HostReaderFactory.get().read(f));
return true;
} catch (AccessDeniedException e) {
log.error(String.format("Failure reading bookmark from %s. %s", f, e.getMessage()));
return false;
}
} else if ("cyberducklicense".equals(f.getExtension())) {
final License l = LicenseFactory.get(f);
if (l.verify(new DisabledLicenseVerifierCallback())) {
try {
f.copy(LocalFactory.get(SupportDirectoryFinderFactory.get().find(), f.getName()));
final NSAlert alert = NSAlert.alert(l.toString(), LocaleFactory.localizedString("Thanks for your support! Your contribution helps to further advance development to make Cyberduck even better.", "License") + "\n\n" + LocaleFactory.localizedString("Your donation key has been copied to the Application Support folder.", "License"), // default
LocaleFactory.localizedString("Continue", "License"), // other
null, null);
alert.setAlertStyle(NSAlert.NSInformationalAlertStyle);
if (new AlertSheetReturnCodeMapper().getOption(alert.runModal()) == SheetCallback.DEFAULT_OPTION) {
for (BrowserController c : MainController.getBrowsers()) {
c.removeDonateWindowTitle();
}
this.updateLicenseMenu();
}
} catch (AccessDeniedException e) {
log.error(e.getMessage());
return false;
}
} else {
final NSAlert alert = NSAlert.alert(LocaleFactory.localizedString("Not a valid registration key", "License"), LocaleFactory.localizedString("This donation key does not appear to be valid.", "License"), // default
LocaleFactory.localizedString("Continue", "License"), // other
null, null);
alert.setAlertStyle(NSAlert.NSWarningAlertStyle);
alert.setShowsHelp(true);
alert.setDelegate(new ProxyController() {
@Action
public boolean alertShowHelp(NSAlert alert) {
BrowserLauncherFactory.get().open(ProviderHelpServiceFactory.get().help());
return true;
}
}.id());
alert.runModal();
}
return true;
} else if ("cyberduckprofile".equals(f.getExtension())) {
try {
final Profile profile = ProfileReaderFactory.get().read(f);
if (profile.isEnabled()) {
if (log.isDebugEnabled()) {
log.debug(String.format("Register profile %s", profile));
}
final ProtocolFactory protocols = ProtocolFactory.get();
protocols.register(profile);
final Host host = new Host(profile, profile.getDefaultHostname(), profile.getDefaultPort());
newDocument().addBookmark(host);
// Register in application support
final Local profiles = LocalFactory.get(SupportDirectoryFinderFactory.get().find(), preferences.getProperty("profiles.folder.name"));
if (!profiles.exists()) {
new DefaultLocalDirectoryFeature().mkdir(profiles);
}
f.copy(LocalFactory.get(profiles, f.getName()));
}
} catch (AccessDeniedException e) {
log.error(String.format("Failure reading profile from %s. %s", f, e));
return false;
}
} else {
// Upload file
this.background(new AbstractBackgroundAction<Void>() {
@Override
public Void run() {
// Wait until bookmarks are loaded
Uninterruptibles.awaitUninterruptibly(bookmarksSemaphore);
return null;
}
@Override
public void cleanup() {
upload(f);
}
@Override
public String getActivity() {
return "Open File";
}
});
return true;
}
}
return false;
}
use of ch.cyberduck.binding.ProxyController in project cyberduck by iterate-ch.
the class ProxyControllerTest method testInvokeNoWait.
@Test
public void testInvokeNoWait() throws Exception {
final CountDownLatch entry = new CountDownLatch(1);
final CountDownLatch invoked = new CountDownLatch(1);
final AtomicBoolean c = new AtomicBoolean();
final ProxyController controller = new ProxyController() {
@Override
public void invoke(final MainAction runnable, final boolean wait) {
assertFalse(wait);
super.invoke(runnable, wait);
assertFalse(c.get());
entry.countDown();
}
};
new Thread(() -> controller.invoke(new DefaultMainAction() {
@Override
public void run() {
c.set(true);
invoked.countDown();
}
}, false)).start();
entry.await(1, TimeUnit.SECONDS);
invoked.await(1, TimeUnit.SECONDS);
assertTrue(c.get());
}
use of ch.cyberduck.binding.ProxyController in project cyberduck by iterate-ch.
the class ProxyControllerTest method testBackground.
@Test
public void testBackground() throws Exception {
final AbstractController controller = new ProxyController();
final CountDownLatch entry = new CountDownLatch(1);
final CountDownLatch exit = new CountDownLatch(1);
final AbstractBackgroundAction<Object> action = new AbstractBackgroundAction<Object>() {
@Override
public void init() {
assertEquals("main", Thread.currentThread().getName());
}
@Override
public Object run() {
assertEquals("background-1", Thread.currentThread().getName());
return null;
}
@Override
public void cleanup() {
assertEquals("main", Thread.currentThread().getName());
assertFalse(controller.getRegistry().contains(this));
}
};
controller.background(action).get();
}
use of ch.cyberduck.binding.ProxyController in project cyberduck by iterate-ch.
the class SparklePeriodicUpdateCheckerTest method testCheck.
@Test
public void testCheck() {
final SparklePeriodicUpdateChecker updater = new SparklePeriodicUpdateChecker(new ProxyController());
updater.check(false);
}
Aggregations