Skip to content

Commit 5be44b6

Browse files
committed
Add fody and use binding to change width
1 parent 6aaca10 commit 5be44b6

File tree

7 files changed

+36
-25
lines changed

7 files changed

+36
-25
lines changed

Flow.Launcher.Core/Resource/Theme.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,6 @@ private void SetWindowAccent(Window w, AccentState state)
365365
var windowHelper = new WindowInteropHelper(w);
366366

367367
// this determines the width of the main query window
368-
w.Width = mainWindowWidth;
369368
windowHelper.EnsureHandle();
370369

371370
var accent = new AccentPolicy { AccentState = state };

Flow.Launcher.Infrastructure/Flow.Launcher.Infrastructure.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@
5050

5151
<ItemGroup>
5252
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
53+
<PackageReference Include="Fody" Version="6.5.5">
54+
<PrivateAssets>all</PrivateAssets>
55+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
56+
</PackageReference>
5357
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="16.10.56" />
5458
<PackageReference Include="NLog" Version="4.7.10" />
5559
<PackageReference Include="NLog.Schema" Version="4.7.10" />
5660
<PackageReference Include="NLog.Web.AspNetCore" Version="4.13.0" />
61+
<PackageReference Include="PropertyChanged.Fody" Version="3.4.0" />
5762
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
5863
<!--ToolGood.Words.Pinyin v3.0.2.6 results in high memory usage when search with pinyin is enabled-->
5964
<!--Bumping to it or higher needs to test and ensure this is no longer a problem-->

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,21 @@
55
using Flow.Launcher.Plugin;
66
using Flow.Launcher.Plugin.SharedModels;
77
using Flow.Launcher;
8+
89
namespace Flow.Launcher.Infrastructure.UserSettings
910
{
1011
public class Settings : BaseModel
1112
{
1213
private string language = "en";
13-
public double windowsize = 580;
1414
public string Hotkey { get; set; } = $"{KeyConstant.Alt} + {KeyConstant.Space}";
1515
public string OpenResultModifiers { get; set; } = KeyConstant.Alt;
1616
public bool ShowOpenResultHotkey { get; set; } = true;
17-
public double WindowSize
18-
{
19-
get => windowsize; set
20-
{
21-
windowsize = value;
22-
OnPropertyChanged();
23-
}
24-
25-
}
17+
public double WindowSize { get; set; } = 580;
2618

2719
public string Language
2820
{
29-
get => language; set
21+
get => language;
22+
set
3023
{
3124
language = value;
3225
OnPropertyChanged();
@@ -62,7 +55,7 @@ public string QuerySearchPrecisionString
6255
try
6356
{
6457
var precisionScore = (SearchPrecisionScore)Enum
65-
.Parse(typeof(SearchPrecisionScore), value);
58+
.Parse(typeof(SearchPrecisionScore), value);
6659

6760
QuerySearchPrecision = precisionScore;
6861
StringMatcher.Instance.UserSettingSearchPrecision = precisionScore;

Flow.Launcher/MainWindow.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
LocationChanged="OnLocationChanged"
2727
Deactivated="OnDeactivated"
2828
PreviewKeyDown="OnKeyDown"
29+
Width="{Binding MainWindowWidth, Mode=OneTime}"
2930
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
3031
d:DataContext="{d:DesignInstance vm:MainViewModel}">
3132
<Window.Resources>

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
2020
using MessageBox = System.Windows.MessageBox;
2121
using NotifyIcon = System.Windows.Forms.NotifyIcon;
22+
using System.Windows.Interop;
2223

2324
namespace Flow.Launcher
2425
{
@@ -131,6 +132,10 @@ private void OnLoaded(object sender, RoutedEventArgs _)
131132
_viewModel.QueryTextCursorMovedToEnd = false;
132133
}
133134
break;
135+
case nameof(MainViewModel.MainWindowWidth):
136+
MinWidth = _viewModel.MainWindowWidth;
137+
MaxWidth = _viewModel.MainWindowWidth;
138+
break;
134139
}
135140
};
136141
_settings.PropertyChanged += (o, e) =>

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using ISavable = Flow.Launcher.Plugin.ISavable;
2323
using System.Windows.Threading;
2424
using NHotkey;
25+
using Windows.Web.Syndication;
2526

2627

2728
namespace Flow.Launcher.ViewModel
@@ -63,6 +64,13 @@ public MainViewModel(Settings settings)
6364
_lastQuery = new Query();
6465

6566
_settings = settings;
67+
_settings.PropertyChanged += (_, args) =>
68+
{
69+
if (args.PropertyName == nameof(Settings.WindowSize))
70+
{
71+
OnPropertyChanged(nameof(MainWindowWidth));
72+
}
73+
};
6674

6775
_historyItemsStorage = new FlowLauncherJsonStorage<History>();
6876
_userSelectedRecordStorage = new FlowLauncherJsonStorage<UserSelectedRecord>();
@@ -378,6 +386,8 @@ private ResultsViewModel SelectedResults
378386
public Visibility ProgressBarVisibility { get; set; }
379387
public Visibility MainWindowVisibility { get; set; }
380388

389+
public double MainWindowWidth => _settings.WindowSize;
390+
381391
public ICommand EscCommand { get; set; }
382392
public ICommand SelectNextItemCommand { get; set; }
383393
public ICommand SelectPrevItemCommand { get; set; }

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ public SettingWindowViewModel(Updater updater, IPortable portable)
3535
Settings = _storage.Load();
3636
Settings.PropertyChanged += (s, e) =>
3737
{
38-
if (e.PropertyName == nameof(Settings.ActivateTimes))
38+
switch (e.PropertyName)
3939
{
40-
OnPropertyChanged(nameof(ActivatedTimes));
40+
case nameof(Settings.ActivateTimes):
41+
OnPropertyChanged(nameof(ActivatedTimes));
42+
break;
4143
}
4244
};
4345
}
@@ -51,7 +53,7 @@ public async void UpdateApp()
5153

5254
public bool AutoUpdates
5355
{
54-
get { return Settings.AutoUpdates; }
56+
get => Settings.AutoUpdates;
5557
set
5658
{
5759
Settings.AutoUpdates = value;
@@ -71,7 +73,7 @@ public bool AutoHideScrollBar
7173
private bool _portableMode = DataLocation.PortableDataLocationInUse();
7274
public bool PortableMode
7375
{
74-
get { return _portableMode; }
76+
get => _portableMode;
7577
set
7678
{
7779
if (!_portable.CanUpdatePortability())
@@ -306,18 +308,14 @@ public bool DropShadowEffect
306308

307309
public double WindowWidthSize
308310
{
309-
get { return Settings.WindowSize; }
310-
set
311-
{
312-
Settings.WindowSize = value;
313-
ThemeManager.Instance.ChangeTheme(Settings.Theme);
314-
}
311+
get => Settings.WindowSize;
312+
set => Settings.WindowSize = value;
315313
}
316314

317315
public bool UseGlyphIcons
318316
{
319-
get { return Settings.UseGlyphIcons; }
320-
set { Settings.UseGlyphIcons = value; }
317+
get => Settings.UseGlyphIcons;
318+
set => Settings.UseGlyphIcons = value;
321319
}
322320

323321
public Brush PreviewBackground

0 commit comments

Comments
 (0)