Skip to content

Commit af313eb

Browse files
authored
Merge pull request #968 from Flow-Launcher/websearchUri
Support Application Uri in OpenUrl API call
2 parents 150ce09 + ef194d0 commit af313eb

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,5 +231,10 @@ public interface IPublicAPI
231231
/// Opens the url. The browser and mode used is based on what's configured in Flow's default browser settings.
232232
/// </summary>
233233
public void OpenUrl(string url, bool? inPrivate = null);
234+
235+
/// <summary>
236+
/// Opens the application URI.
237+
/// </summary>
238+
public void OpenAppUri(string appUri);
234239
}
235240
}

Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static void OpenInBrowserWindow(this string url, string browserPath = "",
6060

6161
try
6262
{
63-
Process.Start(psi);
63+
Process.Start(psi)?.Dispose();
6464
}
6565
catch (System.ComponentModel.Win32Exception)
6666
{
@@ -100,7 +100,7 @@ public static void OpenInBrowserTab(this string url, string browserPath = "", bo
100100
psi.FileName = url;
101101
}
102102

103-
Process.Start(psi);
103+
Process.Start(psi)?.Dispose();
104104
}
105105
// This error may be thrown if browser path is incorrect
106106
catch (System.ComponentModel.Win32Exception)

Flow.Launcher/PublicAPIInstance.cs

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

212-
public void OpenUrl(string url, bool? inPrivate = null)
212+
public void OpenUri(string url, bool? inPrivate = null, bool isAppUri = false)
213213
{
214-
var browserInfo = _settingsVM.Settings.CustomBrowser;
214+
var uri = new Uri(url);
215+
if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
216+
{
217+
var browserInfo = _settingsVM.Settings.CustomBrowser;
215218

216-
var path = browserInfo.Path == "*" ? "" : browserInfo.Path;
219+
var path = browserInfo.Path == "*" ? "" : browserInfo.Path;
217220

218-
if (browserInfo.OpenInTab)
219-
{
220-
url.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
221+
if (browserInfo.OpenInTab)
222+
{
223+
url.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
224+
}
225+
else
226+
{
227+
url.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
228+
}
229+
230+
return;
221231
}
222-
else
232+
233+
if (isAppUri)
223234
{
224-
url.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
235+
Process.Start(new ProcessStartInfo()
236+
{
237+
FileName = url,
238+
UseShellExecute = true
239+
})?.Dispose();
240+
241+
return;
225242
}
226243

244+
throw new InvalidOperationException("URI scheme not specified or supported ");
245+
}
246+
247+
public void OpenUrl(string url, bool? inPrivate = null)
248+
{
249+
OpenUri(url, inPrivate);
250+
}
251+
252+
public void OpenAppUri(string appUri)
253+
{
254+
OpenUri(appUri, isAppUri: true);
227255
}
228256

229257
public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;
@@ -254,4 +282,4 @@ private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, Spe
254282

255283
#endregion
256284
}
257-
}
285+
}

0 commit comments

Comments
 (0)