Skip to content

Commit adbd262

Browse files
authored
Merge branch 'dev' into 250331-NewPluginsPage
2 parents cd39164 + 6ebb73b commit adbd262

File tree

31 files changed

+492
-239
lines changed

31 files changed

+492
-239
lines changed

Flow.Launcher.Core/Configuration/Portable.cs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Portable : IPortable
2222
/// As at Squirrel.Windows version 1.5.2, UpdateManager needs to be disposed after finish
2323
/// </summary>
2424
/// <returns></returns>
25-
private UpdateManager NewUpdateManager()
25+
private static UpdateManager NewUpdateManager()
2626
{
2727
var applicationFolderName = Constant.ApplicationDirectory
2828
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
@@ -81,20 +81,16 @@ public void EnablePortableMode()
8181

8282
public void RemoveShortcuts()
8383
{
84-
using (var portabilityUpdater = NewUpdateManager())
85-
{
86-
portabilityUpdater.RemoveShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.StartMenu);
87-
portabilityUpdater.RemoveShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Desktop);
88-
portabilityUpdater.RemoveShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Startup);
89-
}
84+
using var portabilityUpdater = NewUpdateManager();
85+
portabilityUpdater.RemoveShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.StartMenu);
86+
portabilityUpdater.RemoveShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Desktop);
87+
portabilityUpdater.RemoveShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Startup);
9088
}
9189

9290
public void RemoveUninstallerEntry()
9391
{
94-
using (var portabilityUpdater = NewUpdateManager())
95-
{
96-
portabilityUpdater.RemoveUninstallerRegistryEntry();
97-
}
92+
using var portabilityUpdater = NewUpdateManager();
93+
portabilityUpdater.RemoveUninstallerRegistryEntry();
9894
}
9995

10096
public void MoveUserDataFolder(string fromLocation, string toLocation)
@@ -110,12 +106,10 @@ public void VerifyUserDataAfterMove(string fromLocation, string toLocation)
110106

111107
public void CreateShortcuts()
112108
{
113-
using (var portabilityUpdater = NewUpdateManager())
114-
{
115-
portabilityUpdater.CreateShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.StartMenu, false);
116-
portabilityUpdater.CreateShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Desktop, false);
117-
portabilityUpdater.CreateShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Startup, false);
118-
}
109+
using var portabilityUpdater = NewUpdateManager();
110+
portabilityUpdater.CreateShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.StartMenu, false);
111+
portabilityUpdater.CreateShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Desktop, false);
112+
portabilityUpdater.CreateShortcutsForExecutable(Constant.ApplicationFileName, ShortcutLocation.Startup, false);
119113
}
120114

121115
public void CreateUninstallerEntry()
@@ -129,18 +123,14 @@ public void CreateUninstallerEntry()
129123
subKey2.SetValue("DisplayIcon", Path.Combine(Constant.ApplicationDirectory, "app.ico"), RegistryValueKind.String);
130124
}
131125

132-
using (var portabilityUpdater = NewUpdateManager())
133-
{
134-
_ = portabilityUpdater.CreateUninstallerRegistryEntry();
135-
}
126+
using var portabilityUpdater = NewUpdateManager();
127+
_ = portabilityUpdater.CreateUninstallerRegistryEntry();
136128
}
137129

138-
internal void IndicateDeletion(string filePathTodelete)
130+
private static void IndicateDeletion(string filePathTodelete)
139131
{
140132
var deleteFilePath = Path.Combine(filePathTodelete, DataLocation.DeletionIndicatorFile);
141-
using (var _ = File.CreateText(deleteFilePath))
142-
{
143-
}
133+
using var _ = File.CreateText(deleteFilePath);
144134
}
145135

146136
///<summary>

Flow.Launcher.Core/ExternalPlugins/CommunityPluginSource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Flow.Launcher.Infrastructure.Http;
22
using Flow.Launcher.Infrastructure.Logger;
3+
using Flow.Launcher.Plugin;
34
using System;
45
using System.Collections.Generic;
56
using System.Net;

Flow.Launcher.Core/ExternalPlugins/CommunityPluginStore.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.Threading;
44
using System.Threading.Tasks;
5+
using Flow.Launcher.Plugin;
56

