Skip to content

Commit 7b999c5

Browse files
committed
Merge branch 'dev' into PluginAPIExpand
2 parents a721bd7 + 0c5d166 commit 7b999c5

File tree

16 files changed

+154
-133
lines changed

16 files changed

+154
-133
lines changed

Flow.Launcher.Core/Updater.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
3535
UpdateInfo newUpdateInfo;
3636

3737
if (!silentUpdate)
38-
api.ShowMsg("Please wait...", "Checking for new update");
38+
api.ShowMsg(api.GetTranslation("pleaseWait"),
39+
api.GetTranslation("update_flowlauncher_update_check"));
3940

4041
using var updateManager = await GitHubUpdateManager(GitHubRepository).ConfigureAwait(false);
4142

@@ -51,12 +52,13 @@ public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
5152
if (newReleaseVersion <= currentVersion)
5253
{
5354
if (!silentUpdate)
54-
MessageBox.Show("You already have the latest Flow Launcher version");
55+
MessageBox.Show(api.GetTranslation("update_flowlauncher_already_on_latest"));
5556
return;
5657
}
5758

5859
if (!silentUpdate)
59-
api.ShowMsg("Update found", "Updating...");
60+
api.ShowMsg(api.GetTranslation("update_flowlauncher_update_found"),
61+
api.GetTranslation("update_flowlauncher_updating"));
6062

6163
await updateManager.DownloadReleases(newUpdateInfo.ReleasesToApply).ConfigureAwait(false);
6264

