mirror of
https://github.com/easychen/pushdeer.git
synced 2024-11-01 16:19:19 +08:00
d3050e154f
修改配置为pushdeer官方配置(包名,团队标识,api域名); 补充新添加的文字的英文翻译 (国际化); 设备和key是空列表时,加一个提示,让用户知道可以新增; 尝试解决列表删除项后UI偶尔没刷新的bug; 首次打开提示注册设备; 首次自动生成一个 key; 消息列表放到第一个位置; 推送测试时自动生成一个key; 后台进入前台后, 刷新本地消息列表; 键盘上方添加完成按钮, 用于收键盘; 发送推送测试后 自动收键盘; 及时清角标, 拯救强迫症; 为了保持一致, 设置页也改为可滑动; 添加SelfHosted配置, 可以直接一套代码跑出两种版本; 支持服务自建; 添加Env统一管理环境变量.
86 lines
2.5 KiB
Swift
86 lines
2.5 KiB
Swift
//
|
|
// KeyListView.swift
|
|
// PushDeer
|
|
//
|
|
// Created by HEXT on 2021/12/25.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
/// Key 界面
|
|
struct KeyListView: View {
|
|
@EnvironmentObject private var store: AppState
|
|
var body: some View {
|
|
BaseNavigationView(title: "Key") {
|
|
ScrollView {
|
|
LazyVStack(alignment: .center) {
|
|
ForEach(store.keys.reversed()) { keyItem in
|
|
DeletableView(contentView: {
|
|
CardView {
|
|
KeyItemView(keyItem: keyItem)
|
|
}
|
|
|
|
}, deleteAction: {
|
|
store.keys.removeAll { _keyItem in
|
|
keyItem.id == _keyItem.id
|
|
}
|
|
// 尝试触发 @Published, 看能不能解决 UI 偶尔不更新的问题
|
|
store.keys = store.keys
|
|
HToast.showSuccess(NSLocalizedString("已删除", comment: "删除设备/Key/消息时提示"))
|
|
Task {
|
|
do {
|
|
_ = try await HttpRequest.rmKey(id: keyItem.id)
|
|
} catch {
|
|
|
|
}
|
|
}
|
|
})
|
|
.padding(EdgeInsets(top: 18, leading: 26, bottom: 0, trailing: 24))
|
|
}
|
|
|
|
if store.keys.isEmpty {
|
|
Text("你还未添加过 Key, 发送推送需要使用 Key, 你可以点击右上角 \(Image(systemName: "plus")) 生成一个 Key")
|
|
.foregroundColor(Color(UIColor.lightGray))
|
|
.padding()
|
|
}
|
|
|
|
Spacer(minLength: 30)
|
|
}
|
|
}
|
|
.navigationBarItems(trailing: Button(action: genKey, label: {
|
|
Image(systemName: "plus")
|
|
.foregroundColor(Color(UIColor.lightGray))
|
|
}))
|
|
}
|
|
.onAppear {
|
|
Task {
|
|
let result = try await HttpRequest.getKeys()
|
|
AppState.shared.keys = result.keys
|
|
|
|
// 首次自动生成一个 key
|
|
let hasAlertGenKey = UserDefaults.standard.bool(forKey: "PushDeer_hasAlertGenKey")
|
|
if result.keys.isEmpty && !hasAlertGenKey {
|
|
genKey()
|
|
UserDefaults.standard.set(true, forKey: "PushDeer_hasAlertGenKey")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func genKey() -> Void {
|
|
Task {
|
|
let keys = try await HttpRequest.genKey().keys
|
|
withAnimation(.easeOut) {
|
|
store.keys = keys
|
|
}
|
|
HToast.showSuccess(NSLocalizedString("已添加新Key", comment: ""))
|
|
}
|
|
}
|
|
}
|
|
|
|
struct KeyView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
KeyListView().environmentObject(AppState.shared)
|
|
}
|
|
}
|