67
namespace Flow.Launcher.Core.ExternalPlugins
78
{

Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
using Flow.Launcher.Infrastructure.Logger;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.Threading;
54
using System.Threading.Tasks;
5+
using CommunityToolkit.Mvvm.DependencyInjection;
6+
using Flow.Launcher.Plugin;
67

78
namespace Flow.Launcher.Core.ExternalPlugins
89
{
@@ -17,11 +18,11 @@ public static class PluginsManifest
1718
private static readonly SemaphoreSlim manifestUpdateLock = new(1);
1819

1920
private static DateTime lastFetchedAt = DateTime.MinValue;
20-
private static TimeSpan fetchTimeout = TimeSpan.FromMinutes(2);
21+
private static readonly TimeSpan fetchTimeout = TimeSpan.FromMinutes(2);
2122

2223
public static List<UserPlugin> UserPlugins { get; private set; }
2324

24-
public static async Task<bool> UpdateManifestAsync(CancellationToken token = default, bool usePrimaryUrlOnly = false)
25+
public static async Task<bool> UpdateManifestAsync(bool usePrimaryUrlOnly = false, CancellationToken token = default)
2526
{
2627
try
2728
{
@@ -43,7 +44,7 @@ public static async Task<bool> UpdateManifestAsync(CancellationToken token = def
4344
}
4445
catch (Exception e)
4546
{
46-
Log.Exception($"|PluginsManifest.{nameof(UpdateManifestAsync)}|Http request failed", e);
47+
Ioc.Default.GetRequiredService<IPublicAPI>().LogException(nameof(PluginsManifest), "Http request failed", e);
4748
}
4849
finally
4950
{

Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs

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

Flow.Launcher.Core/Plugin/JsonRPCPluginSettings.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class JsonRPCPluginSettings
2323
protected ConcurrentDictionary<string, object?> Settings { get; set; } = null!;
2424
public required IPublicAPI API { get; init; }
2525

26+
private static readonly string ClassName = nameof(JsonRPCPluginSettings);
27+
2628
private JsonStorage<ConcurrentDictionary<string, object?>> _storage = null!;
2729

2830
private static readonly Thickness SettingPanelMargin = (Thickness)Application.Current.FindResource("SettingPanelMargin");
@@ -122,12 +124,26 @@ public void UpdateSettings(IReadOnlyDictionary<string, object> settings)
122124

123125
public async Task SaveAsync()
124126
{
125-
await _storage.SaveAsync();
127+
try
128+
{
129+
await _storage.SaveAsync();
130+
}
131+
catch (System.Exception e)
132+
{
133+
API.LogException(ClassName, $"Failed to save plugin settings to path: {SettingPath}", e);
134+
}
126135
}
127136

128137
public void Save()
129138
{
130-
_storage.Save();
139+
try
140+
{
141+
_storage.Save();
142+
}
143+
catch (System.Exception e)
144+
{
145+
API.LogException(ClassName, $"Failed to save plugin settings to path: {SettingPath}", e);
146+
}
131147
}
132148

133149
public bool NeedCreateSettingPanel()

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -454,34 +454,23 @@ private static bool SameOrLesserPluginVersionExists(string metadataPath)
454454

455455
#region Public functions
456456

457-
public static bool PluginModified(string uuid)
457+
public static bool PluginModified(string id)
458458
{
459-
return _modifiedPlugins.Contains(uuid);
459+
return _modifiedPlugins.Contains(id);
460460
}
461461

462-
463-
/// <summary>
464-
/// Update a plugin to new version, from a zip file. By default will remove the zip file if update is via url,
465-
/// unless it's a local path installation
466-
/// </summary>
467462
public static async Task UpdatePluginAsync(PluginMetadata existingVersion, UserPlugin newVersion, string zipFilePath)
468463
{
469464
InstallPlugin(newVersion, zipFilePath, checkModified:false);
470465
await UninstallPluginAsync(existingVersion, removePluginFromSettings:false, removePluginSettings:false, checkModified: false);
471466
_modifiedPlugins.Add(existingVersion.ID);
472467
}
473468

474-
/// <summary>
475-
/// Install a plugin. By default will remove the zip file if installation is from url, unless it's a local path installation
476-
/// </summary>
477469
public static void InstallPlugin(UserPlugin plugin, string zipFilePath)
478470
{
479471
InstallPlugin(plugin, zipFilePath, checkModified: true);
480472
}
481473

482-
/// <summary>
483-
/// Uninstall a plugin.
484-
/// </summary>
485474
public static async Task UninstallPluginAsync(PluginMetadata plugin, bool removePluginFromSettings = true, bool removePluginSettings = false)
486475
{
487476
await UninstallPluginAsync(plugin, removePluginFromSettings, removePluginSettings, true);
@@ -525,20 +514,20 @@ internal static void InstallPlugin(UserPlugin plugin, string zipFilePath, bool c
525514
var folderName = string.IsNullOrEmpty(plugin.Version) ? $"{plugin.Name}-{Guid.NewGuid()}" : $"{plugin.Name}-{plugin.Version}";
526515

527516
var defaultPluginIDs = new List<string>
528-
{
529-
"0ECADE17459B49F587BF81DC3A125110", // BrowserBookmark
530-
"CEA0FDFC6D3B4085823D60DC76F28855", // Calculator
531-
"572be03c74c642baae319fc283e561a8", // Explorer
532-
"6A122269676E40EB86EB543B945932B9", // PluginIndicator
533-
"9f8f9b14-2518-4907-b211-35ab6290dee7", // PluginsManager
534-
"b64d0a79-329a-48b0-b53f-d658318a1bf6", // ProcessKiller
535-
"791FC278BA414111B8D1886DFE447410", // Program
536-
"D409510CD0D2481F853690A07E6DC426", // Shell
537-
"CEA08895D2544B019B2E9C5009600DF4", // Sys
538-
"0308FD86DE0A4DEE8D62B9B535370992", // URL
539-
"565B73353DBF4806919830B9202EE3BF", // WebSearch
540-
"5043CETYU6A748679OPA02D27D99677A" // WindowsSettings
541-
};
517+
{
518+
"0ECADE17459B49F587BF81DC3A125110", // BrowserBookmark
519+
"CEA0FDFC6D3B4085823D60DC76F28855", // Calculator
520+
"572be03c74c642baae319fc283e561a8", // Explorer
521+
"6A122269676E40EB86EB543B945932B9", // PluginIndicator
522+
"9f8f9b14-2518-4907-b211-35ab6290dee7", // PluginsManager
523+
"b64d0a79-329a-48b0-b53f-d658318a1bf6", // ProcessKiller
524+
"791FC278BA414111B8D1886DFE447410", // Program
525+
"D409510CD0D2481F853690A07E6DC426", // Shell
526+
"CEA08895D2544B019B2E9C5009600DF4", // Sys
527+
"0308FD86DE0A4DEE8D62B9B535370992", // URL
528+
"565B73353DBF4806919830B9202EE3BF", // WebSearch
529+
"5043CETYU6A748679OPA02D27D99677A" // WindowsSettings
530+
};
542531

543532
// Treat default plugin differently, it needs to be removable along with each flow release
544533
var installDirectory = !defaultPluginIDs.Any(x => x == plugin.ID)

Flow.Launcher.Core/Updater.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44
using System.Net.Http;
55
using System.Net.Sockets;
66
using System.Linq;
7+
using System.Text.Json;
8+
using System.Text.Json.Serialization;
9+
using System.Threading;
710
using System.Threading.Tasks;
811
using System.Windows;
9-
using JetBrains.Annotations;
10-
using Squirrel;
12+
using CommunityToolkit.Mvvm.DependencyInjection;
1113
using Flow.Launcher.Core.Resource;
1214
using Flow.Launcher.Plugin.SharedCommands;
1315
using Flow.Launcher.Infrastructure;
1416
using Flow.Launcher.Infrastructure.Http;
1517
using Flow.Launcher.Infrastructure.Logger;
1618
using Flow.Launcher.Infrastructure.UserSettings;
1719
using Flow.Launcher.Plugin;
18-
using System.Text.Json.Serialization;
19-
using System.Threading;
20+
using JetBrains.Annotations;
21+
using Squirrel;
2022

2123
namespace Flow.Launcher.Core
2224
{
@@ -51,7 +53,7 @@ public async Task UpdateAppAsync(bool silentUpdate = true)
5153
var newReleaseVersion = Version.Parse(newUpdateInfo.FutureReleaseEntry.Version.ToString());
5254
var currentVersion = Version.Parse(Constant.Version);
5355

54-
Log.Info($"|Updater.UpdateApp|Future Release <{newUpdateInfo.FutureReleaseEntry.Formatted()}>");
56+
Log.Info($"|Updater.UpdateApp|Future Release <{Formatted(newUpdateInfo.FutureReleaseEntry)}>");
5557

5658
if (newReleaseVersion <= currentVersion)
5759
{
@@ -70,7 +72,7 @@ public async Task UpdateAppAsync(bool silentUpdate = true)
7072

7173
if (DataLocation.PortableDataLocationInUse())
7274
{
73-
var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}";
75+
var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion}\\{DataLocation.PortableFolderName}";
7476
FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination, (s) => _api.ShowMsgBox(s));
7577
if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination, (s) => _api.ShowMsgBox(s)))
7678
_api.ShowMsgBox(string.Format(_api.GetTranslation("update_flowlauncher_fail_moving_portable_user_profile_data"),
@@ -122,7 +124,7 @@ private class GithubRelease
122124
}
123125

124126
// https://github.com/Squirrel/Squirrel.Windows/blob/master/src/Squirrel/UpdateManager.Factory.cs
125-
private async Task<UpdateManager> GitHubUpdateManagerAsync(string repository)
127+
private static async Task<UpdateManager> GitHubUpdateManagerAsync(string repository)
126128
{
127129
var uri = new Uri(repository);
128130
var api = $"https://api.github.com/repos{uri.AbsolutePath}/releases";
@@ -144,12 +146,22 @@ private async Task<UpdateManager> GitHubUpdateManagerAsync(string repository)
144146
return manager;
145147
}
146148

147-
public string NewVersionTips(string version)
149+
private static string NewVersionTips(string version)
148150
{
149-
var translator = InternationalizationManager.Instance;
151+
var translator = Ioc.Default.GetRequiredService<Internationalization>();
150152
var tips = string.Format(translator.GetTranslation("newVersionTips"), version);
151153

152154
return tips;
153155
}
156+
157+
private static string Formatted<T>(T t)
158+
{
159+
var formatted = JsonSerializer.Serialize(t, new JsonSerializerOptions
160+
{
161+
WriteIndented = true
162+
});
163+
164+
return formatted;
165+
}
154166
}
155167
}

0 commit comments

Comments
 (0)