Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register all custom schemes in connection profiles. Fix #15901. #15904

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.function.Predicate;

import com.google.common.util.concurrent.Uninterruptibles;

Expand Down Expand Up @@ -976,9 +977,8 @@ public Void run() throws BackgroundException {
});
final Rendezvous bonjour = RendezvousFactory.instance();
bonjour.addListener(new NotificationRendezvousListener(bonjour));
if(preferences.getBoolean("defaulthandler.reminder")
&& preferences.getInteger("uses") > 0) {
final SchemeHandler schemeHandler = SchemeHandlerFactory.get();
final SchemeHandler schemeHandler = SchemeHandlerFactory.get();
if(preferences.getBoolean("defaulthandler.reminder") && preferences.getInteger("uses") > 0) {
if(!schemeHandler.isDefaultHandler(Arrays.asList(Scheme.ftp.name(), Scheme.ftps.name(), Scheme.sftp.name()),
new Application(preferences.getProperty("application.identifier")))) {
final NSAlert alert = NSAlert.alert(
Expand All @@ -1005,6 +1005,19 @@ public Void run() throws BackgroundException {
}
}
}
final ProtocolFactory protocols = ProtocolFactory.get();
// Iterate over custom schemes and register by default
for(Protocol protocol : protocols.find()) {
final String[] schemes = protocol.getSchemes();
for(String scheme : schemes) {
if(Arrays.stream(Scheme.values()).filter(Predicate.isEqual(Scheme.s3).negate()).noneMatch(s -> s.name().equals(scheme))) {
if(log.isInfoEnabled()) {
log.info(String.format("Register custom scheme %s", scheme));
}
schemeHandler.setDefaultHandler(new Application(preferences.getProperty("application.identifier")), Collections.singletonList(scheme));
}
}
}
// 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reactive.Concurrency;
using System.Reflection;
using System.Runtime.CompilerServices;
Expand Down Expand Up @@ -583,13 +584,12 @@ private static void InitializeBonjour()

private static void InitializeProtocolHandler()
{
var self = new Application(System.Windows.Forms.Application.ExecutablePath);
if (PreferencesFactory.get().getBoolean("defaulthandler.reminder") &&
PreferencesFactory.get().getInteger("uses") > 0)
var handler = SchemeHandlerFactory.get();
var app = new Application(System.Windows.Forms.Application.ExecutablePath);
if (PreferencesFactory.get().getBoolean("defaulthandler.reminder") && PreferencesFactory.get().getInteger("uses") > 0)
{
var handler = SchemeHandlerFactory.get();
if (
!handler.isDefaultHandler(Arrays.asList(Scheme.ftp.name(), Scheme.ftps.name(), Scheme.sftp.name()), self))
!handler.isDefaultHandler(Arrays.asList(Scheme.ftp.name(), Scheme.ftps.name(), Scheme.sftp.name()), app))
{
Core.Utils.CommandBox(LocaleFactory.localizedString("Default Protocol Handler", "Preferences"),
LocaleFactory.localizedString(
Expand All @@ -610,13 +610,30 @@ private static void InitializeProtocolHandler()
switch (option)
{
case 0:
handler.setDefaultHandler(self,
handler.setDefaultHandler(app,
Arrays.asList(Scheme.ftp.name(), Scheme.ftps.name(), Scheme.sftp.name()));
break;
}
});
}
}
var protocols = Utils.ConvertFromJavaList<Protocol>(ProtocolFactory.get().find());
var schemes = Scheme.values().ToDictionary(x => x.name());
schemes.Remove(Scheme.s3.name());
foreach (var protocol in protocols)
{
foreach (var scheme in protocol.getSchemes())
{
if (!schemes.ContainsKey(scheme))
{
if (Logger.isInfoEnabled())
{
Logger.info($"Register custom scheme {scheme}");
}
handler.setDefaultHandler(app, Arrays.asList(scheme));
}
}
}
}

private static void InitJumpList()
Expand Down