Skip to content

Commit 2f57d4f

Browse files
authored
Merge pull request #1496 from VictoriousRaptor/FixProgramUID
[Program Plugin] Fix program UID and other bugs
2 parents f8b009e + f5701d4 commit 2f57d4f

File tree

17 files changed

+467
-432
lines changed

17 files changed

+467
-432
lines changed

Flow.Launcher.Test/Plugins/ProgramTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void WhenGivenPriReferenceValueShouldReturnCorrectFormat(string packageNa
1919
var app = new UWP.Application();
2020

2121
// Act
22-
var result = app.FormattedPriReferenceValue(packageName, rawPriReferenceValue);
22+
var result = UWP.Application.FormattedPriReferenceValue(packageName, rawPriReferenceValue);
2323

2424
// Assert
2525
Assert.IsTrue(result == expectedFormat,

Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
77
Title="{DynamicResource flowlauncher_plugin_program_directory}"
8-
Width="400"
8+
Width="530"
99
Background="{DynamicResource PopuBGColor}"
1010
Foreground="{DynamicResource PopupTextColor}"
11+
ResizeMode="NoResize"
1112
SizeToContent="Height"
12-
WindowStartupLocation="CenterScreen"
13-
mc:Ignorable="d">
13+
WindowStartupLocation="CenterScreen">
1414
<WindowChrome.WindowChrome>
1515
<WindowChrome CaptionHeight="32" ResizeBorderThickness="{x:Static SystemParameters.WindowResizeBorderThickness}" />
1616
</WindowChrome.WindowChrome>
@@ -19,7 +19,6 @@
1919
<RowDefinition />
2020
<RowDefinition Height="80" />
2121
</Grid.RowDefinitions>
22-
2322
<StackPanel Grid.Row="0">
2423
<StackPanel>
2524
<Grid>
@@ -53,53 +52,96 @@
5352
</Button>
5453
</Grid>
5554
</StackPanel>
56-
<StackPanel Margin="26,12,26,0">
57-
<StackPanel Margin="0,0,0,12">
55+
<StackPanel Margin="26,0,26,0">
56+
<StackPanel Grid.Row="0" Margin="0,0,0,12">
5857
<TextBlock
5958
Grid.Column="0"
6059
Margin="0,0,0,0"
6160
FontSize="20"
6261
FontWeight="SemiBold"
63-
Text="{DynamicResource flowlauncher_plugin_program_directory}"
62+
Text="{DynamicResource flowlauncher_plugin_program_edit_program_source_title}"
6463
TextAlignment="Left" />
6564
</StackPanel>
66-
<StackPanel Margin="0,0,0,10" Orientation="Horizontal">
67-
<TextBox
68-
Name="Directory"
69-
Width="268"
70-
Margin="0,7"
71-
VerticalAlignment="Center" />
72-
<Button
73-
Width="70"
74-
Margin="10"
75-
HorizontalAlignment="Right"
76-
Click="BrowseButton_Click"
77-
Content="{DynamicResource flowlauncher_plugin_program_browse}" />
65+
<StackPanel>
66+
<TextBlock
67+
FontSize="14"
68+
Text="{DynamicResource flowlauncher_plugin_program_edit_program_source_tips}"
69+
TextAlignment="Left"
70+
TextWrapping="WrapWithOverflow" />
71+
</StackPanel>
72+
73+
<StackPanel Margin="0,10,0,0" Orientation="Horizontal">
74+
<Grid Width="470">
75+
<Grid.RowDefinitions>
76+
<RowDefinition />
77+
<RowDefinition />
78+
</Grid.RowDefinitions>
79+
<Grid.ColumnDefinitions>
80+
<ColumnDefinition Width="Auto" />
81+
<ColumnDefinition Width="*" />
82+
</Grid.ColumnDefinitions>
83+
<TextBlock
84+
Grid.Row="0"
85+
Grid.Column="0"
86+
Margin="10"
87+
HorizontalAlignment="Left"
88+
VerticalAlignment="Center"
89+
FontSize="14"
90+
Text="{DynamicResource flowlauncher_plugin_program_directory}" />
91+
<DockPanel
92+
Grid.Row="0"
93+
Grid.Column="1"
94+
LastChildFill="True">
95+
<Button
96+
Width="70"
97+
HorizontalAlignment="Right"
98+
Click="BrowseButton_Click"
99+
DockPanel.Dock="Right"
100+
Content="{DynamicResource flowlauncher_plugin_program_browse}" />
101+
<TextBox
102+
Name="Directory"
103+
Margin="10"
104+
VerticalAlignment="Center"
105+
HorizontalAlignment="Stretch" />
106+
</DockPanel>
107+
<TextBlock
108+
Grid.Row="1"
109+
Grid.Column="0"
110+
Margin="10"
111+
HorizontalAlignment="Left"
112+
VerticalAlignment="Center"
113+
FontSize="14"
114+
Text="{DynamicResource flowlauncher_plugin_program_enabled}" />
115+
<CheckBox x:Name="Chkbox"
116+
Grid.Row="1"
117+
Grid.Column="1"
118+
Margin="10,0"
119+
VerticalAlignment="Center" />
120+
</Grid>
78121
</StackPanel>
79122
</StackPanel>
80123
</StackPanel>
81124
<Border
82125
Grid.Row="1"
126+
Margin="0,14,0,0"
83127
Background="{DynamicResource PopupButtonAreaBGColor}"
84128
BorderBrush="{DynamicResource PopupButtonAreaBorderColor}"
85129
BorderThickness="0,1,0,0">
86130
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
87131
<Button
88132
x:Name="btnCancel"
89133
MinWidth="140"
90-
Margin="0,0,5,0"
134+
Margin="10,0,5,0"
91135
Click="BtnCancel_OnClick"
92136
Content="{DynamicResource cancel}" />
93-
94137
<Button
138+
x:Name="btnAdd"
95139
MinWidth="140"
96-
Margin="5,0,0,0"
97-
HorizontalAlignment="Right"
98-
Click="ButtonAdd_OnClick"
140+
Margin="5,0,10,0"
141+
Click="BtnAdd_OnClick"
99142
Content="{DynamicResource flowlauncher_plugin_program_update}"
100143
Style="{DynamicResource AccentButtonStyle}" />
101144
</StackPanel>
102145
</Border>
103146
</Grid>
104-
105-
</Window>
147+
</Window>

Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,32 @@ namespace Flow.Launcher.Plugin.Program
99
/// <summary>
1010
/// Interaction logic for AddProgramSource.xaml
1111
/// </summary>
12-
public partial class AddProgramSource
12+
public partial class AddProgramSource : Window
1313
{
1414
private PluginInitContext _context;
15-
private Settings.ProgramSource _editing;
15+
private ProgramSource _editing;
1616
private Settings _settings;
17+
private bool update;
1718

1819
public AddProgramSource(PluginInitContext context, Settings settings)
1920
{
2021
InitializeComponent();
2122
_context = context;
2223
_settings = settings;
2324
Directory.Focus();
25+
Chkbox.IsChecked = true;
26+
update = false;
27+
btnAdd.Content = _context.API.GetTranslation("flowlauncher_plugin_program_add");
2428
}
2529

26-
public AddProgramSource(Settings.ProgramSource edit, Settings settings)
30+
public AddProgramSource(PluginInitContext context, Settings settings, ProgramSource source)
2731
{
28-
_editing = edit;
29-
_settings = settings;
30-
3132
InitializeComponent();
33+
_context = context;
34+
_editing = source;
35+
_settings = settings;
36+
update = true;
37+
Chkbox.IsChecked = _editing.Enabled;
3238
Directory.Text = _editing.Location;
3339
}
3440

@@ -47,34 +53,54 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
4753
Close();
4854
}
4955

50-
private void ButtonAdd_OnClick(object sender, RoutedEventArgs e)
56+
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
5157
{
52-
string s = Directory.Text;
53-
if (!System.IO.Directory.Exists(s))
58+
string path = Directory.Text;
59+
bool modified = false;
60+
if (!System.IO.Directory.Exists(path))
5461
{
5562
System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_invalid_path"));
5663
return;
5764
}
58-
if (_editing == null)
65+
if (!update)
5966
{
60-
if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == Directory.Text))
67+
if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier.Equals(path, System.StringComparison.OrdinalIgnoreCase)))
6168
{
62-
var source = new ProgramSource
63-
{
64-
Location = Directory.Text,
65-
UniqueIdentifier = Directory.Text
66-
};
67-
69+
var source = new ProgramSource(path);
70+
modified = true;
6871
_settings.ProgramSources.Insert(0, source);
6972
ProgramSetting.ProgramSettingDisplayList.Add(source);
7073
}
74+
else
75+
{
76+
System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source"));
77+
return;
78+
}
7179
}
7280
else
7381
{
74-
_editing.Location = Directory.Text;
82+
// Separate checks to avoid changing UniqueIdentifier of UWP
83+
if (!_editing.Location.Equals(path, System.StringComparison.OrdinalIgnoreCase))
84+
{
85+
if (ProgramSetting.ProgramSettingDisplayList
86+
.Any(x => x.UniqueIdentifier.Equals(path, System.StringComparison.OrdinalIgnoreCase)))
87+
{
88+
// Check if the new location is used
89+
// No need to check win32 or uwp, just override them
90+
System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source"));
91+
return;
92+
}
93+
modified = true;
94+
_editing.Location = path; // Changes UniqueIdentifier internally
95+
}
96+
if (_editing.Enabled != Chkbox.IsChecked)
97+
{
98+
modified = true;
99+
_editing.Enabled = Chkbox.IsChecked ?? true;
100+
}
75101
}
76102

