Skip to content

Commit c20bb30

Browse files
authored
Merge branch 'dev' into quickswitch
2 parents 45ac0af + 54c949b commit c20bb30

File tree

14 files changed

+482
-72
lines changed

14 files changed

+482
-72
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,19 @@ public static async Task InitializePluginsAsync()
220220
catch (Exception e)
221221
{
222222
API.LogException(ClassName, $"Fail to Init plugin: {pair.Metadata.Name}", e);
223-
pair.Metadata.Disabled = true;
224-
pair.Metadata.HomeDisabled = true;
225-
failedPlugins.Enqueue(pair);
223+
if (pair.Metadata.Disabled && pair.Metadata.HomeDisabled)
224+
{
225+
// If this plugin is already disabled, do not show error message again
226+
// Or else it will be shown every time
227+
API.LogDebug(ClassName, $"Skipped init for <{pair.Metadata.Name}> due to error");
228+
}
229+
else
230+
{
231+
pair.Metadata.Disabled = true;
232+
pair.Metadata.HomeDisabled = true;
233+
failedPlugins.Enqueue(pair);
234+
API.LogDebug(ClassName, $"Disable plugin <{pair.Metadata.Name}> because init failed");
235+
}
226236
}
227237
}));
228238

Flow.Launcher.Infrastructure/Storage/JsonStorage.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ public JsonStorage(string filePath)
4545
FilesFolders.ValidateDirectory(DirectoryPath);
4646
}
4747

48+
public bool Exists()
49+
{
50+
return File.Exists(FilePath);
51+
}
52+
53+
public void Delete()
54+
{
55+
foreach (var path in new[] { FilePath, BackupFilePath, TempFilePath })
56+
{
57+
if (File.Exists(path))
58+
{
59+
File.Delete(path);
60+
}
61+
}
62+
}
63+
4864
public async Task<T> LoadAsync()
4965
{
5066
if (Data != null)

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ public SearchPrecisionScore QuerySearchPrecision
309309

310310
public double WindowLeft { get; set; }
311311
public double WindowTop { get; set; }
312+
public double PreviousScreenWidth { get; set; }
313+
public double PreviousScreenHeight { get; set; }
314+
public double PreviousDpiX { get; set; }
315+
public double PreviousDpiY { get; set; }
312316

313317
/// <summary>
314318
/// Custom left position on selected monitor

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 86 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public MainWindow()
9090

9191
InitSoundEffects();
9292
DataObject.AddPastingHandler(QueryTextBox, QueryTextBox_OnPaste);
93-
93+
ModernWpf.ThemeManager.Current.ActualApplicationThemeChanged += ThemeManager_ActualApplicationThemeChanged;
9494
SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
9595
}
9696

@@ -100,6 +100,11 @@ public MainWindow()
100100

101101
#pragma warning disable VSTHRD100 // Avoid async void methods
102102

103+
private void ThemeManager_ActualApplicationThemeChanged(ModernWpf.ThemeManager sender, object args)
104+
{
105+
_theme.RefreshFrameAsync();
106+
}
107+
103108
private void OnSourceInitialized(object sender, EventArgs e)
104109
{
105110
var handle = Win32Helper.GetWindowHandle(this, true);
@@ -740,8 +745,26 @@ void InitializePositionInner()
740745
{
741746
if (_settings.SearchWindowScreen == SearchWindowScreens.RememberLastLaunchLocation)
742747
{
743-
Top = _settings.WindowTop;
748+
var previousScreenWidth = _settings.PreviousScreenWidth;
749+
var previousScreenHeight = _settings.PreviousScreenHeight;
750+
GetDpi(out var previousDpiX, out var previousDpiY);
751+
752+
_settings.PreviousScreenWidth = SystemParameters.VirtualScreenWidth;
753+
_settings.PreviousScreenHeight = SystemParameters.VirtualScreenHeight;
754+
GetDpi(out var currentDpiX, out var currentDpiY);
755+
756+
if (previousScreenWidth != 0 && previousScreenHeight != 0 &&
757+
previousDpiX != 0 && previousDpiY != 0 &&
758+
(previousScreenWidth != SystemParameters.VirtualScreenWidth ||
759+
previousScreenHeight != SystemParameters.VirtualScreenHeight ||
760+
previousDpiX != currentDpiX || previousDpiY != currentDpiY))
761+
{
762+
AdjustPositionForResolutionChange();
763+
return;
764+
}
765+
744766
Left = _settings.WindowLeft;
767+
Top = _settings.WindowTop;
745768
}
746769
else
747770
{
@@ -754,27 +777,73 @@ void InitializePositionInner()
754777
break;
755778
case SearchWindowAligns.CenterTop:
756779
Left = HorizonCenter(screen);
757-
Top = 10;
780+
Top = VerticalTop(screen);
758781
break;
759782
case SearchWindowAligns.LeftTop:
760783
Left = HorizonLeft(screen);
761-
Top = 10;
784+
Top = VerticalTop(screen);
762785
break;
763786
case SearchWindowAligns.RightTop:
764787
Left = HorizonRight(screen);
765-
Top = 10;
788+
Top = VerticalTop(screen);
766789
break;
767790
case SearchWindowAligns.Custom:
768-
Left = Win32Helper.TransformPixelsToDIP(this,
769-
screen.WorkingArea.X + _settings.CustomWindowLeft, 0).X;
770-
Top = Win32Helper.TransformPixelsToDIP(this, 0,
771-
screen.WorkingArea.Y + _settings.CustomWindowTop).Y;
791+
var customLeft = Win32Helper.TransformPixelsToDIP(this,
792+
screen.WorkingArea.X + _settings.CustomWindowLeft, 0);
793+
var customTop = Win32Helper.TransformPixelsToDIP(this, 0,
794+
screen.WorkingArea.Y + _settings.CustomWindowTop);
795+
Left = customLeft.X;
796+
Top = customTop.Y;
772797
break;
773798
}
774799
}
775800
}
776801
}
777802

