From c56c343ed6c7fbfae717dc6cce7a55e8f2a952a3 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 18 Oct 2022 14:51:13 +0800
Subject: [PATCH 01/58] Add Checkbox to edit program source window
1. Add Checkbox to edit program source window
2. Double click item to edit
---
.../AddProgramSource.xaml | 93 ++++++++++++++-----
.../AddProgramSource.xaml.cs | 38 ++++----
.../Views/ProgramSetting.xaml | 1 +
.../Views/ProgramSetting.xaml.cs | 19 +++-
4 files changed, 107 insertions(+), 44 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
index 9230eb06254..b1e21a3e3b0 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
@@ -5,12 +5,12 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="{DynamicResource flowlauncher_plugin_program_directory}"
- Width="400"
+ Width="530"
Background="{DynamicResource PopuBGColor}"
Foreground="{DynamicResource PopupTextColor}"
+ ResizeMode="NoResize"
SizeToContent="Height"
- WindowStartupLocation="CenterScreen"
- mc:Ignorable="d">
+ WindowStartupLocation="CenterScreen">
@@ -19,7 +19,6 @@
-
@@ -53,8 +52,8 @@
-
-
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -87,19 +132,17 @@
-
-
-
+
\ No newline at end of file
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index 045d363b3fe..3442a1a22e6 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -9,27 +9,31 @@ namespace Flow.Launcher.Plugin.Program
///
/// Interaction logic for AddProgramSource.xaml
///
- public partial class AddProgramSource
+ public partial class AddProgramSource : Window
{
private PluginInitContext _context;
- private Settings.ProgramSource _editing;
+ private Settings.ProgramSource _updating;
private Settings _settings;
+ private bool update;
public AddProgramSource(PluginInitContext context, Settings settings)
{
InitializeComponent();
_context = context;
_settings = settings;
- Directory.Focus();
+ tbDirectory.Focus();
+ Chkbox.IsChecked = true;
+ update = false;
}
- public AddProgramSource(Settings.ProgramSource edit, Settings settings)
+ public AddProgramSource(Settings.ProgramSource source, Settings settings)
{
- _editing = edit;
+ _updating = source;
_settings = settings;
-
+ update = true;
InitializeComponent();
- Directory.Text = _editing.Location;
+ Chkbox.IsChecked = _updating.Enabled;
+ tbDirectory.Text = _updating.Location;
}
private void BrowseButton_Click(object sender, RoutedEventArgs e)
@@ -38,7 +42,7 @@ private void BrowseButton_Click(object sender, RoutedEventArgs e)
DialogResult result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
- Directory.Text = dialog.SelectedPath;
+ tbDirectory.Text = dialog.SelectedPath;
}
}
@@ -47,22 +51,23 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
Close();
}
- private void ButtonAdd_OnClick(object sender, RoutedEventArgs e)
+ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
{
- string s = Directory.Text;
- if (!System.IO.Directory.Exists(s))
+ string path = tbDirectory.Text;
+ if (!System.IO.Directory.Exists(path))
{
System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_invalid_path"));
return;
}
- if (_editing == null)
+ if (!update)
{
- if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == Directory.Text))
+ if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == path))
{
var source = new ProgramSource
{
- Location = Directory.Text,
- UniqueIdentifier = Directory.Text
+ Location = path,
+ UniqueIdentifier = path,
+ Enabled = Chkbox.IsChecked ?? true
};
_settings.ProgramSources.Insert(0, source);
@@ -71,7 +76,8 @@ private void ButtonAdd_OnClick(object sender, RoutedEventArgs e)
}
else
{
- _editing.Location = Directory.Text;
+ _updating.Location = path;
+ _updating.Enabled = Chkbox.IsChecked ?? true;
}
DialogResult = true;
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml
index f078794654b..fa2d4551f3e 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml
@@ -116,6 +116,7 @@
Drop="programSourceView_Drop"
GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler"
PreviewMouseRightButtonUp="ProgramSourceView_PreviewMouseRightButtonUp"
+ MouseDoubleClick="ProgramSourceView_MouseDoubleClick"
SelectionMode="Extended">
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index 1a31e8c2833..dcfdd118559 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@@ -352,12 +352,25 @@ private void Row_OnClick(object sender, RoutedEventArgs e)
if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(selectedItems))
{
- btnProgramSourceStatus.Content = "Disable";
+ btnProgramSourceStatus.Content = "Disable"; // todo
}
else
{
btnProgramSourceStatus.Content = "Enable";
}
}
+
+ private void ProgramSourceView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
+ {
+ var selectedProgramSource = programSourceView.SelectedItem as Settings.ProgramSource;
+ if (selectedProgramSource != null)
+ {
+ var add = new AddProgramSource(selectedProgramSource, _settings);
+ if (add.ShowDialog() ?? false)
+ {
+ ReIndexing();
+ }
+ }
+ }
}
-}
\ No newline at end of file
+}
From 6bb3b39e371715aa63041946be1539ff46fc7dbc Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 18 Oct 2022 14:51:24 +0800
Subject: [PATCH 02/58] Merge remote-tracking branch 'upstream/dev' into
ProgramPluginUI
From 3196dc559ab74b2979e439fbd40cec3af8e2d1cb Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 18 Oct 2022 15:10:16 +0800
Subject: [PATCH 03/58] Update text
---
Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml | 4 ++--
Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
index b1e21a3e3b0..a286eb48547 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
@@ -59,13 +59,13 @@
Margin="0,0,0,0"
FontSize="20"
FontWeight="SemiBold"
- Text="{DynamicResource flowlauncher_plugin_program_directory}"
+ Text="{DynamicResource flowlauncher_plugin_program_edit_program_source}"
TextAlignment="Left" />
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml
index 8d8cae02c9f..101f75bc917 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml
@@ -34,6 +34,9 @@
Please select a program source
Are you sure you want to delete the selected program sources?
+ Edit Program Source
+ Edit directory and status of this program source.
+
OK
Flow Launcher will only index files that end with the following suffixes. (Each suffix should split by ';' )
Successfully updated file suffixes
From dcec3611de87e4845ab6ec32be220b7aff6960df Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 18 Oct 2022 19:28:12 +0800
Subject: [PATCH 04/58] Fix button text issue
---
.../AddProgramSource.xaml | 2 +-
.../AddProgramSource.xaml.cs | 3 +-
.../Languages/en.xaml | 4 +-
.../Flow.Launcher.Plugin.Program/Settings.cs | 11 ++++++
.../Views/ProgramSetting.xaml | 3 +-
.../Views/ProgramSetting.xaml.cs | 39 ++++++++-----------
6 files changed, 35 insertions(+), 27 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
index a286eb48547..af62a8f6427 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
@@ -59,7 +59,7 @@
Margin="0,0,0,0"
FontSize="20"
FontWeight="SemiBold"
- Text="{DynamicResource flowlauncher_plugin_program_edit_program_source}"
+ Text="{DynamicResource flowlauncher_plugin_program_edit_program_source_title}"
TextAlignment="Left" />
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index 3442a1a22e6..49e066754b2 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -24,14 +24,15 @@ public AddProgramSource(PluginInitContext context, Settings settings)
tbDirectory.Focus();
Chkbox.IsChecked = true;
update = false;
+ btnAdd.Content = _context.API.GetTranslation("flowlauncher_plugin_program_add");
}
public AddProgramSource(Settings.ProgramSource source, Settings settings)
{
+ InitializeComponent();
_updating = source;
_settings = settings;
update = true;
- InitializeComponent();
Chkbox.IsChecked = _updating.Enabled;
tbDirectory.Text = _updating.Location;
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml
index 101f75bc917..0da7e83b32d 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml
@@ -34,10 +34,10 @@
Please select a program source
Are you sure you want to delete the selected program sources?
- Edit Program Source
+ Program Source
Edit directory and status of this program source.
- OK
+ Update
Flow Launcher will only index files that end with the following suffixes. (Each suffix should split by ';' )
Successfully updated file suffixes
File suffixes can't be empty
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
index d97ddd9932a..3fd6a22061a 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using System.Windows.Input;
namespace Flow.Launcher.Plugin.Program
{
@@ -41,6 +42,16 @@ public class ProgramSource
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
public bool Enabled { get; set; } = true;
public string UniqueIdentifier { get; set; }
+
+ public override bool Equals(object obj)
+ {
+ return obj is ProgramSource other && other.UniqueIdentifier.ToLower() == this.UniqueIdentifier.ToLower();
+ }
+
+ public override int GetHashCode()
+ {
+ return HashCode.Combine(UniqueIdentifier.ToLower());
+ }
}
public class DisabledProgramSource : ProgramSource { }
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml
index fa2d4551f3e..b3c17be28cf 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml
@@ -116,7 +116,8 @@
Drop="programSourceView_Drop"
GridViewColumnHeader.Click="GridViewColumnHeaderClickedHandler"
PreviewMouseRightButtonUp="ProgramSourceView_PreviewMouseRightButtonUp"
- MouseDoubleClick="ProgramSourceView_MouseDoubleClick"
+ MouseDoubleClick="programSourceView_MouseDoubleClick"
+ SelectionChanged="programSourceView_SelectionChanged"
SelectionMode="Extended">
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index dcfdd118559..79082da567b 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -235,18 +235,14 @@ private void btnProgramSourceStatus_OnClick(object sender, RoutedEventArgs e)
.SelectedItems.Cast()
.ToList();
- if (selectedItems.Count() == 0)
+ if (selectedItems.Count == 0)
{
string msg = context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source");
MessageBox.Show(msg);
return;
}
- if (selectedItems
- .Where(t1 => !_settings
- .ProgramSources
- .Any(x => t1.UniqueIdentifier == x.UniqueIdentifier))
- .Count() == 0)
+ if (IsAllItemsUserAdded(selectedItems))
{
var msg = string.Format(context.API.GetTranslation("flowlauncher_plugin_program_delete_program_source"));
@@ -257,7 +253,7 @@ private void btnProgramSourceStatus_OnClick(object sender, RoutedEventArgs e)
DeleteProgramSources(selectedItems);
}
- else if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(selectedItems))
+ else if (HasMoreOrEqualEnabledItems(selectedItems))
{
ProgramSettingDisplayList.SetProgramSourcesStatus(selectedItems, false);
@@ -329,42 +325,36 @@ private void Sort(string sortBy, ListSortDirection direction)
dataView.Refresh();
}
- private bool IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(List selectedItems)
+ private static bool HasMoreOrEqualEnabledItems(List items)
{
- return selectedItems.Where(x => x.Enabled).Count() >= selectedItems.Where(x => !x.Enabled).Count();
+ return items.Where(x => x.Enabled).Count() >= items.Count / 2;
}
- private void Row_OnClick(object sender, RoutedEventArgs e)
+ private void programSourceView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedItems = programSourceView
.SelectedItems.Cast()
.ToList();
- if (selectedItems
- .Where(t1 => !_settings
- .ProgramSources
- .Any(x => t1.UniqueIdentifier == x.UniqueIdentifier))
- .Count() == 0)
+ if (IsAllItemsUserAdded(selectedItems))
{
btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_delete");
- return;
}
-
- if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(selectedItems))
+ else if (HasMoreOrEqualEnabledItems(selectedItems))
{
- btnProgramSourceStatus.Content = "Disable"; // todo
+ btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_disable");
}
else
{
- btnProgramSourceStatus.Content = "Enable";
+ btnProgramSourceStatus.Content = context.API.GetTranslation("flowlauncher_plugin_program_enable");
}
}
- private void ProgramSourceView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
+ private void programSourceView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var selectedProgramSource = programSourceView.SelectedItem as Settings.ProgramSource;
if (selectedProgramSource != null)
- {
+ {
var add = new AddProgramSource(selectedProgramSource, _settings);
if (add.ShowDialog() ?? false)
{
@@ -372,5 +362,10 @@ private void ProgramSourceView_MouseDoubleClick(object sender, MouseButtonEventA
}
}
}
+
+ private bool IsAllItemsUserAdded(List items)
+ {
+ return items.All(x => _settings.ProgramSources.Any(y => y == x));
+ }
}
}
From 569f69a2708b602c849eb7bdf568c2666ef6d924 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 18 Oct 2022 20:07:43 +0800
Subject: [PATCH 05/58] bugfix
---
.../Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index 79082da567b..b1ced189ec2 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -365,7 +365,7 @@ private void programSourceView_MouseDoubleClick(object sender, MouseButtonEventA
private bool IsAllItemsUserAdded(List items)
{
- return items.All(x => _settings.ProgramSources.Any(y => y == x));
+ return items.All(x => _settings.ProgramSources.Any(y => y.UniqueIdentifier == x.UniqueIdentifier));
}
}
}
From bcd2b8d658da3fc0040b5c0e8abf24bc994bd963 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 18 Oct 2022 20:25:43 +0800
Subject: [PATCH 06/58] bugfix
---
Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml | 3 +--
Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml | 1 +
Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml | 2 +-
.../Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs | 1 +
4 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
index af62a8f6427..f349a3a38a5 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
@@ -94,7 +94,6 @@
LastChildFill="True">
+ Text="{DynamicResource flowlauncher_plugin_program_enabled}" />
Add
Name
Enable
+ Enabled
Disable
Location
All Programs
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml
index b3c17be28cf..171f6081bab 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml
@@ -128,7 +128,7 @@
-
+
_settings.HideAppsPath;
From fac76af685c2bb865f208a1abad39c5f89652fa2 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 18 Oct 2022 21:30:55 +0800
Subject: [PATCH 07/58] Reindex when disable program from results
---
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index f0a53ed7758..ed7cc627f38 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -196,12 +196,17 @@ private void DisableProgram(IProgram programToDelete)
return;
if (_uwps.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
+ {
_uwps.FirstOrDefault(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
.Enabled = false;
-
- if (_win32s.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
+ Task.Run(IndexUwpPrograms);
+ }
+ else if (_win32s.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
+ {
_win32s.FirstOrDefault(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
.Enabled = false;
+ Task.Run(IndexWin32Programs);
+ }
_settings.DisabledProgramSources
.Add(
@@ -213,6 +218,7 @@ private void DisableProgram(IProgram programToDelete)
Enabled = false
}
);
+ _settings.LastIndexTime = DateTime.Today;
}
public static void StartProcess(Func runProcess, ProcessStartInfo info)
From 58ad92b812992d9db12a7cf7351ff58afa4f05ca Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 18 Oct 2022 21:46:28 +0800
Subject: [PATCH 08/58] Revert changes in Settings.cs
---
Plugins/Flow.Launcher.Plugin.Program/Settings.cs | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
index 3fd6a22061a..d61ecd2a3f9 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
-using System.Windows.Input;
namespace Flow.Launcher.Plugin.Program
{
@@ -10,7 +9,7 @@ public class Settings
public DateTime LastIndexTime { get; set; }
public List ProgramSources { get; set; } = new List();
public List DisabledProgramSources { get; set; } = new List();
- public string[] ProgramSuffixes { get; set; } = {"appref-ms", "exe", "lnk"};
+ public string[] ProgramSuffixes { get; set; } = { "appref-ms", "exe", "lnk" };
public bool EnableStartMenuSource { get; set; } = true;
@@ -42,16 +41,6 @@ public class ProgramSource
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
public bool Enabled { get; set; } = true;
public string UniqueIdentifier { get; set; }
-
- public override bool Equals(object obj)
- {
- return obj is ProgramSource other && other.UniqueIdentifier.ToLower() == this.UniqueIdentifier.ToLower();
- }
-
- public override int GetHashCode()
- {
- return HashCode.Combine(UniqueIdentifier.ToLower());
- }
}
public class DisabledProgramSource : ProgramSource { }
From 81d295498b4c548b9d4bffc048b03616264d820d Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 20 Oct 2022 16:15:56 +0800
Subject: [PATCH 09/58] Move ProgramSource definition
---
.../AddProgramSource.xaml.cs | 4 +-
.../Flow.Launcher.Plugin.Program/Settings.cs | 21 +---
.../Views/Commands/ProgramSettingDisplay.cs | 4 +-
.../Views/Models/ProgramSource.cs | 102 +++++++++++++++++-
.../Views/ProgramSetting.xaml.cs | 6 +-
5 files changed, 108 insertions(+), 29 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index 045d363b3fe..25bc3d67055 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -12,7 +12,7 @@ namespace Flow.Launcher.Plugin.Program
public partial class AddProgramSource
{
private PluginInitContext _context;
- private Settings.ProgramSource _editing;
+ private ProgramSource _editing;
private Settings _settings;
public AddProgramSource(PluginInitContext context, Settings settings)
@@ -23,7 +23,7 @@ public AddProgramSource(PluginInitContext context, Settings settings)
Directory.Focus();
}
- public AddProgramSource(Settings.ProgramSource edit, Settings settings)
+ public AddProgramSource(ProgramSource edit, Settings settings)
{
_editing = edit;
_settings = settings;
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
index d97ddd9932a..af5b7bc7d2c 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using Flow.Launcher.Plugin.Program.Views.Models;
namespace Flow.Launcher.Plugin.Program
{
@@ -24,25 +25,5 @@ public class Settings
internal const string Explorer = "explorer";
internal const string ExplorerArgs = "%s";
-
- ///
- /// Contains user added folder location contents as well as all user disabled applications
- ///
- ///
- /// Win32 class applications set UniqueIdentifier using their full file path
- /// UWP class applications set UniqueIdentifier using their Application User Model ID
- /// Custom user added program sources set UniqueIdentifier using their location
- ///
- public class ProgramSource
- {
- private string name;
-
- public string Location { get; set; }
- public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
- public bool Enabled { get; set; } = true;
- public string UniqueIdentifier { get; set; }
- }
-
- public class DisabledProgramSource : ProgramSource { }
}
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
index 3129b2b996e..5be38a7b350 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
@@ -9,7 +9,7 @@ namespace Flow.Launcher.Plugin.Program.Views.Commands
{
internal static class ProgramSettingDisplay
{
- internal static List LoadProgramSources(this List programSources)
+ internal static List LoadProgramSources(this List programSources)
{
var list = new List();
@@ -108,7 +108,7 @@ internal static void StoreDisabledInSettings(this List list)
.ToList()
.ForEach(x => Main._settings.DisabledProgramSources
.Add(
- new Settings.DisabledProgramSource
+ new DisabledProgramSource
{
Name = x.Name,
Location = x.Location,
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
index 8e3184ff7fb..e42552696ea 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
@@ -1,5 +1,103 @@
-
+using System;
+using System.IO;
+using Flow.Launcher.Plugin.Program.Programs;
+
namespace Flow.Launcher.Plugin.Program.Views.Models
{
- public class ProgramSource : Settings.ProgramSource { }
+ ///
+ /// Contains user added folder location contents as well as all user disabled applications
+ ///
+ ///
+ /// Win32 class applications set UniqueIdentifier using their full file path
+ /// UWP class applications set UniqueIdentifier using their Application User Model ID
+ /// Custom user added program sources set UniqueIdentifier using their location
+ ///
+ public class ProgramSource
+ {
+ private string name;
+
+ public string Location;
+ public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
+ public bool Enabled { get; set; } = true;
+ private string uid { get; set; }
+
+ ///
+ /// Guranteed lowercase.
+ ///
+ public string UniqueIdentifier { get => uid; set => uid = value.ToLowerInvariant(); }
+
+ public ProgramSource()
+ {
+ }
+
+ ///
+ /// Custom user added source.
+ ///
+ ///
+ ///
+ public ProgramSource(string location, bool enabled)
+ {
+ Location = location;
+ Enabled = enabled;
+ UniqueIdentifier = location;
+ }
+
+ public ProgramSource(ProgramSource source)
+ {
+ Location = source.Location;
+ Name = source.Name;
+ Enabled = source.Enabled;
+ UniqueIdentifier = source.UniqueIdentifier;
+ }
+
+ public ProgramSource(IProgram source)
+ {
+ Location = source.Location;
+ Name = source.Name;
+ Enabled = source.Enabled;
+ UniqueIdentifier = source.UniqueIdentifier;
+ }
+
+ public override bool Equals(object obj)
+ {
+ return obj is ProgramSource other && other.UniqueIdentifier == this.UniqueIdentifier;
+ }
+
+ public bool Equals(IProgram program)
+ {
+ return program != null && program.UniqueIdentifier == this.UniqueIdentifier;
+ }
+
+ public static bool operator ==(ProgramSource a, ProgramSource b)
+ {
+ return a is not null && a.Equals(b);
+ }
+
+ public static bool operator !=(ProgramSource a, ProgramSource b)
+ {
+ return !(a == b);
+ }
+
+ public override int GetHashCode()
+ {
+ return HashCode.Combine(uid);
+ }
+ }
+
+ public class DisabledProgramSource : ProgramSource
+ {
+ public DisabledProgramSource() { }
+
+ public DisabledProgramSource(string location) : base(location, false) { }
+
+ public DisabledProgramSource(ProgramSource source) : base(source)
+ {
+ Enabled = false;
+ }
+
+ public DisabledProgramSource(IProgram program) : base(program)
+ {
+ Enabled = false;
+ }
+ }
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index 1a31e8c2833..0c4892abc58 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -1,4 +1,4 @@
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
@@ -147,7 +147,7 @@ private void DeleteProgramSources(List itemsToDelete)
private void btnEditProgramSource_OnClick(object sender, RoutedEventArgs e)
{
- var selectedProgramSource = programSourceView.SelectedItem as Settings.ProgramSource;
+ var selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
if (selectedProgramSource != null)
{
var add = new AddProgramSource(selectedProgramSource, _settings);
@@ -360,4 +360,4 @@ private void Row_OnClick(object sender, RoutedEventArgs e)
}
}
}
-}
\ No newline at end of file
+}
From c85af888f938326304d7ccfc0c4ffdee328935b6 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 20 Oct 2022 16:31:26 +0800
Subject: [PATCH 10/58] Make UID lowercase
---
.../Programs/IProgram.cs | 2 +-
.../Programs/UWP.cs | 3 ++-
.../Programs/Win32.cs | 20 ++++++++++++++-----
3 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/IProgram.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/IProgram.cs
index d4c96e5b730..9ddd84f2636 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/IProgram.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/IProgram.cs
@@ -6,7 +6,7 @@ public interface IProgram
{
List ContextMenus(IPublicAPI api);
Result Result(string query, IPublicAPI api);
- string UniqueIdentifier { get; set; }
+ string UniqueIdentifier { get; set; } // get should guarantee lowercase
string Name { get; }
string Location { get; }
bool Enabled { get; }
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
index ad7387f107f..9f270d2e17a 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
@@ -298,7 +298,7 @@ public override int GetHashCode()
public class Application : IProgram
{
public string AppListEntry { get; set; }
- public string UniqueIdentifier { get; set; }
+ public string UniqueIdentifier { get => _uid; set => _uid = value.ToLowerInvariant(); }
public string DisplayName { get; set; }
public string Description { get; set; }
public string UserModelId { get; set; }
@@ -317,6 +317,7 @@ public class Application : IProgram
public Application() { }
+ private string _uid = string.Empty;
public Result Result(string query, IPublicAPI api)
{
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index 6a8b232e94e..428d36c6e3c 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -17,6 +17,7 @@
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Channels;
+using Flow.Launcher.Plugin.Program.Views.Models;
namespace Flow.Launcher.Plugin.Program.Programs
{
@@ -24,9 +25,16 @@ namespace Flow.Launcher.Plugin.Program.Programs
public class Win32 : IProgram, IEquatable
{
public string Name { get; set; }
- public string UniqueIdentifier { get; set; }
+ public string UniqueIdentifier { get => _uid; set => _uid = value.ToLowerInvariant(); }
public string IcoPath { get; set; }
- public string FullPath { get; set; }
+ public string FullPath {
+ get => _fullPath;
+ set
+ {
+ _fullPath = value;
+ _uid = value.ToLowerInvariant();
+ }
+ }
public string LnkResolvedPath { get; set; }
public string ParentDirectory { get; set; }
public string ExecutableName { get; set; }
@@ -37,6 +45,8 @@ public class Win32 : IProgram, IEquatable
private const string ShortcutExtension = "lnk";
private const string ExeExtension = "exe";
+ private string _uid = string.Empty;
+ private string _fullPath = string.Empty;
private static readonly Win32 Default = new Win32()
{
@@ -47,7 +57,7 @@ public class Win32 : IProgram, IEquatable
LnkResolvedPath = null,
ParentDirectory = string.Empty,
ExecutableName = null,
- UniqueIdentifier = string.Empty,
+ //UniqueIdentifier = string.Empty,
Valid = false,
Enabled = false
};
@@ -208,7 +218,7 @@ private static Win32 Win32Program(string path)
Name = Path.GetFileNameWithoutExtension(path),
IcoPath = path,
FullPath = path,
- UniqueIdentifier = path,
+ //UniqueIdentifier = path,
ParentDirectory = Directory.GetParent(path).FullName,
Description = string.Empty,
Valid = true,
@@ -333,7 +343,7 @@ private static string Extension(string path)
}
}
- private static IEnumerable UnregisteredPrograms(List sources, string[] suffixes)
+ private static IEnumerable UnregisteredPrograms(List sources, string[] suffixes)
{
var paths = ExceptDisabledSource(sources.Where(s => Directory.Exists(s.Location) && s.Enabled)
.SelectMany(s => ProgramPaths(s.Location, suffixes)), x => x)
From 4f2dc062d23167f9d66f1f45b618a33620bef713 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 20 Oct 2022 16:36:58 +0800
Subject: [PATCH 11/58] fix
---
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index f0a53ed7758..1dcaa01ae3d 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -11,6 +11,7 @@
using Flow.Launcher.Infrastructure.Storage;
using Flow.Launcher.Plugin.Program.Programs;
using Flow.Launcher.Plugin.Program.Views;
+using Flow.Launcher.Plugin.Program.Views.Models;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
@@ -205,7 +206,7 @@ private void DisableProgram(IProgram programToDelete)
_settings.DisabledProgramSources
.Add(
- new Settings.DisabledProgramSource
+ new DisabledProgramSource
{
Name = programToDelete.Name,
Location = programToDelete.Location,
From db67d3b925875c460e17e08961aa5a611dd5daae Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 20 Oct 2022 16:47:49 +0800
Subject: [PATCH 12/58] Remove unnecessary Count()
---
.../Views/Commands/ProgramSettingDisplay.cs | 7 ++++---
.../Views/Models/ProgramSource.cs | 2 +-
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
index 5be38a7b350..c261065f6f4 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
@@ -133,14 +133,15 @@ internal static void RemoveDisabledFromSettings(this List list)
internal static bool IsReindexRequired(this List selectedItems)
{
- if (selectedItems.Where(t1 => t1.Enabled && !Main._uwps.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)).Count() > 0
- && selectedItems.Where(t1 => t1.Enabled && !Main._win32s.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)).Count() > 0)
+ // Not in cache
+ if (selectedItems.Any(t1 => t1.Enabled && !Main._uwps.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier))
+ && selectedItems.Any(t1 => t1.Enabled && !Main._win32s.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)))
return true;
// ProgramSources holds list of user added directories,
// so when we enable/disable we need to reindex to show/not show the programs
// that are found in those directories.
- if (selectedItems.Where(t1 => Main._settings.ProgramSources.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)).Count() > 0)
+ if (selectedItems.Any(t1 => Main._settings.ProgramSources.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier)))
return true;
return false;
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
index e42552696ea..5f4ec90f76d 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
@@ -28,7 +28,7 @@ public class ProgramSource
public ProgramSource()
{
- }
+ } // TODO Remove
///
/// Custom user added source.
From 4da7a5e078d783a832b54925ce934851d514933a Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 20 Oct 2022 16:55:14 +0800
Subject: [PATCH 13/58] Remove DisabledProgramSource()
---
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 11 +----------
.../Views/Commands/ProgramSettingDisplay.cs | 10 +---------
.../Views/Models/ProgramSource.cs | 12 +-----------
3 files changed, 3 insertions(+), 30 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index 1dcaa01ae3d..a1916f58a90 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -204,16 +204,7 @@ private void DisableProgram(IProgram programToDelete)
_win32s.FirstOrDefault(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
.Enabled = false;
- _settings.DisabledProgramSources
- .Add(
- new DisabledProgramSource
- {
- Name = programToDelete.Name,
- Location = programToDelete.Location,
- UniqueIdentifier = programToDelete.UniqueIdentifier,
- Enabled = false
- }
- );
+ _settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
}
public static void StartProcess(Func runProcess, ProcessStartInfo info)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
index c261065f6f4..5e2a288f7f1 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
@@ -107,15 +107,7 @@ internal static void StoreDisabledInSettings(this List list)
&& !Main._settings.DisabledProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
.ToList()
.ForEach(x => Main._settings.DisabledProgramSources
- .Add(
- new DisabledProgramSource
- {
- Name = x.Name,
- Location = x.Location,
- UniqueIdentifier = x.UniqueIdentifier,
- Enabled = false
- }
- ));
+ .Add(new DisabledProgramSource(x)));
}
internal static void RemoveDisabledFromSettings(this List list)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
index 5f4ec90f76d..f562d992b54 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
@@ -68,16 +68,6 @@ public bool Equals(IProgram program)
return program != null && program.UniqueIdentifier == this.UniqueIdentifier;
}
- public static bool operator ==(ProgramSource a, ProgramSource b)
- {
- return a is not null && a.Equals(b);
- }
-
- public static bool operator !=(ProgramSource a, ProgramSource b)
- {
- return !(a == b);
- }
-
public override int GetHashCode()
{
return HashCode.Combine(uid);
@@ -86,7 +76,7 @@ public override int GetHashCode()
public class DisabledProgramSource : ProgramSource
{
- public DisabledProgramSource() { }
+ //public DisabledProgramSource() { }
public DisabledProgramSource(string location) : base(location, false) { }
From bc54b07fdc575b386c1b36acbfcd724aa195103c Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 20 Oct 2022 17:00:18 +0800
Subject: [PATCH 14/58] manually set win32 uid when construct
---
.../Flow.Launcher.Plugin.Program/Programs/Win32.cs | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index 428d36c6e3c..4e6a84f5713 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -27,14 +27,7 @@ public class Win32 : IProgram, IEquatable
public string Name { get; set; }
public string UniqueIdentifier { get => _uid; set => _uid = value.ToLowerInvariant(); }
public string IcoPath { get; set; }
- public string FullPath {
- get => _fullPath;
- set
- {
- _fullPath = value;
- _uid = value.ToLowerInvariant();
- }
- }
+ public string FullPath { get; set; }
public string LnkResolvedPath { get; set; }
public string ParentDirectory { get; set; }
public string ExecutableName { get; set; }
@@ -46,7 +39,6 @@ public string FullPath {
private const string ShortcutExtension = "lnk";
private const string ExeExtension = "exe";
private string _uid = string.Empty;
- private string _fullPath = string.Empty;
private static readonly Win32 Default = new Win32()
{
@@ -57,7 +49,7 @@ public string FullPath {
LnkResolvedPath = null,
ParentDirectory = string.Empty,
ExecutableName = null,
- //UniqueIdentifier = string.Empty,
+ UniqueIdentifier = string.Empty,
Valid = false,
Enabled = false
};
@@ -218,7 +210,7 @@ private static Win32 Win32Program(string path)
Name = Path.GetFileNameWithoutExtension(path),
IcoPath = path,
FullPath = path,
- //UniqueIdentifier = path,
+ UniqueIdentifier = path,
ParentDirectory = Directory.GetParent(path).FullName,
Description = string.Empty,
Valid = true,
From 7832ab689801aaf689ad4b953e629ea48c949dd1 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 20 Oct 2022 17:15:16 +0800
Subject: [PATCH 15/58] Remove ProgramSource()
---
.../AddProgramSource.xaml.cs | 6 +--
.../Views/Commands/ProgramSettingDisplay.cs | 44 ++-----------------
.../Views/Models/ProgramSource.cs | 6 +--
.../Views/ProgramSetting.xaml.cs | 8 +---
4 files changed, 9 insertions(+), 55 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index 25bc3d67055..4276023e638 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -59,11 +59,7 @@ private void ButtonAdd_OnClick(object sender, RoutedEventArgs e)
{
if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == Directory.Text))
{
- var source = new ProgramSource
- {
- Location = Directory.Text,
- UniqueIdentifier = Directory.Text
- };
+ var source = new ProgramSource(Directory.Text);
_settings.ProgramSources.Insert(0, source);
ProgramSetting.ProgramSettingDisplayList.Add(source);
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
index 5e2a288f7f1..06e72176dc8 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
@@ -13,16 +13,7 @@ internal static List LoadProgramSources(this List
{
var list = new List();
- programSources.ForEach(x => list
- .Add(
- new ProgramSource
- {
- Enabled = x.Enabled,
- Location = x.Location,
- Name = x.Name,
- UniqueIdentifier = x.UniqueIdentifier
- }
- ));
+ programSources.ForEach(x => list.Add(new ProgramSource(x)));
// Even though these are disabled, we still want to display them so users can enable later on
Main._settings
@@ -32,16 +23,7 @@ internal static List LoadProgramSources(this List
.Any(x => t1.UniqueIdentifier == x.UniqueIdentifier))
.Select(x => x)
.ToList()
- .ForEach(x => list
- .Add(
- new ProgramSource
- {
- Enabled = x.Enabled,
- Location = x.Location,
- Name = x.Name,
- UniqueIdentifier = x.UniqueIdentifier
- }
- ));
+ .ForEach(x => list.Add(new ProgramSource(x)));
return list;
}
@@ -51,30 +33,12 @@ internal static void LoadAllApplications(this List list)
Main._win32s
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
.ToList()
- .ForEach(t1 => ProgramSetting.ProgramSettingDisplayList
- .Add(
- new ProgramSource
- {
- Name = t1.Name,
- Location = t1.ParentDirectory,
- UniqueIdentifier = t1.UniqueIdentifier,
- Enabled = t1.Enabled
- }
- ));
+ .ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource(t1)));
Main._uwps
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
.ToList()
- .ForEach(t1 => ProgramSetting.ProgramSettingDisplayList
- .Add(
- new ProgramSource
- {
- Name = t1.DisplayName,
- Location = t1.Package.Location,
- UniqueIdentifier = t1.UniqueIdentifier,
- Enabled = t1.Enabled
- }
- ));
+ .ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource(t1)));
}
internal static void SetProgramSourcesStatus(this List list, List selectedProgramSourcesToDisable, bool status)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
index f562d992b54..7d7ca89021c 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
@@ -26,16 +26,14 @@ public class ProgramSource
///
public string UniqueIdentifier { get => uid; set => uid = value.ToLowerInvariant(); }
- public ProgramSource()
- {
- } // TODO Remove
+ //public ProgramSource() {}
///
/// Custom user added source.
///
///
///
- public ProgramSource(string location, bool enabled)
+ public ProgramSource(string location, bool enabled=true)
{
Location = location;
Enabled = enabled;
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index 0c4892abc58..364977b71ac 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -199,13 +199,9 @@ private void programSourceView_Drop(object sender, DragEventArgs e)
{
foreach (string directory in directories)
{
- if (Directory.Exists(directory) && !ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == directory))
+ if (Directory.Exists(directory) && !ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == directory.ToLowerInvariant()))
{
- var source = new ProgramSource
- {
- Location = directory,
- UniqueIdentifier = directory
- };
+ var source = new ProgramSource(directory);
directoriesToAdd.Add(source);
}
From cc1e32333cb0a0e6c00c7c7e61ce9388e201c05e Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 20 Oct 2022 17:21:36 +0800
Subject: [PATCH 16/58] Remove unnecessary Count()
---
.../Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index 364977b71ac..645c8d98441 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -207,7 +207,7 @@ private void programSourceView_Drop(object sender, DragEventArgs e)
}
}
- if (directoriesToAdd.Count() > 0)
+ if (directoriesToAdd.Count > 0)
{
directoriesToAdd.ForEach(x => _settings.ProgramSources.Add(x));
directoriesToAdd.ForEach(x => ProgramSettingDisplayList.Add(x));
@@ -231,7 +231,7 @@ private void btnProgramSourceStatus_OnClick(object sender, RoutedEventArgs e)
.SelectedItems.Cast()
.ToList();
- if (selectedItems.Count() == 0)
+ if (selectedItems.Count == 0)
{
string msg = context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source");
MessageBox.Show(msg);
From 8a488ad88e05bbb617e8f4156408838ceb02f4e3 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 20 Oct 2022 17:22:31 +0800
Subject: [PATCH 17/58] CA1829
---
.../Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index 645c8d98441..364977b71ac 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -207,7 +207,7 @@ private void programSourceView_Drop(object sender, DragEventArgs e)
}
}
- if (directoriesToAdd.Count > 0)
+ if (directoriesToAdd.Count() > 0)
{
directoriesToAdd.ForEach(x => _settings.ProgramSources.Add(x));
directoriesToAdd.ForEach(x => ProgramSettingDisplayList.Add(x));
@@ -231,7 +231,7 @@ private void btnProgramSourceStatus_OnClick(object sender, RoutedEventArgs e)
.SelectedItems.Cast()
.ToList();
- if (selectedItems.Count == 0)
+ if (selectedItems.Count() == 0)
{
string msg = context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source");
MessageBox.Show(msg);
From 463f417a42670ae0d15f840eb782d14ae7be0b3b Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 20 Oct 2022 18:16:46 +0800
Subject: [PATCH 18/58] bugfix
---
.../Views/Models/ProgramSource.cs | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
index 7d7ca89021c..a2cdb44f13b 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
@@ -16,7 +16,7 @@ public class ProgramSource
{
private string name;
- public string Location;
+ public string Location { get; set; }
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
public bool Enabled { get; set; } = true;
private string uid { get; set; }
@@ -26,13 +26,13 @@ public class ProgramSource
///
public string UniqueIdentifier { get => uid; set => uid = value.ToLowerInvariant(); }
- //public ProgramSource() {}
+ public ProgramSource() { } // only for json deserialization
///
- /// Custom user added source.
+ /// Add source by location
///
- ///
- ///
+ /// location of program source
+ /// enabled
public ProgramSource(string location, bool enabled=true)
{
Location = location;
@@ -74,7 +74,7 @@ public override int GetHashCode()
public class DisabledProgramSource : ProgramSource
{
- //public DisabledProgramSource() { }
+ public DisabledProgramSource() { } // only for json deserialization
public DisabledProgramSource(string location) : base(location, false) { }
From cbcae41d0a4ada953851a8974df8cf6c362155fa Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 20 Oct 2022 20:54:16 +0800
Subject: [PATCH 19/58] bugfix
---
Plugins/Flow.Launcher.Plugin.Program/Programs/IProgram.cs | 2 +-
Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs | 4 +---
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/IProgram.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/IProgram.cs
index 9ddd84f2636..d4c96e5b730 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/IProgram.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/IProgram.cs
@@ -6,7 +6,7 @@ public interface IProgram
{
List ContextMenus(IPublicAPI api);
Result Result(string query, IPublicAPI api);
- string UniqueIdentifier { get; set; } // get should guarantee lowercase
+ string UniqueIdentifier { get; set; }
string Name { get; }
string Location { get; }
bool Enabled { get; }
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
index 9f270d2e17a..4ca6c987747 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
@@ -298,7 +298,7 @@ public override int GetHashCode()
public class Application : IProgram
{
public string AppListEntry { get; set; }
- public string UniqueIdentifier { get => _uid; set => _uid = value.ToLowerInvariant(); }
+ public string UniqueIdentifier { get; set; }
public string DisplayName { get; set; }
public string Description { get; set; }
public string UserModelId { get; set; }
@@ -317,8 +317,6 @@ public class Application : IProgram
public Application() { }
- private string _uid = string.Empty;
-
public Result Result(string query, IPublicAPI api)
{
string title;
From e72810ca2c45acbe6a660d466bee8204545f5d04 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 20 Oct 2022 22:47:28 +0800
Subject: [PATCH 20/58] Temporary fix for sharing violation
Sharing violation may occur when reindexing after deleting user added source, causing some uwp programs can't be indexed. Don't actually know why it happens. Try to fix it.
---
Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
index 4ca6c987747..8c14335f947 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
@@ -60,8 +60,8 @@ private void InitializeAppInfo()
InitPackageVersion(namespaces);
const uint noAttribute = 0x80;
- const Stgm exclusiveRead = Stgm.Read | Stgm.ShareExclusive;
- var hResult = SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out IStream stream);
+ const Stgm nonExclusiveRead = Stgm.Read | Stgm.ShareDenyNone;
+ var hResult = SHCreateStreamOnFileEx(path, nonExclusiveRead, noAttribute, false, null, out IStream stream);
if (hResult == Hresult.Ok)
{
@@ -85,7 +85,7 @@ private void InitializeAppInfo()
Apps = new List().ToArray();
}
- if (Marshal.ReleaseComObject(stream) > 0)
+ if (stream != null && Marshal.ReleaseComObject(stream) > 0)
{
Log.Error("Flow.Launcher.Plugin.Program.Programs.UWP", "AppxManifest.xml was leaked");
}
@@ -784,6 +784,7 @@ private enum Stgm : uint
{
Read = 0x0,
ShareExclusive = 0x10,
+ ShareDenyNone = 0x40
}
private enum Hresult : uint
From 02b23756ff291003fc95d4f9292deea0b3dbb44d Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Fri, 21 Oct 2022 18:34:49 +0800
Subject: [PATCH 21/58] set AppxPackageHelper to static
---
.../Programs/AppxPackageHelper.cs | 7 ++++---
Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs | 3 +--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/AppxPackageHelper.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/AppxPackageHelper.cs
index e48f30757be..654566ffe99 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/AppxPackageHelper.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/AppxPackageHelper.cs
@@ -9,12 +9,13 @@ namespace Flow.Launcher.Plugin.Program.Programs
{
public class AppxPackageHelper
{
+ private static readonly IAppxFactory appxFactory = (IAppxFactory)new AppxFactory();
+
// This function returns a list of attributes of applications
- public List getAppsFromManifest(IStream stream)
+ public static List GetAppsFromManifest(IStream stream)
{
List apps = new List();
- var appxFactory = new AppxFactory();
- var reader = ((IAppxFactory)appxFactory).CreateManifestReader(stream);
+ var reader = appxFactory.CreateManifestReader(stream);
var manifestApps = reader.GetApplications();
while (manifestApps.GetHasCurrent())
{
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
index 8c14335f947..e8697856d7c 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
@@ -53,7 +53,6 @@ public UWP(Package package)
private void InitializeAppInfo()
{
- AppxPackageHelper _helper = new AppxPackageHelper();
var path = Path.Combine(Location, "AppxManifest.xml");
var namespaces = XmlNamespaces(path);
@@ -67,7 +66,7 @@ private void InitializeAppInfo()
{
var apps = new List();
- List _apps = _helper.getAppsFromManifest(stream);
+ List _apps = AppxPackageHelper.GetAppsFromManifest(stream);
foreach (var _app in _apps)
{
var app = new Application(_app, this);
From 3362d1cba711d1d9f938c346103c07a6781c9462 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Fri, 21 Oct 2022 18:35:10 +0800
Subject: [PATCH 22/58] CA1825
---
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 12 +++---------
Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs | 12 +++---------
2 files changed, 6 insertions(+), 18 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index a1916f58a90..d09a8bd805d 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -83,13 +83,9 @@ public async Task InitAsync(PluginInitContext context)
Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|Preload programs cost", () =>
{
_win32Storage = new BinaryStorage("Win32");
- _win32s = _win32Storage.TryLoad(new Win32[]
- {
- });
+ _win32s = _win32Storage.TryLoad(Array.Empty());
_uwpStorage = new BinaryStorage("UWP");
- _uwps = _uwpStorage.TryLoad(new UWP.Application[]
- {
- });
+ _uwps = _uwpStorage.TryLoad(Array.Empty());
});
Log.Info($"|Flow.Launcher.Plugin.Program.Main|Number of preload win32 programs <{_win32s.Length}>");
Log.Info($"|Flow.Launcher.Plugin.Program.Main|Number of preload uwps <{_uwps.Length}>");
@@ -124,9 +120,7 @@ public static void IndexUwpPrograms()
{
var windows10 = new Version(10, 0);
var support = Environment.OSVersion.Version.Major >= windows10.Major;
- var applications = support ? UWP.All() : new UWP.Application[]
- {
- };
+ var applications = support ? UWP.All() : Array.Empty();
_uwps = applications;
ResetCache();
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
index e8697856d7c..764aa0a6313 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
@@ -109,9 +109,7 @@ private string[] XmlNamespaces(string path)
ProgramLogger.LogException($"|UWP|XmlNamespaces|{path}" +
$"|Error occured while trying to get the XML from {path}", new ArgumentNullException());
- return new string[]
- {
- };
+ return Array.Empty();
}
}
@@ -184,9 +182,7 @@ public static Application[] All()
}
else
{
- return new Application[]
- {
- };
+ return Array.Empty();
}
}
@@ -232,9 +228,7 @@ private static IEnumerable CurrentUserPackages()
}
else
{
- return new Package[]
- {
- };
+ return Array.Empty();
}
}
From d92ea580b2ca9574e13dca7ad29f5d78420971af Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Fri, 21 Oct 2022 18:39:03 +0800
Subject: [PATCH 23/58] CA1822
---
Flow.Launcher.Test/Plugins/ProgramTest.cs | 2 +-
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 3 ++-
Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs | 4 ++--
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/Flow.Launcher.Test/Plugins/ProgramTest.cs b/Flow.Launcher.Test/Plugins/ProgramTest.cs
index a0d2243ce75..e3a05f484f0 100644
--- a/Flow.Launcher.Test/Plugins/ProgramTest.cs
+++ b/Flow.Launcher.Test/Plugins/ProgramTest.cs
@@ -19,7 +19,7 @@ public void WhenGivenPriReferenceValueShouldReturnCorrectFormat(string packageNa
var app = new UWP.Application();
// Act
- var result = app.FormattedPriReferenceValue(packageName, rawPriReferenceValue);
+ var result = UWP.Application.FormattedPriReferenceValue(packageName, rawPriReferenceValue);
// Assert
Assert.IsTrue(result == expectedFormat,
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index d09a8bd805d..c64cd74ec5c 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -185,7 +185,7 @@ public List LoadContextMenus(Result selectedResult)
return menuOptions;
}
- private void DisableProgram(IProgram programToDelete)
+ private static void DisableProgram(IProgram programToDelete)
{
if (_settings.DisabledProgramSources.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
return;
@@ -219,6 +219,7 @@ public async Task ReloadDataAsync()
{
await IndexProgramsAsync();
}
+
public void Dispose()
{
Win32.Dispose();
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
index 764aa0a6313..b2008c17868 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
@@ -91,7 +91,7 @@ private void InitializeAppInfo()
}
/// http://www.hanselman.com/blog/GetNamespacesFromAnXMLDocumentWithXPathDocumentAndLINQToXML.aspx
- private string[] XmlNamespaces(string path)
+ private static string[] XmlNamespaces(string path)
{
XDocument z = XDocument.Load(path);
if (z.Root != null)
@@ -536,7 +536,7 @@ internal string ResourceFromPri(string packageFullName, string packageName, stri
}
}
- public string FormattedPriReferenceValue(string packageName, string rawPriReferenceValue)
+ public static string FormattedPriReferenceValue(string packageName, string rawPriReferenceValue)
{
const string prefix = "ms-resource:";
From 84b1c26369da18326d7877c525463de73c6441d8 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Sat, 22 Oct 2022 00:28:17 +0800
Subject: [PATCH 24/58] Fix image file usage
See https://github.com/microsoft/PowerToys/pull/5109
---
Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
index b2008c17868..948e9b43704 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
@@ -18,7 +18,6 @@
using Rect = System.Windows.Rect;
using Flow.Launcher.Plugin.SharedModels;
using Flow.Launcher.Infrastructure.Logger;
-using System.Runtime.Versioning;
using System.Threading.Channels;
namespace Flow.Launcher.Plugin.Program.Programs
@@ -688,9 +687,14 @@ public ImageSource Logo()
private BitmapImage ImageFromPath(string path)
{
+ // TODO: Consider using infrastructure.image.imageloader?
if (File.Exists(path))
{
- var image = new BitmapImage(new Uri(path));
+ var image = new BitmapImage();
+ image.BeginInit();
+ image.UriSource = new Uri(path);
+ image.CacheOption = BitmapCacheOption.OnLoad;
+ image.EndInit();
return image;
}
else
From 31453e59424336e09fbda61e9658e39fb0d6024a Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Mon, 24 Oct 2022 14:31:19 +0800
Subject: [PATCH 25/58] Review update
---
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 4 ++--
.../Views/Models/ProgramSource.cs | 6 ++++--
.../Views/ProgramSetting.xaml.cs | 3 ++-
3 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index c64cd74ec5c..9a4e8e5a354 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -191,11 +191,11 @@ private static void DisableProgram(IProgram programToDelete)
return;
if (_uwps.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
- _uwps.FirstOrDefault(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
+ _uwps.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
.Enabled = false;
if (_win32s.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
- _win32s.FirstOrDefault(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
+ _win32s.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
.Enabled = false;
_settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
index a2cdb44f13b..45b706a9b67 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
@@ -19,12 +19,12 @@ public class ProgramSource
public string Location { get; set; }
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
public bool Enabled { get; set; } = true;
- private string uid { get; set; }
///
- /// Guranteed lowercase.
+ /// Guaranteed lowercase.
///
public string UniqueIdentifier { get => uid; set => uid = value.ToLowerInvariant(); }
+ private string uid { get; set; }
public ProgramSource() { } // only for json deserialization
@@ -74,6 +74,8 @@ public override int GetHashCode()
public class DisabledProgramSource : ProgramSource
{
+ public new bool Enabled { get; init; }
+
public DisabledProgramSource() { } // only for json deserialization
public DisabledProgramSource(string location) : base(location, false) { }
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index 364977b71ac..a1c85087cb9 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -199,7 +199,8 @@ private void programSourceView_Drop(object sender, DragEventArgs e)
{
foreach (string directory in directories)
{
- if (Directory.Exists(directory) && !ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == directory.ToLowerInvariant()))
+ if (Directory.Exists(directory)
+ && !ProgramSettingDisplayList.Any(x => x.UniqueIdentifier.Equals(directory, System.StringComparison.InvariantCultureIgnoreCase)))
{
var source = new ProgramSource(directory);
From 9bf1645a4050c34852bf3473a5c01776de1a67b8 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Mon, 24 Oct 2022 23:06:37 +0800
Subject: [PATCH 26/58] Use String.Equals
---
Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index 4276023e638..f41fd484bf2 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -57,7 +57,7 @@ private void ButtonAdd_OnClick(object sender, RoutedEventArgs e)
}
if (_editing == null)
{
- if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == Directory.Text))
+ if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier.Equals(Directory.Text, System.StringComparison.InvariantCultureIgnoreCase)))
{
var source = new ProgramSource(Directory.Text);
From 8a4ff3bada821100b7032f1b2810f8dfcdae8b35 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Mon, 24 Oct 2022 23:16:09 +0800
Subject: [PATCH 27/58] use shallow copy
---
Plugins/Flow.Launcher.Plugin.Program/Settings.cs | 2 +-
.../Views/Commands/ProgramSettingDisplay.cs | 4 +---
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
index af5b7bc7d2c..3afb499f55e 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
@@ -9,7 +9,7 @@ public class Settings
{
public DateTime LastIndexTime { get; set; }
public List ProgramSources { get; set; } = new List();
- public List DisabledProgramSources { get; set; } = new List();
+ public List DisabledProgramSources { get; set; } = new List(); // For disabled single programs
public string[] ProgramSuffixes { get; set; } = {"appref-ms", "exe", "lnk"};
public bool EnableStartMenuSource { get; set; } = true;
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
index 06e72176dc8..6fb6ce8f4bf 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
@@ -11,9 +11,7 @@ internal static class ProgramSettingDisplay
{
internal static List LoadProgramSources(this List programSources)
{
- var list = new List();
-
- programSources.ForEach(x => list.Add(new ProgramSource(x)));
+ var list = new List(programSources);
// Even though these are disabled, we still want to display them so users can enable later on
Main._settings
From cb295bbd9053a743b696c9c1b31c376d3b52d078 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Mon, 24 Oct 2022 23:26:41 +0800
Subject: [PATCH 28/58] Refactor
---
.../Views/Commands/ProgramSettingDisplay.cs | 27 +++++++------------
.../Views/ProgramSetting.xaml.cs | 12 ++++-----
2 files changed, 16 insertions(+), 23 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
index 6fb6ce8f4bf..4ebca8cf3fb 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
@@ -9,24 +9,17 @@ namespace Flow.Launcher.Plugin.Program.Views.Commands
{
internal static class ProgramSettingDisplay
{
- internal static List LoadProgramSources(this List programSources)
+ internal static List LoadProgramSources()
{
- var list = new List(programSources);
-
// Even though these are disabled, we still want to display them so users can enable later on
- Main._settings
- .DisabledProgramSources
- .Where(t1 => !Main._settings
- .ProgramSources // program sourcces added above already, so exlcude
- .Any(x => t1.UniqueIdentifier == x.UniqueIdentifier))
- .Select(x => x)
- .ToList()
- .ForEach(x => list.Add(new ProgramSource(x)));
-
- return list;
+ return Main._settings
+ .DisabledProgramSources
+ .Select(s => new ProgramSource(s))
+ .Union(Main._settings.ProgramSources)
+ .ToList();
}
- internal static void LoadAllApplications(this List list)
+ internal static void DisplayAllPrograms()
{
Main._win32s
.Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
@@ -39,7 +32,7 @@ internal static void LoadAllApplications(this List list)
.ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource(t1)));
}
- internal static void SetProgramSourcesStatus(this List list, List selectedProgramSourcesToDisable, bool status)
+ internal static void SetProgramSourcesStatus(List selectedProgramSourcesToDisable, bool status)
{
ProgramSetting.ProgramSettingDisplayList
.Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
@@ -57,7 +50,7 @@ internal static void SetProgramSourcesStatus(this List list, List
.ForEach(t1 => t1.Enabled = status);
}
- internal static void StoreDisabledInSettings(this List list)
+ internal static void StoreDisabledInSettings()
{
Main._settings.ProgramSources
.Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && !x.Enabled))
@@ -72,7 +65,7 @@ internal static void StoreDisabledInSettings(this List list)
.Add(new DisabledProgramSource(x)));
}
- internal static void RemoveDisabledFromSettings(this List list)
+ internal static void RemoveDisabledFromSettings()
{
Main._settings.ProgramSources
.Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled))
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index a1c85087cb9..eaf953f9aaf 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -88,7 +88,7 @@ public ProgramSetting(PluginInitContext context, Settings settings, Win32[] win3
private void Setting_Loaded(object sender, RoutedEventArgs e)
{
- ProgramSettingDisplayList = _settings.ProgramSources.LoadProgramSources();
+ ProgramSettingDisplayList = ProgramSettingDisplay.LoadProgramSources();
programSourceView.ItemsSource = ProgramSettingDisplayList;
ViewRefresh();
@@ -221,7 +221,7 @@ private void programSourceView_Drop(object sender, DragEventArgs e)
private void btnLoadAllProgramSource_OnClick(object sender, RoutedEventArgs e)
{
- ProgramSettingDisplayList.LoadAllApplications();
+ ProgramSettingDisplay.DisplayAllPrograms();
ViewRefresh();
}
@@ -256,15 +256,15 @@ private void btnProgramSourceStatus_OnClick(object sender, RoutedEventArgs e)
}
else if (IsSelectedRowStatusEnabledMoreOrEqualThanDisabled(selectedItems))
{
- ProgramSettingDisplayList.SetProgramSourcesStatus(selectedItems, false);
+ ProgramSettingDisplay.SetProgramSourcesStatus(selectedItems, false);
- ProgramSettingDisplayList.StoreDisabledInSettings();
+ ProgramSettingDisplay.StoreDisabledInSettings();
}
else
{
- ProgramSettingDisplayList.SetProgramSourcesStatus(selectedItems, true);
+ ProgramSettingDisplay.SetProgramSourcesStatus(selectedItems, true);
- ProgramSettingDisplayList.RemoveDisabledFromSettings();
+ ProgramSettingDisplay.RemoveDisabledFromSettings();
}
if (selectedItems.IsReindexRequired())
From d7d863547c1b103b4f91ae4ba399305bde16cc3b Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Mon, 24 Oct 2022 23:31:02 +0800
Subject: [PATCH 29/58] comment
---
Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index 49e066754b2..8b934528e3e 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -78,7 +78,7 @@ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
else
{
_updating.Location = path;
- _updating.Enabled = Chkbox.IsChecked ?? true;
+ _updating.Enabled = Chkbox.IsChecked ?? true; // Fixme, need to add to disabled source if not custom source
}
DialogResult = true;
From cd6c4ddb5e7a5702a05b97d83f8cd3d65444ad3e Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Mon, 24 Oct 2022 23:31:53 +0800
Subject: [PATCH 30/58] revert rename
---
.../Flow.Launcher.Plugin.Program/AddProgramSource.xaml | 2 +-
.../Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
index f349a3a38a5..39d5f8a4e19 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml
@@ -99,7 +99,7 @@
DockPanel.Dock="Right"
Content="{DynamicResource flowlauncher_plugin_program_browse}" />
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index 8b934528e3e..e5ea2eda267 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -21,7 +21,7 @@ public AddProgramSource(PluginInitContext context, Settings settings)
InitializeComponent();
_context = context;
_settings = settings;
- tbDirectory.Focus();
+ Directory.Focus();
Chkbox.IsChecked = true;
update = false;
btnAdd.Content = _context.API.GetTranslation("flowlauncher_plugin_program_add");
@@ -34,7 +34,7 @@ public AddProgramSource(Settings.ProgramSource source, Settings settings)
_settings = settings;
update = true;
Chkbox.IsChecked = _updating.Enabled;
- tbDirectory.Text = _updating.Location;
+ Directory.Text = _updating.Location;
}
private void BrowseButton_Click(object sender, RoutedEventArgs e)
@@ -43,7 +43,7 @@ private void BrowseButton_Click(object sender, RoutedEventArgs e)
DialogResult result = dialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.OK)
{
- tbDirectory.Text = dialog.SelectedPath;
+ Directory.Text = dialog.SelectedPath;
}
}
@@ -54,7 +54,7 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
{
- string path = tbDirectory.Text;
+ string path = Directory.Text;
if (!System.IO.Directory.Exists(path))
{
System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_invalid_path"));
From 440337ba2205dee7fa5ef8c629a94d4a8e7dd2b6 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 25 Oct 2022 00:09:20 +0800
Subject: [PATCH 31/58] bugfix
---
.../Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs | 2 --
1 file changed, 2 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
index 45b706a9b67..5deb6b3967b 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
@@ -74,8 +74,6 @@ public override int GetHashCode()
public class DisabledProgramSource : ProgramSource
{
- public new bool Enabled { get; init; }
-
public DisabledProgramSource() { } // only for json deserialization
public DisabledProgramSource(string location) : base(location, false) { }
From 1aa3668ea413d20d50491588ea1cfc15567bfbfd Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 25 Oct 2022 01:13:36 +0800
Subject: [PATCH 32/58] bugfix
---
Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs | 3 +--
Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs | 8 ++++----
2 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
index 948e9b43704..6ea927cb773 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
@@ -174,8 +174,7 @@ public static Application[] All()
var updatedListWithoutDisabledApps = applications
.Where(t1 => !Main._settings.DisabledProgramSources
- .Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
- .Select(x => x);
+ .Any(x => x.UniqueIdentifier == t1.UniqueIdentifier));
return updatedListWithoutDisabledApps.ToArray();
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index 4e6a84f5713..2c7b0c3ff3d 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -338,8 +338,8 @@ private static string Extension(string path)
private static IEnumerable UnregisteredPrograms(List sources, string[] suffixes)
{
var paths = ExceptDisabledSource(sources.Where(s => Directory.Exists(s.Location) && s.Enabled)
- .SelectMany(s => ProgramPaths(s.Location, suffixes)), x => x)
- .Distinct();
+ .SelectMany(s => ProgramPaths(s.Location, suffixes)))
+ .Distinct();
var programs = paths.Select(x => Extension(x) switch
{
@@ -452,9 +452,9 @@ private static Win32 GetProgramFromPath(string path)
return entry;
}
- public static IEnumerable ExceptDisabledSource(IEnumerable sources)
+ public static IEnumerable ExceptDisabledSource(IEnumerable paths)
{
- return ExceptDisabledSource(sources, x => x);
+ return ExceptDisabledSource(paths, x => x.ToLowerInvariant());
}
public static IEnumerable ExceptDisabledSource(IEnumerable sources,
From 0a19b02792775431c8e648c092f1d66e1fa82149 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 25 Oct 2022 14:41:46 +0800
Subject: [PATCH 33/58] Fix merge
---
.../AddProgramSource.xaml.cs | 12 ++++++------
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 18 +++++++++++++-----
2 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index a0e3754e883..1d2740cd793 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -27,14 +27,14 @@ public AddProgramSource(PluginInitContext context, Settings settings)
btnAdd.Content = _context.API.GetTranslation("flowlauncher_plugin_program_add");
}
- public AddProgramSource(ProgramSource edit, Settings settings)
+ public AddProgramSource(ProgramSource source, Settings settings)
{
InitializeComponent();
- _updating = source;
+ _editing = source;
_settings = settings;
update = true;
- Chkbox.IsChecked = _updating.Enabled;
- Directory.Text = _updating.Location;
+ Chkbox.IsChecked = _editing.Enabled;
+ Directory.Text = _editing.Location;
}
private void BrowseButton_Click(object sender, RoutedEventArgs e)
@@ -72,8 +72,8 @@ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
}
else
{
- _updating.Location = path;
- _updating.Enabled = Chkbox.IsChecked ?? true; // Fixme, need to add to disabled source if not custom source
+ _editing.Location = path;
+ _editing.Enabled = Chkbox.IsChecked ?? true; // Fixme, need to add to disabled source if not custom source
}
DialogResult = true;
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index 61efbb92363..cc368ab4b10 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -194,16 +194,24 @@ private static void DisableProgram(IProgram programToDelete)
{
_uwps.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
.Enabled = false;
-
+ var t1 = Task.Run(() =>
+ {
+ IndexWin32Programs();
+ _settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
+ _settings.LastIndexTime = DateTime.Today;
+ });
}
-
- if (_win32s.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
+ else if (_win32s.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
{
_win32s.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
.Enabled = false;
+ var t1 = Task.Run(() =>
+ {
+ IndexUwpPrograms();
+ _settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
+ _settings.LastIndexTime = DateTime.Today;
+ });
}
-
- _settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
}
public static void StartProcess(Func runProcess, ProcessStartInfo info)
From 2f9b19ddfcf481ef30cd797f9b4953c9a63390ca Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 25 Oct 2022 15:27:47 +0800
Subject: [PATCH 34/58] Fix 1356
---
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 4 ++--
.../Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs | 3 ++-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index cc368ab4b10..bf1014c44fa 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -194,10 +194,10 @@ private static void DisableProgram(IProgram programToDelete)
{
_uwps.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
.Enabled = false;
+ _settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
var t1 = Task.Run(() =>
{
IndexWin32Programs();
- _settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
_settings.LastIndexTime = DateTime.Today;
});
}
@@ -205,10 +205,10 @@ private static void DisableProgram(IProgram programToDelete)
{
_win32s.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
.Enabled = false;
+ _settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
var t1 = Task.Run(() =>
{
IndexUwpPrograms();
- _settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
_settings.LastIndexTime = DateTime.Today;
});
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index ff056ff139e..c78c4fa9aa2 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -325,7 +325,8 @@ private void Sort(string sortBy, ListSortDirection direction)
private static bool HasMoreOrEqualEnabledItems(List items)
{
- return items.Where(x => x.Enabled).Count() >= items.Count / 2;
+ var enableCount = items.Where(x => x.Enabled).Count();
+ return enableCount >= items.Count - enableCount;
}
private void programSourceView_SelectionChanged(object sender, SelectionChangedEventArgs e)
From 874383bd076d8dd2f3a0e5be965f07eb003e87fd Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Tue, 25 Oct 2022 17:39:01 +0800
Subject: [PATCH 35/58] bugfix and refactor
1. Fix issues with uid.
2. Implement #1486.
---
.../AddProgramSource.xaml.cs | 13 ++++---
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 4 +--
.../Programs/Win32.cs | 2 +-
.../Views/Commands/ProgramSettingDisplay.cs | 33 ++++++++---------
.../Views/Models/ProgramSource.cs | 33 +++++++++++------
.../Views/ProgramSetting.xaml.cs | 36 +++++++++++--------
6 files changed, 74 insertions(+), 47 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index 1d2740cd793..1445cdb7b67 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -55,6 +55,7 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
{
string path = Directory.Text;
+ bool modified = false;
if (!System.IO.Directory.Exists(path))
{
System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_invalid_path"));
@@ -65,18 +66,22 @@ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier.Equals(path, System.StringComparison.InvariantCultureIgnoreCase)))
{
var source = new ProgramSource(path);
-
+ modified = true;
_settings.ProgramSources.Insert(0, source);
ProgramSetting.ProgramSettingDisplayList.Add(source);
}
}
else
{
- _editing.Location = path;
- _editing.Enabled = Chkbox.IsChecked ?? true; // Fixme, need to add to disabled source if not custom source
+ modified = _editing.Location != path || _editing.Enabled != Chkbox.IsChecked;
+ if (modified)
+ {
+ _editing.SetLocation(path);
+ _editing.Enabled = Chkbox.IsChecked ?? true;
+ }
}
- DialogResult = true;
+ DialogResult = modified;
Close();
}
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index bf1014c44fa..6786a225812 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -197,7 +197,7 @@ private static void DisableProgram(IProgram programToDelete)
_settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
var t1 = Task.Run(() =>
{
- IndexWin32Programs();
+ IndexUwpPrograms();
_settings.LastIndexTime = DateTime.Today;
});
}
@@ -208,7 +208,7 @@ private static void DisableProgram(IProgram programToDelete)
_settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
var t1 = Task.Run(() =>
{
- IndexUwpPrograms();
+ IndexWin32Programs();
_settings.LastIndexTime = DateTime.Today;
});
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index 2c7b0c3ff3d..b5969affcd4 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -25,7 +25,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
public class Win32 : IProgram, IEquatable
{
public string Name { get; set; }
- public string UniqueIdentifier { get => _uid; set => _uid = value.ToLowerInvariant(); }
+ public string UniqueIdentifier { get => _uid; set => _uid = value.ToLowerInvariant(); } // For path comparison
public string IcoPath { get; set; }
public string FullPath { get; set; }
public string LnkResolvedPath { get; set; }
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
index 4ebca8cf3fb..efa7900b013 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
@@ -52,30 +52,31 @@ internal static void SetProgramSourcesStatus(List selectedProgram
internal static void StoreDisabledInSettings()
{
- Main._settings.ProgramSources
- .Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && !x.Enabled))
- .ToList()
- .ForEach(t1 => t1.Enabled = false);
+ // no need since using refernce now
+ //Main._settings.ProgramSources
+ // .Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && !x.Enabled))
+ // .ToList()
+ // .ForEach(t1 => t1.Enabled = false);
- ProgramSetting.ProgramSettingDisplayList
+ // Disabled, not in DisabledProgramSources or ProgramSources
+ var tmp = ProgramSetting.ProgramSettingDisplayList
.Where(t1 => !t1.Enabled
- && !Main._settings.DisabledProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
- .ToList()
- .ForEach(x => Main._settings.DisabledProgramSources
- .Add(new DisabledProgramSource(x)));
+ && !Main._settings.DisabledProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier)
+ && !Main._settings.ProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
+ .Select(x => new DisabledProgramSource(x));
+
+ Main._settings.DisabledProgramSources.AddRange(tmp);
}
internal static void RemoveDisabledFromSettings()
{
- Main._settings.ProgramSources
- .Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled))
- .ToList()
- .ForEach(t1 => t1.Enabled = true);
+ //Main._settings.ProgramSources
+ // .Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled))
+ // .ToList()
+ // .ForEach(t1 => t1.Enabled = true);
Main._settings.DisabledProgramSources
- .Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled))
- .ToList()
- .ForEach(x => Main._settings.DisabledProgramSources.Remove(x));
+ .RemoveAll(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled));
}
internal static bool IsReindexRequired(this List selectedItems)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
index 5deb6b3967b..8efa3ef6dc6 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
@@ -1,5 +1,7 @@
using System;
using System.IO;
+using System.Text.Json.Serialization;
+using System.Windows.Media.Imaging;
using Flow.Launcher.Plugin.Program.Programs;
namespace Flow.Launcher.Plugin.Program.Views.Models
@@ -16,17 +18,20 @@ public class ProgramSource
{
private string name;
- public string Location { get; set; }
+ public string Location { get; private set; }
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
public bool Enabled { get; set; } = true;
- ///
- /// Guaranteed lowercase.
- ///
- public string UniqueIdentifier { get => uid; set => uid = value.ToLowerInvariant(); }
- private string uid { get; set; }
+ public string UniqueIdentifier { get; private set; }
- public ProgramSource() { } // only for json deserialization
+ [JsonConstructor]
+ public ProgramSource(string name, string location, bool enabled, string uniqueIdentifier)
+ {
+ Location = location;
+ this.name = name;
+ Enabled = enabled;
+ UniqueIdentifier = uniqueIdentifier;
+ }
///
/// Add source by location
@@ -37,7 +42,7 @@ public ProgramSource(string location, bool enabled=true)
{
Location = location;
Enabled = enabled;
- UniqueIdentifier = location;
+ UniqueIdentifier = location.ToLowerInvariant(); // For path comparison
}
public ProgramSource(ProgramSource source)
@@ -68,13 +73,21 @@ public bool Equals(IProgram program)
public override int GetHashCode()
{
- return HashCode.Combine(uid);
+ return HashCode.Combine(UniqueIdentifier);
+ }
+
+ public void SetLocation(string value)
+ {
+ if (Location == value) return;
+ Location = value;
+ UniqueIdentifier = value.ToLowerInvariant(); // Update
}
}
public class DisabledProgramSource : ProgramSource
{
- public DisabledProgramSource() { } // only for json deserialization
+ [JsonConstructor]
+ public DisabledProgramSource(string name, string location, bool enabled, string uniqueIdentifier) : base(name, location, enabled, uniqueIdentifier) { }
public DisabledProgramSource(string location) : base(location, false) { }
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index c78c4fa9aa2..77d29fab18d 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -149,19 +149,34 @@ private void DeleteProgramSources(List itemsToDelete)
private void btnEditProgramSource_OnClick(object sender, RoutedEventArgs e)
{
var selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
- if (selectedProgramSource != null)
+ EditProgramSource(selectedProgramSource);
+ }
+
+ private void EditProgramSource(ProgramSource selectedProgramSource)
+ {
+ if (selectedProgramSource == null)
+ {
+ string msg = context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source");
+ MessageBox.Show(msg);
+ }
+ else
{
var add = new AddProgramSource(selectedProgramSource, _settings);
if (add.ShowDialog() ?? false)
{
+ if (selectedProgramSource.Enabled)
+ {
+ ProgramSettingDisplay.SetProgramSourcesStatus(new List { selectedProgramSource }, true); // sync status in win32, uwp and disabled
+ ProgramSettingDisplay.RemoveDisabledFromSettings();
+ }
+ else
+ {
+ ProgramSettingDisplay.SetProgramSourcesStatus(new List { selectedProgramSource }, false);
+ ProgramSettingDisplay.StoreDisabledInSettings();
+ }
ReIndexing();
}
}
- else
- {
- string msg = context.API.GetTranslation("flowlauncher_plugin_program_pls_select_program_source");
- MessageBox.Show(msg);
- }
}
private void btnReindex_Click(object sender, RoutedEventArgs e)
@@ -352,14 +367,7 @@ private void programSourceView_SelectionChanged(object sender, SelectionChangedE
private void programSourceView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
- if (selectedProgramSource != null)
- {
- var add = new AddProgramSource(selectedProgramSource, _settings);
- if (add.ShowDialog() ?? false)
- {
- ReIndexing();
- }
- }
+ EditProgramSource(selectedProgramSource);
}
private bool IsAllItemsUserAdded(List items)
From efece39c1e4e24c562bca3169361426074a6f6b8 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Fri, 28 Oct 2022 16:44:44 +0800
Subject: [PATCH 36/58] Fix var for task.run
---
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index 6786a225812..e8672e249c8 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -195,7 +195,7 @@ private static void DisableProgram(IProgram programToDelete)
_uwps.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
.Enabled = false;
_settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
- var t1 = Task.Run(() =>
+ _ = Task.Run(() =>
{
IndexUwpPrograms();
_settings.LastIndexTime = DateTime.Today;
@@ -206,7 +206,7 @@ private static void DisableProgram(IProgram programToDelete)
_win32s.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
.Enabled = false;
_settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
- var t1 = Task.Run(() =>
+ _ = Task.Run(() =>
{
IndexWin32Programs();
_settings.LastIndexTime = DateTime.Today;
From 6e19b49f91efe3bb0d77fb49fd89c9b86ae11b9f Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Fri, 28 Oct 2022 16:50:08 +0800
Subject: [PATCH 37/58] Freeze logo
---
Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
index 6ea927cb773..86511a42284 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
@@ -691,9 +691,10 @@ private BitmapImage ImageFromPath(string path)
{
var image = new BitmapImage();
image.BeginInit();
- image.UriSource = new Uri(path);
+ image.UriSource = new Uri(path);
image.CacheOption = BitmapCacheOption.OnLoad;
image.EndInit();
+ image.Freeze();
return image;
}
else
From 3efa0e185de32329fc13b442f4754b8fa8c017da Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Fri, 28 Oct 2022 18:06:44 +0800
Subject: [PATCH 38/58] Remove DisabledProgramSource
---
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 12 ++++++------
.../Flow.Launcher.Plugin.Program/Settings.cs | 2 +-
.../Views/Commands/ProgramSettingDisplay.cs | 6 ++----
.../Views/Models/ProgramSource.cs | 18 ------------------
4 files changed, 9 insertions(+), 29 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index e8672e249c8..7bc773d28ca 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -192,9 +192,9 @@ private static void DisableProgram(IProgram programToDelete)
if (_uwps.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
{
- _uwps.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
- .Enabled = false;
- _settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
+ var program = _uwps.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier);
+ program.Enabled = false;
+ _settings.DisabledProgramSources.Add(new ProgramSource(program));
_ = Task.Run(() =>
{
IndexUwpPrograms();
@@ -203,9 +203,9 @@ private static void DisableProgram(IProgram programToDelete)
}
else if (_win32s.Any(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier))
{
- _win32s.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier)
- .Enabled = false;
- _settings.DisabledProgramSources.Add(new DisabledProgramSource(programToDelete));
+ var program = _win32s.First(x => x.UniqueIdentifier == programToDelete.UniqueIdentifier);
+ program.Enabled = false;
+ _settings.DisabledProgramSources.Add(new ProgramSource(program));
_ = Task.Run(() =>
{
IndexWin32Programs();
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
index 3afb499f55e..a9f88c6dc2d 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
@@ -9,7 +9,7 @@ public class Settings
{
public DateTime LastIndexTime { get; set; }
public List ProgramSources { get; set; } = new List();
- public List DisabledProgramSources { get; set; } = new List(); // For disabled single programs
+ public List DisabledProgramSources { get; set; } = new List(); // For disabled single programs
public string[] ProgramSuffixes { get; set; } = {"appref-ms", "exe", "lnk"};
public bool EnableStartMenuSource { get; set; } = true;
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
index efa7900b013..8a2a5adeefc 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
@@ -14,7 +14,6 @@ internal static List LoadProgramSources()
// Even though these are disabled, we still want to display them so users can enable later on
return Main._settings
.DisabledProgramSources
- .Select(s => new ProgramSource(s))
.Union(Main._settings.ProgramSources)
.ToList();
}
@@ -62,8 +61,7 @@ internal static void StoreDisabledInSettings()
var tmp = ProgramSetting.ProgramSettingDisplayList
.Where(t1 => !t1.Enabled
&& !Main._settings.DisabledProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier)
- && !Main._settings.ProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
- .Select(x => new DisabledProgramSource(x));
+ && !Main._settings.ProgramSources.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier));
Main._settings.DisabledProgramSources.AddRange(tmp);
}
@@ -76,7 +74,7 @@ internal static void RemoveDisabledFromSettings()
// .ForEach(t1 => t1.Enabled = true);
Main._settings.DisabledProgramSources
- .RemoveAll(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled));
+ .RemoveAll(t1 => t1.Enabled);
}
internal static bool IsReindexRequired(this List selectedItems)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
index 8efa3ef6dc6..6d24d12d585 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
@@ -83,22 +83,4 @@ public void SetLocation(string value)
UniqueIdentifier = value.ToLowerInvariant(); // Update
}
}
-
- public class DisabledProgramSource : ProgramSource
- {
- [JsonConstructor]
- public DisabledProgramSource(string name, string location, bool enabled, string uniqueIdentifier) : base(name, location, enabled, uniqueIdentifier) { }
-
- public DisabledProgramSource(string location) : base(location, false) { }
-
- public DisabledProgramSource(ProgramSource source) : base(source)
- {
- Enabled = false;
- }
-
- public DisabledProgramSource(IProgram program) : base(program)
- {
- Enabled = false;
- }
- }
}
From cc7d2bc8553e17939af13ff7064b134a898e1e03 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Fri, 28 Oct 2022 20:00:38 +0800
Subject: [PATCH 39/58] Fix location setter and uid case
---
.../AddProgramSource.xaml.cs | 4 +-
.../Views/Models/ProgramSource.cs | 43 ++++++++++---------
.../Views/ProgramSetting.xaml.cs | 2 +-
3 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index 1445cdb7b67..31d44a6d4f6 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -63,7 +63,7 @@ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
}
if (!update)
{
- if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier.Equals(path, System.StringComparison.InvariantCultureIgnoreCase)))
+ if (!ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier.Equals(path, System.StringComparison.OrdinalIgnoreCase)))
{
var source = new ProgramSource(path);
modified = true;
@@ -76,7 +76,7 @@ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
modified = _editing.Location != path || _editing.Enabled != Chkbox.IsChecked;
if (modified)
{
- _editing.SetLocation(path);
+ _editing.Location = path;
_editing.Enabled = Chkbox.IsChecked ?? true;
}
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
index 6d24d12d585..4282eab062b 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
@@ -18,7 +18,16 @@ public class ProgramSource
{
private string name;
- public string Location { get; private set; }
+ private string loc;
+ public string Location
+ {
+ get => loc;
+ set
+ {
+ loc = value;
+ UniqueIdentifier = value.ToLowerInvariant();
+ }
+ }
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
public bool Enabled { get; set; } = true;
@@ -27,10 +36,17 @@ public class ProgramSource
[JsonConstructor]
public ProgramSource(string name, string location, bool enabled, string uniqueIdentifier)
{
- Location = location;
+ loc = location;
this.name = name;
Enabled = enabled;
- UniqueIdentifier = uniqueIdentifier;
+ if (location.Equals(uniqueIdentifier, StringComparison.OrdinalIgnoreCase))
+ {
+ UniqueIdentifier = location.ToLowerInvariant(); // To make sure old config can be reset to case-insensitive
+ }
+ else
+ {
+ UniqueIdentifier = uniqueIdentifier; // For uwp apps
+ }
}
///
@@ -38,24 +54,16 @@ public ProgramSource(string name, string location, bool enabled, string uniqueId
///
/// location of program source
/// enabled
- public ProgramSource(string location, bool enabled=true)
+ public ProgramSource(string location, bool enabled = true)
{
- Location = location;
+ loc = location;
Enabled = enabled;
UniqueIdentifier = location.ToLowerInvariant(); // For path comparison
}
- public ProgramSource(ProgramSource source)
- {
- Location = source.Location;
- Name = source.Name;
- Enabled = source.Enabled;
- UniqueIdentifier = source.UniqueIdentifier;
- }
-
public ProgramSource(IProgram source)
{
- Location = source.Location;
+ loc = source.Location;
Name = source.Name;
Enabled = source.Enabled;
UniqueIdentifier = source.UniqueIdentifier;
@@ -75,12 +83,5 @@ public override int GetHashCode()
{
return HashCode.Combine(UniqueIdentifier);
}
-
- public void SetLocation(string value)
- {
- if (Location == value) return;
- Location = value;
- UniqueIdentifier = value.ToLowerInvariant(); // Update
- }
}
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index 77d29fab18d..a7ee299d5da 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -216,7 +216,7 @@ private void programSourceView_Drop(object sender, DragEventArgs e)
foreach (string directory in directories)
{
if (Directory.Exists(directory)
- && !ProgramSettingDisplayList.Any(x => x.UniqueIdentifier.Equals(directory, System.StringComparison.InvariantCultureIgnoreCase)))
+ && !ProgramSettingDisplayList.Any(x => x.UniqueIdentifier.Equals(directory, System.StringComparison.OrdinalIgnoreCase)))
{
var source = new ProgramSource(directory);
From 0b247db1b2f51e361b88ced8f662d3384a7b4bbe Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Sun, 30 Oct 2022 01:27:41 +0800
Subject: [PATCH 40/58] minor changes
---
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 2 +-
Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs | 11 +++--------
.../Flow.Launcher.Plugin.Program/Programs/Win32.cs | 2 +-
.../Views/ProgramSetting.xaml.cs | 7 +++----
4 files changed, 8 insertions(+), 14 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index 7bc773d28ca..3b03f89f682 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -99,7 +99,7 @@ public async Task InitAsync(PluginInitContext context)
var b = Task.Run(() =>
{
- Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|Win32Program index cost", IndexUwpPrograms);
+ Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|UWPProgram index cost", IndexUwpPrograms);
});
if (cacheEmpty)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
index 86511a42284..fb460362289 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
@@ -41,13 +41,8 @@ public UWP(Package package)
FullName = package.Id.FullName;
FamilyName = package.Id.FamilyName;
InitializeAppInfo();
- Apps = Apps.Where(a =>
- {
- var valid =
- !string.IsNullOrEmpty(a.UserModelId) &&
- !string.IsNullOrEmpty(a.DisplayName);
- return valid;
- }).ToArray();
+ Apps = Apps.Where(a => !string.IsNullOrEmpty(a.UserModelId) && !string.IsNullOrEmpty(a.DisplayName))
+ .ToArray();
}
private void InitializeAppInfo()
@@ -80,7 +75,7 @@ private void InitializeAppInfo()
ProgramLogger.LogException($"|UWP|InitializeAppInfo|{path}" +
"|Error caused while trying to get the details of the UWP program", e);
- Apps = new List().ToArray();
+ Apps = Array.Empty();
}
if (stream != null && Marshal.ReleaseComObject(stream) > 0)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index b5969affcd4..deb297ca633 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -496,7 +496,7 @@ private static IEnumerable ProgramsHasher(IEnumerable programs)
if (temp.Any())
return DistinctBy(temp, x => x.Description);
return g.Take(1);
- }).ToArray();
+ });
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index a7ee299d5da..1ee18ae3705 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
@@ -224,7 +223,7 @@ private void programSourceView_Drop(object sender, DragEventArgs e)
}
}
- if (directoriesToAdd.Count() > 0)
+ if (directoriesToAdd.Count > 0)
{
directoriesToAdd.ForEach(x => _settings.ProgramSources.Add(x));
directoriesToAdd.ForEach(x => ProgramSettingDisplayList.Add(x));
@@ -347,8 +346,8 @@ private static bool HasMoreOrEqualEnabledItems(List items)
private void programSourceView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedItems = programSourceView
- .SelectedItems.Cast()
- .ToList();
+ .SelectedItems.Cast()
+ .ToList();
if (IsAllItemsUserAdded(selectedItems))
{
From 4296652edf11b329a28f54c21df6c08525a3813f Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Sun, 30 Oct 2022 02:37:22 +0800
Subject: [PATCH 41/58] Time when manually reindex
---
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 13 ++++++++++---
.../Flow.Launcher.Plugin.Program/Programs/Win32.cs | 7 ++++---
.../Views/Models/ProgramSource.cs | 1 -
3 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index 3b03f89f682..2622b16fa00 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -127,9 +127,16 @@ public static void IndexUwpPrograms()
public static async Task IndexProgramsAsync()
{
- var t1 = Task.Run(IndexWin32Programs);
- var t2 = Task.Run(IndexUwpPrograms);
- await Task.WhenAll(t1, t2).ConfigureAwait(false);
+ var a = Task.Run(() =>
+ {
+ Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|Win32Program index cost", IndexWin32Programs);
+ });
+
+ var b = Task.Run(() =>
+ {
+ Stopwatch.Normal("|Flow.Launcher.Plugin.Program.Main|UWPProgram index cost", IndexUwpPrograms);
+ });
+ await Task.WhenAll(a, b).ConfigureAwait(false);
_settings.LastIndexTime = DateTime.Today;
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index deb297ca633..dc5407f1a58 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -246,7 +246,7 @@ private static Win32 LnkProgram(string path)
if (extension == ExeExtension && File.Exists(target))
{
program.LnkResolvedPath = program.FullPath;
- program.FullPath = Path.GetFullPath(target).ToLower();
+ program.FullPath = Path.GetFullPath(target).ToLowerInvariant();
program.ExecutableName = Path.GetFileName(target);
var description = _helper.description;
@@ -324,7 +324,7 @@ private static IEnumerable ProgramPaths(string directory, string[] suffi
private static string Extension(string path)
{
- var extension = Path.GetExtension(path)?.ToLower();
+ var extension = Path.GetExtension(path)?.ToLowerInvariant();
if (!string.IsNullOrEmpty(extension))
{
return extension.Substring(1);
@@ -489,7 +489,8 @@ public static IEnumerable DistinctBy(IEnumerable source, Func
private static IEnumerable ProgramsHasher(IEnumerable programs)
{
- return programs.GroupBy(p => p.FullPath.ToLower())
+ return programs.GroupBy(p => p.FullPath.ToLowerInvariant())
+ .AsParallel()
.SelectMany(g =>
{
var temp = g.Where(g => !string.IsNullOrEmpty(g.Description)).ToList();
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
index 4282eab062b..fb32fb892a7 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Models/ProgramSource.cs
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Text.Json.Serialization;
-using System.Windows.Media.Imaging;
using Flow.Launcher.Plugin.Program.Programs;
namespace Flow.Launcher.Plugin.Program.Views.Models
From a5d7005497fe469d34f27cafedb66e09b0ad19ec Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Sun, 30 Oct 2022 02:42:35 +0800
Subject: [PATCH 42/58] refactor foreach
---
.../Views/Commands/ProgramSettingDisplay.cs | 69 +++++++++----------
1 file changed, 32 insertions(+), 37 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
index 8a2a5adeefc..e4d7c323a5f 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/Commands/ProgramSettingDisplay.cs
@@ -1,8 +1,5 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Flow.Launcher.Plugin.Program.Views.Models;
namespace Flow.Launcher.Plugin.Program.Views.Commands
@@ -20,43 +17,47 @@ internal static List LoadProgramSources()
internal static void DisplayAllPrograms()
{
- Main._win32s
- .Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
- .ToList()
- .ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource(t1)));
+ var win32 = Main._win32s
+ .Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
+ .Select(x => new ProgramSource(x));
- Main._uwps
- .Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
- .ToList()
- .ForEach(t1 => ProgramSetting.ProgramSettingDisplayList.Add(new ProgramSource(t1)));
+ var uwp = Main._uwps
+ .Where(t1 => !ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier))
+ .Select(x => new ProgramSource(x));
+
+ ProgramSetting.ProgramSettingDisplayList.AddRange(win32);
+ ProgramSetting.ProgramSettingDisplayList.AddRange(uwp);
}
internal static void SetProgramSourcesStatus(List selectedProgramSourcesToDisable, bool status)
{
- ProgramSetting.ProgramSettingDisplayList
- .Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
- .ToList()
- .ForEach(t1 => t1.Enabled = status);
+ foreach(var program in ProgramSetting.ProgramSettingDisplayList)
+ {
+ if (selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == program.UniqueIdentifier && program.Enabled != status))
+ {
+ program.Enabled = status;
+ }
+ }
- Main._win32s
- .Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
- .ToList()
- .ForEach(t1 => t1.Enabled = status);
+ foreach(var program in Main._win32s)
+ {
+ if (selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == program.UniqueIdentifier && program.Enabled != status))
+ {
+ program.Enabled = status;
+ }
+ }
- Main._uwps
- .Where(t1 => selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && t1.Enabled != status))
- .ToList()
- .ForEach(t1 => t1.Enabled = status);
+ foreach (var program in Main._uwps)
+ {
+ if (selectedProgramSourcesToDisable.Any(x => x.UniqueIdentifier == program.UniqueIdentifier && program.Enabled != status))
+ {
+ program.Enabled = status;
+ }
+ }
}
internal static void StoreDisabledInSettings()
{
- // no need since using refernce now
- //Main._settings.ProgramSources
- // .Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && !x.Enabled))
- // .ToList()
- // .ForEach(t1 => t1.Enabled = false);
-
// Disabled, not in DisabledProgramSources or ProgramSources
var tmp = ProgramSetting.ProgramSettingDisplayList
.Where(t1 => !t1.Enabled
@@ -68,13 +69,7 @@ internal static void StoreDisabledInSettings()
internal static void RemoveDisabledFromSettings()
{
- //Main._settings.ProgramSources
- // .Where(t1 => ProgramSetting.ProgramSettingDisplayList.Any(x => x.UniqueIdentifier == t1.UniqueIdentifier && x.Enabled))
- // .ToList()
- // .ForEach(t1 => t1.Enabled = true);
-
- Main._settings.DisabledProgramSources
- .RemoveAll(t1 => t1.Enabled);
+ Main._settings.DisabledProgramSources.RemoveAll(t1 => t1.Enabled);
}
internal static bool IsReindexRequired(this List selectedItems)
From 134870815a8d64b34d20a27d53b8d81745ba83d7 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Sun, 30 Oct 2022 02:49:33 +0800
Subject: [PATCH 43/58] revert
---
Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index dc5407f1a58..5073d26db41 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -497,7 +497,7 @@ private static IEnumerable ProgramsHasher(IEnumerable programs)
if (temp.Any())
return DistinctBy(temp, x => x.Description);
return g.Take(1);
- });
+ }).ToArray();
}
From 70b0e3bc2c60c073389b83c17bd60f5d4d46e78a Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Sun, 30 Oct 2022 18:43:44 +0800
Subject: [PATCH 44/58] Fix uid change when editing uwp sources
---
.../AddProgramSource.xaml.cs | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index 31d44a6d4f6..469068b7a35 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -73,10 +73,14 @@ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
}
else
{
- modified = _editing.Location != path || _editing.Enabled != Chkbox.IsChecked;
- if (modified)
+ if (!_editing.Location.Equals(path, System.StringComparison.OrdinalIgnoreCase))
{
- _editing.Location = path;
+ modified = true;
+ _editing.Location = path; // Changes UniqueIdentifier internally
+ }
+ if (_editing.Enabled != Chkbox.IsChecked)
+ {
+ modified = true;
_editing.Enabled = Chkbox.IsChecked ?? true;
}
}
From a523584c672d60832ef3a9c1b9f544469a6f8949 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 3 Nov 2022 16:10:11 +0800
Subject: [PATCH 45/58] Fix indexing unwanted protocols in custom sources
---
Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index c540106cdc7..f32f146136c 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -390,8 +390,7 @@ private static IEnumerable UnregisteredPrograms(List sourc
ShortcutExtension => LnkProgram(x),
UrlExtension => UrlProgram(x),
_ => Win32Program(x)
- });
-
+ }).Where(x => x.Valid);
return programs;
}
@@ -442,7 +441,7 @@ private static IEnumerable AppPathsPrograms(string[] suffixes)
var filtered = ExceptDisabledSource(toFilter);
- return filtered.Select(GetProgramFromPath).ToList(); // ToList due to disposing issue
+ return filtered.Select(GetProgramFromPath).Where(x => x.Valid).ToList(); // ToList due to disposing issue
}
private static IEnumerable GetPathFromRegistry(RegistryKey root)
From 36f67b8f32f4a705caddaa61585abddb439de1e0 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 3 Nov 2022 17:33:38 +0800
Subject: [PATCH 46/58] refactor usage of getprotocols
---
.../Programs/Win32.cs | 58 ++++++++-----------
1 file changed, 24 insertions(+), 34 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index f32f146136c..4c24da6658d 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -293,7 +293,7 @@ private static Win32 LnkProgram(string path)
#endif
}
- private static Win32 UrlProgram(string path)
+ private static Win32 UrlProgram(string path, string[] protocols)
{
var program = Win32Program(path);
program.Valid = false;
@@ -308,7 +308,7 @@ private static Win32 UrlProgram(string path)
{
return program;
}
- foreach(var protocol in Main._settings.GetProtocols())
+ foreach(var protocol in protocols)
{
if(url.StartsWith(protocol))
{
@@ -370,7 +370,7 @@ private static string Extension(string path)
var extension = Path.GetExtension(path)?.ToLowerInvariant();
if (!string.IsNullOrEmpty(extension))
{
- return extension.Substring(1);
+ return extension.Substring(1); // remove dot
}
else
{
@@ -378,27 +378,18 @@ private static string Extension(string path)
}
}
- private static IEnumerable UnregisteredPrograms(List sources, string[] suffixes)
+ private static IEnumerable UnregisteredPrograms(List sources, string[] suffixes, string[] protocols)
{
var paths = ExceptDisabledSource(sources.Where(s => Directory.Exists(s.Location) && s.Enabled)
.SelectMany(s => ProgramPaths(s.Location, suffixes)))
.Distinct();
- var programs = paths.Select(x => Extension(x) switch
- {
- ExeExtension => ExeProgram(x),
- ShortcutExtension => LnkProgram(x),
- UrlExtension => UrlProgram(x),
- _ => Win32Program(x)
- }).Where(x => x.Valid);
-
+ var programs = paths.Select(x => GetProgramFromPath(x, protocols)).Where(x => x.Valid);
return programs;
}
- private static IEnumerable StartMenuPrograms(string[] suffixes)
+ private static IEnumerable StartMenuPrograms(string[] suffixes, string[] protocols)
{
- var disabledProgramsList = Main._settings.DisabledProgramSources;
-
var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
var directory2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms);
var paths1 = ProgramPaths(directory1, suffixes);
@@ -407,16 +398,11 @@ private static IEnumerable StartMenuPrograms(string[] suffixes)
var toFilter = paths1.Concat(paths2);
var programs = ExceptDisabledSource(toFilter.Distinct())
- .Select(x => Extension(x) switch
- {
- ShortcutExtension => LnkProgram(x),
- UrlExtension => UrlProgram(x),
- _ => Win32Program(x)
- }).Where(x => x.Valid);
+ .Select(x => GetProgramFromPath(x, protocols)).Where(x => x.Valid);
return programs;
}
- private static IEnumerable AppPathsPrograms(string[] suffixes)
+ private static IEnumerable AppPathsPrograms(string[] suffixes, string[] protocols)
{
// https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121
const string appPaths = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths";
@@ -436,12 +422,11 @@ private static IEnumerable AppPathsPrograms(string[] suffixes)
toFilter = toFilter.Concat(GetPathFromRegistry(rootUser));
}
-
toFilter = toFilter.Distinct().Where(p => suffixes.Contains(Extension(p)));
- var filtered = ExceptDisabledSource(toFilter);
-
- return filtered.Select(GetProgramFromPath).Where(x => x.Valid).ToList(); // ToList due to disposing issue
+ var programs = ExceptDisabledSource(toFilter)
+ .Select(x => GetProgramFromPath(x, protocols)).Where(x => x.Valid).ToList(); // ToList due to disposing issue
+ return programs;
}
private static IEnumerable GetPathFromRegistry(RegistryKey root)
@@ -481,7 +466,7 @@ private static string GetProgramPathFromRegistrySubKeys(RegistryKey root, string
}
}
- private static Win32 GetProgramFromPath(string path)
+ private static Win32 GetProgramFromPath(string path, string[] protocols)
{
if (string.IsNullOrEmpty(path))
return Default;
@@ -491,9 +476,13 @@ private static Win32 GetProgramFromPath(string path)
if (!File.Exists(path))
return Default;
- var entry = Win32Program(path);
-
- return entry;
+ return Extension(path) switch
+ {
+ ShortcutExtension => LnkProgram(path),
+ ExeExtension => ExeProgram(path),
+ UrlExtension => UrlProgram(path, protocols),
+ _ => Win32Program(path)
+ }; ;
}
public static IEnumerable ExceptDisabledSource(IEnumerable paths)
@@ -550,8 +539,9 @@ public static Win32[] All(Settings settings)
try
{
var programs = Enumerable.Empty();
-
- var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.GetSuffixes());
+ var suffixes = settings.GetSuffixes();
+ var protocols = settings.GetProtocols();
+ var unregistered = UnregisteredPrograms(settings.ProgramSources, suffixes, protocols);
programs = programs.Concat(unregistered);
@@ -559,13 +549,13 @@ public static Win32[] All(Settings settings)
if (settings.EnableRegistrySource)
{
- var appPaths = AppPathsPrograms(settings.GetSuffixes());
+ var appPaths = AppPathsPrograms(suffixes, protocols);
autoIndexPrograms = autoIndexPrograms.Concat(appPaths);
}
if (settings.EnableStartMenuSource)
{
- var startMenu = StartMenuPrograms(settings.GetSuffixes());
+ var startMenu = StartMenuPrograms(suffixes, protocols);
autoIndexPrograms = autoIndexPrograms.Concat(startMenu);
}
From b0a4ac7996deb1615a2884dfbf0178b623805c5e Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 3 Nov 2022 17:40:16 +0800
Subject: [PATCH 47/58] Enable parallel query for custom sources
---
Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index 4c24da6658d..8f09ee147d8 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -381,6 +381,7 @@ private static string Extension(string path)
private static IEnumerable UnregisteredPrograms(List sources, string[] suffixes, string[] protocols)
{
var paths = ExceptDisabledSource(sources.Where(s => Directory.Exists(s.Location) && s.Enabled)
+ .AsParallel()
.SelectMany(s => ProgramPaths(s.Location, suffixes)))
.Distinct();
From 4d63895919099b66c8751fc1c30a86e9708ebb52 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 3 Nov 2022 17:59:37 +0800
Subject: [PATCH 48/58] Formatting and use default for invalid programs
---
.../Programs/Win32.cs | 22 ++++++++-----------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index 8f09ee147d8..08442354e76 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -227,10 +227,7 @@ private static Win32 Win32Program(string path)
ProgramLogger.LogException($"|Win32|Win32Program|{path}" +
$"|Permission denied when trying to load the program from {path}", e);
- return new Win32()
- {
- Valid = false, Enabled = false
- };
+ return Default;
}
}
@@ -308,9 +305,9 @@ private static Win32 UrlProgram(string path, string[] protocols)
{
return program;
}
- foreach(var protocol in protocols)
+ foreach (var protocol in protocols)
{
- if(url.StartsWith(protocol))
+ if (url.StartsWith(protocol))
{
program.LnkResolvedPath = url;
program.Valid = true;
@@ -347,10 +344,7 @@ private static Win32 ExeProgram(string path)
ProgramLogger.LogException($"|Win32|ExeProgram|{path}" +
$"|Permission denied when trying to load the program from {path}", e);
- return new Win32()
- {
- Valid = false, Enabled = false
- };
+ return Default;
}
}
@@ -361,7 +355,8 @@ private static IEnumerable ProgramPaths(string directory, string[] suffi
return Directory.EnumerateFiles(directory, "*", new EnumerationOptions
{
- IgnoreInaccessible = true, RecurseSubdirectories = true
+ IgnoreInaccessible = true,
+ RecurseSubdirectories = true
}).Where(x => suffixes.Contains(Extension(x)));
}
@@ -542,6 +537,7 @@ public static Win32[] All(Settings settings)
var programs = Enumerable.Empty();
var suffixes = settings.GetSuffixes();
var protocols = settings.GetProtocols();
+
var unregistered = UnregisteredPrograms(settings.ProgramSources, suffixes, protocols);
programs = programs.Concat(unregistered);
@@ -634,7 +630,7 @@ public static async Task MonitorDirectoryChangeAsync()
await Task.Run(Main.IndexWin32Programs);
}
}
-
+
public static void WatchDirectory(string directory)
{
if (!Directory.Exists(directory))
@@ -647,7 +643,7 @@ public static void WatchDirectory(string directory)
watcher.Deleted += static (_, _) => indexQueue.Writer.TryWrite(default);
watcher.EnableRaisingEvents = true;
watcher.IncludeSubdirectories = true;
-
+
Watchers.Add(watcher);
}
From befa19c4bb5109928d7d6cd9d0e6936322ea666b Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 3 Nov 2022 18:20:13 +0800
Subject: [PATCH 49/58] remove unnecessary using
---
Plugins/Flow.Launcher.Plugin.Program/FileChangeWatcher.cs | 8 +-------
.../Flow.Launcher.Plugin.Program/Logger/ProgramLogger.cs | 5 -----
Plugins/Flow.Launcher.Plugin.Program/Main.cs | 4 ----
.../Programs/ApplicationActivationHelper.cs | 2 --
.../Programs/AppxPackageHelper.cs | 2 --
.../Programs/ShellLinkHelper.cs | 3 ---
Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs | 5 -----
Plugins/Flow.Launcher.Plugin.Program/Settings.cs | 1 -
8 files changed, 1 insertion(+), 29 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/FileChangeWatcher.cs b/Plugins/Flow.Launcher.Plugin.Program/FileChangeWatcher.cs
index 4ede37dec5d..ab716116fcf 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/FileChangeWatcher.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/FileChangeWatcher.cs
@@ -1,10 +1,4 @@
-using System.Collections.Generic;
-using System.IO;
-using System.Threading.Tasks;
-using Flow.Launcher.Infrastructure.Logger;
-using Flow.Launcher.Plugin.Program.Programs;
-
-namespace Flow.Launcher.Plugin.Program
+namespace Flow.Launcher.Plugin.Program
{
//internal static class FileChangeWatcher
//{
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Logger/ProgramLogger.cs b/Plugins/Flow.Launcher.Plugin.Program/Logger/ProgramLogger.cs
index cbf4960a33e..1ae6d8a29b2 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Logger/ProgramLogger.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Logger/ProgramLogger.cs
@@ -1,13 +1,8 @@
using NLog;
-using NLog.Config;
-using NLog.Targets;
using System;
-using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Security;
-using Flow.Launcher.Infrastructure;
-using Flow.Launcher.Infrastructure.UserSettings;
namespace Flow.Launcher.Plugin.Program.Logger
{
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Main.cs b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
index 2622b16fa00..8126bbf198d 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Main.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Main.cs
@@ -1,7 +1,5 @@
using System;
-using System.Collections.Concurrent;
using System.Collections.Generic;
-using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using System.Threading;
@@ -13,8 +11,6 @@
using Flow.Launcher.Plugin.Program.Views;
using Flow.Launcher.Plugin.Program.Views.Models;
using Microsoft.Extensions.Caching.Memory;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.Primitives;
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
namespace Flow.Launcher.Plugin.Program
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/ApplicationActivationHelper.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/ApplicationActivationHelper.cs
index 4b8423ed6fe..790a70392e6 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/ApplicationActivationHelper.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/ApplicationActivationHelper.cs
@@ -1,8 +1,6 @@
using System;
-using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
-using System.Text.RegularExpressions;
namespace Flow.Launcher.Plugin.Program.Programs
{
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/AppxPackageHelper.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/AppxPackageHelper.cs
index 654566ffe99..73a25dd0d26 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/AppxPackageHelper.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/AppxPackageHelper.cs
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
-using System.Text;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
-using Windows.Storage;
namespace Flow.Launcher.Plugin.Program.Programs
{
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/ShellLinkHelper.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/ShellLinkHelper.cs
index d17048dcbd8..72b7b0a91cb 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/ShellLinkHelper.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/ShellLinkHelper.cs
@@ -1,11 +1,8 @@
using System;
-using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
-using System.IO;
using Accessibility;
using System.Runtime.InteropServices.ComTypes;
-using System.Security.Policy;
namespace Flow.Launcher.Plugin.Program.Programs
{
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index 08442354e76..5a3295c38b5 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -11,15 +11,10 @@
using Flow.Launcher.Plugin.Program.Logger;
using Flow.Launcher.Plugin.SharedCommands;
using Flow.Launcher.Plugin.SharedModels;
-using Flow.Launcher.Infrastructure.Logger;
-using System.Collections;
using System.Diagnostics;
-using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
using System.Diagnostics.CodeAnalysis;
-using System.Text.RegularExpressions;
using System.Threading.Channels;
using Flow.Launcher.Plugin.Program.Views.Models;
-using Flow.Launcher.Infrastructure.Image;
using IniParser;
namespace Flow.Launcher.Plugin.Program.Programs
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
index c349d4f2882..44d4483b922 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.IO;
using System.Linq;
using System.Text.Json.Serialization;
using Flow.Launcher.Plugin.Program.Views.Models;
From 7d27d735e24b643888dcc701988be7133a61078f Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 3 Nov 2022 18:24:37 +0800
Subject: [PATCH 50/58] Delete FileChangeWatcher.cs
---
.../FileChangeWatcher.cs | 52 -------------------
1 file changed, 52 deletions(-)
delete mode 100644 Plugins/Flow.Launcher.Plugin.Program/FileChangeWatcher.cs
diff --git a/Plugins/Flow.Launcher.Plugin.Program/FileChangeWatcher.cs b/Plugins/Flow.Launcher.Plugin.Program/FileChangeWatcher.cs
deleted file mode 100644
index ab716116fcf..00000000000
--- a/Plugins/Flow.Launcher.Plugin.Program/FileChangeWatcher.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-namespace Flow.Launcher.Plugin.Program
-{
- //internal static class FileChangeWatcher
- //{
- // private static readonly List WatchedPath = new List();
- // // todo remove previous watcher events
- // public static void AddAll(List sources, string[] suffixes)
- // {
- // foreach (var s in sources)
- // {
- // if (Directory.Exists(s.Location))
- // {
- // AddWatch(s.Location, suffixes);
- // }
- // }
- // }
-
- // public static void AddWatch(string path, string[] programSuffixes, bool includingSubDirectory = true)
- // {
- // if (WatchedPath.Contains(path)) return;
- // if (!Directory.Exists(path))
- // {
- // Log.Warn($"|FileChangeWatcher|{path} doesn't exist");
- // return;
- // }
-
- // WatchedPath.Add(path);
- // foreach (string fileType in programSuffixes)
- // {
- // FileSystemWatcher watcher = new FileSystemWatcher
- // {
- // Path = path,
- // IncludeSubdirectories = includingSubDirectory,
- // Filter = $"*.{fileType}",
- // EnableRaisingEvents = true
- // };
- // watcher.Changed += FileChanged;
- // watcher.Created += FileChanged;
- // watcher.Deleted += FileChanged;
- // watcher.Renamed += FileChanged;
- // }
- // }
-
- // private static void FileChanged(object source, FileSystemEventArgs e)
- // {
- // Task.Run(() =>
- // {
- // Main.IndexPrograms();
- // });
- // }
- //}
-}
From 85256ef42fb658a24298a5d2726aa310956539fd Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Thu, 3 Nov 2022 18:38:36 +0800
Subject: [PATCH 51/58] Comments
---
Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs | 1 +
Plugins/Flow.Launcher.Plugin.Program/Settings.cs | 8 ++++++++
2 files changed, 9 insertions(+)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index 5a3295c38b5..52673cc1deb 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -370,6 +370,7 @@ private static string Extension(string path)
private static IEnumerable UnregisteredPrograms(List sources, string[] suffixes, string[] protocols)
{
+ // Disabled custom sources are not in DisabledProgramSources
var paths = ExceptDisabledSource(sources.Where(s => Directory.Exists(s.Location) && s.Enabled)
.AsParallel()
.SelectMany(s => ProgramPaths(s.Location, suffixes)))
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
index 44d4483b922..fb28c1cf2a2 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
@@ -9,7 +9,15 @@ namespace Flow.Launcher.Plugin.Program
public class Settings
{
public DateTime LastIndexTime { get; set; }
+
+ ///
+ /// User-added program sources' directories
+ ///
public List ProgramSources { get; set; } = new List();
+
+ ///
+ /// Disabled single programs, not including User-added directories
+ ///
public List DisabledProgramSources { get; set; } = new List();
[Obsolete, JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
From 4725b0df07ce8e8b2577a28665325f18893a6bc6 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Fri, 4 Nov 2022 00:47:52 +0800
Subject: [PATCH 52/58] Implement object.Equals for uwp and win32
---
.../Programs/UWP.cs | 17 +++++++++++++++++
.../Programs/Win32.cs | 12 ++++++++++++
.../Flow.Launcher.Plugin.Program/Settings.cs | 2 +-
3 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
index fb460362289..0a57ae74c09 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
@@ -761,6 +761,23 @@ public override string ToString()
{
return $"{DisplayName}: {Description}";
}
+
+ public override bool Equals(object obj)
+ {
+ if (obj is Application other)
+ {
+ return UniqueIdentifier == other.UniqueIdentifier;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public override int GetHashCode()
+ {
+ return UniqueIdentifier.GetHashCode();
+ }
}
public enum PackageVersion
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index 52673cc1deb..5016bee1287 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -586,6 +586,18 @@ public bool Equals([AllowNull] Win32 other)
return UniqueIdentifier == other.UniqueIdentifier;
}
+ public override bool Equals(object obj)
+ {
+ if (obj is Win32 other)
+ {
+ return UniqueIdentifier == other.UniqueIdentifier;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
private static IEnumerable GetStartMenuPaths()
{
var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
index fb28c1cf2a2..84cc2e4eebf 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Settings.cs
@@ -20,7 +20,7 @@ public class Settings
///
public List DisabledProgramSources { get; set; } = new List();
- [Obsolete, JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
+ [Obsolete("Should use GetSuffixes() instead."), JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string[] ProgramSuffixes { get; set; } = null;
public string[] CustomSuffixes { get; set; } = Array.Empty(); // Custom suffixes only
public string[] CustomProtocols { get; set; } = Array.Empty();
From ff430c71d3b7fca9ae2cbce929cbb2208f2a412d Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Fri, 4 Nov 2022 14:15:42 +0800
Subject: [PATCH 53/58] Fix duplicate program sources when editing
---
.../AddProgramSource.xaml.cs | 16 +++++++++++++++-
.../Languages/en.xaml | 1 +
.../Views/ProgramSetting.xaml.cs | 2 +-
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index 469068b7a35..fddb69f2a76 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -27,9 +27,10 @@ public AddProgramSource(PluginInitContext context, Settings settings)
btnAdd.Content = _context.API.GetTranslation("flowlauncher_plugin_program_add");
}
- public AddProgramSource(ProgramSource source, Settings settings)
+ public AddProgramSource(PluginInitContext context, ProgramSource source, Settings settings)
{
InitializeComponent();
+ _context = context;
_editing = source;
_settings = settings;
update = true;
@@ -70,11 +71,24 @@ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
_settings.ProgramSources.Insert(0, source);
ProgramSetting.ProgramSettingDisplayList.Add(source);
}
+ else
+ {
+ System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source"));
+ return;
+ }
}
else
{
if (!_editing.Location.Equals(path, System.StringComparison.OrdinalIgnoreCase))
{
+ if (ProgramSetting.ProgramSettingDisplayList
+ .Any(x => x.UniqueIdentifier.Equals(path, System.StringComparison.OrdinalIgnoreCase)))
+ {
+ // Check if the new location is used
+ // No need to check win32 or uwp, just override them
+ System.Windows.MessageBox.Show(_context.API.GetTranslation("flowlauncher_plugin_program_duplicate_program_source"));
+ return;
+ }
modified = true;
_editing.Location = path; // Changes UniqueIdentifier internally
}
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml b/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml
index 2a166cc9508..eacda542b8f 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml
+++ b/Plugins/Flow.Launcher.Plugin.Program/Languages/en.xaml
@@ -35,6 +35,7 @@
Please select a program source
Are you sure you want to delete the selected program sources?
+ Another program source with the same location alreaday exists.
Program Source
Edit directory and status of this program source.
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index 1ee18ae3705..3daf1939fd1 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -160,7 +160,7 @@ private void EditProgramSource(ProgramSource selectedProgramSource)
}
else
{
- var add = new AddProgramSource(selectedProgramSource, _settings);
+ var add = new AddProgramSource(context, selectedProgramSource, _settings);
if (add.ShowDialog() ?? false)
{
if (selectedProgramSource.Enabled)
From 5f6bcdef6ee94917cf81b0624ebe9d2175036e7a Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Fri, 4 Nov 2022 14:17:37 +0800
Subject: [PATCH 54/58] Comment
---
Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index fddb69f2a76..c598cc543dc 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -79,6 +79,7 @@ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
}
else
{
+ // Separate checks to avoid changing UniqueIdentifier of UWP
if (!_editing.Location.Equals(path, System.StringComparison.OrdinalIgnoreCase))
{
if (ProgramSetting.ProgramSettingDisplayList
From 0079a882be059e9b6f3856fe74b5680230437d84 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Fri, 4 Nov 2022 14:57:57 +0800
Subject: [PATCH 55/58] minor refactor
---
Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs | 2 +-
.../Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
index c598cc543dc..e88c9b988d1 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/AddProgramSource.xaml.cs
@@ -27,7 +27,7 @@ public AddProgramSource(PluginInitContext context, Settings settings)
btnAdd.Content = _context.API.GetTranslation("flowlauncher_plugin_program_add");
}
- public AddProgramSource(PluginInitContext context, ProgramSource source, Settings settings)
+ public AddProgramSource(PluginInitContext context, Settings settings, ProgramSource source)
{
InitializeComponent();
_context = context;
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
index 3daf1939fd1..175cb06a64f 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs
@@ -160,7 +160,7 @@ private void EditProgramSource(ProgramSource selectedProgramSource)
}
else
{
- var add = new AddProgramSource(context, selectedProgramSource, _settings);
+ var add = new AddProgramSource(context, _settings, selectedProgramSource);
if (add.ShowDialog() ?? false)
{
if (selectedProgramSource.Enabled)
From 1e8cc9afb510022db1dffc0ce22cc206223f4bf5 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Sat, 5 Nov 2022 13:21:57 +0800
Subject: [PATCH 56/58] Slightly speed up uwp index
---
.../Programs/AppxPackageHelper.cs | 3 +--
.../Flow.Launcher.Plugin.Program/Programs/UWP.cs | 15 +++++----------
2 files changed, 6 insertions(+), 12 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/AppxPackageHelper.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/AppxPackageHelper.cs
index 73a25dd0d26..62416609e9c 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/AppxPackageHelper.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/AppxPackageHelper.cs
@@ -7,11 +7,10 @@ namespace Flow.Launcher.Plugin.Program.Programs
{
public class AppxPackageHelper
{
- private static readonly IAppxFactory appxFactory = (IAppxFactory)new AppxFactory();
-
// This function returns a list of attributes of applications
public static List GetAppsFromManifest(IStream stream)
{
+ IAppxFactory appxFactory = (IAppxFactory)new AppxFactory();
List apps = new List();
var reader = appxFactory.CreateManifestReader(stream);
var manifestApps = reader.GetApplications();
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
index 0a57ae74c09..b754aa5b45f 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
@@ -41,8 +41,6 @@ public UWP(Package package)
FullName = package.Id.FullName;
FamilyName = package.Id.FamilyName;
InitializeAppInfo();
- Apps = Apps.Where(a => !string.IsNullOrEmpty(a.UserModelId) && !string.IsNullOrEmpty(a.DisplayName))
- .ToArray();
}
private void InitializeAppInfo()
@@ -58,16 +56,13 @@ private void InitializeAppInfo()
if (hResult == Hresult.Ok)
{
- var apps = new List();
-
List _apps = AppxPackageHelper.GetAppsFromManifest(stream);
- foreach (var _app in _apps)
- {
- var app = new Application(_app, this);
- apps.Add(app);
- }
- Apps = apps.Where(a => a.AppListEntry != "none").ToArray();
+ Apps = _apps.Select(x => new Application(x, this))
+ .Where(a => a.AppListEntry != "none"
+ && !string.IsNullOrEmpty(a.UserModelId)
+ && !string.IsNullOrEmpty(a.DisplayName))
+ .ToArray();
}
else
{
From 59c355eed2ce3156aa302bc8f5a791036c94a085 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Sat, 5 Nov 2022 13:48:16 +0800
Subject: [PATCH 57/58] remove unused property
---
Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
index b754aa5b45f..b4f78565b23 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/UWP.cs
@@ -59,8 +59,7 @@ private void InitializeAppInfo()
List _apps = AppxPackageHelper.GetAppsFromManifest(stream);
Apps = _apps.Select(x => new Application(x, this))
- .Where(a => a.AppListEntry != "none"
- && !string.IsNullOrEmpty(a.UserModelId)
+ .Where(a => !string.IsNullOrEmpty(a.UserModelId)
&& !string.IsNullOrEmpty(a.DisplayName))
.ToArray();
}
@@ -278,7 +277,6 @@ public override int GetHashCode()
[Serializable]
public class Application : IProgram
{
- public string AppListEntry { get; set; }
public string UniqueIdentifier { get; set; }
public string DisplayName { get; set; }
public string Description { get; set; }
From f5701d44ac62bf70b2026189257c0d053cd04b73 Mon Sep 17 00:00:00 2001
From: Vic <10308169+VictoriousRaptor@users.noreply.github.com>
Date: Mon, 14 Nov 2022 15:27:06 +0800
Subject: [PATCH 58/58] fix merge
---
Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
index d739aab0adc..c13b32e80fc 100644
--- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
+++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs
@@ -402,7 +402,7 @@ private static IEnumerable StartMenuPrograms(string[] suffixes, string[]
return programs;
}
- private static IEnumerable PATHPrograms(string[] suffixes)
+ private static IEnumerable PATHPrograms(string[] suffixes, string[] protocols)
{
var pathEnv = Environment.GetEnvironmentVariable("Path");
if (String.IsNullOrEmpty(pathEnv))
@@ -418,14 +418,14 @@ private static IEnumerable PATHPrograms(string[] suffixes)
.Select(x => Extension(x) switch
{
ShortcutExtension => LnkProgram(x),
- UrlExtension => UrlProgram(x),
+ UrlExtension => UrlProgram(x, protocols),
ExeExtension => ExeProgram(x),
_ => Win32Program(x)
});
return programs;
}
- private static IEnumerable AppPathsPrograms(string[] suffixes)
+ private static IEnumerable AppPathsPrograms(string[] suffixes, string[] protocols)
{
// https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121
const string appPaths = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths";
@@ -585,7 +585,7 @@ public static Win32[] All(Settings settings)
if (settings.EnablePATHSource)
{
- var path = PATHPrograms(settings.GetSuffixes());
+ var path = PATHPrograms(settings.GetSuffixes(), protocols);
autoIndexPrograms = autoIndexPrograms.Concat(path);
}