Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to opt in to prerelease versions #93

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/EventLogExpert.Library/Models/GitReleaseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public record GitReleaseModel
{
[JsonPropertyName("name")] public string Version { get; set; } = null!;

[JsonPropertyName("prerelease")] public bool IsPrerelease { get; set; }

[JsonPropertyName("published_at")] public DateTime ReleaseDate { get; set; }

[JsonPropertyName("assets")] public List<GitReleaseAsset> Assets { get; set; } = null!;
}

Expand Down
2 changes: 2 additions & 0 deletions src/EventLogExpert.Library/Models/SettingsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ namespace EventLogExpert.Library.Models;
public record SettingsModel
{
public string TimeZoneId { get; set; } = string.Empty;

public bool IsPrereleaseEnabled { get; set; }
}
9 changes: 9 additions & 0 deletions src/EventLogExpert/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ public App(IDispatcher fluxorDispatcher)

MainPage = new NavigationPage(new MainPage(fluxorDispatcher));
}

protected override Window CreateWindow(IActivationState? activationState)
{
var window = base.CreateWindow(activationState);

window.Title = "EventLogExpert";

return window;
}
}
10 changes: 6 additions & 4 deletions src/EventLogExpert/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
<MenuFlyoutSubItem Text="Other Logs" x:Name="OtherLogsFlyoutSubitem" />
</MenuFlyoutSubItem>
</MenuBarItem>
<MenuBarItem Text="View">
<MenuFlyoutItem Text="Load New Events" Clicked="LoadNewEvents_Clicked" />
<MenuFlyoutItem Text="Continuously Update" Clicked="ContinuouslyUpdate_Clicked" />
</MenuBarItem>
<MenuBarItem Text="Tools">
<MenuFlyoutItem Text="Settings" Clicked="OpenSettingsModal_Clicked" />
<!-- Option to export providers? -->
<!-- Manual check for updates option or an about page with option to check for updates? -->
</MenuBarItem>
<MenuBarItem Text="View">
<MenuFlyoutItem Text="Load New Events" Clicked="LoadNewEvents_Clicked" />
<MenuFlyoutItem Text="Continuously Update" Clicked="ContinuouslyUpdate_Clicked" />
<MenuBarItem Text="Help">
<MenuFlyoutItem Text="Check for Updates" Clicked="CheckForUpdates_Clicked" />
</MenuBarItem>
</ContentPage.MenuBarItems>

Expand Down
41 changes: 22 additions & 19 deletions src/EventLogExpert/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ public async void OpenFile_Clicked(object sender, EventArgs e)
Utils.UpdateAppTitle(result?.FullPath);
}

private void CheckForUpdates_Clicked(object? sender, EventArgs e) =>
_fluxorDispatcher.Dispatch(new SettingsAction.CheckForUpdates());

private void ContinuouslyUpdate_Clicked(object sender, EventArgs e)
{
if (((MenuFlyoutItem)sender).Text == "Continuously Update")
{
_fluxorDispatcher.Dispatch(new EventLogAction.SetContinouslyUpdate(true));
((MenuFlyoutItem)sender).Text = "Continuously Update ✓";
}
else
{
_fluxorDispatcher.Dispatch(new EventLogAction.SetContinouslyUpdate(false));
((MenuFlyoutItem)sender).Text = "Continuously Update";
}
}

private void LoadNewEvents_Clicked(object sender, EventArgs e)
{
_fluxorDispatcher.Dispatch(new EventLogAction.LoadNewEvents());
}

private void OpenLiveLog_Clicked(object? sender, EventArgs e)
{
if (sender == null) return;
Expand Down Expand Up @@ -86,23 +108,4 @@ private void PopulateOtherLogsMenu()
OtherLogsFlyoutSubitem.Add(m);
}
}

private void LoadNewEvents_Clicked(object sender, EventArgs e)
{
_fluxorDispatcher.Dispatch(new EventLogAction.LoadNewEvents());
}

private void ContinuouslyUpdate_Clicked(object sender, EventArgs e)
{
if (((MenuFlyoutItem)sender).Text == "Continuously Update")
{
_fluxorDispatcher.Dispatch(new EventLogAction.SetContinouslyUpdate(true));
((MenuFlyoutItem)sender).Text = "Continuously Update ✓";
}
else
{
_fluxorDispatcher.Dispatch(new EventLogAction.SetContinouslyUpdate(false));
((MenuFlyoutItem)sender).Text = "Continuously Update";
}
}
}
7 changes: 7 additions & 0 deletions src/EventLogExpert/Shared/Components/BooleanSelect.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="toggle">
<input type="radio" id="@Id false" name="@Id" value="false" checked="@(!Value)" @onchange="SetValue" />
<label for="@Id false">Disabled</label>

