Skip to content

Commit 813d900

Browse files
authored
Merge pull request #1002 from Flow-Launcher/fix_app_uri_logic
[Dev] Fix application URI logic when opening via WebSearch plugin
2 parents 0fad707 + 95ef8bb commit 813d900

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,26 @@ public interface IPublicAPI
228228
public void OpenDirectory(string DirectoryPath, string FileName = null);
229229

230230
/// <summary>
231-
/// Opens the url. The browser and mode used is based on what's configured in Flow's default browser settings.
231+
/// Opens the URL with the given Uri object.
232+
/// The browser and mode used is based on what's configured in Flow's default browser settings.
233+
/// </summary>
234+
public void OpenUrl(Uri url, bool? inPrivate = null);
235+
236+
/// <summary>
237+
/// Opens the URL with the given string.
238+
/// The browser and mode used is based on what's configured in Flow's default browser settings.
239+
/// Non-C# plugins should use this method.
232240
/// </summary>
233241
public void OpenUrl(string url, bool? inPrivate = null);
234242

235243
/// <summary>
236-
/// Opens the application URI.
244+
/// Opens the application URI with the given Uri object, e.g. obsidian://search-query-example
245+
/// </summary>
246+
public void OpenAppUri(Uri appUri);
247+
248+
/// <summary>
249+
/// Opens the application URI with the given string, e.g. obsidian://search-query-example
250+
/// Non-C# plugins should use this method
237251
/// </summary>
238252
public void OpenAppUri(string appUri);
239253
}

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,8 @@ public void OpenDirectory(string DirectoryPath, string FileName = null)
209209
explorer.Start();
210210
}
211211

212-
public void OpenUri(string url, bool? inPrivate = null, bool isAppUri = false)
212+
private void OpenUri(Uri uri, bool? inPrivate = null)
213213
{
214-
var uri = new Uri(url);
215214
if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
216215
{
217216
var browserInfo = _settingsVM.Settings.CustomBrowser;
@@ -220,38 +219,43 @@ public void OpenUri(string url, bool? inPrivate = null, bool isAppUri = false)
220219

221220
if (browserInfo.OpenInTab)
222221
{
223-
url.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
222+
uri.AbsoluteUri.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
224223
}
225224
else
226225
{
227-
url.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
226+
uri.AbsoluteUri.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
228227
}
229-
230-
return;
231228
}
232-
233-
if (isAppUri)
229+
else
234230
{
235231
Process.Start(new ProcessStartInfo()
236232
{
237-
FileName = url,
233+
FileName = uri.AbsoluteUri,
238234
UseShellExecute = true
239235
})?.Dispose();
240236

241237
return;
242238
}
243-
244-
throw new InvalidOperationException("URI scheme not specified or supported ");
245239
}
246240

247241
public void OpenUrl(string url, bool? inPrivate = null)
242+
{
243+
OpenUri(new Uri(url), inPrivate);
244+
}
245+
246+
public void OpenUrl(Uri url, bool? inPrivate = null)
248247
{
249248
OpenUri(url, inPrivate);
250249
}
251250

252251
public void OpenAppUri(string appUri)
253252
{
254-
OpenUri(appUri, isAppUri: true);
253+
OpenUri(new Uri(appUri));
254+
}
255+
256+
public void OpenAppUri(Uri appUri)
257+
{
258+
OpenUri(appUri);
255259
}
256260

257261
public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;

Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
4949
var title = keyword;
5050
string subtitle = _context.API.GetTranslation("flowlauncher_plugin_websearch_search") + " " + searchSource.Title;
5151

52-
//Action Keyword match apear on top
52+
// Action Keyword match apear on top
5353
var score = searchSource.ActionKeyword == SearchSourceGlobalPluginWildCardSign ? scoreStandard : scoreStandard + 1;
5454

55+
// This populates the associated action keyword search entry
5556
if (string.IsNullOrEmpty(keyword))
5657
{
5758
var result = new Result
@@ -61,6 +62,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
6162
IcoPath = searchSource.IconPath,
6263
Score = score
6364
};
65+
6466
results.Add(result);
6567
}
6668
else
@@ -93,7 +95,6 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
9395

9496
if (token.IsCancellationRequested)
9597
return null;
96-
9798
}
9899

99100
return results;

0 commit comments

Comments
 (0)