Skip to content

Commit 037e0f8

Browse files
authored
Merge pull request #800 from onesounds/GlobalBrowserSetting
Global browser setting / Private mode option
2 parents f86dd9d + b3b85c1 commit 037e0f8

File tree

29 files changed

+701
-336
lines changed

29 files changed

+701
-336
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Flow.Launcher.Plugin;
2+
using System.Text.Json.Serialization;
3+
4+
namespace Flow.Launcher.Infrastructure.UserSettings
5+
{
6+
public class CustomBrowserViewModel : BaseModel
7+
{
8+
public string Name { get; set; }
9+
public string Path { get; set; }
10+
public string PrivateArg { get; set; }
11+
public bool EnablePrivate { get; set; }
12+
public bool OpenInTab { get; set; } = true;
13+
[JsonIgnore]
14+
public bool OpenInNewWindow => !OpenInTab;
15+
public bool Editable { get; set; } = true;
16+
17+
public CustomBrowserViewModel Copy()
18+
{
19+
return new CustomBrowserViewModel
20+
{
21+
Name = Name,
22+
Path = Path,
23+
OpenInTab = OpenInTab,
24+
PrivateArg = PrivateArg,
25+
EnablePrivate = EnablePrivate,
26+
Editable = Editable
27+
};
28+
}
29+
}
30+
}
31+
32+
33+

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public string Language
3939
public string ResultFontWeight { get; set; }
4040
public string ResultFontStretch { get; set; }
4141
public bool UseGlyphIcons { get; set; } = true;
42+
public bool UseAnimation { get; set; } = true;
43+
public bool UseSound { get; set; } = true;
4244
public bool FirstLaunch { get; set; } = true;
4345

4446
public int CustomExplorerIndex { get; set; } = 0;
@@ -84,8 +86,52 @@ public CustomExplorerViewModel CustomExplorer
8486
}
8587
};
8688

87-
public bool UseAnimation { get; set; } = true;
88-
public bool UseSound { get; set; } = true;
89+
public int CustomBrowserIndex { get; set; } = 0;
90+
91+
[JsonIgnore]
92+
public CustomBrowserViewModel CustomBrowser
93+
{
94+
get => CustomBrowserList[CustomBrowserIndex];
95+
set => CustomBrowserList[CustomBrowserIndex] = value;
96+
}
97+
98+
public List<CustomBrowserViewModel> CustomBrowserList { get; set; } = new()
99+
{
100+
new()
101+
{
102+
Name = "Default",
103+
Path = "*",
104+
PrivateArg = "",
105+
EnablePrivate = false,
106+
Editable = false
107+
},
108+
new()
109+
{
110+
Name = "Google Chrome",
111+
Path = "chrome",
112+
PrivateArg = "-incognito",
113+
EnablePrivate = false,
114+
Editable = false
115+
},
116+
new()
117+
{
118+
Name = "Mozilla Firefox",
119+
Path = "firefox",
120+
PrivateArg = "-private",
121+
EnablePrivate = false,
122+
Editable = false
123+
}
124+
,
125+
new()
126+
{
127+
Name = "MS Edge",
128+
Path = "msedge",
129+
PrivateArg = "-inPrivate",
130+
EnablePrivate = false,
131+
Editable = false
132+
}
133+
};
134+
89135

90136
/// <summary>
91137
/// when false Alphabet static service will always return empty results

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,10 @@ public interface IPublicAPI
226226
/// <param name="DirectoryPath">Directory Path to open</param>
227227
/// <param name="FileName">Extra FileName Info</param>
228228
public void OpenDirectory(string DirectoryPath, string FileName = null);
229+
230+
/// <summary>
231+
/// Opens the url. The browser and mode used is based on what's configured in Flow's default browser settings.
232+
/// </summary>
233+
public void OpenUrl(string url, bool? inPrivate = null);
229234
}
230235
}

Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,21 @@ private static string GetDefaultBrowserPath()
3535
/// Opens search in a new browser. If no browser path is passed in then Chrome is used.
3636
/// Leave browser path blank to use Chrome.
3737
/// </summary>
38-
public static void NewBrowserWindow(this string url, string browserPath = "")
38+
public static void OpenInBrowserWindow(this string url, string browserPath = "", bool inPrivate = false, string privateArg = "")
3939
{
4040
browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath;
4141

4242
var browserExecutableName = browserPath?
43-
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
44-
.Last();
43+
.Split(new[]
44+
{
45+
Path.DirectorySeparatorChar
46+
}, StringSplitOptions.None)
47+
.Last();
4548

4649
var browser = string.IsNullOrEmpty(browserExecutableName) ? "chrome" : browserPath;
4750

4851
// Internet Explorer will open url in new browser window, and does not take the --new-window parameter
49-
var browserArguements = browserExecutableName == "iexplore.exe" ? url : "--new-window " + url;
52+
var browserArguements = (browserExecutableName == "iexplore.exe" ? "" : "--new-window ") + (inPrivate ? $"{privateArg} " : "") + url;
5053

5154
var psi = new ProcessStartInfo
5255
{
@@ -61,24 +64,36 @@ public static void NewBrowserWindow(this string url, string browserPath = "")
6164
}
6265
catch (System.ComponentModel.Win32Exception)
6366
{
64-
Process.Start(new ProcessStartInfo { FileName = url, UseShellExecute = true });
67+
Process.Start(new ProcessStartInfo
68+
{
69+
FileName = url, UseShellExecute = true
70+
});
6571
}
6672
}
6773

