Skip to content

Commit cf1d162

Browse files
authored
Merge branch 'dev' into administrator_mode
2 parents 9797ad1 + e6c4cc2 commit cf1d162

File tree

12 files changed

+413
-37
lines changed

12 files changed

+413
-37
lines changed

Flow.Launcher/SettingPages/ViewModels/SettingsPaneHotkeyViewModel.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@ private void CustomHotkeyEdit()
8989
if (window.ShowDialog() is not true) return;
9090

9191
var index = Settings.CustomPluginHotkeys.IndexOf(settingItem);
92-
Settings.CustomPluginHotkeys[index] = new CustomPluginHotkey(window.Hotkey, window.ActionKeyword);
93-
HotKeyMapper.RemoveHotkey(settingItem.Hotkey); // remove origin hotkey
94-
HotKeyMapper.SetCustomQueryHotkey(Settings.CustomPluginHotkeys[index]); // set new hotkey
92+
if (index >= 0 && index < Settings.CustomPluginHotkeys.Count)
93+
{
94+
Settings.CustomPluginHotkeys[index] = new CustomPluginHotkey(window.Hotkey, window.ActionKeyword);
95+
HotKeyMapper.RemoveHotkey(settingItem.Hotkey); // remove origin hotkey
96+
HotKeyMapper.SetCustomQueryHotkey(Settings.CustomPluginHotkeys[index]); // set new hotkey
97+
}
9598
}
9699

97100
[RelayCommand]
@@ -150,7 +153,10 @@ private void CustomShortcutEdit()
150153
if (window.ShowDialog() is not true) return;
151154

152155
var index = Settings.CustomShortcuts.IndexOf(settingItem);
153-
Settings.CustomShortcuts[index] = new CustomShortcutModel(window.Key, window.Value);
156+
if (index >= 0 && index < Settings.CustomShortcuts.Count)
157+
{
158+
Settings.CustomShortcuts[index] = new CustomShortcutModel(window.Key, window.Value);
159+
}
154160
}
155161

