diff --git a/osu.Desktop/MacOS/MacOsAppLocationChecker.cs b/osu.Desktop/MacOS/MacOsAppLocationChecker.cs new file mode 100644 index 0000000000..aca82441b3 --- /dev/null +++ b/osu.Desktop/MacOS/MacOsAppLocationChecker.cs @@ -0,0 +1,55 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.IO; +using osu.Framework; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Game.Graphics; +using osu.Game.Localisation; +using osu.Game.Overlays; +using osu.Game.Overlays.Notifications; + +namespace osu.Desktop.MacOS +{ + /// + /// Checks if the game is located at `Applications` folder and displays a warning notification if not so. + /// + public partial class MacOSAppLocationChecker : Component + { + [Resolved] + private INotificationOverlay notification { get; set; } = null!; + + protected override void LoadComplete() + { + base.LoadComplete(); + + string assemblyPath = RuntimeInfo.EntryAssembly.Location; + + bool inRootApp = assemblyPath.StartsWith("/Applications/", StringComparison.Ordinal); + bool inUserApp = assemblyPath.StartsWith(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Applications/"), StringComparison.Ordinal); + + if (!inRootApp && !inUserApp) + notification.Post(new MacOSAppLocationNotification()); + + Expire(); + } + + private partial class MacOSAppLocationNotification : SimpleNotification + { + public MacOSAppLocationNotification() + { + Text = NotificationsStrings.MacOSAppLocation(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + Icon = FontAwesome.Solid.ShieldAlt; + IconContent.Colour = colours.YellowDark; + } + } + } +} diff --git a/osu.Desktop/OsuGameDesktop.cs b/osu.Desktop/OsuGameDesktop.cs index a860a0ec2e..054e27d396 100644 --- a/osu.Desktop/OsuGameDesktop.cs +++ b/osu.Desktop/OsuGameDesktop.cs @@ -14,6 +14,7 @@ using osu.Desktop.Updater; using osu.Framework; using osu.Framework.Logging; using osu.Game.Updater; +using osu.Desktop.MacOS; using osu.Desktop.Windows; using osu.Framework.Allocation; using osu.Game.Configuration; @@ -131,8 +132,17 @@ namespace osu.Desktop LoadComponentAsync(new DiscordRichPresence(), Add); - if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows) - LoadComponentAsync(new GameplayWinKeyBlocker(), Add); + switch (RuntimeInfo.OS) + { + case RuntimeInfo.Platform.Windows: + LoadComponentAsync(new GameplayWinKeyBlocker(), Add); + break; + + case RuntimeInfo.Platform.macOS when !IsPackageManaged && IsDeployedBuild: + if (!IsPackageManaged && IsDeployedBuild) + LoadComponentAsync(new MacOSAppLocationChecker(), Add); + break; + } LoadComponentAsync(new ElevatedPrivilegesChecker(), Add); diff --git a/osu.Desktop/Security/ElevatedPrivilegesChecker.cs b/osu.Desktop/Security/ElevatedPrivilegesChecker.cs index 1ac0a8153a..a1e81d0d3e 100644 --- a/osu.Desktop/Security/ElevatedPrivilegesChecker.cs +++ b/osu.Desktop/Security/ElevatedPrivilegesChecker.cs @@ -27,6 +27,8 @@ namespace osu.Desktop.Security if (Environment.IsPrivilegedProcess) notifications.Post(new ElevatedPrivilegesNotification()); + + Expire(); } private partial class ElevatedPrivilegesNotification : SimpleNotification diff --git a/osu.Game/Localisation/NotificationsStrings.cs b/osu.Game/Localisation/NotificationsStrings.cs index a8dac2d25c..59237111a3 100644 --- a/osu.Game/Localisation/NotificationsStrings.cs +++ b/osu.Game/Localisation/NotificationsStrings.cs @@ -235,6 +235,11 @@ Click to see what's new!", version); /// public static LocalisableString ElevatedPrivileges(LocalisableString user) => new TranslatableString(getKey(@"elevated_privileges"), @"Running osu! as {0} does not improve performance, may break integrations and poses a security risk. Please run the game as a normal user.", user); + /// + /// "On macOS, installing osu! to a directory other than /Applications or {0}/Applications can cause issues with updating the game. Please move your game installation to one of these locations." + /// + public static LocalisableString MacOSAppLocation(LocalisableString userProfile) => new TranslatableString(getKey(@"macos_app_location"), @"On macOS, installing osu! to a directory other than /Applications or {0}/Applications can cause issues with updating the game. Please move your game installation to one of these locations.", userProfile); + /// /// "Screenshot saved! Click to view. /// {0}"