77-
DialogResult = true;
103+
DialogResult = modified;
78104
Close();
79105
}
80106
}

Plugins/Flow.Launcher.Plugin.Program/FileChangeWatcher.cs

Lines changed: 0 additions & 58 deletions
This file was deleted.

Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<system:String x:Key="flowlauncher_plugin_program_add">Add</system:String>
1111
<system:String x:Key="flowlauncher_plugin_program_name">Name</system:String>
1212
<system:String x:Key="flowlauncher_plugin_program_enable">Enable</system:String>
13+
<system:String x:Key="flowlauncher_plugin_program_enabled">Enabled</system:String>
1314
<system:String x:Key="flowlauncher_plugin_program_disable">Disable</system:String>
1415
<system:String x:Key="flowlauncher_plugin_program_location">Location</system:String>
1516
<system:String x:Key="flowlauncher_plugin_program_all_programs">All Programs</system:String>
@@ -38,8 +39,12 @@
3839

3940
<system:String x:Key="flowlauncher_plugin_program_pls_select_program_source">Please select a program source</system:String>
4041
<system:String x:Key="flowlauncher_plugin_program_delete_program_source">Are you sure you want to delete the selected program sources?</system:String>
42+
<system:String x:Key="flowlauncher_plugin_program_duplicate_program_source">Another program source with the same location alreaday exists.</system:String>
4143

