pushdeer/ios/PushDeer-iOS/PushDeer/View/SettingsView.swift
hext d3050e154f 添加自建服务配置, 优化交互, 修复bug.
修改配置为pushdeer官方配置(包名,团队标识,api域名);
补充新添加的文字的英文翻译 (国际化);
设备和key是空列表时,加一个提示,让用户知道可以新增;
尝试解决列表删除项后UI偶尔没刷新的bug;
首次打开提示注册设备;
首次自动生成一个 key;
消息列表放到第一个位置;
推送测试时自动生成一个key;
后台进入前台后, 刷新本地消息列表;
键盘上方添加完成按钮, 用于收键盘;
发送推送测试后 自动收键盘;
及时清角标, 拯救强迫症;
为了保持一致, 设置页也改为可滑动;
添加SelfHosted配置, 可以直接一套代码跑出两种版本;
支持服务自建;
添加Env统一管理环境变量.
2022-02-14 01:13:26 +08:00

72 lines
2.1 KiB
Swift

//
// SettingsView.swift
// PushDeer
//
// Created by HEXT on 2021/12/25.
//
import SwiftUI
//import StoreKit
///
struct SettingsView: View {
@EnvironmentObject private var store: AppState
var body: some View {
BaseNavigationView(title: "设置") {
ScrollView {
VStack {
SettingsItemView(title: NSLocalizedString("登录为", comment: "") + " " + userName(), button: NSLocalizedString("退出", comment: "退出登录按钮上的文字")) {
store.token = ""
}
.padding(EdgeInsets(top: 18, leading: 20, bottom: 0, trailing: 20))
if Env.isSelfHosted {
SettingsItemView(title: NSLocalizedString("API endpoint", comment: ""), button: NSLocalizedString("重置", comment: "")) {
store.api_endpoint = ""
store.token = ""
}
.padding(EdgeInsets(top: 18, leading: 20, bottom: 0, trailing: 20))
}
SettingsItemView(title: NSLocalizedString("喜欢PushDeer?", comment: ""), button: NSLocalizedString("评分", comment: "")) {
let urlStr = "itms-apps://itunes.apple.com/app/id\(Env.appStoreId)?action=write-review"
UIApplication.shared.open(URL(string: urlStr)!, options: [:], completionHandler: nil)
// , 3,
// SKStoreReviewController.requestReview()
}
.padding(EdgeInsets(top: 18, leading: 20, bottom: 0, trailing: 20))
Spacer()
}
}
}
.onAppear {
if store.userInfo != nil {
return
}
Task {
store.userInfo = try await HttpRequest.getUserInfo()
}
}
}
func userName() -> String {
if let name = store.userInfo?.name {
if name.isEmpty {
return NSLocalizedString("苹果用户", comment: "")
} else {
return name
}
} else {
return "--"
}
}
}
struct SettingsView_Previews: PreviewProvider {
static var previews: some View {
SettingsView().environmentObject(AppState.shared)
}
}