Last active
April 6, 2024 10:13
-
-
Save benigumocom/342c9f935afc1229225f77e79f5f7694 to your computer and use it in GitHub Desktop.
【Swift】ログイン時に起動する - SMAppService 👉 https://android.benigumo.com/20240406/smappservice/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import ServiceManagement | |
// view | |
Toggle( | |
"Launch at login", | |
isOn: Binding( | |
get: { SMAppService.mainApp.isEnabled }, | |
set: { _ in SMAppService.mainApp.toggle() } | |
) | |
) | |
// extention | |
extension SMAppService { | |
var isEnabled: Bool { | |
status == .enabled | |
} | |
func toggle() { | |
try? isEnabled ? unregister() : register() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment