Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenn committed Apr 3, 2024
1 parent 8368dd2 commit dd55ba6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions BrowserPicker.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=ngen/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=olsvc/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Runsafe/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=runtimeconfig/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=safelinks/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=shortener/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Shorteners/@EntryIndexedValue">True</s:Boolean>
Expand Down
2 changes: 1 addition & 1 deletion src/BrowserPicker.App/View/BrowserList.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<Button Command="{Binding Select}" CommandParameter="{Binding Path=DataContext.Url.TargetURL,RelativeSource={RelativeSource AncestorType={x:Type ScrollViewer}}}" Margin="2">
<Button.Style>
<Style TargetType="Button">
<Setter Property="UIElement.Visibility" Value="Visible" />
<Setter Property="Visibility" Value="Visible" />
<Style.Triggers>
<DataTrigger Binding="{Binding Model.Disabled}" Value="True">
<Setter Property="UIElement.Visibility" Value="Collapsed" />
Expand Down
12 changes: 9 additions & 3 deletions src/BrowserPicker.App/ViewModel/ApplicationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
using System.Windows;
using System.Windows.Input;
using BrowserPicker.Framework;
#if DEBUG
using JetBrains.Annotations;
#endif

namespace BrowserPicker.ViewModel;

public sealed class ApplicationViewModel : ModelBase
{
#if DEBUG
// Used by WPF designer
[UsedImplicitly]
public ApplicationViewModel()
Expand All @@ -24,7 +27,7 @@ public ApplicationViewModel()
WellKnownBrowsers.List.Select(b => new BrowserViewModel(new BrowserModel(b, null, null), this))
);
}

internal ApplicationViewModel(ConfigurationViewModel config)
{
Url = new UrlHandler(config.Settings, "https://github.com/mortenn/BrowserPicker");
Expand All @@ -34,8 +37,9 @@ internal ApplicationViewModel(ConfigurationViewModel config)
WellKnownBrowsers.List.Select(b => new BrowserViewModel(new BrowserModel(b, null, null), this))
);
}
#endif

public ApplicationViewModel(List<string> arguments, IBrowserPickerConfiguration settings)
public ApplicationViewModel(IReadOnlyCollection<string> arguments, IBrowserPickerConfiguration settings)
{
var options = arguments.Where(arg => arg[0] == '/').ToList();
force_choice = options.Contains("/choose");
Expand Down Expand Up @@ -67,11 +71,13 @@ public void Initialize()
}

BrowserViewModel start = GetBrowserToLaunch(Url.UnderlyingTargetURL ?? Url.TargetURL);
#if DEBUG
if (Debugger.IsAttached && start != null)
{
Debug.WriteLine($"Skipping launch of browser {start.Model.Name} due to debugger being attached");
return;
}
#endif
start?.Select.Execute(null);
}

Expand Down Expand Up @@ -113,7 +119,7 @@ internal string GetBrowserToLaunchForUrl(string targetUrl)
.Select(rule => new { rule, matchLength = rule.MatchLength(url) })
.Where(o => o.matchLength > 0)
.ToList();

return auto.Count <= 0
? null
: auto.OrderByDescending(o => o.matchLength).First().rule.Browser;
Expand Down
7 changes: 3 additions & 4 deletions src/BrowserPicker.App/ViewModel/ConfigurationViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using BrowserPicker.Framework;
using System.ComponentModel;
using JetBrains.Annotations;
using System.Threading;
using System.Linq;
using System.Collections.ObjectModel;
using System.Windows.Input;
using BrowserPicker.View;
using System.Windows;
using System.Collections.Generic;
#if DEBUG
using System.Threading.Tasks;
using JetBrains.Annotations;
#endif

namespace BrowserPicker.ViewModel;

Expand Down Expand Up @@ -41,7 +43,6 @@ public ConfigurationViewModel()
ConfigurationMode = true
};
Settings.BrowserList.AddRange(ParentViewModel.Choices.Select(m => m.Model));
AvailableBrowsers = [.. ParentViewModel.Choices];
test_defaults_url = ParentViewModel.Url?.UnderlyingTargetURL ?? ParentViewModel.Url?.TargetURL;
}

Expand Down Expand Up @@ -145,8 +146,6 @@ public bool AutoAddDefault
set => SetProperty(ref auto_add_default, value);
}

public List<BrowserViewModel> AvailableBrowsers { get; init; }

public ObservableCollection<DefaultSetting> Defaults { get; } = [];

public MatchType NewDefaultMatchType
Expand Down
4 changes: 3 additions & 1 deletion src/BrowserPicker/UrlHandler.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using BrowserPicker.Framework;
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
#if DEBUG
using JetBrains.Annotations;
#endif

namespace BrowserPicker;

Expand Down

0 comments on commit dd55ba6

Please sign in to comment.