Skip to content

Commit 95ef8bb

Browse files
committed
add overload for using Uri object
1 parent 96cf9fe commit 95ef8bb

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +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.
232-
/// Also supports application URIs e.g. obsidian://search-query-example
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.
233240
/// </summary>
234241
public void OpenUrl(string url, bool? inPrivate = null);
235242

236243
/// <summary>
237-
/// Opens the application URI, e.g. obsidian://search-query-example
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
238251
/// </summary>
239252
public void OpenAppUri(string appUri);
240253
}

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 21 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-
private void OpenUri(string url, bool? inPrivate = null)
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,33 +219,43 @@ private void OpenUri(string url, bool? inPrivate = null)
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
}
228+
}
229+
else
230+
{
231+
Process.Start(new ProcessStartInfo()
232+
{
233+
FileName = uri.AbsoluteUri,
234+
UseShellExecute = true
235+
})?.Dispose();
229236

230237
return;
231238
}
232-
233-
OpenAppUri(url);
234239
}
235240

236241
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)
237247
{
238248
OpenUri(url, inPrivate);
239249
}
240250

241251
public void OpenAppUri(string appUri)
242252
{
243-
Process.Start(new ProcessStartInfo()
244-
{
245-
FileName = appUri,
246-
UseShellExecute = true
247-
})?.Dispose();
253+
OpenUri(new Uri(appUri));
254+
}
248255

249-
return;
256+
public void OpenAppUri(Uri appUri)
257+
{
258+
OpenUri(appUri);
250259
}
251260

252261
public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;

0 commit comments

Comments
 (0)