156162
[RelayCommand]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows;
4+
using System.Windows.Data;
5+
6+
namespace Flow.Launcher.Plugin.Url.Converters;
7+
8+
[ValueConversion(typeof(bool), typeof(Visibility))]
9+
public class BoolToVisibilityConverter : IValueConverter
10+
{
11+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
12+
{
13+
if (value is not bool)
14+
throw new ArgumentException("value should be boolean", nameof(value));
15+
16+
return (bool)value ? Visibility.Visible : Visibility.Collapsed;
17+
}
18+
19+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
20+
{
21+
throw new InvalidOperationException();
22+
}
23+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
5+
namespace Flow.Launcher.Plugin.Url.Converters;
6+
7+
[ValueConversion(typeof(bool), typeof(bool))]
8+
public class InverseBoolConverter : IValueConverter
9+
{
10+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
11+
{
12+
if (value is not bool)
13+
throw new ArgumentException("value should be boolean", nameof(value));
14+
15+
return !(bool)value;
16+
}
17+
18+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
19+
{
20+
if (value is not bool)
21+
throw new ArgumentException("value should be boolean", nameof(value));
22+
23+
return !(bool)value;
24+
}
25+
}
Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:system="clr-namespace:System;assembly=mscorlib">
1+
<ResourceDictionary
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:system="clr-namespace:System;assembly=mscorlib">
45

5-
<system:String x:Key="flowlauncher_plugin_url_open_search_in">Open search in:</system:String>
6-
<system:String x:Key="flowlauncher_plugin_new_window">New Window</system:String>
7-
<system:String x:Key="flowlauncher_plugin_new_tab">New Tab</system:String>
8-
96
<system:String x:Key="flowlauncher_plugin_url_open_url">Open url:{0}</system:String>
107
<system:String x:Key="flowlauncher_plugin_url_cannot_open_url">Can't open url:{0}</system:String>
118

129
<system:String x:Key="flowlauncher_plugin_url_plugin_name">URL</system:String>
1310
<system:String x:Key="flowlauncher_plugin_url_plugin_description">Open the typed URL from Flow Launcher</system:String>
1411

15-
<system:String x:Key="flowlauncher_plugin_url_plugin_set_tip">Please set your browser path:</system:String>
1612
<system:String x:Key="flowlauncher_plugin_url_plugin_choose">Choose</system:String>
1713
<system:String x:Key="flowlauncher_plugin_url_plugin_filter">Application(*.exe)|*.exe|All files|*.*</system:String>
14+
15+
<system:String x:Key="flowlauncher_plugin_url_use_custom_browser">Use custom instead of Flow's default web browser</system:String>
16+
<system:String x:Key="flowlauncher_plugin_url_browser_path">Browser path</system:String>
17+
18+
<system:String x:Key="flowlauncher_plugin_url_new_tab">New tab</system:String>
19+
<system:String x:Key="flowlauncher_plugin_url_new_window">New window</system:String>
20+
21+
<system:String x:Key="flowlauncher_plugin_url_private_mode">Private mode</system:String>
22+
23+
<system:String x:Key="flowlauncher_plugin_url_usehttps">Prefer https over http</system:String>
1824
</ResourceDictionary>

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

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Text.RegularExpressions;
4+
using System.Windows.Controls;
5+
using Flow.Launcher.Plugin.SharedCommands;
46

57
namespace Flow.Launcher.Plugin.Url
68
{
7-
public class Main : IPlugin, IPluginI18n
9+
public class Main : IPlugin, IPluginI18n, ISettingProvider
810
{
911
//based on https://gist.github.com/dperini/729294
10-
private const string urlPattern = "^" +
12+
private const string UrlPattern = "^" +
1113
// protocol identifier
1214
"(?:(?:https?|ftp)://|)" +
1315
// user:pass authentication
@@ -39,33 +41,47 @@ public class Main : IPlugin, IPluginI18n
3941
// resource path
4042
"(?:/\\S*)?" +
4143
"$";
42-
Regex reg = new Regex(urlPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
44+
private readonly Regex UrlRegex = new(UrlPattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
4345
internal static PluginInitContext Context { get; private set; }
44-
private Settings _settings;
45-
46+
internal static Settings Settings { get; private set; }
47+
4648
public List<Result> Query(Query query)
4749
{
4850
var raw = query.Search;
4951
if (IsURL(raw))
5052
{
51-
return new List<Result>
52-
{
53-
new Result
53+
return
54+
[
55+
new()
5456
{
5557
Title = raw,
5658
SubTitle = Localize.flowlauncher_plugin_url_open_url(raw),
5759
IcoPath = "Images/url.png",
5860
Score = 8,
5961
Action = _ =>
6062
{
61-
if (!raw.ToLower().StartsWith("http"))
63+
if (!raw.StartsWith("http://", StringComparison.OrdinalIgnoreCase) && !raw.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
6264
{
63-
raw = "http://" + raw;
65+
raw = GetHttpPreference() + "://" + raw;
6466
}
6567
try
6668
{
67-
Context.API.OpenUrl(raw);
68-
69+
if (Settings.UseCustomBrowser)
70+
{
71+
if (Settings.OpenInNewBrowserWindow)
72+
{
73+
SearchWeb.OpenInBrowserWindow(raw, Settings.BrowserPath, Settings.OpenInPrivateMode, Settings.PrivateModeArgument);
74+
}
75+
else
76+
{
77+
SearchWeb.OpenInBrowserTab(raw, Settings.BrowserPath, Settings.OpenInPrivateMode, Settings.PrivateModeArgument);
78+
}
79+
}
80+
else
81+
{
82+
Context.API.OpenWebUrl(raw);
83+
}
84+
6985
return true;
7086
}
7187
catch(Exception)
@@ -75,16 +91,22 @@ public List<Result> Query(Query query)
7591
}
7692
}
7793
}
78-
};
94+
];
7995
}
80-
return new List<Result>(0);
96+
97+
return [];
98+
}
99+
100+
private static string GetHttpPreference()
101+
{
102+
return Settings.AlwaysOpenWithHttps ? "https" : "http";
81103
}
82104

83105
public bool IsURL(string raw)
84106
{
85107
raw = raw.ToLower();
86108

87-
if (reg.Match(raw).Value == raw) return true;
109+
if (UrlRegex.Match(raw).Value == raw) return true;
88110

89111
if (raw == "localhost" || raw.StartsWith("localhost:") ||
90112
raw == "http://localhost" || raw.StartsWith("http://localhost:") ||
@@ -100,8 +122,8 @@ public bool IsURL(string raw)
100122
public void Init(PluginInitContext context)
101123
{
102124
Context = context;
103-
104-
_settings = context.API.LoadSettingJsonStorage<Settings>();
125+
126+
Settings = context.API.LoadSettingJsonStorage<Settings>();
105127
}
106128

107129
public string GetTranslatedPluginTitle()
@@ -113,5 +135,10 @@ public string GetTranslatedPluginDescription()
113135
{
114136
return Localize.flowlauncher_plugin_url_plugin_description();
115137
}
138+
139+
public Control CreateSettingPanel()
140+
{
141+
return new SettingsControl();
142+
}
116143
}
117144
}
Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,53 @@
11
namespace Flow.Launcher.Plugin.Url
22
{
3-
public class Settings
3+
public class Settings : BaseModel
44
{
5-
public string BrowserPath { get; set; }
5+
private bool _useCustomBrowser = false;
6+
public bool UseCustomBrowser
7+
{
8+
get => _useCustomBrowser;
9+
set
10+
{
11+
if (_useCustomBrowser != value)
12+
{
13+
_useCustomBrowser = value;
14+
OnPropertyChanged();
15+
}
16+
}
17+
}
618

7-
public bool OpenInNewBrowserWindow { get; set; } = true;
19+
private string _browserPath = string.Empty;
20+
public string BrowserPath
21+
{
22+
get => _browserPath;
23+
set
24+
{
25+
if (_browserPath != value)
26+
{
27+
_browserPath = value;
28+
OnPropertyChanged();
29+
}
30+
}
31+
}
32+
33+
private bool _openInNewBrowserWindow = true;
34+
public bool OpenInNewBrowserWindow
35+
{
36+
get => _openInNewBrowserWindow;
37+
set
38+
{
39+
if (_openInNewBrowserWindow != value)
40+
{
41+
_openInNewBrowserWindow = value;
42+
OnPropertyChanged();
43+
}
44+
}
45+
}
46+
47+
public bool OpenInPrivateMode { get; set; } = false;
48+
49+
public string PrivateModeArgument { get; set; } = string.Empty;
50+
51+
public bool AlwaysOpenWithHttps { get; set; } = false;
852
}
953
}

0 commit comments

Comments
 (0)