Run the macOS app unsandboxed so it can update itself
Installing an update in place and relaunching needs to replace /Applications/Pipelines.app, which the sandbox forbids. Settings move once from the old sandbox container into the regular defaults.
This commit is contained in:
@@ -3,6 +3,11 @@ import FlutterMacOS
|
||||
|
||||
@main
|
||||
class AppDelegate: FlutterAppDelegate {
|
||||
override func applicationWillFinishLaunching(_ notification: Notification) {
|
||||
migrateSandboxedPreferences()
|
||||
super.applicationWillFinishLaunching(notification)
|
||||
}
|
||||
|
||||
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||||
return true
|
||||
}
|
||||
@@ -10,4 +15,26 @@ class AppDelegate: FlutterAppDelegate {
|
||||
override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
|
||||
return true
|
||||
}
|
||||
|
||||
/// The app ran sandboxed before self-update, so its settings (servers,
|
||||
/// sign-in, preferences) live in its container. Copy them once into the
|
||||
/// unsandboxed defaults so the update keeps them.
|
||||
private func migrateSandboxedPreferences() {
|
||||
let defaults = UserDefaults.standard
|
||||
let marker = "pipelines.migratedFromSandbox"
|
||||
guard !defaults.bool(forKey: marker),
|
||||
let bundle = Bundle.main.bundleIdentifier
|
||||
else { return }
|
||||
if ProcessInfo.processInfo.environment["APP_SANDBOX_CONTAINER_ID"] != nil {
|
||||
return // Still sandboxed: these defaults are the container's.
|
||||
}
|
||||
let path = NSHomeDirectory()
|
||||
+ "/Library/Containers/\(bundle)/Data/Library/Preferences/\(bundle).plist"
|
||||
if let old = NSDictionary(contentsOfFile: path) as? [String: Any] {
|
||||
for (key, value) in old where defaults.object(forKey: key) == nil {
|
||||
defaults.set(value, forKey: key)
|
||||
}
|
||||
}
|
||||
defaults.set(true, forKey: marker)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<true/>
|
||||
<false/>
|
||||
<key>com.apple.security.cs.allow-jit</key>
|
||||
<true/>
|
||||
<key>com.apple.security.files.downloads.read-write</key>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<true/>
|
||||
<false/>
|
||||
<key>com.apple.security.files.downloads.read-write</key>
|
||||
<true/>
|
||||
<key>com.apple.security.files.user-selected.read-write</key>
|
||||
|
||||
Reference in New Issue
Block a user