@@ -67,8 +69,9 @@ public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
6769
var targetDestination = updateManager.RootAppDirectory + $"\\app-{newReleaseVersion.ToString()}\\{DataLocation.PortableFolderName}";
6870
FilesFolders.CopyAll(DataLocation.PortableDataPath, targetDestination);
6971
if (!FilesFolders.VerifyBothFolderFilesEqual(DataLocation.PortableDataPath, targetDestination))
70-
MessageBox.Show("Flow Launcher was not able to move your user profile data to the new update version. Please manually " +
71-
$"move your profile data folder from {DataLocation.PortableDataPath} to {targetDestination}");
72+
MessageBox.Show(string.Format(api.GetTranslation("update_flowlauncher_fail_moving_portable_user_profile_data"),
73+
DataLocation.PortableDataPath,
74+
targetDestination));
7275
}
7376
else
7477
{
@@ -79,15 +82,16 @@ public async Task UpdateApp(IPublicAPI api, bool silentUpdate = true)
7982

8083
Log.Info($"|Updater.UpdateApp|Update success:{newVersionTips}");
8184

82-
if (MessageBox.Show(newVersionTips, "New Update", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
85+
if (MessageBox.Show(newVersionTips, api.GetTranslation("update_flowlauncher_new_update"), MessageBoxButton.YesNo) == MessageBoxResult.Yes)
8386
{
8487
UpdateManager.RestartApp(Constant.ApplicationFileName);
8588
}
8689
}
8790
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
8891
{
8992
Log.Exception($"|Updater.UpdateApp|Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
90-
api.ShowMsg("Update Failed", "Check your connection and try updating proxy settings to github-cloud.s3.amazonaws.com.");
93+
api.ShowMsg(api.GetTranslation("update_flowlauncher_fail"),
94+
api.GetTranslation("update_flowlauncher_check_connection"));
9195
return;
9296
}
9397
}

Flow.Launcher.Test/Plugins/ExplorerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ private async Task<List<Result>> MethodWindowsIndexSearchReturnsZeroResultsAsync
2424
return new List<Result>();
2525
}
2626

27-
private List<Result> MethodDirectoryInfoClassSearchReturnsTwoResults(Query dummyQuery, string dummyString)
27+
private List<Result> MethodDirectoryInfoClassSearchReturnsTwoResults(Query dummyQuery, string dummyString, CancellationToken token)
2828
{
2929
return new List<Result>
3030
{

Flow.Launcher/CustomQueryHotkeySetting.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Icon="Images\app.png"
66
ResizeMode="NoResize"
77
WindowStartupLocation="CenterScreen"
8-
Title="Custom Plugin Hotkey" Height="200" Width="674.766">
8+
Title="{DynamicResource customeQueryHotkeyTitle}" Height="200" Width="674.766">
99
<Window.InputBindings>
1010
<KeyBinding Key="Escape" Command="Close"/>
1111
</Window.InputBindings>

Flow.Launcher/Languages/en.xaml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<!--Setting General-->
1818
<system:String x:Key="flowlauncher_settings">Flow Launcher Settings</system:String>
1919
<system:String x:Key="general">General</system:String>
20+
<system:String x:Key="portableMode">Portable Mode</system:String>
2021
<system:String x:Key="startFlowLauncherOnSystemStartup">Start Flow Launcher on system startup</system:String>
2122
<system:String x:Key="hideFlowLauncherWhenLoseFocus">Hide Flow Launcher when focus is lost</system:String>
2223
<system:String x:Key="dontPromptUpdateMsg">Do not show new version notifications</system:String>
@@ -39,12 +40,13 @@
3940
<!--Setting Plugin-->
4041
<system:String x:Key="plugin">Plugin</system:String>
4142
<system:String x:Key="browserMorePlugins">Find more plugins</system:String>
43+
<system:String x:Key="enable">Enable</system:String>
4244
<system:String x:Key="disable">Disable</system:String>
4345
<system:String x:Key="actionKeywords">Action keyword:</system:String>
4446
<system:String x:Key="currentActionKeywords">Current action keyword:</system:String>
4547
<system:String x:Key="newActionKeyword">New action keyword:</system:String>
46-
<system:String x:Key="currentPriority">Current Priority: </system:String>
47-
<system:String x:Key="newPriority">New Priority: </system:String>
48+
<system:String x:Key="currentPriority">Current Priority:</system:String>
49+
<system:String x:Key="newPriority">New Priority:</system:String>
4850
<system:String x:Key="pluginDirectory">Plugin Directory</system:String>
4951
<system:String x:Key="author">Author</system:String>
5052
<system:String x:Key="plugin_init_time">Init time:</system:String>
@@ -109,7 +111,7 @@
109111
<!--Priority Setting Dialog-->
110112
<system:String x:Key="priority_tips">Greater the number, the higher the result will be ranked. Try setting it as 5. If you want the results to be lower than any other plugin's, provide a negative number</system:String>
111113
<system:String x:Key="invalidPriority">Please provide an valid integer for Priority!</system:String>
112-
114+
113115
<!--Action Keyword Setting Dialog-->
114116
<system:String x:Key="oldActionKeywords">Old Action Keyword</system:String>
115117
<system:String x:Key="newActionKeywords">New Action Keyword</system:String>
@@ -122,6 +124,7 @@
122124
<system:String x:Key="actionkeyword_tips">Use * if you don't want to specify an action keyword</system:String>
123125

124126
<!--Custom Query Hotkey Dialog-->
127+
<system:String x:Key="customeQueryHotkeyTitle">Custom Plugin Hotkey</system:String>
125128
<system:String x:Key="preview">Preview</system:String>
126129
<system:String x:Key="hotkeyIsNotUnavailable">Hotkey is unavailable, please select a new hotkey</system:String>
127130
<system:String x:Key="invalidPluginHotkey">Invalid plugin hotkey</system:String>
@@ -146,11 +149,23 @@
146149
<system:String x:Key="reportWindow_report_failed">Failed to send report</system:String>
147150
<system:String x:Key="reportWindow_flowlauncher_got_an_error">Flow Launcher got an error</system:String>
148151

152+
<!--General Notice-->
153+
<system:String x:Key="pleaseWait">Please wait...</system:String>
154+
149155
<!--update-->
156+
<system:String x:Key="update_flowlauncher_update_check">Checking for new update</system:String>
157+
<system:String x:Key="update_flowlauncher_already_on_latest">You already have the latest Flow Launcher version</system:String>
158+
<system:String x:Key="update_flowlauncher_update_found">Update found</system:String>
159+
<system:String x:Key="update_flowlauncher_updating">Updating...</system:String>
160+
<system:String x:Key="update_flowlauncher_fail_moving_portable_user_profile_data">Flow Launcher was not able to move your user profile data to the new update version.
161+
Please manually move your profile data folder from {0} to {1}</system:String>
162+
<system:String x:Key="update_flowlauncher_new_update">New Update</system:String>
150163
<system:String x:Key="update_flowlauncher_update_new_version_available">New Flow Launcher release {0} is now available</system:String>
151164
<system:String x:Key="update_flowlauncher_update_error">An error occurred while trying to install software updates</system:String>
152165
<system:String x:Key="update_flowlauncher_update">Update</system:String>
153166
<system:String x:Key="update_flowlauncher_update_cancel">Cancel</system:String>
167+
<system:String x:Key="update_flowlauncher_fail">Update Failed</system:String>
168+
<system:String x:Key="update_flowlauncher_check_connection">Check your connection and try updating proxy settings to github-cloud.s3.amazonaws.com.</system:String>
154169
<system:String x:Key="update_flowlauncher_update_restart_flowlauncher_tip">This upgrade will restart Flow Launcher</system:String>
155170
<system:String x:Key="update_flowlauncher_update_upadte_files">Following files will be updated</system:String>
156171
<system:String x:Key="update_flowlauncher_update_files">Update files</system:String>

Flow.Launcher/SettingWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<ScrollViewer ui:ScrollViewerHelper.AutoHideScrollBars="True" Margin="60,30,0,30">
3838
<StackPanel Orientation="Vertical">
3939
<ui:ToggleSwitch Margin="10" IsOn="{Binding PortableMode}">
40-
<TextBlock Text="Portable Mode" />
40+
<TextBlock Text="{DynamicResource portableMode}" />
4141
</ui:ToggleSwitch>
4242
<CheckBox Margin="10" IsChecked="{Binding Settings.StartFlowLauncherOnSystemStartup}"
4343
Checked="OnAutoStartupChecked" Unchecked="OnAutoStartupUncheck">
@@ -166,7 +166,7 @@
166166
</TextBlock>
167167
</ToolTipService.ToolTip>
168168
</TextBlock>
169-
<ui:ToggleSwitch Grid.Column="1" OffContent="Disabled" OnContent="Enabled"
169+
<ui:ToggleSwitch Grid.Column="1" OffContent="{DynamicResource disable}" OnContent="{DynamicResource enable}"
170170
MaxWidth="110" HorizontalAlignment="Right"
171171
IsOn="{Binding PluginState}"/>
172172
</Grid>

Flow.Launcher/ViewModel/ResultsViewModel.cs

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -139,52 +139,28 @@ public void KeepResultsExcept(PluginMetadata metadata)
139139
/// </summary>
140140
public void AddResults(List<Result> newRawResults, string resultId)
141141
{
142-
lock (_collectionLock)
143-
{
144-
var newResults = NewResults(newRawResults, resultId);
145-
146-
// https://social.msdn.microsoft.com/Forums/vstudio/en-US/5ff71969-f183-4744-909d-50f7cd414954/binding-a-tabcontrols-selectedindex-not-working?forum=wpf
147-
// fix selected index flow
148-
var updateTask = Task.Run(() =>
149-
{
150-
// update UI in one run, so it can avoid UI flickering
151-
152-
Results.Update(newResults);
153-
if (Results.Any())
154-
SelectedItem = Results[0];
155-
});
156-
if (!updateTask.Wait(300))
157-
{
158-
updateTask.Dispose();
159-
throw new TimeoutException("Update result use too much time.");
160-
}
142+
var newResults = NewResults(newRawResults, resultId);
161143

162-
}
163-
164-
if (Visbility != Visibility.Visible && Results.Count > 0)
165-
{
166-
Margin = new Thickness { Top = 8 };
167-
SelectedIndex = 0;
168-
Visbility = Visibility.Visible;
169-
}
170-
else
171-
{
172-
Margin = new Thickness { Top = 0 };
173-
Visbility = Visibility.Collapsed;
174-
}
144+
UpdateResults(newResults);
175145
}
176146
/// <summary>
177147
/// To avoid deadlock, this method should not called from main thread
178148
/// </summary>
179149
public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates, CancellationToken token)
180150
{
181151
var newResults = NewResults(resultsForUpdates);
152+
182153
if (token.IsCancellationRequested)
183154
return;
155+
156+
UpdateResults(newResults, token);
157+
}
158+
159+
private void UpdateResults(List<ResultViewModel> newResults, CancellationToken token = default)
160+
{
184161
lock (_collectionLock)
185162
{
186163
// update UI in one run, so it can avoid UI flickering
187-
188164
Results.Update(newResults, token);
189165
if (Results.Any())
190166
SelectedItem = Results[0];
@@ -202,7 +178,6 @@ public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates, Cancella
202178
Visbility = Visibility.Collapsed;
203179
break;
204180
}
205-
206181
}
207182

208183
private List<ResultViewModel> NewResults(List<Result> newRawResults, string resultId)
@@ -212,10 +187,10 @@ private List<ResultViewModel> NewResults(List<Result> newRawResults, string resu
212187

213188
var results = Results as IEnumerable<ResultViewModel>;
214189

215-
var newResults = newRawResults.Select(r => new ResultViewModel(r, _settings)).ToList();
190+
var newResults = newRawResults.Select(r => new ResultViewModel(r, _settings));
216191

217192
return results.Where(r => r.Result.PluginID != resultId)
218-
.Concat(results.Intersect(newResults).Union(newResults))
193+
.Concat(newResults)
219194
.OrderByDescending(r => r.Result.Score)
220195
.ToList();
221196
}
@@ -228,8 +203,7 @@ private List<ResultViewModel> NewResults(IEnumerable<ResultsForUpdate> resultsFo
228203
var results = Results as IEnumerable<ResultViewModel>;
229204

230205
return results.Where(r => r != null && !resultsForUpdates.Any(u => u.Metadata.ID == r.Result.PluginID))
231-
.Concat(
232-
resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings)))
206+
.Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings)))
233207
.OrderByDescending(rv => rv.Result.Score)
234208
.ToList();
235209
}
@@ -266,49 +240,50 @@ private static void FormattedTextPropertyChanged(DependencyObject d, DependencyP
266240
}
267241
#endregion
268242

