Skip to content

Commit c218f3e

Browse files
Create app image desktop file
1 parent 99740c5 commit c218f3e

File tree

10 files changed

+106
-16
lines changed

10 files changed

+106
-16
lines changed

MSURandomizer/MSURandomizer.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
</PropertyGroup>
1414

1515
<ItemGroup>
16-
<AvaloniaResource Include="Assets\**" />
16+
<EmbeddedResource Include="Assets\**" />
17+
<AvaloniaResource Include="Assets\MSURandomizerIcon.ico" />
1718
</ItemGroup>
1819

1920
<ItemGroup>
@@ -33,14 +34,15 @@
3334
<!--Condition
3435
below is needed to remove Avalonia.Diagnostics package from build output in Release
3536
configuration.-->
36-
<PackageReference Include="MattEqualsCoder.AvaloniaControls" Version="1.5.3" />
37+
<PackageReference Include="MattEqualsCoder.AppImageDesktopFileCreator" Version="0.2.0" />
38+
<PackageReference Include="MattEqualsCoder.AvaloniaControls" Version="1.9.0" />
3739
<PackageReference Include="MattEqualsCoder.GitHubReleaseChecker" Version="1.1.3" />
38-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
40+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.9" />
3941
<PackageReference Include="ReactiveUI.Fody" Version="19.5.41" />
4042
<PackageReference Include="Serilog.Extensions.Hosting" Version="9.0.0" />
4143
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
4244
<PackageReference Include="Serilog.Sinks.Debug" Version="3.0.0" />
43-
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
45+
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
4446
</ItemGroup>
4547

4648

MSURandomizer/Program.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
using Avalonia.ReactiveUI;
33
using System;
44
using System.Linq;
5+
using System.Reflection;
6+
using System.Runtime.Versioning;
57
using System.Threading;
68
using System.Threading.Tasks;
9+
using AppImageDesktopFileCreator;
710
using Avalonia.Threading;
811
using AvaloniaControls.Controls;
912
using AvaloniaControls.Services;
@@ -25,7 +28,6 @@ sealed class Program
2528
[STAThread]
2629
public static void Main(string[] args)
2730
{
28-
2931
var loggerConfiguration = new LoggerConfiguration();
3032

3133
#if DEBUG
@@ -90,6 +92,26 @@ public static void Main(string[] args)
9092
Dispatcher.UIThread.MainLoop(source.Token);
9193
}
9294
}
95+
96+
[SupportedOSPlatform("linux")]
97+
internal static CreateDesktopFileResponse BuildLinuxDesktopFile()
98+
{
99+
var assembly = Assembly.GetExecutingAssembly();
100+
return new DesktopFileBuilder("org.mattequalscoder.msurandomizer", "MSU Randomizer")
101+
.AddDescription("UI application for applying, randomizing, and shuffling MSUs")
102+
.AddCategory(DesktopFileCategories.Game)
103+
.AddWindowClass("MSURandomizer")
104+
.AddIcon(assembly, "MSURandomizer.Assets.icon.16.png", 16)
105+
.AddIcon(assembly, "MSURandomizer.Assets.icon.32.png", 32)
106+
.AddIcon(assembly, "MSURandomizer.Assets.icon.48.png", 48)
107+
.AddIcon(assembly, "MSURandomizer.Assets.icon.64.png", 64)
108+
.AddIcon(assembly, "MSURandomizer.Assets.icon.128.png", 128)
109+
.AddIcon(assembly, "MSURandomizer.Assets.icon.256.png", 256)
110+
.AddIcon(assembly, "MSURandomizer.Assets.icon.512.png", 512)
111+
.AddIcon(assembly, "MSURandomizer.Assets.icon.svg")
112+
.AddUninstallAction(Directories.AppDataFolder)
113+
.Build();
114+
}
93115

94116
// Avalonia configuration, don't remove; also used by visual designer.
95117
private static AppBuilder BuildAvaloniaApp()