74+
[Obsolete("This is provided for backwards compatibility after 1.9.0 release, e.g. GitHub plugin. Use the new method instead")]
75+
public static void NewBrowserWindow(this string url, string browserPath = "")
76+
{
77+
OpenInBrowserWindow(url, browserPath);
78+
}
79+
6880
/// <summary>
6981
/// Opens search as a tab in the default browser chosen in Windows settings.
7082
/// </summary>
71-
public static void NewTabInBrowser(this string url, string browserPath = "")
83+
public static void OpenInBrowserTab(this string url, string browserPath = "", bool inPrivate = false, string privateArg = "")
7284
{
7385
browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath;
7486

75-
var psi = new ProcessStartInfo() { UseShellExecute = true };
87+
var psi = new ProcessStartInfo()
88+
{
89+
UseShellExecute = true
90+
};
7691
try
7792
{
7893
if (!string.IsNullOrEmpty(browserPath))
7994
{
8095
psi.FileName = browserPath;
81-
psi.Arguments = url;
96+
psi.Arguments = (inPrivate ? $"{privateArg} " : "") + url;
8297
}
8398
else
8499
{
@@ -90,8 +105,17 @@ public static void NewTabInBrowser(this string url, string browserPath = "")
90105
// This error may be thrown if browser path is incorrect
91106
catch (System.ComponentModel.Win32Exception)
92107
{
93-
Process.Start(new ProcessStartInfo { FileName = url, UseShellExecute = true });
108+
Process.Start(new ProcessStartInfo
109+
{
110+
FileName = url, UseShellExecute = true
111+
});
94112
}
95113
}
114+
115+
[Obsolete("This is provided for backwards compatibility after 1.9.0 release, e.g. GitHub plugin. Use the new method instead")]
116+
public static void NewTabInBrowser(this string url, string browserPath = "")
117+
{
118+
OpenInBrowserTab(url, browserPath);
119+
}
96120
}
97-
}
121+
}

Flow.Launcher/Languages/en.xaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
<system:String x:Key="ignoreHotkeysOnFullscreenToolTip">Disable Flow Launcher activation when a full screen application is active (Recommended for games).</system:String>
3939
<system:String x:Key="defaultFileManager">Default File Manager</system:String>
4040
<system:String x:Key="defaultFileManagerToolTip">Select the file manager to use when opening the folder.</system:String>
41+
<system:String x:Key="defaultBrowser">Default Web Browser</system:String>
42+
<system:String x:Key="defaultBrowserToolTip">Setting for New Tab, New Window, Private Mode.</system:String>
4143
<system:String x:Key="pythonDirectory">Python Directory</system:String>
4244
<system:String x:Key="autoUpdates">Auto Update</system:String>
4345
<system:String x:Key="selectPythonDirectory">Select</system:String>
@@ -164,6 +166,16 @@
164166
<system:String x:Key="fileManager_directory_arg">Arg For Folder</system:String>
165167
<system:String x:Key="fileManager_file_arg">Arg For File</system:String>
166168

169+
<!-- DefaultBrowser Setting Dialog -->
170+
<system:String x:Key="defaultBrowserTitle">Default Web Browser</system:String>
171+
<system:String x:Key="defaultBrowser_tips">The default setting follows the OS default browser setting. If specified separately, flow uses that browser.</system:String>
172+
<system:String x:Key="defaultBrowser_name">Browser</system:String>
173+
<system:String x:Key="defaultBrowser_profile_name">Browser Name</system:String>
174+
<system:String x:Key="defaultBrowser_path">Browser Path</system:String>
175+
<system:String x:Key="defaultBrowser_newtab">New Window</system:String>
176+
<system:String x:Key="defaultBrowser_newWindow">New Tab</system:String>
177+
<system:String x:Key="defaultBrowser_parameter">Priviate Mode</system:String>
178+
167179
<!-- Priority Setting Dialog -->
168180
<system:String x:Key="changePriorityWindow">Change Priority</system:String>
169181
<system:String x:Key="priority_tips">Greater the number, the higher the result will be ranked. Try setting it as 5. If you want the results to be lower than any other plugin's, provide a negative number</system:String>

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void ShellRun(string cmd, string filename = "cmd.exe")
114114
var startInfo = ShellCommand.SetProcessStartInfo(filename, arguments: args, createNoWindow: true);
115115
ShellCommand.Execute(startInfo);
116116
}
117-
117+
118118
public void CopyToClipboard(string text)
119119
{
120120
Clipboard.SetDataObject(text);
@@ -196,7 +196,7 @@ public void SavePluginSettings()
196196

197197
public void OpenDirectory(string DirectoryPath, string FileName = null)
198198
{
199-
using Process explorer = new Process();
199+
using var explorer = new Process();
200200
var explorerInfo = _settingsVM.Settings.CustomExplorer;
201201
explorer.StartInfo = new ProcessStartInfo
202202
{
@@ -209,6 +209,23 @@ public void OpenDirectory(string DirectoryPath, string FileName = null)
209209
explorer.Start();
210210
}
211211

212+
public void OpenUrl(string url, bool? inPrivate = null)
213+
{
214+
var browserInfo = _settingsVM.Settings.CustomBrowser;
215+
216+
var path = browserInfo.Path == "*" ? "" : browserInfo.Path;
217+
218+
if (browserInfo.OpenInTab)
219+
{
220+
url.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
221+
}
222+
else
223+
{
224+
url.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg);
225+
}
226+
227+
}
228+
212229
public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;
213230

214231
private readonly List<Func<int, int, SpecialKeyState, bool>> _globalKeyboardHandlers = new();

0 commit comments

Comments
 (0)