Skip to content

Commit 78715eb

Browse files
Add popup on startup to create desktop file
1 parent d565aa4 commit 78715eb

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

setup/Smz3CasRandomizer.desktop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ X-AppImage-Name=${APP_ID};
1212
X-AppImage-Version=${APP_VERSION};
1313
X-AppImage-Arch=${PACKAGE_ARCH};
1414
MimeType=
15-
Keywords=
15+
Keywords=metroid;zelda;smz3;randomizer;tracker

src/TrackerCouncil.Smz3.Data/Options/GeneralOptions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public class GeneralOptions : INotifyPropertyChanged
8888
public int UndoExpirationTime { get; set; } = 3;
8989
public double UIScaleFactor { get; set; } = 1;
9090

91+
public bool SkipDesktopFile { get; set; }
92+
9193
public Dictionary<string, SpriteOptions> LinkSpriteOptions { get; set; } = new();
9294
public Dictionary<string, SpriteOptions> SamusSpriteOptions { get; set; } = new();
9395
public Dictionary<string, SpriteOptions> ShipSpriteOptions { get; set; } = new();

src/TrackerCouncil.Smz3.UI/Services/MainWindowService.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Reflection;
66
using System.Threading.Tasks;
7+
using AppImageDesktopFileCreator;
78
using Avalonia.Threading;
89
using AvaloniaControls.Controls;
910
using AvaloniaControls.ControlServices;
@@ -44,6 +45,12 @@ public MainWindowViewModel InitializeModel(MainWindow window)
4445
{
4546
_options = optionsFactory.Create();
4647
_model.OpenSetupWindow = !_options.GeneralOptions.HasOpenedSetupWindow;
48+
49+
if (!_model.OpenSetupWindow && OperatingSystem.IsLinux() && !_options.GeneralOptions.SkipDesktopFile)
50+
{
51+
_model.OpenDesktopFileWindow = !DesktopFileCreator.CheckIfDesktopFileExists("org.trackercouncil.smz3");
52+
}
53+
4754
ITaskService.Run(CheckForUpdates);
4855
ITaskService.Run(StartPySpeechService);
4956
return _model;
@@ -63,6 +70,19 @@ public void IgnoreUpdate()
6370
_model.DisplayNewVersionBanner = false;
6471
}
6572

73+
public void HandleUserDesktopResponse(bool addDesktopFile)
74+
{
75+
if (addDesktopFile && OperatingSystem.IsLinux())
76+
{
77+
App.BuildLinuxDesktopFile();
78+
}
79+
else
80+
{
81+
_options.GeneralOptions.SkipDesktopFile = true;
82+
_options.Save();
83+
}
84+
}
85+
6686
public async Task<bool> ValidateTwitchToken()
6787
{
6888
if (string.IsNullOrEmpty(_options.GeneralOptions.TwitchOAuthToken))

src/TrackerCouncil.Smz3.UI/ViewModels/MainWindowViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ public MainWindowViewModel()
1414
public string NewVersionGitHubUrl { get; set; } = "";
1515

1616
public bool OpenSetupWindow { get; set; }
17+
18+
public bool OpenDesktopFileWindow { get; set; }
1719
}

src/TrackerCouncil.Smz3.UI/Views/MainWindow.axaml.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Threading.Tasks;
44
using Avalonia.Interactivity;
5+
using Avalonia.Threading;
56
using AvaloniaControls;
67
using AvaloniaControls.Controls;
78
using AvaloniaControls.Services;
@@ -88,6 +89,15 @@ private async void Control_OnLoaded(object? sender, RoutedEventArgs e)
8889
_ = ITaskService.Run(_service.DownloadConfigsAsync);
8990
_ = ITaskService.Run(_service.DownloadSpritesAsync);
9091

92+
if (_model.OpenSetupWindow || _model.OpenDesktopFileWindow)
93+
{
94+
_ = Dispatcher.UIThread.InvokeAsync(OpenStartingWindows);
95+
}
96+
}
97+
98+
private async Task OpenStartingWindows()
99+
{
100+
await Task.Delay(TimeSpan.FromSeconds(0.5));
91101
if (_model.OpenSetupWindow && _serviceProvider != null)
92102
{
93103
var result = await _serviceProvider.GetRequiredService<SetupWindow>()
@@ -101,6 +111,14 @@ private async void Control_OnLoaded(object? sender, RoutedEventArgs e)
101111
_ = SoloRomListPanel.OpenGenerationWindow();
102112
}
103113
}
114+
else if (_model.OpenDesktopFileWindow)
115+
{
116+
_model.OpenDesktopFileWindow = false;
117+
var response = await MessageWindow.ShowYesNoDialog(
118+
"Would you like to add SMZ3 to your menu by creating a desktop file?",
119+
"SMZ3 Cas' Randomizer", this);
120+
_service!.HandleUserDesktopResponse(response);
121+
}
104122
}
105123

106124
private void OptionsMenuItem_OnClick(object? sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)