MSURandomizer/Services/MsuWindowService.cs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using System.Threading.Tasks;
6+
using AppImageDesktopFileCreator;
67
using Avalonia.Platform.Storage;
78
using Avalonia.Threading;
89
using AvaloniaControls;
@@ -41,23 +42,23 @@ public class MsuWindowService(ILogger<MsuWindowService> logger,
4142

4243
public MsuWindowViewModel InitializeModel()
4344
{
44-
msuLookupService.OnMsuLookupStarted += (sender, args) =>
45+
msuLookupService.OnMsuLookupStarted += (_, _) =>
4546
{
4647
Model.AreMsusLoading = true;
4748
};
4849

49-
msuLookupService.OnMsuLookupComplete += (sender, args) =>
50+
msuLookupService.OnMsuLookupComplete += (_, _) =>
5051
{
5152
Model.AreMsusLoading = false;
5253
};
5354

54-
msuMonitorService.MsuMonitorStarted += (sender, args) =>
55+
msuMonitorService.MsuMonitorStarted += (_, _) =>
5556
{
5657
Model.IsMsuMonitorActive = true;
5758
MsuMonitorStarted?.Invoke(this, EventArgs.Empty);
5859
};
5960

60-
msuMonitorService.MsuMonitorStopped += (sender, args) =>
61+
msuMonitorService.MsuMonitorStopped += (_, _) =>
6162
{
6263
Model.IsMsuMonitorActive = false;
6364
MsuMonitorStopped?.Invoke(this, EventArgs.Empty);
@@ -83,10 +84,31 @@ public MsuWindowViewModel InitializeModel()
8384
Model.DisplayMsuTypeComboBox = false;
8485
Model.FilterColumnIndex = 0;
8586
}
87+
88+
Model.DisplaySettingsWindowOnLoad = Model is { MsuWindowDisplayOptionsButton: true, HasMsuFolder: false };
89+
90+
if (OperatingSystem.IsLinux() && Model.MsuWindowDisplayOptionsButton && !userOptions.MsuUserOptions.SkipDesktopFile &&
91+
!DesktopFileCreator.CheckIfDesktopFileExists("org.mattequalscoder.msurandomizer"))
92+
{
93+
Model.DisplayDesktopPopupOnLoad = true;
94+
}
8695

8796
return Model;
8897
}
8998

99+
public void HandleUserDesktopResponse(bool addDesktopFile)
100+
{
101+
if (addDesktopFile && OperatingSystem.IsLinux())
102+
{
103+
Program.BuildLinuxDesktopFile();
104+
}
105+
else
106+
{
107+
userOptions.MsuUserOptions.SkipDesktopFile = true;
108+
userOptions.Save();
109+
}
110+
}
111+
90112
private void AppInitializationServiceOnInitializationComplete(object? sender, EventArgs e)
91113
{
92114
if (appInitializationService.LatestFullRelease == null)
@@ -96,7 +118,7 @@ private void AppInitializationServiceOnInitializationComplete(object? sender, Ev
96118

97119
Dispatcher.UIThread.Invoke(() =>
98120
{
99-
var messageWindow = new MessageWindow(new MessageWindowRequest()
121+
var messageWindow = new MessageWindow(new MessageWindowRequest
100122
{
101123
Title = $"MSU Randomizer {appInitializationService.LatestFullRelease.Tag}",
102124
Message = "A new version of the MSU Randomizer has been released.",
@@ -106,7 +128,7 @@ private void AppInitializationServiceOnInitializationComplete(object? sender, Ev
106128
CheckBoxText = "Do not check for updates",
107129
Buttons = MessageWindowButtons.OK
108130
});
109-
messageWindow.Closed += (o, args) =>
131+
messageWindow.Closed += (_, _) =>
110132
{
111133
if (messageWindow.DialogResult?.CheckedBox == true)
112134
{
@@ -368,7 +390,6 @@ private void MsuTypeServiceOnOnMsuTypeLoadComplete(object? sender, EventArgs e)
368390
foreach (var entry in userOptions.MsuUserOptions.MsuDirectories)
369391
{
370392
var path = entry.Key;
371-
var msuTypeName = entry.Value;
372393
var directoryMsuType = msuTypeService.GetMsuType(Model.SelectedMsuType);
373394
if (directoryMsuType == null)
374395
{

MSURandomizer/Services/SettingsWindowService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public void RemoveDirectory(string directory)
7676
}
7777
}
7878

79+
public void CreateDesktopFile()
80+
{
81+
82+
}
83+
7984
private bool HasPathUpdated(MsuUserOptions options)
8085
{
8186
if (_model.MsuDirectoryList.Count != options.MsuDirectories.Count)

MSURandomizer/ViewModels/MsuWindowViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public class MsuWindowViewModel : ViewModelBase
9393
public bool HasGitHubUrl => !string.IsNullOrEmpty(GitHubUrl);
9494

9595
public bool HasMsuFolder { get; set; }
96+
97+
public bool DisplayDesktopPopupOnLoad { get; set; }
98+
99+
public bool DisplaySettingsWindowOnLoad { get; set; }
96100

97101
public int FilterColumnIndex { get; set; } = 1;
98102
}

MSURandomizer/ViewModels/SettingsWindowViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public class SettingsWindowViewModel : ViewModelBase
4646
[Reactive]
4747
[ReactiveLinkedProperties(nameof(TrackDisplayExample))]
4848
public TrackDisplayFormat TrackDisplayFormat { get; set; }
49+
50+
public bool DisplayDesktopFileButton => OperatingSystem.IsLinux();
4951

5052
public string TrackDisplayExample =>
5153
"Ex" + TrackDisplayFormat.GetDescription()[

MSURandomizer/Views/MsuWindow.axaml.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,33 @@ public void ShowDialog(Window window, bool isSingleSelect, string? msuBasePath =
7676
private void Control_OnLoaded(object? sender, RoutedEventArgs e)
7777
{
7878
_service?.FinishInitialization();
79-
if (!Design.IsDesignMode && _model is { HasMsuFolder: false, MsuWindowDisplayOptionsButton: true })
79+
80+
if (Design.IsDesignMode)
81+
{
82+
return;
83+
}
84+
85+
if (!Design.IsDesignMode && (_model.DisplayDesktopPopupOnLoad || _model.DisplaySettingsWindowOnLoad))
8086
{
8187
ITaskService.Run(async () =>
8288
{
8389
await Task.Delay(TimeSpan.FromSeconds(.5));
84-
_ = Dispatcher.UIThread.InvokeAsync(() =>
90+
_ = Dispatcher.UIThread.Invoke(async () =>
8591
{
86-
var settingsWindow = new SettingsWindow();
87-
settingsWindow.ShowDialog(this);
92+
if (_model.DisplayDesktopPopupOnLoad)
93+
{
94+
_model.DisplayDesktopPopupOnLoad = false;
95+
var response = await MessageWindow.ShowYesNoDialog(
96+
"Would you like to add the MSU Randomizer to your menu by creating a desktop file?",
97+
"MSU Randomizer", this);
98+
_service!.HandleUserDesktopResponse(response);
99+
}
100+
101+
if (_model.DisplaySettingsWindowOnLoad)
102+
{
103+
var settingsWindow = new SettingsWindow();
104+
await settingsWindow.ShowDialog(this);
105+
}
88106
});
89107
});
90108
}

MSURandomizer/Views/SettingsWindow.axaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@
127127
></TextBox>
128128
</controls:LabeledControl>
129129

130+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0 10 0 0" IsVisible="{Binding DisplayDesktopFileButton}">
131+
<Button Click="CreateDesktopFileButton_OnClick">
132+
Create Linux .desktop File
133+
</Button>
134+
</StackPanel>
135+
130136
</StackPanel>
131137
</controls:CardControl>
132138

MSURandomizer/Views/SettingsWindow.axaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,12 @@ private void RemoveDirectoryButton_OnClick(object? sender, RoutedEventArgs e)
8181
}
8282
_service.RemoveDirectory(directory);
8383
}
84+
85+
private void CreateDesktopFileButton_OnClick(object? sender, RoutedEventArgs e)
86+
{
87+
if (OperatingSystem.IsLinux())
88+
{
89+
Program.BuildLinuxDesktopFile();
90+
}
91+
}
8492
}

MSURandomizerLibrary/Configs/MsuUserOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ public class MsuUserOptions
153153
/// </summary>
154154
[YamlIgnore] public Dictionary<MsuType, string> MsuTypePaths { get; set; } = new();
155155

156+
public bool SkipDesktopFile { get; set; }
157+
156158
/// <summary>
157159
/// Gets the MSU Settings for a specific MSU path
158160
/// </summary>

0 commit comments

Comments
 (0)