From ce804d58ae308981453c3ecdc9c3c2f14687d598 Mon Sep 17 00:00:00 2001
From: Ariver <ar@MacBook-Air.local>
Date: Mon, 11 May 2026 13:14:12 +0800
Subject: [PATCH] Prepare App Store sandbox build
---
Apptag/ApptagApp.swift | 27 ++++++++++++++++++++-------
1 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/Apptag/ApptagApp.swift b/Apptag/ApptagApp.swift
index ff4466d..9698519 100644
--- a/Apptag/ApptagApp.swift
+++ b/Apptag/ApptagApp.swift
@@ -94,6 +94,9 @@
// MARK: - Launch at Login (LaunchAgent, zero permissions)
private static let launchAgentLabel = "com.apptag.launcher"
+ static var supportsLaunchAtLogin: Bool {
+ ProcessInfo.processInfo.environment["APP_SANDBOX_CONTAINER_ID"] == nil
+ }
private static var launchAgentURL: URL {
FileManager.default.homeDirectoryForCurrentUser
@@ -101,6 +104,7 @@
}
static func enableLaunchAtLogin() {
+ guard supportsLaunchAtLogin else { return }
let plist: [String: Any] = [
"Label": Self.launchAgentLabel,
"ProgramArguments": ["open", Bundle.main.bundlePath, "--hide"],
@@ -118,6 +122,7 @@
}
static func disableLaunchAtLogin() {
+ guard supportsLaunchAtLogin else { return }
let uid = getuid()
let task = Process()
task.launchPath = "/bin/launchctl"
@@ -129,6 +134,12 @@
/// On first launch, enable login item by default via LaunchAgent.
/// Does NOT require App Management permission.
private func setupLaunchAtLogin() {
+ guard Self.supportsLaunchAtLogin else {
+ if UserDefaults.standard.object(forKey: "launchAtLogin") == nil {
+ UserDefaults.standard.set(false, forKey: "launchAtLogin")
+ }
+ return
+ }
let key = "launchAtLogin"
if UserDefaults.standard.object(forKey: key) == nil {
UserDefaults.standard.set(true, forKey: key)
@@ -635,14 +646,16 @@
VStack(alignment: .leading, spacing: 0) {
// Toggle row — centered as a rectangular block
HStack(spacing: 20) {
- Toggle(tr("settings.launchAtLogin"), isOn: $launchAtLogin)
- .onChange(of: launchAtLogin) { _, enabled in
- if enabled {
- AppDelegate.enableLaunchAtLogin()
- } else {
- AppDelegate.disableLaunchAtLogin()
+ if AppDelegate.supportsLaunchAtLogin {
+ Toggle(tr("settings.launchAtLogin"), isOn: $launchAtLogin)
+ .onChange(of: launchAtLogin) { _, enabled in
+ if enabled {
+ AppDelegate.enableLaunchAtLogin()
+ } else {
+ AppDelegate.disableLaunchAtLogin()
+ }
}
- }
+ }
Toggle(tr("settings.showInDock"), isOn: $showDockIcon)
Toggle(tr("settings.hideAppNames"), isOn: $hideAppNames)
}
--
Gitblit v1.9.3