269-
public class ResultCollection : ObservableCollection<ResultViewModel>
243+
public class ResultCollection : List<ResultViewModel>, INotifyCollectionChanged
270244
{
271245
private long editTime = 0;
272246

273-
private bool _suppressNotifying = false;
274-
275247
private CancellationToken _token;
276248

277-
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
249+
public event NotifyCollectionChangedEventHandler CollectionChanged;
250+
251+
252+
protected void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
278253
{
279-
if (!_suppressNotifying)
280-
{
281-
base.OnCollectionChanged(e);
282-
}
254+
CollectionChanged?.Invoke(this, e);
283255
}
284256

285-
public void BulkAddRange(IEnumerable<ResultViewModel> resultViews)
257+
public void BulkAddAll(List<ResultViewModel> resultViews)
286258
{
287-
// suppress notifying before adding all element
288-
_suppressNotifying = true;
289-
foreach (var item in resultViews)
290-
{
291-
Add(item);
292-
}
293-
_suppressNotifying = false;
294-
// manually update event
295-
// wpf use directx / double buffered already, so just reset all won't cause ui flickering
259+
AddRange(resultViews);
260+
261+
// can return because the list will be cleared next time updated, which include a reset event
296262
if (_token.IsCancellationRequested)
297263
return;
264+
265+
// manually update event
266+
// wpf use directx / double buffered already, so just reset all won't cause ui flickering
298267
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
299268
}
300-
public void AddRange(IEnumerable<ResultViewModel> Items)
269+
private void AddAll(List<ResultViewModel> Items)
301270
{
302-
foreach (var item in Items)
271+
for (int i = 0; i < Items.Count; i++)
303272
{
273+
var item = Items[i];
304274
if (_token.IsCancellationRequested)
305275
return;
306276
Add(item);
277+
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, i));
307278
}
308279
}
309-
public void RemoveAll()
280+
public void RemoveAll(int Capacity = 512)
310281
{
311-
ClearItems();
282+
Clear();
283+
if (this.Capacity > 8000 && Capacity < this.Capacity)
284+
this.Capacity = Capacity;
285+
286+
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
312287
}
313288

314289
/// <summary>
@@ -323,15 +298,19 @@ public void Update(List<ResultViewModel> newItems, CancellationToken token = def
323298

324299
if (editTime < 10 || newItems.Count < 30)
325300
{
326-
if (Count != 0) ClearItems();
327-
AddRange(newItems);
301+
if (Count != 0) RemoveAll(newItems.Count);
302+
AddAll(newItems);
328303
editTime++;
329304
return;
330305
}
331306
else
332307
{
333308
Clear();
334-
BulkAddRange(newItems);
309+
BulkAddAll(newItems);
310+
if (Capacity > 8000 && newItems.Count < 3000)
311+
{
312+
Capacity = newItems.Count;
313+
}
335314
editTime++;
336315
}
337316
}

0 commit comments

Comments
 (0)