Send app to background if started hidden

Sandbox had to be enabled in order to submit binary to App Store
Connect, therefore command line arguments cannot be used to tell
if the app was started by the launcher.

However, given that launcher starts app in hidden state, we can
safely assert that if the app is hidden on start, it was started
by the launcher.

See f33380b4e2

Also drop automatic signing on Mac bundle and unused utils.
This commit is contained in:
Davide De Rosa 2022-07-18 02:27:56 +02:00
parent 32e548421f
commit 04faf57d4c
7 changed files with 12 additions and 24 deletions

View File

@ -1800,7 +1800,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "-"; CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 3284; CURRENT_PROJECT_VERSION = 3284;
@ -1816,6 +1816,7 @@
MTL_FAST_MATH = YES; MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "$(CFG_MAC_ID)"; PRODUCT_BUNDLE_IDENTIFIER = "$(CFG_MAC_ID)";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = macosx; SDKROOT = macosx;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_EMIT_LOC_STRINGS = YES;
@ -1832,7 +1833,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++17";
CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "-"; CODE_SIGN_IDENTITY = "-";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES; COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO; COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 3284; CURRENT_PROJECT_VERSION = 3284;
@ -1848,6 +1849,7 @@
MTL_FAST_MATH = YES; MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "$(CFG_MAC_ID)"; PRODUCT_BUNDLE_IDENTIFIER = "$(CFG_MAC_ID)";
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = macosx; SDKROOT = macosx;
SKIP_INSTALL = YES; SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_EMIT_LOC_STRINGS = YES;

View File

@ -33,7 +33,7 @@ class AppDelegate: NSObject, UIApplicationDelegate, ObservableObject {
#if targetEnvironment(macCatalyst) #if targetEnvironment(macCatalyst)
mac.configure() mac.configure()
mac.menu.install() mac.menu.install()
if ProcessInfo.processInfo.arguments.contains(Constants.Global.appArgumentBackground) { if mac.utils.isStartedByLauncher {
mac.utils.sendAppToBackground() mac.utils.sendAppToBackground()
} }
#endif #endif

View File

@ -27,11 +27,7 @@ import Foundation
@objc @objc
public protocol MacUtils { public protocol MacUtils {
var isForeground: Bool { get } var isStartedByLauncher: Bool { get }
func toggleForeground()
func bringAppToForeground()
func sendAppToBackground() func sendAppToBackground()
} }

View File

@ -44,7 +44,5 @@ enum Constants {
static let appBuildNumber = Int(Bundle.main.infoDictionary![kCFBundleVersionKey as String] as! String)! static let appBuildNumber = Int(Bundle.main.infoDictionary![kCFBundleVersionKey as String] as! String)!
static let appVersionString = "\(appVersionNumber) (\(appBuildNumber))" static let appVersionString = "\(appVersionNumber) (\(appBuildNumber))"
static let appArgumentBackground = "-background"
} }
} }

View File

@ -40,9 +40,11 @@ class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
NSApp.terminate(self) NSApp.terminate(self)
return return
} }
let cfg = NSWorkspace.OpenConfiguration() let cfg = NSWorkspace.OpenConfiguration()
cfg.hides = true cfg.hides = true
cfg.arguments = [Constants.Global.appArgumentBackground] cfg.activates = false
cfg.addsToRecentItems = false
NSWorkspace.shared.openApplication(at: appURL, configuration: cfg) { app, error in NSWorkspace.shared.openApplication(at: appURL, configuration: cfg) { app, error in
if let error = error { if let error = error {
NSLog("Unable to launch main app: \(error)") NSLog("Unable to launch main app: \(error)")

View File

@ -3,6 +3,6 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>com.apple.security.app-sandbox</key> <key>com.apple.security.app-sandbox</key>
<false/> <true/>
</dict> </dict>
</plist> </plist>

View File

@ -27,20 +27,10 @@ import Foundation
import AppKit import AppKit
class DefaultMacUtils: MacUtils { class DefaultMacUtils: MacUtils {
lazy private(set) var isStartedByLauncher = NSApp.isHidden
private let transformer = ObservableProcessTransformer.shared private let transformer = ObservableProcessTransformer.shared
var isForeground: Bool {
transformer.isForeground
}
func toggleForeground() {
transformer.toggleForeground()
}
func bringAppToForeground() {
transformer.bringToForeground()
}
func sendAppToBackground() { func sendAppToBackground() {
transformer.sendToBackground() transformer.sendToBackground()
} }