fix
This commit is contained in:
parent
03a26b2f31
commit
aca4bf1ec2
38
punchnet/Core/LaunchManager.swift
Normal file
38
punchnet/Core/LaunchManager.swift
Normal file
@ -0,0 +1,38 @@
|
||||
//
|
||||
// LaunchManager.swift
|
||||
// punchnet
|
||||
//
|
||||
// Created by 安礼成 on 2026/3/23.
|
||||
//
|
||||
import ServiceManagement
|
||||
import Observation
|
||||
|
||||
@Observable
|
||||
class LaunchManager {
|
||||
// 获取当前主 App 的服务实例
|
||||
private let service = SMAppService.mainApp
|
||||
|
||||
// 检查当前是否已开启自启动
|
||||
var launchAtLogin: Bool
|
||||
|
||||
init() {
|
||||
self.launchAtLogin = (service.status == .enabled)
|
||||
}
|
||||
|
||||
func toggleLaunchAtLogin(enabled: Bool) throws {
|
||||
if enabled {
|
||||
try service.register()
|
||||
} else {
|
||||
try service.unregister()
|
||||
}
|
||||
|
||||
// 3. 重点:操作完成后,手动更新存储属性以触发 View 刷新
|
||||
self.launchAtLogin = (service.status == .enabled)
|
||||
}
|
||||
|
||||
// 4. 提供一个手动同步方法(用于应对用户在系统设置中修改的情况)
|
||||
func refreshLaunchStatus() {
|
||||
self.launchAtLogin = (service.status == .enabled)
|
||||
}
|
||||
|
||||
}
|
||||
@ -29,22 +29,18 @@ extension SDLAPIClient {
|
||||
let hasUpdate: Bool
|
||||
let latestVersion: String
|
||||
let latestBuild: Int
|
||||
// 强制升级的url地址
|
||||
let forceUpdateUrl: String?
|
||||
let forceUpdate: Bool
|
||||
let downloadUrl: String
|
||||
let releaseNotes: String
|
||||
let minSupportedVersion: String
|
||||
let publishTime: Int
|
||||
|
||||
// 是否强制升级
|
||||
var forceUpdate: Bool {
|
||||
return forceUpdateUrl != nil
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case hasUpdate = "has_update"
|
||||
case latestVersion = "latest_version"
|
||||
case latestBuild = "latest_build"
|
||||
case forceUpdateUrl = "force_update"
|
||||
case forceUpdate = "force_update"
|
||||
case downloadUrl = "download_url"
|
||||
case releaseNotes = "release_notes"
|
||||
case minSupportedVersion = "min_supported_version"
|
||||
case publishTime = "publish_time"
|
||||
|
||||
@ -7,11 +7,14 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SettingsSystemView: View {
|
||||
// 启动管理
|
||||
@State private var launchManager = LaunchManager()
|
||||
|
||||
// 为每个设置项提供独立的状态
|
||||
@State private var launchAtLogin: Bool = false
|
||||
@State private var autoConnect: Bool = false
|
||||
@AppStorage("autoConnect") private var autoConnect: Bool = false
|
||||
@AppStorage("autoUpdate") private var autoUpdate: Bool = true
|
||||
|
||||
@State private var showMainUI: Bool = true
|
||||
@State private var autoUpdate: Bool = true
|
||||
|
||||
var body: some View {
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
@ -21,13 +24,26 @@ struct SettingsSystemView: View {
|
||||
systemSectionHeader(title: "启动与运行", icon: "power.circle.fill")
|
||||
|
||||
VStack(spacing: 0) {
|
||||
ToggleRow(icon: "macwindow.badge.plus", title: "开机时自动启动", isOn: $launchAtLogin)
|
||||
ToggleRow(icon: "macwindow.badge.plus", title: "开机时自动启动", isOn: Binding(
|
||||
get: {
|
||||
launchManager.launchAtLogin
|
||||
},
|
||||
set: { newValue in
|
||||
do {
|
||||
try launchManager.toggleLaunchAtLogin(enabled: newValue)
|
||||
} catch let err {
|
||||
NSLog("toggle get error: \(err)")
|
||||
}
|
||||
}
|
||||
))
|
||||
|
||||
Divider().padding(.leading, 48) // 为图标留出间距
|
||||
Divider()
|
||||
.padding(.leading, 48) // 为图标留出间距
|
||||
|
||||
ToggleRow(icon: "bolt.horizontal.icloud.fill", title: "应用启动后自动连接", isOn: $autoConnect)
|
||||
|
||||
Divider().padding(.leading, 48)
|
||||
Divider()
|
||||
.padding(.leading, 48)
|
||||
|
||||
ToggleRow(icon: "macwindow", title: "启动时显示主界面", isOn: $showMainUI)
|
||||
}
|
||||
@ -56,6 +72,9 @@ struct SettingsSystemView: View {
|
||||
.padding(32)
|
||||
.frame(maxWidth: 600, alignment: .leading)
|
||||
}
|
||||
.onAppear {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 辅助头部
|
||||
|
||||
@ -38,6 +38,7 @@ class AppUpdateManager {
|
||||
} catch {
|
||||
print("Update check failed: \(error)")
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ struct AppUpdateView: View {
|
||||
}
|
||||
|
||||
Button {
|
||||
if let forceUpdateUrl = info.forceUpdateUrl, let url = URL(string: forceUpdateUrl) {
|
||||
if let url = URL(string: info.downloadUrl) {
|
||||
NSWorkspace.shared.open(url)
|
||||
}
|
||||
} label: {
|
||||
|
||||
@ -45,7 +45,8 @@ struct punchnetApp: App {
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup(id: "main") {
|
||||
RootView()
|
||||
// RootView()
|
||||
SettingsView()
|
||||
.navigationTitle("")
|
||||
.environment(self.appContext)
|
||||
.environment(self.userContext)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user