Skip to content

Commit ff175d7

Browse files
committed
Fix icons and fix unlock issue
1 parent f7da6f8 commit ff175d7

File tree

25 files changed

+167
-10
lines changed

25 files changed

+167
-10
lines changed

AppScope/app.json5

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"app": {
33
"bundleName": "com.kilodim.authenticator",
44
"vendor": "kilodim",
5-
"versionCode": 1000012,
6-
"versionName": "1.0.12",
5+
"versionCode": 1000014,
6+
"versionName": "1.0.13",
77
"icon": "$media:icon",
88
"label": "$string:app_name"
99
}
6.38 KB
Loading
81.1 KB
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"layered-image": {
3+
"background" : "$media:background",
4+
"foreground" : "$media:foreground"
5+
}
6+
}
-1.99 KB
Binary file not shown.

entry/src/main/ets/entryability/EntryAbility.ets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export default class EntryAbility extends UIAbility {
4141
PersistentStorage.persistProp("enableSafeMode", false)
4242
PersistentStorage.persistProp("hideToken", false)
4343
PersistentStorage.persistProp("enhanceNetwork", false)
44+
PersistentStorage.persistProp("developmentMode", false)
4445
PersistentStorage.persistProp("privacyState", "Unknown")
4546
if (AppStorage.get("enableAutoDarkMode")) {
4647
this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);

entry/src/main/ets/pages/Add.ets

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { util } from "@kit.ArkTS";
66
export struct Add {
77
@Consume("pageStack") pageStack: NavPathStack;
88
@Consume("authDataStore") authDataStore: AuthDataStore
9+
@StorageLink("developmentMode") developmentMode: boolean = false
910

1011
build() {
1112
NavDestination() {
@@ -174,7 +175,11 @@ export struct Add {
174175
.height(40)
175176
.width("100%")
176177
.onClick(() => {
177-
this.pageStack.pushPathByName("AddSteamToken", undefined)
178+
if (this.developmentMode) {
179+
this.pageStack.pushPathByName("AddSteamToken", undefined)
180+
} else {
181+
this.pageStack.pushPathByName("AddSteamSecret", undefined)
182+
}
178183
})
179184

180185
Row() {
@@ -417,4 +422,100 @@ export struct AddUri {
417422
}
418423
.title("通过 TOTP URI 添加")
419424
}
425+
}
426+
427+
@Component
428+
export struct AddSteamSecret {
429+
@Consume("pageStack") pageStack: NavPathStack;
430+
@Consume("authDataStore") authDataStore: AuthDataStore;
431+
@State account: string = ""
432+
@State secret: string = ""
433+
434+
build() {
435+
NavDestination() {
436+
Column() {
437+
Row() {
438+
Text("提供方")
439+
.width("30%")
440+
.fontWeight(FontWeight.Bold)
441+
.textAlign(TextAlign.Start)
442+
Text("Steam")
443+
.width("60%")
444+
.fontWeight(FontWeight.Bold)
445+
.textAlign(TextAlign.End)
446+
}
447+
.height(40)
448+
.alignItems(VerticalAlign.Center)
449+
.margin({ bottom: 10 })
450+
451+
Row() {
452+
Text("账号")
453+
.width("30%")
454+
.fontWeight(FontWeight.Bold)
455+
.textAlign(TextAlign.Start)
456+
TextInput({ text: this.account, placeholder: "用户名或邮箱" })
457+
.width("60%")
458+
.fontWeight(FontWeight.Bold)
459+
.textAlign(TextAlign.End)
460+
.maxLength(50)
461+
.onChange((v) => this.account = v.trim())
462+
}
463+
.height(40)
464+
.alignItems(VerticalAlign.Center)
465+
.margin({ bottom: 10 })
466+
467+
Row() {
468+
Text("密钥")
469+
.width("30%")
470+
.fontWeight(FontWeight.Bold)
471+
.textAlign(TextAlign.Start)
472+
TextInput({ text: this.secret, placeholder: "由 A-Z,2-7 组成的字符串" })
473+
.width("60%")
474+
.fontWeight(FontWeight.Bold)
475+
.textAlign(TextAlign.End)
476+
.maxLength(50)
477+
.onChange((v) => this.secret = v.trim())
478+
}
479+
.margin({ bottom: 10 })
480+
481+
Row() {
482+
Text("令牌位数")
483+
.width("30%")
484+
.fontWeight(FontWeight.Bold)
485+
.textAlign(TextAlign.Start)
486+
Text("5")
487+
.width("60%")
488+
.fontWeight(FontWeight.Bold)
489+
.textAlign(TextAlign.End)
490+
}
491+
.height(40)
492+
.alignItems(VerticalAlign.Center)
493+
.margin({ bottom: 10 })
494+
495+
Row() {
496+
Button('添加')
497+
.onClick(() => {
498+
try {
499+
if (this.secret.length <= 1 || !this.secret.match(/^[A-Z2-7]+$/)) {
500+
throw new Error("密钥只能由 A-Z,2-7 组成,至少 2 个字符")
501+
}
502+
let encodedProvider = encodeURIComponent("Steam")
503+
let encodedAccount = encodeURIComponent(this.account)
504+
let uri =
505+
`otpauth://totp/${encodedProvider}:${encodedAccount}?secret=${this.secret}&issuer=${encodedProvider}&digits=5`
506+
this.authDataStore.addAuthItem(uri)
507+
this.pageStack.clear()
508+
} catch (e) {
509+
this.getUIContext().getPromptAction().showToast({
510+
message: `TOTP 错误:${e}`
511+
})
512+
}
513+
})
514+
.width(150)
515+
.enabled(this.account != "" && this.secret != "")
516+
}
517+
}
518+
}
519+
.title("添加 Steam 令牌")
520+
}
420521
}

entry/src/main/ets/pages/Index.ets

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SymbolGlyphModifier } from "@ohos.arkui.modifier"
22
import { scanCore, scanBarcode } from '@kit.ScanKit';
33
import { hilog } from '@kit.PerformanceAnalysisKit';
4-
import { systemDateTime } from '@kit.BasicServicesKit';
4+
import { BusinessError, systemDateTime } from '@kit.BasicServicesKit';
55
import { cryptoFramework } from '@kit.CryptoArchitectureKit';
66
import { Setting } from './Setting';
77
import { userAuth } from '@kit.UserAuthenticationKit';
@@ -10,7 +10,7 @@ import { AuthData, AuthDataStore, PromptParams, SteamAccountData } from './Base'
1010
import { SteamConfirmationList } from './SteamConfirmationList';
1111
import { SteamConfirmationDetail } from './SteamConfirmationDetail';
1212
import { Confirmation } from './Steam';
13-
import { Add, AddSecret, AddUri } from "./Add";
13+
import { Add, AddSecret, AddSteamSecret, AddUri } from "./Add";
1414
import {
1515
AddSteamToken,
1616
SteamConfirmLink,
@@ -61,6 +61,29 @@ struct Index {
6161
}
6262
}
6363

64+
isAvailableAuthType(authType: userAuth.UserAuthType, authLevel: userAuth.AuthTrustLevel): boolean {
65+
try {
66+
userAuth.getAvailableStatus(authType, authLevel);
67+
return true
68+
} catch (error) {
69+
const err: BusinessError = error as BusinessError;
70+
hilog.error(0x0001, '[Auth Sample]',
71+
`Current auth trust level [${authType}/${authLevel}] is not supported. Code is ${err?.code}, message is ${err?.message}`);
72+
}
73+
return false
74+
}
75+
76+
unlock(): void {
77+
// 获取认证状态
78+
if (!this.isAvailableAuthType(userAuth.UserAuthType.PIN, userAuth.AuthTrustLevel.ATL3) &&
79+
!this.isAvailableAuthType(userAuth.UserAuthType.FINGERPRINT, userAuth.AuthTrustLevel.ATL3) &&
80+
!this.isAvailableAuthType(userAuth.UserAuthType.FACE, userAuth.AuthTrustLevel.ATL3)) {
81+
this.safe = true
82+
return
83+
}
84+
this.onPageShow()
85+
}
86+
6487
onPageShow(): void {
6588
if (!this.enableSafeMode) {
6689
this.safe = true
@@ -138,6 +161,8 @@ struct Index {
138161
SteamConfirmationDetail({ confirmation: param as Confirmation })
139162
} else if (name == "SteamRefreshToken") {
140163
SteamRefreshToken({ authData: param["baseAuthData"], steamAuthData: param["authData"] })
164+
} else if (name == "AddSteamSecret") {
165+
AddSteamSecret()
141166
}
142167
}
143168

@@ -367,7 +392,7 @@ struct Index {
367392
{
368393
value: "unlock",
369394
symbolIcon: new SymbolGlyphModifier($r('sys.symbol.lock')),
370-
action: () => this.onPageShow()
395+
action: () => this.unlock()
371396
},
372397
])
373398
.title($r("app.string.EntryAbility_label"))
@@ -422,10 +447,10 @@ struct Index {
422447
try {
423448
scanBarcode.startScanForResult(getContext(this), options).then((result: scanBarcode.ScanResult) => {
424449
try {
425-
this.authDataStore.addAuthItem(result.originalValue)
426-
this.getUIContext().getPromptAction().showToast({
427-
message: "成功添加令牌"
428-
})
450+
this.authDataStore.addAuthItem(result.originalValue)
451+
this.getUIContext().getPromptAction().showToast({
452+
message: "成功添加令牌"
453+
})
429454
} catch (error) {
430455
this.getUIContext().getPromptAction().showToast({
431456
message: `扫码失败:${error}`

entry/src/main/ets/pages/Setting.ets

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export struct Setting {
1111
@StorageLink("hideToken") hideToken: boolean = false
1212
@StorageLink("enhanceNetwork") enhanceNetwork: boolean = false
1313
@StorageLink("privacyState") privacyState: string = "Unknown"
14+
@StorageLink("developmentMode") developmentMode: boolean = false
1415
@Consume("authDataStore") authDataStore: AuthDataStore
16+
private developmentCounter: number = 0
1517
private appInfo?: bundleManager.BundleInfo = undefined
1618

1719
aboutToAppear(): void {
@@ -94,6 +96,22 @@ export struct Setting {
9496
.width("80%")
9597
.fontWeight(FontWeight.Bold)
9698
.textAlign(TextAlign.Start)
99+
.onClick(() => {
100+
this.developmentCounter++
101+
if (this.developmentCounter >= 10) {
102+
this.developmentCounter = 0
103+
this.developmentMode = !this.developmentMode
104+
if (this.developmentMode) {
105+
this.getUIContext().getPromptAction().showToast({
106+
message: "已启用开发者模式"
107+
})
108+
} else {
109+
this.getUIContext().getPromptAction().showToast({
110+
message: "已关闭开发者模式"
111+
})
112+
}
113+
}
114+
})
97115
Toggle({ type: ToggleType.Switch, isOn: this.enhanceNetwork })
98116
.onChange((isOn) => {
99117
this.enhanceNetwork = isOn
6.38 KB
Loading

0 commit comments

Comments
 (0)