803+
private void AdjustPositionForResolutionChange()
804+
{
805+
var screenWidth = SystemParameters.VirtualScreenWidth;
806+
var screenHeight = SystemParameters.VirtualScreenHeight;
807+
GetDpi(out var currentDpiX, out var currentDpiY);
808+
809+
var previousLeft = _settings.WindowLeft;
810+
var previousTop = _settings.WindowTop;
811+
GetDpi(out var previousDpiX, out var previousDpiY);
812+
813+
var widthRatio = screenWidth / _settings.PreviousScreenWidth;
814+
var heightRatio = screenHeight / _settings.PreviousScreenHeight;
815+
var dpiXRatio = currentDpiX / previousDpiX;
816+
var dpiYRatio = currentDpiY / previousDpiY;
817+
818+
var newLeft = previousLeft * widthRatio * dpiXRatio;
819+
var newTop = previousTop * heightRatio * dpiYRatio;
820+
821+
var screenLeft = SystemParameters.VirtualScreenLeft;
822+
var screenTop = SystemParameters.VirtualScreenTop;
823+
824+
var maxX = screenLeft + screenWidth - ActualWidth;
825+
var maxY = screenTop + screenHeight - ActualHeight;
826+
827+
Left = Math.Max(screenLeft, Math.Min(newLeft, maxX));
828+
Top = Math.Max(screenTop, Math.Min(newTop, maxY));
829+
}
830+
831+
private void GetDpi(out double dpiX, out double dpiY)
832+
{
833+
var source = PresentationSource.FromVisual(this);
834+
if (source != null && source.CompositionTarget != null)
835+
{
836+
var matrix = source.CompositionTarget.TransformToDevice;
837+
dpiX = 96 * matrix.M11;
838+
dpiY = 96 * matrix.M22;
839+
}
840+
else
841+
{
842+
dpiX = 96;
843+
dpiY = 96;
844+
}
845+
}
846+
778847
private Screen SelectedScreen()
779848
{
780849
Screen screen;
@@ -835,6 +904,13 @@ private double HorizonLeft(Screen screen)
835904
return left;
836905
}
837906

907+
public double VerticalTop(Screen screen)
908+
{
909+
var dip1 = Win32Helper.TransformPixelsToDIP(this, 0, screen.WorkingArea.Y);
910+
var top = dip1.Y + 10;
911+
return top;
912+
}
913+
838914
#endregion
839915

840916
#region Window Animation
@@ -1249,6 +1325,7 @@ protected virtual void Dispose(bool disposing)
12491325
_notifyIcon?.Dispose();
12501326
animationSoundWMP?.Close();
12511327
animationSoundWPF?.Dispose();
1328+
ModernWpf.ThemeManager.Current.ActualApplicationThemeChanged -= ThemeManager_ActualApplicationThemeChanged;
12521329
SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
12531330
}
12541331

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ public SettingsPaneThemeViewModel(Settings settings, Theme theme)
479479
)
480480
}
481481
};
482-
var vm = new ResultsViewModel(Settings);
482+
// Set main view model to null because the results are for preview only
483+
var vm = new ResultsViewModel(Settings, null);
483484
vm.AddResults(results, "PREVIEW");
484485
PreviewResults = vm;
485486
}

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,40 @@ public void UpdatePositionAndState()
137137

138138
if (previousTop == null || previousLeft == null || !IsPositionValid(previousTop.Value, previousLeft.Value))
139139
{
140-
Top = WindowTop();
141-
Left = WindowLeft();
140+
SetWindowPosition(WindowTop(), WindowLeft());
142141
}
143142
else
144143
{
145-
Top = previousTop.Value;
146-
Left = previousLeft.Value;
144+
var left = _settings.SettingWindowLeft.Value;
145+
var top = _settings.SettingWindowTop.Value;
146+
AdjustWindowPosition(ref top, ref left);
147+
SetWindowPosition(top, left);
147148
}
148149

149150
WindowState = _settings.SettingWindowState;
150151
}
151152

153+
private void SetWindowPosition(double top, double left)
154+
{
155+
// Ensure window does not exceed screen boundaries
156+
top = Math.Max(top, SystemParameters.VirtualScreenTop);
157+
left = Math.Max(left, SystemParameters.VirtualScreenLeft);
158+
top = Math.Min(top, SystemParameters.VirtualScreenHeight - ActualHeight);
159+
left = Math.Min(left, SystemParameters.VirtualScreenWidth - ActualWidth);
160+
161+
Top = top;
162+
Left = left;
163+
}
164+
165+
private void AdjustWindowPosition(ref double top, ref double left)
166+
{
167+
// Adjust window position if it exceeds screen boundaries
168+
top = Math.Max(top, SystemParameters.VirtualScreenTop);
169+
left = Math.Max(left, SystemParameters.VirtualScreenLeft);
170+
top = Math.Min(top, SystemParameters.VirtualScreenHeight - ActualHeight);
171+
left = Math.Min(left, SystemParameters.VirtualScreenWidth - ActualWidth);
172+
}
173+
152174
private static bool IsPositionValid(double top, double left)
153175
{
154176
foreach (var screen in Screen.AllScreens)

0 commit comments

Comments
 (0)