Skip to content

Commit

Permalink
Merge pull request #22 from eveloki/local
Browse files Browse the repository at this point in the history
Update:index page add quickly scancode button
  • Loading branch information
SolidFaker authored Nov 14, 2024
2 parents aa09121 + cf72fce commit e578b5f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 14 deletions.
34 changes: 22 additions & 12 deletions entry/src/main/ets/dialogs/OTPConfigDialog.ets
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import { hilog } from '@kit.PerformanceAnalysisKit';
import { getIconPathByIssuer, HMACAlgorithm } from '../utils/TokenUtils';
import { TokenIcon } from '../components/TokenIcon';

@Entry
@Preview
@CustomDialog
export struct TOTPConfigDialog {
controller?: CustomDialogController;
@Prop conf_json?: string = '';
@State conf: TokenConfig = new TokenConfig();
@State btn_camera_clicked: number = 0;
//弹窗扫码值 初始化 给首页快速扫码使用
@State scan_code_original_Value:string='';

cancel?: () => void;
confirm: (new_conf: string) => void = () => {};
Expand All @@ -21,6 +24,9 @@ export struct TOTPConfigDialog {
if (this.conf_json != undefined && this.conf_json.length > 0) {
this.conf = JSON.parse(this.conf_json!);
}
if (this.scan_code_original_Value!='') {
this.addNewConfigOTP(this.scan_code_original_Value);
}
}

addNewConfigOTP(uri: string): void {
Expand Down Expand Up @@ -68,6 +74,21 @@ export struct TOTPConfigDialog {
this.conf.TokenDigits = parseInt(parameters['digits'] ?? '6');
}

scanCode():void{
let options: scanBarcode.ScanOptions = {
scanTypes: [scanCore.ScanType.ALL],
enableMultiMode: true,
enableAlbum: true
};
scanBarcode.startScanForResult(getContext(this), options).then((result: scanBarcode.ScanResult) => {
this.addNewConfigOTP(result.originalValue)
hilog.info(0x0001, '[Scan CPSample]', `Succeeded in getting ScanResult by promise with options, result is ${JSON.stringify(result)}`);
}).catch((error: BusinessError) => {
hilog.error(0x0001, '[Scan CPSample]',
`Failed to get ScanResult by promise with options. Code:${error.code}, message: ${error.message}`);
});
}

build() {
Column({ space: 10 }) {
Row() {
Expand All @@ -87,18 +108,7 @@ export struct TOTPConfigDialog {
this.btn_camera_clicked)
.onClick(() => {
this.btn_camera_clicked++
let options: scanBarcode.ScanOptions = {
scanTypes: [scanCore.ScanType.ALL],
enableMultiMode: true,
enableAlbum: true
};
scanBarcode.startScanForResult(getContext(this), options).then((result: scanBarcode.ScanResult) => {
this.addNewConfigOTP(result.originalValue)
hilog.info(0x0001, '[Scan CPSample]', `Succeeded in getting ScanResult by promise with options, result is ${JSON.stringify(result)}`);
}).catch((error: BusinessError) => {
hilog.error(0x0001, '[Scan CPSample]',
`Failed to get ScanResult by promise with options. Code:${error.code}, message: ${error.message}`);
});
this.scanCode();
})
}
.width('100%')
Expand Down
24 changes: 24 additions & 0 deletions entry/src/main/ets/pages/Index.ets
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { bundleManager,common } from '@kit.AbilityKit';
import { TokenConfig, otpType } from '../utils/TokenConfig';
import { TOTPConfigDialog } from '../dialogs/OTPConfigDialog';
import { FortiConfigDialog } from '../dialogs/FortiConfigDialog';
import { scanCore, scanBarcode } from '@kit.ScanKit';
import { TokenItem } from '../components/TokenItem';
import { SettingPage } from '../pages/SettingPage'
import { HashMap, util } from '@kit.ArkTS';
Expand Down Expand Up @@ -359,6 +360,29 @@ struct Index {
@Builder
TokenAddMenu() {
Menu() {
MenuItem({ content: $r('app.string.app_scan_code') })
.onClick(() => {
let options: scanBarcode.ScanOptions = {
scanTypes: [scanCore.ScanType.ALL],
enableMultiMode: true,
enableAlbum: true
};
scanBarcode.startScanForResult(getContext(this), options).then((result: scanBarcode.ScanResult) => {
this.dialog_totp_config = new CustomDialogController({
builder: TOTPConfigDialog({
scan_code_original_Value:result.originalValue,//弹窗立刻扫码赋值
confirm: (new_conf) => {this.updateTokenConfig(JSON.parse(new_conf))}
})
})
this.dialog_totp_config.open()
hilog.info(0x0001, '[Scan CPSample]', `Succeeded in getting ScanResult by promise with options, result is ${JSON.stringify(result)}`);
}).catch((error: BusinessError) => {
hilog.error(0x0001, '[Scan CPSample]',
`Failed to get ScanResult by promise with options. Code:${error.code}, message: ${error.message}`);
});

})
.accessibilityText($r('app.string.app_scan_code'))
MenuItem({ content: $r('app.string.tab_token_add_key') })
.onClick(() => {
this.dialog_totp_config = new CustomDialogController({
Expand Down
4 changes: 2 additions & 2 deletions entry/src/main/ets/pages/SettingPage.ets
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ export struct SettingPage {
this.RdbCloudSyncEnable = IsOn;
AppPreference.setRdbCloudSyncEnable(IsOn);
}
})
ItemDescription({ description: $r('app.string.data_rdb_cloud_sync_des') })
}).visibility(Visibility.None)
ItemDescription({ description: $r('app.string.data_rdb_cloud_sync_des') }).visibility(Visibility.None)
Divider().vertical(false).height(2)
SubItemButton({
symbol: $r('sys.symbol.arrow_counterclockwise_clock'),
Expand Down
4 changes: 4 additions & 0 deletions entry/src/main/resources/base/element/string.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@
{
"name": "app_issue_feedback",
"value": "Issue Feedback"
},
{
"name": "app_scan_code",
"value": "Scan Code"
}
]
}
4 changes: 4 additions & 0 deletions entry/src/main/resources/zh_CN/element/string.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@
{
"name": "app_issue_feedback",
"value": "问题反馈"
},
{
"name": "app_scan_code",
"value": "快捷扫码"
}
]
}

0 comments on commit e578b5f

Please sign in to comment.