42-
<system:String x:Key="flowlauncher_plugin_program_update">OK</system:String>
44+
<system:String x:Key="flowlauncher_plugin_program_edit_program_source_title">Program Source</system:String>
45+
<system:String x:Key="flowlauncher_plugin_program_edit_program_source_tips">Edit directory and status of this program source.</system:String>
46+
47+
<system:String x:Key="flowlauncher_plugin_program_update">Update</system:String>
4348
<system:String x:Key="flowlauncher_plugin_program_only_index_tip">Program Plugin will only index files with selected suffixes and .url files with selected protocols.</system:String>
4449
<system:String x:Key="flowlauncher_plugin_program_update_file_suffixes">Successfully updated file suffixes</system:String>
4550
<system:String x:Key="flowlauncher_plugin_program_suffixes_cannot_empty">File suffixes can't be empty</system:String>

Plugins/Flow.Launcher.Plugin.Program/Logger/ProgramLogger.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
using NLog;
2-
using NLog.Config;
3-
using NLog.Targets;
42
using System;
5-
using System.Diagnostics;
63
using System.IO;
74
using System.Runtime.CompilerServices;
85
using System.Security;
9-
using Flow.Launcher.Infrastructure;
10-
using Flow.Launcher.Infrastructure.UserSettings;
116

127
namespace Flow.Launcher.Plugin.Program.Logger
138
{

0 commit comments

Comments
 (0)