Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertBeekman committed Mar 21, 2024
2 parents 4c2eca2 + da3d47d commit e5cb058
Show file tree
Hide file tree
Showing 27 changed files with 490 additions and 330 deletions.
16 changes: 13 additions & 3 deletions src/Artemis.Core/Utilities/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace Artemis.Core;
/// </summary>
public static class Utilities
{
private static bool _shuttingDown;

/// <summary>
/// Call this before even initializing the Core to make sure the folders required for operation are in place
/// </summary>
Expand All @@ -33,7 +35,11 @@ public static void PrepareFirstLaunch()
/// </summary>
public static void Shutdown()
{
if (_shuttingDown)
return;

// Request a graceful shutdown, whatever UI we're running can pick this up
_shuttingDown = true;
OnShutdownRequested();
}

Expand All @@ -45,9 +51,13 @@ public static void Shutdown()
/// <param name="extraArgs">A list of extra arguments to pass to Artemis when restarting</param>
public static void Restart(bool elevate, TimeSpan delay, params string[] extraArgs)
{
if (_shuttingDown)
return;

if (!OperatingSystem.IsWindows() && elevate)
throw new ArtemisCoreException("Elevation on non-Windows platforms is not supported.");

_shuttingDown = true;
OnRestartRequested(new RestartEventArgs(elevate, delay, extraArgs.ToList()));
}

Expand Down Expand Up @@ -106,12 +116,12 @@ public static void CreateAccessibleDirectory(string path)
/// Occurs when the core has requested an application shutdown
/// </summary>
public static event EventHandler? ShutdownRequested;

/// <summary>
/// Occurs when the core has requested an application restart
/// </summary>
public static event EventHandler<RestartEventArgs>? RestartRequested;

/// <summary>
/// Occurs when the core has requested a pending application update to be applied
/// </summary>
Expand Down Expand Up @@ -151,7 +161,7 @@ private static void OnShutdownRequested()
{
ShutdownRequested?.Invoke(null, EventArgs.Empty);
}

private static void OnUpdateRequested(UpdateEventArgs e)
{
UpdateRequested?.Invoke(null, e);
Expand Down
22 changes: 13 additions & 9 deletions src/Artemis.Storage/StorageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static class StorageManager
{
private static bool _ranMigrations;
private static bool _inUse;
private static object _factoryLock = new();

/// <summary>
/// Creates a backup of the database if the last backup is older than 10 minutes
Expand Down Expand Up @@ -39,19 +40,22 @@ public static void CreateBackup(string dataFolder)

File.Copy(database, Path.Combine(backupFolder, $"artemis-{DateTime.Now:yyyy-dd-M--HH-mm-ss}.db"));
}

public static ArtemisDbContext CreateDbContext(string dataFolder)
{
_inUse = true;
lock (_factoryLock)
{
_inUse = true;

ArtemisDbContext dbContext = new() {DataFolder = dataFolder};
if (_ranMigrations)
return dbContext;
ArtemisDbContext dbContext = new() {DataFolder = dataFolder};
if (_ranMigrations)
return dbContext;

dbContext.Database.Migrate();
dbContext.Database.ExecuteSqlRaw("PRAGMA optimize");
_ranMigrations = true;
dbContext.Database.Migrate();
dbContext.Database.ExecuteSqlRaw("PRAGMA optimize");
_ranMigrations = true;

return dbContext;
return dbContext;
}
}
}
59 changes: 33 additions & 26 deletions src/Artemis.UI/Routing/Routes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,57 +20,64 @@ namespace Artemis.UI.Routing;

public static class Routes
{
public static List<IRouterRegistration> ArtemisRoutes = new()
{
public static List<IRouterRegistration> ArtemisRoutes =
[
new RouteRegistration<BlankViewModel>("blank"),
new RouteRegistration<HomeViewModel>("home"),
new RouteRegistration<WorkshopViewModel>("workshop")
{
Children = new List<IRouterRegistration>
{
Children =
[
new RouteRegistration<WorkshopOfflineViewModel>("offline/{message:string}"),
new RouteRegistration<EntriesViewModel>("entries")
{
Children = new List<IRouterRegistration>
{
new RouteRegistration<PluginListViewModel>("plugins/{page:int}"),
new RouteRegistration<PluginDetailsViewModel>("plugins/details/{entryId:long}"),
new RouteRegistration<ProfileListViewModel>("profiles/{page:int}"),
new RouteRegistration<ProfileDetailsViewModel>("profiles/details/{entryId:long}"),
new RouteRegistration<LayoutListViewModel>("layouts/{page:int}"),
new RouteRegistration<LayoutDetailsViewModel>("layouts/details/{entryId:long}"),
}
Children =
[
new RouteRegistration<PluginListViewModel>("plugins")
{
Children = [new RouteRegistration<PluginDetailsViewModel>("details/{entryId:long}")]
},
new RouteRegistration<ProfileListViewModel>("profiles")
{
Children = [new RouteRegistration<ProfileDetailsViewModel>("details/{entryId:long}")]
},
new RouteRegistration<LayoutListViewModel>("layouts")
{
Children = [new RouteRegistration<LayoutDetailsViewModel>("details/{entryId:long}")]
},
]
},

new RouteRegistration<WorkshopLibraryViewModel>("library")
{
Children = new List<IRouterRegistration>
{
Children =
[
new RouteRegistration<InstalledTabViewModel>("installed"),
new RouteRegistration<SubmissionsTabViewModel>("submissions"),
new RouteRegistration<SubmissionDetailViewModel>("submissions/{entryId:long}"),
}
new RouteRegistration<SubmissionDetailViewModel>("submissions/{entryId:long}")
]
}
}
]
},

new RouteRegistration<SurfaceEditorViewModel>("surface-editor"),
new RouteRegistration<SettingsViewModel>("settings")
{
Children = new List<IRouterRegistration>
{
Children =
[
new RouteRegistration<GeneralTabViewModel>("general"),
new RouteRegistration<PluginsTabViewModel>("plugins"),
new RouteRegistration<DevicesTabViewModel>("devices"),
new RouteRegistration<ReleasesTabViewModel>("releases")
{
Children = new List<IRouterRegistration>
{
new RouteRegistration<ReleaseDetailsViewModel>("{releaseId:guid}")
}
Children = [new RouteRegistration<ReleaseDetailsViewModel>("{releaseId:guid}")]
},

new RouteRegistration<AccountTabViewModel>("account"),
new RouteRegistration<AboutTabViewModel>("about")
}
]
},

new RouteRegistration<ProfileEditorViewModel>("profile-editor/{profileConfigurationId:guid}")
};
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task<bool> BrowseLayouts()
if (!await _windowService.ShowConfirmContentDialog("Open workshop", "Do you want to close this window and view the workshop?"))
return false;

await _router.Navigate("workshop/entries/layouts/1");
await _router.Navigate("workshop/entries/layouts");
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Artemis.UI/Screens/Sidebar/SidebarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public SidebarViewModel(IRouter router, IProfileService profileService, IWindowS
new(MaterialIconKind.HomeOutline, "Home", "home"),
new(MaterialIconKind.TestTube, "Workshop", "workshop", null, new ObservableCollection<SidebarScreenViewModel>
{
new(MaterialIconKind.FolderVideo, "Profiles", "workshop/entries/profiles/1", "workshop/entries/profiles"),
new(MaterialIconKind.KeyboardVariant, "Layouts", "workshop/entries/layouts/1", "workshop/entries/layouts"),
new(MaterialIconKind.Connection, "Plugins", "workshop/entries/plugins/1", "workshop/entries/plugins"),
new(MaterialIconKind.FolderVideo, "Profiles", "workshop/entries/profiles", "workshop/entries/profiles"),
new(MaterialIconKind.KeyboardVariant, "Layouts", "workshop/entries/layouts", "workshop/entries/layouts"),
new(MaterialIconKind.Connection, "Plugins", "workshop/entries/plugins", "workshop/entries/plugins"),
new(MaterialIconKind.Bookshelf, "Library", "workshop/library"),
}),

Expand Down
6 changes: 3 additions & 3 deletions src/Artemis.UI/Screens/Workshop/Entries/EntriesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public EntriesViewModel(IRouter router)

Tabs = new ObservableCollection<RouteViewModel>
{
new("Profiles", "workshop/entries/profiles/1", "workshop/entries/profiles"),
new("Layouts", "workshop/entries/layouts/1", "workshop/entries/layouts"),
new("Plugins", "workshop/entries/plugins/1", "workshop/entries/plugins"),
new("Profiles", "workshop/entries/profiles", "workshop/entries/profiles"),
new("Layouts", "workshop/entries/layouts", "workshop/entries/layouts"),
new("Plugins", "workshop/entries/plugins", "workshop/entries/plugins"),
};

this.WhenActivated(d =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:entries="clr-namespace:Artemis.UI.Screens.Workshop.Entries"
xmlns:system="clr-namespace:System;assembly=System.Runtime"
xmlns:list="clr-namespace:Artemis.UI.Screens.Workshop.Entries.List"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.UI.Screens.Workshop.Entries.List.EntryListInputView"
Expand All @@ -25,15 +23,6 @@
<ComboBoxItem>Download count</ComboBoxItem>
</ComboBox>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal" Spacing="5">
<TextBlock VerticalAlignment="Center">Show per page</TextBlock>
<ComboBox Width="65" SelectedItem="{CompiledBinding EntriesPerPage}">
<system:Int32>10</system:Int32>
<system:Int32>20</system:Int32>
<system:Int32>50</system:Int32>
<system:Int32>100</system:Int32>
</ComboBox>
</StackPanel>
<TextBlock Grid.Column="3" VerticalAlignment="Center" Margin="5 0 0 0" MinWidth="75" TextAlignment="Right">
<Run Text="{CompiledBinding TotalCount}"/>
<Run Text="total"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Artemis.UI.Screens.Workshop.Entries.List;
public partial class EntryListInputViewModel : ViewModelBase
{
private static string? _lastSearch;
private readonly PluginSetting<int> _entriesPerPage;
private readonly PluginSetting<int> _sortBy;
private string? _search;
[Notify] private string _searchWatermark = "Search";
Expand All @@ -18,9 +17,7 @@ public partial class EntryListInputViewModel : ViewModelBase
public EntryListInputViewModel(ISettingsService settingsService)
{
_search = _lastSearch;
_entriesPerPage = settingsService.GetSetting("Workshop.EntriesPerPage", 10);
_sortBy = settingsService.GetSetting("Workshop.SortBy", 10);
_entriesPerPage.AutoSave = true;
_sortBy.AutoSave = true;
}

Expand All @@ -33,17 +30,7 @@ public string? Search
_lastSearch = value;
}
}

public int EntriesPerPage
{
get => _entriesPerPage.Value;
set
{
_entriesPerPage.Value = value;
this.RaisePropertyChanged();
}
}


public int SortBy
{
get => _sortBy.Value;
Expand Down
Loading

0 comments on commit e5cb058

Please sign in to comment.