Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBeekman committed Feb 17, 2024
2 parents c61e3d2 + 0b6bf56 commit 00c510c
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/Artemis.UI.Windows/Providers/AutoRunProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private async Task RemoveAutoRunTask(string autorunName)
/// <inheritdoc />
public async Task EnableAutoRun(bool recreate, int autoRunDelay)
{
if (Constants.CurrentVersion == "development")
if (Constants.CurrentVersion == "local")
return;

await CleanupOldAutorun();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private async Task InstallRelease(Guid releaseId, string releaseVersion)
// If the main window is not open the user isn't busy, restart straight away
if (!_mainWindowService.IsMainWindowOpen)
{
_updateService.RestartForUpdate(true);
_updateService.RestartForUpdate("WindowsNotification", true);
return;
}

Expand Down Expand Up @@ -165,6 +165,6 @@ private async void ToastNotificationManagerCompatOnOnActivated(ToastNotification
else if (action == "cancel")
_cancellationTokenSource?.Cancel();
else if (action == "restart-for-update")
_updateService.RestartForUpdate(false);
_updateService.RestartForUpdate("WindowsNotification", false);
}
}
18 changes: 10 additions & 8 deletions src/Artemis.UI/Screens/Root/RootViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public RootViewModel(IRouter router,
router.SetRoot(this);
mainWindowService.ConfigureMainWindowProvider(this);

DisplayAccordingToSettings();
OpenScreen = ReactiveCommand.Create<string?>(ExecuteOpenScreen);
OpenDebugger = ReactiveCommand.CreateFromTask(ExecuteOpenDebugger);
Exit = ReactiveCommand.CreateFromTask(ExecuteExit);
Expand All @@ -74,10 +73,17 @@ public RootViewModel(IRouter router,
.Select(vm => vm ?? _defaultTitleBarViewModel)
.ToProperty(this, vm => vm.TitleBarViewModel);

if (ShouldShowUI())
{
ShowSplashScreen();
_coreService.Initialized += (_, _) => Dispatcher.UIThread.InvokeAsync(OpenMainWindow);
}

Task.Run(() =>
{
// Before doing heavy lifting, initialize the update service which may prompt a restart
if (_updateService.Initialize())
// Only initialize with an update check if we're not going to show the UI
if (_updateService.Initialize(!ShouldShowUI()))
return;

// Workshop service goes first so it has a chance to clean up old workshop entries and introduce new ones
Expand Down Expand Up @@ -118,17 +124,13 @@ private void CurrentMainWindowOnClosing(object? sender, EventArgs e)
OnMainWindowClosed();
}

private void DisplayAccordingToSettings()
private bool ShouldShowUI()
{
bool autoRunning = Constants.StartupArguments.Contains("--autorun");
bool minimized = Constants.StartupArguments.Contains("--minimized");
bool showOnAutoRun = _settingsService.GetSetting("UI.ShowOnStartup", true).Value;

if ((autoRunning && !showOnAutoRun) || minimized)
return;

ShowSplashScreen();
_coreService.Initialized += (_, _) => Dispatcher.UIThread.InvokeAsync(OpenMainWindow);
return (autoRunning && showOnAutoRun) || !minimized;
}

private void ShowSplashScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public override async Task OnNavigating(ReleaseDetailsViewModelParameters parame

private void ExecuteRestart()
{
_updateService.RestartForUpdate(false);
_updateService.RestartForUpdate("ReleaseDetails", false);
}

private async Task ExecuteInstall(CancellationToken cancellationToken)
Expand Down
2 changes: 1 addition & 1 deletion src/Artemis.UI/Screens/Settings/Updating/ReleaseView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<TextBlock Grid.Row="1" Grid.Column="0" Text="{CompiledBinding Release.CreatedAt, Converter={StaticResource DateTimeConverter}}" VerticalAlignment="Center" Classes="subtitle" FontSize="13" />
<avalonia:MaterialIcon Classes="status-icon" Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" Kind="CheckCircle" ToolTip.Tip="Current version"
IsVisible="{CompiledBinding IsCurrentVersion}" />
<avalonia:MaterialIcon Classes="status-icon" Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" Kind="History" ToolTip.Tip="Previous version"
<avalonia:MaterialIcon Classes="status-icon" Grid.Row="0" Grid.Column="1" Grid.RowSpan="2" Kind="History" ToolTip.Tip="Last previously installed version"
IsVisible="{CompiledBinding IsPreviousVersion}" />
</Grid>
<StackPanel Margin="4" IsVisible="{CompiledBinding !ShowStatusIndicator}">
Expand Down
5 changes: 5 additions & 0 deletions src/Artemis.UI/SerilogAvaloniaSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ public bool IsEnabled(AvaloniaLogLevel level, string area)
{
SerilogLogLevel logLevel = GetSerilogLogLevel(level, area);

#if DEBUG
// Except with binding errors, ignore anything that is information or lower
return (area == "Binding" || logLevel > SerilogLogLevel.Information) && _logger.IsEnabled(logLevel);
#else
// Ignore binding errors in release builds, shoo
return area != "Binding" && logLevel > SerilogLogLevel.Information && _logger.IsEnabled(logLevel);
#endif
}

/// <inheritdoc />
Expand Down
6 changes: 4 additions & 2 deletions src/Artemis.UI/Services/Updating/IUpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ public interface IUpdateService : IArtemisUIService
/// <summary>
/// Restarts the application to install a pending update.
/// </summary>
/// <param name="source">The source from which the restart is requested.</param>
/// <param name="silent">A boolean indicating whether to perform a silent install of the update.</param>
void RestartForUpdate(bool silent);
void RestartForUpdate(string source, bool silent);

/// <summary>
/// Initializes the update service.
/// </summary>
/// <param name="performAutoUpdate"></param>
/// <returns>A boolean indicating whether a restart will occur to install a pending update.</returns>
bool Initialize();
bool Initialize(bool performAutoUpdate);
}
27 changes: 15 additions & 12 deletions src/Artemis.UI/Services/Updating/UpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,19 @@ private async Task AutoInstallUpdate(IGetNextRelease_NextPublishedRelease releas
{
ReleaseInstaller installer = _getReleaseInstaller(release.Id);
await installer.InstallAsync(CancellationToken.None);
RestartForUpdate(true);
RestartForUpdate("AutoInstallUpdate", true);
}

private async void HandleAutoUpdateEvent(object? sender, EventArgs e)
{
if (Constants.CurrentVersion == "local")
return;
// The event can trigger from multiple sources with a timer acting as a fallback, only actual perform an action once per max 59 minutes

// The event can trigger from multiple sources with a timer acting as a fallback, only actually perform an action once per max 59 minutes
if (DateTime.UtcNow - _lastAutoUpdateCheck < TimeSpan.FromMinutes(59))
return;
_lastAutoUpdateCheck = DateTime.UtcNow;

if (!_autoCheck.Value || _suspendAutoCheck)
return;

Expand Down Expand Up @@ -157,7 +157,7 @@ public async Task CacheLatestRelease()
public async Task<bool> CheckForUpdate()
{
_logger.Information("Performing auto-update check");

IOperationResult<IGetNextReleaseResult> result = await _updatingClient.GetNextRelease.ExecuteAsync(Constants.CurrentVersion, Channel, _updatePlatform);
result.EnsureNoErrors();

Expand All @@ -171,7 +171,7 @@ public async Task<bool> CheckForUpdate()
// Unless auto install is enabled, only offer it once per session
if (!_autoInstall.Value)
_suspendAutoCheck = true;

// If the window is open show the changelog, don't auto-update while the user is busy
if (_mainWindowService.IsMainWindowOpen || !_autoInstall.Value)
{
Expand All @@ -194,8 +194,10 @@ public ReleaseInstaller GetReleaseInstaller(Guid releaseId)
}

/// <inheritdoc />
public void RestartForUpdate(bool silent)
public void RestartForUpdate(string source, bool silent)
{
_logger.Information("Restarting for update required by {Source}, silent: {Silent}", source, silent);

if (!Directory.Exists(Path.Combine(Constants.UpdatingFolder, "pending")))
throw new ArtemisUIException("Cannot install update, none is pending.");

Expand All @@ -204,11 +206,11 @@ public void RestartForUpdate(bool silent)
}

/// <inheritdoc />
public bool Initialize()
public bool Initialize(bool performAutoUpdate)
{
if (Constants.CurrentVersion == "local")
return false;

string? channelArgument = Constants.StartupArguments.FirstOrDefault(a => a.StartsWith("--channel="));
if (channelArgument != null)
Channel = channelArgument.Split("=")[1];
Expand All @@ -235,7 +237,7 @@ public bool Initialize()
_logger.Information("Installing pending update");
try
{
RestartForUpdate(true);
RestartForUpdate("PendingFolder", true);
return true;
}
catch (Exception e)
Expand All @@ -246,9 +248,10 @@ public bool Initialize()
}

ProcessReleaseStatus();

// Trigger the auto update event so that it doesn't take an hour for the first check to happen
HandleAutoUpdateEvent(this, EventArgs.Empty);
if (performAutoUpdate)
HandleAutoUpdateEvent(this, EventArgs.Empty);

_logger.Information("Update service initialized for {Channel} channel", Channel);
return false;
Expand Down
24 changes: 19 additions & 5 deletions src/Artemis.WebClient.Workshop/Services/WorkshopService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,26 @@ public void Initialize()
{
if (_initialized)
throw new ArtemisWorkshopException("Workshop service is already initialized");

RemoveOrphanedFiles();
_pluginManagementService.AdditionalPluginDirectories.AddRange(GetInstalledEntries().Where(e => e.EntryType == EntryType.Plugin).Select(e => e.GetReleaseDirectory()));
_initialized = true;

try
{
if (!Directory.Exists(Constants.WorkshopFolder))
Directory.CreateDirectory(Constants.WorkshopFolder);

RemoveOrphanedFiles();

_pluginManagementService.AdditionalPluginDirectories.AddRange(GetInstalledEntries()
.Where(e => e.EntryType == EntryType.Plugin)
.Select(e => e.GetReleaseDirectory()));

_initialized = true;
}
catch (Exception e)
{
_logger.Error(e, "Failed to initialize workshop service");
}
}

private void RemoveOrphanedFiles()
{
List<InstalledEntry> entries = GetInstalledEntries();
Expand Down

0 comments on commit 00c510c

Please sign in to comment.