Skip to content

Commit d1bfd1c

Browse files
committed
- Change the if code to switch.
- Change String to enum. - Remove duplicated code.
1 parent 3c8acaa commit d1bfd1c

File tree

2 files changed

+24
-51
lines changed

2 files changed

+24
-51
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public bool HideNotifyIcon
199199
}
200200
public bool LeaveCmdOpen { get; set; }
201201
public bool HideWhenDeactive { get; set; } = true;
202-
public string LauncherPosition { get; set; } = "RememberLastLaunchLocation";
202+
public LauncherPositions LauncherPosition { get; set; } = LauncherPositions.RememberLastLaunchLocation;
203203
public bool IgnoreHotkeysOnFullscreen { get; set; }
204204

205205
public HttpProxy Proxy { get; set; } = new HttpProxy();

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -182,30 +182,28 @@ private void OnLoaded(object sender, RoutedEventArgs _)
182182

183183
private void InitializePosition()
184184
{
185-
if (_settings.LauncherPosition == "RememberLastLaunchLocation")
185+
switch (_settings.LauncherPosition)
186186
{
187-
Top = _settings.WindowTop;
188-
Left = _settings.WindowLeft;
189-
}
190-
else if(_settings.LauncherPosition == "MouseScreenCenter")
191-
{
192-
Left = WindowLeft();
193-
Top = WindowTop();
194-
}
195-
else if (_settings.LauncherPosition == "MouseScreenCenterTop")
196-
{
197-
Left = WindowLeft();
198-
Top = 10;
199-
}
200-
else if (_settings.LauncherPosition == "MouseScreenLeftTop")
201-
{
202-
Left = 10;
203-
Top = 10;
204-
}
205-
else if (_settings.LauncherPosition == "MouseScreenRightTop")
206-
{
207-
Left = WindowRight();
208-
Top = 10;
187+
case LauncherPositions.RememberLastLaunchLocation:
188+
Top = _settings.WindowTop;
189+
Left = _settings.WindowLeft;
190+
break;
191+
case LauncherPositions.MouseScreenCenter:
192+
Left = WindowLeft();
193+
Top = WindowTop();
194+
break;
195+
case LauncherPositions.MouseScreenCenterTop:
196+
Left = WindowLeft();
197+
Top = 10;
198+
break;
199+
case LauncherPositions.MouseScreenLeftTop:
200+
Left = 10;
201+
Top = 10;
202+
break;
203+
case LauncherPositions.MouseScreenRightTop:
204+
Left = WindowRight();
205+
Top = 10;
206+
break;
209207
}
210208
}
211209

@@ -445,39 +443,14 @@ private void UpdatePosition()
445443
{
446444
if (_animating)
447445
return;
448-
449-
if (_settings.LauncherPosition == "RememberLastLaunchLocation")
450-
{
451-
Left = _settings.WindowLeft;
452-
Top = _settings.WindowTop;
453-
}
454-
else if (_settings.LauncherPosition == "MouseScreenCenter")
455-
{
456-
Left = WindowLeft();
457-
Top = WindowTop();
458-
}
459-
else if (_settings.LauncherPosition == "MouseScreenCenterTop")
460-
{
461-
Left = WindowLeft();
462-
Top = 10;
463-
}
464-
else if (_settings.LauncherPosition == "MouseScreenLeftTop")
465-
{
466-
Left = 10;
467-
Top = 10;
468-
}
469-
else if (_settings.LauncherPosition == "MouseScreenRightTop")
470-
{
471-
Left = WindowRight();
472-
Top = 10;
473-
}
446+
InitializePosition();
474447
}
475448

476449
private void OnLocationChanged(object sender, EventArgs e)
477450
{
478451
if (_animating)
479452
return;
480-
if (_settings.LauncherPosition == "RememberLastLaunchLocation")
453+
if (_settings.LauncherPosition == LauncherPositions.RememberLastLaunchLocation)
481454
{
482455
_settings.WindowLeft = Left;
483456
_settings.WindowTop = Top;

0 commit comments

Comments
 (0)