<input type="radio" id="@Id true" name="@Id" value="true" checked="@(Value)" @onchange="SetValue" />
<label for="@Id true">Enabled</label>
</div>
23 changes: 23 additions & 0 deletions src/EventLogExpert/Shared/Components/BooleanSelect.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// // Copyright (c) Microsoft Corporation.
// // Licensed under the MIT License.

using Microsoft.AspNetCore.Components;

namespace EventLogExpert.Shared.Components;

public partial class BooleanSelect
{
[Parameter] public string Id { get; set; } = Guid.NewGuid().ToString();

[Parameter] public bool Value { get; set; }

[Parameter] public EventCallback<bool> ValueChanged { get; set; }

private async Task SetValue(ChangeEventArgs args)
{
if (!bool.TryParse(args.Value?.ToString(), out bool value)) { return; }

Value = value;
await ValueChanged.InvokeAsync(Value);
}
}
46 changes: 46 additions & 0 deletions src/EventLogExpert/Shared/Components/BooleanSelect.razor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.toggle {
display: flex;
overflow: hidden;
margin-left: 5px;
}

.toggle input {
position: absolute !important;
clip: rect(0, 0, 0, 0);
height: 1px;
width: 1px;
border: 0;
overflow: hidden;
}

.toggle label {
background-color: var(--background-darkgray);
color: var(--clr-lightblue);
line-height: 1;
text-align: center;
padding: 4px 8px;
margin-right: -1px;
border: 1px solid rgba(0, 0, 0, 0.2);
box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px rgba(255, 255, 255, 0.1);
transition: all 0.1s ease-in-out;
}

.toggle label:hover { cursor: pointer; }

.toggle input:checked + label:first-of-type {
background-color: var(--clr-red);
box-shadow: none;
color: #fff;
opacity: 0.75;
}

.toggle input:checked + label:last-of-type {
background-color: var(--clr-green);
box-shadow: none;
color: var(--clr-black);
opacity: 0.75;
}

.toggle label:first-of-type { border-radius: 4px 0 0 4px; }

.toggle label:last-of-type { border-radius: 0 4px 4px 0; }
12 changes: 9 additions & 3 deletions src/EventLogExpert/Shared/Components/SettingsModal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@
}
</div>

<div class="button-group">
<button class="button-save" type="submit">Save</button>
<button class="button-primary" type="reset" @onclick="Close">Exit</button>
<div class="footer-group">
<div class="prerelease-group">
Pre-release Builds: <BooleanSelect @bind-Value="_request.IsPrereleaseEnabled" />
</div>

<div class="button-group">
<button class="button-save" type="submit">Save</button>
<button class="button-primary" type="button" @onclick="Close">Exit</button>
</div>
</div>

</EditForm>
Expand Down
23 changes: 18 additions & 5 deletions src/EventLogExpert/Shared/Components/SettingsModal.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ public partial class SettingsModal

protected override void OnInitialized()
{
SubscribeToAction<SettingsAction.OpenMenu>(Load);
SettingsState.StateChanged += (s, e) => ResetRequestModel();

base.OnInitialized();
}

private async void Close() => await JSRuntime.InvokeVoidAsync("closeSettingsModal");
private async void Close()
{
await JSRuntime.InvokeVoidAsync("closeSettingsModal");
ResetRequestModel();
}

private async void ImportProvider()
{
Expand Down Expand Up @@ -56,11 +61,13 @@ private async void ImportProvider()
}
catch
{ // TODO: Log Error
return;
}

bool answer = await Application.Current.MainPage.DisplayAlert("Reboot Required",
bool answer = await Application.Current!.MainPage!.DisplayAlert("Reboot Required",
"In order to use these providers, a restart of the application is required. Would you like to restart now?",
"Yes", "No");
"Yes",
"No");

if (!answer)
{
Expand All @@ -73,7 +80,13 @@ private async void ImportProvider()
if (res == 0) { Application.Current.Quit(); }
}

