Skip to content

Commit 21c5c77

Browse files
authored
Merge branch 'dev' into FixProgramSource
2 parents fe66cad + 6dd34b9 commit 21c5c77

File tree

3 files changed

+158
-126
lines changed

3 files changed

+158
-126
lines changed

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public MainWindow(Settings settings, MainViewModel mainVM)
5757
DataContext = mainVM;
5858
_viewModel = mainVM;
5959
_settings = settings;
60-
60+
6161
InitializeComponent();
6262
InitializePosition();
6363
animationSound.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
@@ -67,7 +67,7 @@ public MainWindow()
6767
{
6868
InitializeComponent();
6969
}
70-
70+
7171
private void OnCopy(object sender, ExecutedRoutedEventArgs e)
7272
{
7373
if (QueryTextBox.SelectionLength == 0)
@@ -115,6 +115,8 @@ private void OnLoaded(object sender, RoutedEventArgs _)
115115
switch (e.PropertyName)
116116
{
117117
case nameof(MainViewModel.MainWindowVisibilityStatus):
118+
{
119+
Dispatcher.Invoke(() =>
118120
{
119121
if (_viewModel.MainWindowVisibilityStatus)
120122
{
@@ -140,35 +142,35 @@ private void OnLoaded(object sender, RoutedEventArgs _)
140142
isProgressBarStoryboardPaused = false;
141143
}
142144

143-
if(_settings.UseAnimation)
145+
if (_settings.UseAnimation)
144146
WindowAnimator();
145147
}
146148
else if (!isProgressBarStoryboardPaused)
147149
{
148150
_progressBarStoryboard.Stop(ProgressBar);
149151
isProgressBarStoryboardPaused = true;
150152
}
151-
152-
break;
153-
}
153+
});
154+
break;
155+
}
154156
case nameof(MainViewModel.ProgressBarVisibility):
157+
{
158+
Dispatcher.Invoke(() =>
155159
{
156-
Dispatcher.Invoke(() =>
160+
if (_viewModel.ProgressBarVisibility == Visibility.Hidden && !isProgressBarStoryboardPaused)
157161
{
158-
if (_viewModel.ProgressBarVisibility == Visibility.Hidden && !isProgressBarStoryboardPaused)
159-
{
160-
_progressBarStoryboard.Stop(ProgressBar);
161-
isProgressBarStoryboardPaused = true;
162-
}
163-
else if (_viewModel.MainWindowVisibilityStatus &&
164-
isProgressBarStoryboardPaused)
165-
{
166-
_progressBarStoryboard.Begin(ProgressBar, true);
167-
isProgressBarStoryboardPaused = false;
168-
}
169-
});
170-
break;
171-
}
162+
_progressBarStoryboard.Stop(ProgressBar);
163+
isProgressBarStoryboardPaused = true;
164+
}
165+
else if (_viewModel.MainWindowVisibilityStatus &&
166+
isProgressBarStoryboardPaused)
167+
{
168+
_progressBarStoryboard.Begin(ProgressBar, true);
169+
isProgressBarStoryboardPaused = false;
170+
}
171+
});
172+
break;
173+
}
172174
case nameof(MainViewModel.QueryTextCursorMovedToEnd):
173175
if (_viewModel.QueryTextCursorMovedToEnd)
174176
{
@@ -251,35 +253,45 @@ private void InitializeNotifyIcon()
251253

252254
contextMenu = new ContextMenu();
253255

254-
var openIcon = new FontIcon { Glyph = "\ue71e" };
256+
var openIcon = new FontIcon
257+
{
258+
Glyph = "\ue71e"
259+
};
255260
var open = new MenuItem
256261
{
257-
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")",
258-
Icon = openIcon
262+
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") + " (" + _settings.Hotkey + ")", Icon = openIcon
263+
};
264+
var gamemodeIcon = new FontIcon
265+
{
266+
Glyph = "\ue7fc"
259267
};
260-
var gamemodeIcon = new FontIcon { Glyph = "\ue7fc" };
261268
var gamemode = new MenuItem
262269
{
263-
Header = InternationalizationManager.Instance.GetTranslation("GameMode"),
264-
Icon = gamemodeIcon
270+
Header = InternationalizationManager.Instance.GetTranslation("GameMode"), Icon = gamemodeIcon
271+
};
272+
var positionresetIcon = new FontIcon
273+
{
274+
Glyph = "\ue73f"
265275
};
266-
var positionresetIcon = new FontIcon { Glyph = "\ue73f" };
267276
var positionreset = new MenuItem
268277
{
269-
Header = InternationalizationManager.Instance.GetTranslation("PositionReset"),
270-
Icon = positionresetIcon
278+
Header = InternationalizationManager.Instance.GetTranslation("PositionReset"), Icon = positionresetIcon
279+
};
280+
var settingsIcon = new FontIcon
281+
{
282+
Glyph = "\ue713"
271283
};
272-
var settingsIcon = new FontIcon { Glyph = "\ue713" };
273284
var settings = new MenuItem
274285
{
275-
Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"),
276-
Icon = settingsIcon
286+
Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings"), Icon = settingsIcon
287+
};
288+
var exitIcon = new FontIcon
289+
{
290+
Glyph = "\ue7e8"
277291
};
278-
var exitIcon = new FontIcon { Glyph = "\ue7e8" };
279292
var exit = new MenuItem
280293
{
281-
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"),
282-
Icon = exitIcon
294+
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit"), Icon = exitIcon
283295
};
284296

285297
open.Click += (o, e) => _viewModel.ToggleFlowLauncher();
@@ -342,15 +354,15 @@ private void ToggleGameMode()
342354
}
343355
private async void PositionReset()
344356
{
345-
_viewModel.Show();
346-
await Task.Delay(300); // If don't give a time, Positioning will be weird.
347-
Left = HorizonCenter();
348-
Top = VerticalCenter();
357+
_viewModel.Show();
358+
await Task.Delay(300); // If don't give a time, Positioning will be weird.
359+
Left = HorizonCenter();
360+
Top = VerticalCenter();
349361
}
350362
private void InitProgressbarAnimation()
351363
{
352364
var da = new DoubleAnimation(ProgressBar.X2, ActualWidth + 150,
353-
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
365+
new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
354366
var da1 = new DoubleAnimation(ProgressBar.X1, ActualWidth + 50, new Duration(new TimeSpan(0, 0, 0, 0, 1600)));
355367
Storyboard.SetTargetProperty(da, new PropertyPath("(Line.X2)"));
356368
Storyboard.SetTargetProperty(da1, new PropertyPath("(Line.X1)"));
@@ -392,11 +404,11 @@ public void WindowAnimator()
392404
};
393405
var IconMotion = new DoubleAnimation
394406
{
395-
From = 12,
396-
To = 0,
397-
EasingFunction = easing,
398-
Duration = TimeSpan.FromSeconds(0.36),
399-
FillBehavior = FillBehavior.Stop
407+
From = 12,
408+
To = 0,
409+
EasingFunction = easing,
410+
Duration = TimeSpan.FromSeconds(0.36),
411+
FillBehavior = FillBehavior.Stop
400412
};
401413

402414
var ClockOpacity = new DoubleAnimation
@@ -468,10 +480,10 @@ private void OnPreviewDragOver(object sender, DragEventArgs e)
468480
private async void OnContextMenusForSettingsClick(object sender, RoutedEventArgs e)
469481
{
470482
_viewModel.Hide();
471-
472-
if(_settings.UseAnimation)
483+
484+
if (_settings.UseAnimation)
473485
await Task.Delay(100);
474-
486+
475487
App.API.OpenSettingDialog();
476488
}
477489

@@ -489,7 +501,7 @@ private async void OnDeactivated(object sender, EventArgs e)
489501
// and always after Settings window is closed.
490502
if (_settings.UseAnimation)
491503
await Task.Delay(100);
492-
504+
493505
if (_settings.HideWhenDeactive)
494506
{
495507
_viewModel.Hide();
@@ -527,7 +539,7 @@ public void HideStartup()
527539
_viewModel.Show();
528540
}
529541
}
530-
542+
531543
public double HorizonCenter()
532544
{
533545
var screen = Screen.FromPoint(System.Windows.Forms.Cursor.Position);
@@ -609,9 +621,9 @@ private void OnKeyDown(object sender, KeyEventArgs e)
609621
&& QueryTextBox.Text.Length > 0
610622
&& QueryTextBox.CaretIndex == QueryTextBox.Text.Length)
611623
{
612-
var queryWithoutActionKeyword =
624+
var queryWithoutActionKeyword =
613625
QueryBuilder.Build(QueryTextBox.Text.Trim(), PluginManager.NonGlobalPlugins)?.Search;
614-
626+
615627
if (FilesFolders.IsLocationPathString(queryWithoutActionKeyword))
616628
{
617629
_viewModel.BackspaceCommand.Execute(null);
@@ -663,7 +675,7 @@ private void MoveQueryTextToEnd()
663675
{
664676
// QueryTextBox seems to be update with a DispatcherPriority as low as ContextIdle.
665677
// To ensure QueryTextBox is up to date with QueryText from the View, we need to Dispatch with such a priority
666-
Dispatcher.Invoke(() => QueryTextBox.CaretIndex = QueryTextBox.Text.Length, System.Windows.Threading.DispatcherPriority.ContextIdle);
678+
Dispatcher.Invoke(() => QueryTextBox.CaretIndex = QueryTextBox.Text.Length);
667679
}
668680

669681
public void InitializeColorScheme()
@@ -680,7 +692,7 @@ public void InitializeColorScheme()
680692

681693
private void QueryTextBox_KeyUp(object sender, KeyEventArgs e)
682694
{
683-
if(_viewModel.QueryText != QueryTextBox.Text)
695+
if (_viewModel.QueryText != QueryTextBox.Text)
684696
{
685697
BindingExpression be = QueryTextBox.GetBindingExpression(System.Windows.Controls.TextBox.TextProperty);
686698
be.UpdateSource();

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using System.Collections.Specialized;
2525
using CommunityToolkit.Mvvm.Input;
2626
using System.Globalization;
27+
using System.Windows.Threading;
2728

2829
namespace Flow.Launcher.ViewModel
2930
{
@@ -65,7 +66,8 @@ public MainViewModel(Settings settings)
6566
Settings = settings;
6667
Settings.PropertyChanged += (_, args) =>
6768
{
68-
switch (args.PropertyName) {
69+
switch (args.PropertyName)
70+
{
6971
case nameof(Settings.WindowSize):
7072
OnPropertyChanged(nameof(MainWindowWidth));
7173
break;
@@ -365,6 +367,7 @@ public string QueryText
365367
set
366368
{
367369
_queryText = value;
370+
OnPropertyChanged();
368371
Query();
369372
}
370373
}
@@ -426,19 +429,24 @@ private void DecreaseMaxResult()
426429
/// <param name="reQuery">Force query even when Query Text doesn't change</param>
427430
public void ChangeQueryText(string queryText, bool reQuery = false)
428431
{
429-
if (QueryText != queryText)
430-
{
431-
// re-query is done in QueryText's setter method
432-
QueryText = queryText;
433-
// set to false so the subsequent set true triggers
434-
// PropertyChanged and MoveQueryTextToEnd is called
435-
QueryTextCursorMovedToEnd = false;
436-
}
437-
else if (reQuery)
432+
Application.Current.Dispatcher.Invoke(() =>
438433
{
439-
Query();
440-
}
441-
QueryTextCursorMovedToEnd = true;
434+
if (QueryText != queryText)
435+
{
436+
437+
// re-query is done in QueryText's setter method
438+
QueryText = queryText;
439+
// set to false so the subsequent set true triggers
440+
// PropertyChanged and MoveQueryTextToEnd is called
441+
QueryTextCursorMovedToEnd = false;
442+
443+
}
444+
else if (reQuery)
445+
{
446+
Query();
447+
}
448+
QueryTextCursorMovedToEnd = true;
449+
});
442450
}
443451

444452
public bool LastQuerySelected { get; set; }
@@ -752,11 +760,14 @@ private Query ConstructQuery(string queryText, IEnumerable<CustomShortcutModel>
752760
queryBuilder.Replace('@' + shortcut.Key, shortcut.Expand());
753761
}
754762

755-
foreach (var shortcut in builtInShortcuts)
763+
Application.Current.Dispatcher.Invoke(() =>
756764
{
757-
queryBuilder.Replace(shortcut.Key, shortcut.Expand());
758-
queryBuilderTmp.Replace(shortcut.Key, shortcut.Expand());
759-
}
765+
foreach (var shortcut in builtInShortcuts)
766+
{
767+
queryBuilder.Replace(shortcut.Key, shortcut.Expand());
768+
queryBuilderTmp.Replace(shortcut.Key, shortcut.Expand());
769+
}
770+
});
760771

761772
// show expanded builtin shortcuts
762773
// use private field to avoid infinite recursion
@@ -879,11 +890,14 @@ public void ToggleFlowLauncher()
879890

880891
public void Show()
881892
{
882-
MainWindowVisibility = Visibility.Visible;
893+
Application.Current.Dispatcher.Invoke(() =>
894+
{
895+
MainWindowVisibility = Visibility.Visible;
883896

884-
MainWindowVisibilityStatus = true;
897+
MainWindowOpacity = 1;
885898

886-
MainWindowOpacity = 1;
899+
MainWindowVisibilityStatus = true;
900+
});
887901
}
888902

889903
public async void Hide()

0 commit comments

Comments
 (0)