private void Load(SettingsAction.OpenMenu action) => _request.TimeZoneId = SettingsState.Value.TimeZoneId;
private void ResetRequestModel()
{
_request.TimeZoneId = SettingsState.Value.TimeZoneId;
_request.IsPrereleaseEnabled = SettingsState.Value.IsPrereleaseEnabled;

StateHasChanged();
}

private void Save()
{
Expand Down
10 changes: 10 additions & 0 deletions src/EventLogExpert/Shared/Components/SettingsModal.razor.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@

.provider-list > p { margin: 0; }

.footer-group {
display: flex;
justify-content: space-between;
}

.prerelease-group {
display: flex;
align-items: center;
}

.button-group {
display: flex;
justify-content: flex-end;
Expand Down
2 changes: 2 additions & 0 deletions src/EventLogExpert/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

@inherits LayoutComponentBase

@inject IState<SettingsState> SettingsState

<SettingsModal />

<div class="page">
Expand Down
31 changes: 25 additions & 6 deletions src/EventLogExpert/Shared/MainLayout.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,35 @@ public void Dispose()
GC.SuppressFinalize(this);
}

protected override void OnInitialized()
protected override async Task OnInitializedAsync()
{
Utils.UpdateAppTitle();
Dispatcher.Dispatch(new SettingsAction.LoadProviders(Utils.DatabasePath));
Dispatcher.Dispatch(new SettingsAction.LoadSettings(Utils.SettingsPath));
Dispatcher.Dispatch(new SettingsAction.LoadProviders(Utils.DatabasePath));

ActionSubscriber.SubscribeToAction<SettingsAction.OpenMenu>(this, OpenSettingsModal);
Utils.CheckForUpdates();
base.OnInitialized();
ActionSubscriber.SubscribeToAction<SettingsAction.CheckForUpdates>(this, CheckForUpdates);

await Utils.CheckForUpdates(SettingsState.Value.IsPrereleaseEnabled);
Utils.UpdateAppTitle();

await base.OnInitializedAsync();
}

private void OpenSettingsModal(SettingsAction.OpenMenu action) =>
private async void CheckForUpdates(SettingsAction.CheckForUpdates action)
{
bool result = await Utils.CheckForUpdates(SettingsState.Value.IsPrereleaseEnabled);

if (result is false && Application.Current?.MainPage is not null)
{
await Application.Current.MainPage.DisplayAlert("No Updates Available",
"You are currently running the latest version.",
"Ok");
}
}

private void OpenSettingsModal(SettingsAction.OpenMenu action)
{

JSRuntime.InvokeVoidAsync("openSettingsModal").AsTask();
}
}
2 changes: 2 additions & 0 deletions src/EventLogExpert/Store/Settings/SettingsAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace EventLogExpert.Store.Settings;

public record SettingsAction
{
public record CheckForUpdates : SettingsAction;

public record LoadProviders(string Path) : SettingsAction;

public record LoadSettings(string Path) : SettingsAction;
Expand Down
7 changes: 5 additions & 2 deletions src/EventLogExpert/Store/Settings/SettingsReducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public static SettingsState ReduceLoadSettings(SettingsState state, SettingsActi

return state with
{
TimeZoneId = config.TimeZoneId, TimeZone = TimeZoneInfo.FindSystemTimeZoneById(config.TimeZoneId)
TimeZoneId = config.TimeZoneId,
TimeZone = TimeZoneInfo.FindSystemTimeZoneById(config.TimeZoneId),
IsPrereleaseEnabled = config.IsPrereleaseEnabled
};
}

Expand All @@ -61,7 +63,8 @@ public static SettingsState ReduceSave(SettingsState state, SettingsAction.Save
return state with
{
TimeZoneId = action.Settings.TimeZoneId,
TimeZone = TimeZoneInfo.FindSystemTimeZoneById(action.Settings.TimeZoneId)
TimeZone = TimeZoneInfo.FindSystemTimeZoneById(action.Settings.TimeZoneId),
IsPrereleaseEnabled = action.Settings.IsPrereleaseEnabled
};
}
catch
Expand Down
2 changes: 2 additions & 0 deletions src/EventLogExpert/Store/Settings/SettingsState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public record SettingsState

public TimeZoneInfo TimeZone { get; init; } = null!;

public bool IsPrereleaseEnabled { get; init; }

public IEnumerable<string> LoadedProviders { get; init; } = Enumerable.Empty<string>();
}
Loading