Skip to content

Commit 1b618bc

Browse files
Refactor cloud backup and improve OAuth
Updated cloud backup service screens to use ChewieTheme for consistent colors, improved OAuth safety tips, and added server status checks before authentication. Enhanced UI feedback for backup and encryption settings, refactored context menu and token layout interactions, and fixed typos and minor logic issues. These changes improve user experience, maintainability, and security awareness across backup and token management features.
1 parent 89550c2 commit 1b618bc

File tree

74 files changed

+1196
-710
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1196
-710
lines changed

lib/Database/database_manager.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import '../Utils/hive_util.dart';
3737
enum EncryptDatabaseStatus { defaultPassword, customPassword }
3838

3939
class DatabaseManager {
40-
static const _dbName = "cloudotp.db";
40+
static const _dbName = "cloudotps.db";
4141
static const _unencrypedFileHeader = "SQLite format 3";
4242
static const _dbVersion = 6;
4343
static Database? _database;

lib/Screens/Backup/aliyundrive_service_screen.dart

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ class _AliyunDriveServiceScreenState extends State<AliyunDriveServiceScreen>
4545
bool get wantKeepAlive => true;
4646
final TextEditingController _sizeController = TextEditingController();
4747
final TextEditingController _accountController = TextEditingController();
48-
final TextEditingController _emailController = TextEditingController();
4948
CloudServiceConfig? _aliyunDriveCloudServiceConfig;
5049
AliyunDriveCloudService? _aliyunDriveCloudService;
5150
bool inited = false;
@@ -69,7 +68,6 @@ class _AliyunDriveServiceScreenState extends State<AliyunDriveServiceScreen>
6968
if (_aliyunDriveCloudServiceConfig != null) {
7069
_sizeController.text = _aliyunDriveCloudServiceConfig!.size;
7170
_accountController.text = _aliyunDriveCloudServiceConfig!.account ?? "";
72-
_emailController.text = _aliyunDriveCloudServiceConfig!.email ?? "";
7371
_aliyunDriveCloudService = AliyunDriveCloudService(
7472
_aliyunDriveCloudServiceConfig!,
7573
onConfigChanged: updateConfig,
@@ -105,7 +103,6 @@ class _AliyunDriveServiceScreenState extends State<AliyunDriveServiceScreen>
105103
}
106104
_sizeController.text = _aliyunDriveCloudServiceConfig!.size;
107105
_accountController.text = _aliyunDriveCloudServiceConfig!.account ?? "";
108-
_emailController.text = _aliyunDriveCloudServiceConfig!.email ?? "";
109106
CloudServiceConfigDao.updateConfig(_aliyunDriveCloudServiceConfig!);
110107
}
111108

@@ -188,6 +185,8 @@ class _AliyunDriveServiceScreenState extends State<AliyunDriveServiceScreen>
188185
padding: const EdgeInsets.symmetric(horizontal: 6),
189186
child: CheckboxItem(
190187
title: S.current.enable + S.current.cloudTypeAliyunDrive,
188+
description: S.current.cloudOAuthSafeTip(
189+
S.current.cloudTypeAliyunDrive, CloudService.serverEndpoint),
191190
value: _aliyunDriveCloudServiceConfig?.enabled ?? false,
192191
onTap: () {
193192
setState(() {
@@ -211,12 +210,6 @@ class _AliyunDriveServiceScreenState extends State<AliyunDriveServiceScreen>
211210
disabled: true,
212211
title: S.current.cloudDisplayName,
213212
),
214-
InputItem(
215-
controller: _emailController,
216-
textInputAction: TextInputAction.next,
217-
disabled: true,
218-
title: S.current.cloudEmail,
219-
),
220213
InputItem(
221214
controller: _sizeController,
222215
textInputAction: TextInputAction.next,
@@ -233,7 +226,7 @@ class _AliyunDriveServiceScreenState extends State<AliyunDriveServiceScreen>
233226
padding: const EdgeInsets.symmetric(horizontal: 16),
234227
child: RoundIconTextButton(
235228
text: S.current.cloudSignin,
236-
background: Theme.of(context).primaryColor,
229+
background: ChewieTheme.primaryColor,
237230
fontSizeDelta: 2,
238231
onPressed: () async {
239232
try {
@@ -256,7 +249,7 @@ class _AliyunDriveServiceScreenState extends State<AliyunDriveServiceScreen>
256249
child: RoundIconTextButton(
257250
text: S.current.cloudPullBackup,
258251
padding: const EdgeInsets.symmetric(vertical: 12),
259-
color: Theme.of(context).primaryColor,
252+
color: ChewieTheme.primaryColor,
260253
fontSizeDelta: 2,
261254
onPressed: () async {
262255
CustomLoadingDialog.showLoading(title: S.current.cloudPulling);
@@ -310,7 +303,7 @@ class _AliyunDriveServiceScreenState extends State<AliyunDriveServiceScreen>
310303
Expanded(
311304
child: RoundIconTextButton(
312305
padding: const EdgeInsets.symmetric(horizontal: 12),
313-
background: Theme.of(context).primaryColor,
306+
background: ChewieTheme.primaryColor,
314307
text: S.current.cloudPushBackup,
315308
fontSizeDelta: 2,
316309
onPressed: () async {

lib/Screens/Backup/box_service_screen.dart

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
import 'dart:typed_data';
1717

1818
import 'package:awesome_chewie/awesome_chewie.dart';
19+
import 'package:awesome_cloud/awesome_cloud.dart';
1920
import 'package:awesome_cloud/models/box_response.dart';
2021
import 'package:cloudotp/Models/cloud_service_config.dart';
2122
import 'package:cloudotp/TokenUtils/Cloud/cloud_service.dart';
2223
import 'package:flutter/material.dart';
23-
import 'package:awesome_cloud/awesome_cloud.dart';
2424

2525
import '../../Database/cloud_service_config_dao.dart';
2626
import '../../TokenUtils/Cloud/box_cloud_service.dart';
@@ -146,26 +146,33 @@ class _BoxServiceScreenState extends State<BoxServiceScreen>
146146
if (showLoading) {
147147
CustomLoadingDialog.showLoading(title: S.current.cloudConnecting);
148148
}
149-
await currentService.authenticate().then((value) async {
150-
setState(() {
151-
currentConfig.connected = (value == CloudServiceStatus.success);
152-
});
153-
if (!currentConfig.connected) {
154-
switch (value) {
155-
case CloudServiceStatus.connectionError:
156-
IToast.show(S.current.cloudConnectionError);
157-
break;
158-
case CloudServiceStatus.unauthorized:
159-
IToast.show(S.current.cloudOauthFailed);
160-
break;
161-
default:
162-
IToast.show(S.current.cloudUnknownError);
163-
break;
164-
}
149+
await currentService.checkServer().then((value) async {
150+
if (!value) {
151+
IToast.show(
152+
S.current.cloudOAuthUnavailable(CloudService.serverEndpoint));
165153
} else {
166-
_boxCloudServiceConfig!.configured = true;
167-
updateConfig(_boxCloudServiceConfig!);
168-
if (showSuccessToast) IToast.show(S.current.cloudAuthSuccess);
154+
await currentService.authenticate().then((value) async {
155+
setState(() {
156+
currentConfig.connected = (value == CloudServiceStatus.success);
157+
});
158+
if (!currentConfig.connected) {
159+
switch (value) {
160+
case CloudServiceStatus.connectionError:
161+
IToast.show(S.current.cloudConnectionError);
162+
break;
163+
case CloudServiceStatus.unauthorized:
164+
IToast.show(S.current.cloudOauthFailed);
165+
break;
166+
default:
167+
IToast.show(S.current.cloudUnknownError);
168+
break;
169+
}
170+
} else {
171+
_boxCloudServiceConfig!.configured = true;
172+
updateConfig(_boxCloudServiceConfig!);
173+
if (showSuccessToast) IToast.show(S.current.cloudAuthSuccess);
174+
}
175+
});
169176
}
170177
});
171178
if (showLoading) CustomLoadingDialog.dismissLoading();
@@ -189,7 +196,8 @@ class _BoxServiceScreenState extends State<BoxServiceScreen>
189196
padding: const EdgeInsets.symmetric(horizontal: 6),
190197
child: CheckboxItem(
191198
title: S.current.enable + S.current.cloudTypeBox,
192-
description: S.current.cloudTypeBoxTip,
199+
description: S.current.cloudOAuthSafeTip(
200+
S.current.cloudTypeBox, CloudService.serverEndpoint),
193201
value: _boxCloudServiceConfig?.enabled ?? false,
194202
onTap: () {
195203
setState(() {
@@ -235,7 +243,7 @@ class _BoxServiceScreenState extends State<BoxServiceScreen>
235243
padding: const EdgeInsets.symmetric(horizontal: 16),
236244
child: RoundIconTextButton(
237245
text: S.current.cloudSignin,
238-
background: Theme.of(context).primaryColor,
246+
background: ChewieTheme.primaryColor,
239247
fontSizeDelta: 2,
240248
onPressed: () async {
241249
try {
@@ -258,7 +266,7 @@ class _BoxServiceScreenState extends State<BoxServiceScreen>
258266
child: RoundIconTextButton(
259267
text: S.current.cloudPullBackup,
260268
padding: const EdgeInsets.symmetric(vertical: 12),
261-
color: Theme.of(context).primaryColor,
269+
color: ChewieTheme.primaryColor,
262270
fontSizeDelta: 2,
263271
onPressed: () async {
264272
CustomLoadingDialog.showLoading(title: S.current.cloudPulling);
@@ -312,7 +320,7 @@ class _BoxServiceScreenState extends State<BoxServiceScreen>
312320
Expanded(
313321
child: RoundIconTextButton(
314322
padding: const EdgeInsets.symmetric(horizontal: 12),
315-
background: Theme.of(context).primaryColor,
323+
background: ChewieTheme.primaryColor,
316324
text: S.current.cloudPushBackup,
317325
fontSizeDelta: 2,
318326
onPressed: () async {

lib/Screens/Backup/cloud_service_screen.dart

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,20 @@ import 'package:cloudotp/Screens/Backup/s3_service_screen.dart';
2525
import 'package:cloudotp/Screens/Backup/webdav_service_screen.dart';
2626
import 'package:flutter/material.dart';
2727
import 'package:group_button/group_button.dart';
28+
import 'package:lucide_icons/lucide_icons.dart';
2829

30+
import '../../TokenUtils/Cloud/cloud_service.dart';
2931
import '../../generated/l10n.dart';
3032
import '../Setting/base_setting_screen.dart';
3133

3234
class CloudServiceScreen extends BaseSettingScreen {
3335
const CloudServiceScreen({
3436
super.key,
37+
this.showBack = true,
3538
});
3639

40+
final bool showBack;
41+
3742
static const String routeName = "/service/cloud";
3843

3944
@override
@@ -63,7 +68,8 @@ class _CloudServiceScreenState extends State<CloudServiceScreen>
6368
padding: widget.padding,
6469
showTitleBar: widget.showTitleBar,
6570
title: S.current.cloudBackupServiceSetting,
66-
showBack: true,
71+
showBack: widget.showBack,
72+
titleLeftMargin: widget.showBack ? 5 : 15,
6773
onTapBack: () {
6874
if (ResponsiveUtil.isLandscape()) {
6975
chewieProvider.dialogNavigatorState?.popPage();
@@ -72,6 +78,41 @@ class _CloudServiceScreenState extends State<CloudServiceScreen>
7278
}
7379
},
7480
overrideBody: _buildBody(),
81+
desktopActions: [
82+
ToolButton(
83+
context: context,
84+
icon: LucideIcons.info,
85+
buttonSize: const Size(32, 32),
86+
onPressed: _showServerInfo,
87+
tooltipPosition: TooltipPosition.bottom,
88+
tooltip: S.current.cloudOAuthDialogTitle,
89+
),
90+
],
91+
actions: [
92+
CircleIconButton(
93+
icon: Icon(
94+
LucideIcons.info,
95+
color: ChewieTheme.iconColor,
96+
),
97+
onTap: _showServerInfo,
98+
),
99+
],
100+
);
101+
}
102+
103+
_showServerInfo() {
104+
DialogBuilder.showConfirmDialog(
105+
context,
106+
title: S.current.cloudOAuthDialogTitle,
107+
message: S.current.cloudOAuthDialogMessage(CloudService.serverEndpoint,
108+
CloudService.serverGithubUrl, CloudService.serverGithubRepoName),
109+
renderHtml: true,
110+
cancelButtonText: S.current.cloudOAuthDialogGoToRepo,
111+
confirmButtonText: S.current.cloudOAuthDialogConfirm,
112+
onTapConfirm: () {},
113+
onTapCancel: () {
114+
UriUtil.openExternal(CloudService.serverGithubUrl);
115+
},
75116
);
76117
}
77118

lib/Screens/Backup/dropbox_service_screen.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class _DropboxServiceScreenState extends State<DropboxServiceScreen>
236236
padding: const EdgeInsets.symmetric(horizontal: 16),
237237
child: RoundIconTextButton(
238238
text: S.current.cloudSignin,
239-
background: Theme.of(context).primaryColor,
239+
background: ChewieTheme.primaryColor,
240240
fontSizeDelta: 2,
241241
onPressed: () async {
242242
try {
@@ -259,7 +259,7 @@ class _DropboxServiceScreenState extends State<DropboxServiceScreen>
259259
child: RoundIconTextButton(
260260
text: S.current.cloudPullBackup,
261261
padding: const EdgeInsets.symmetric(vertical: 12),
262-
color: Theme.of(context).primaryColor,
262+
color: ChewieTheme.primaryColor,
263263
fontSizeDelta: 2,
264264
onPressed: () async {
265265
CustomLoadingDialog.showLoading(title: S.current.cloudPulling);
@@ -314,7 +314,7 @@ class _DropboxServiceScreenState extends State<DropboxServiceScreen>
314314
Expanded(
315315
child: RoundIconTextButton(
316316
padding: const EdgeInsets.symmetric(horizontal: 12),
317-
background: Theme.of(context).primaryColor,
317+
background: ChewieTheme.primaryColor,
318318
text: S.current.cloudPushBackup,
319319
fontSizeDelta: 2,
320320
onPressed: () async {

lib/Screens/Backup/googledrive_service_screen.dart

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import 'dart:typed_data';
1717

18+
import 'package:awesome_chewie/awesome_chewie.dart';
19+
import 'package:awesome_cloud/awesome_cloud.dart';
1820
import 'package:cloudotp/Models/cloud_service_config.dart';
1921
import 'package:cloudotp/TokenUtils/Cloud/cloud_service.dart';
2022
import 'package:flutter/material.dart';
@@ -23,8 +25,6 @@ import '../../Database/cloud_service_config_dao.dart';
2325
import '../../TokenUtils/Cloud/googledrive_cloud_service.dart';
2426
import '../../TokenUtils/export_token_util.dart';
2527
import '../../TokenUtils/import_token_util.dart';
26-
import 'package:awesome_cloud/awesome_cloud.dart';
27-
import 'package:awesome_chewie/awesome_chewie.dart';
2828
import '../../Widgets/BottomSheet/Backups/googledrive_backups_bottom_sheet.dart';
2929
import '../../generated/l10n.dart';
3030

@@ -131,26 +131,32 @@ class _GoogleDriveServiceScreenState extends State<GoogleDriveServiceScreen>
131131
if (showLoading) {
132132
CustomLoadingDialog.showLoading(title: S.current.cloudConnecting);
133133
}
134-
await currentService.authenticate().then((value) async {
135-
setState(() {
136-
currentConfig.connected = value == CloudServiceStatus.success;
137-
});
138-
if (!currentConfig.connected) {
139-
switch (value) {
140-
case CloudServiceStatus.connectionError:
141-
IToast.show(S.current.cloudConnectionError);
142-
break;
143-
case CloudServiceStatus.unauthorized:
144-
IToast.show(S.current.cloudOauthFailed);
145-
break;
146-
default:
147-
IToast.show(S.current.cloudUnknownError);
148-
break;
149-
}
134+
await currentService.checkServer().then((value) async {
135+
if (!value) {
136+
IToast.show(S.current.cloudOAuthUnavailable(CloudService.serverEndpoint));
150137
} else {
151-
_googledriveCloudServiceConfig!.configured = true;
152-
updateConfig(_googledriveCloudServiceConfig!);
153-
if (showSuccessToast) IToast.show(S.current.cloudAuthSuccess);
138+
await currentService.authenticate().then((value) async {
139+
setState(() {
140+
currentConfig.connected = value == CloudServiceStatus.success;
141+
});
142+
if (!currentConfig.connected) {
143+
switch (value) {
144+
case CloudServiceStatus.connectionError:
145+
IToast.show(S.current.cloudConnectionError);
146+
break;
147+
case CloudServiceStatus.unauthorized:
148+
IToast.show(S.current.cloudOauthFailed);
149+
break;
150+
default:
151+
IToast.show(S.current.cloudUnknownError);
152+
break;
153+
}
154+
} else {
155+
_googledriveCloudServiceConfig!.configured = true;
156+
updateConfig(_googledriveCloudServiceConfig!);
157+
if (showSuccessToast) IToast.show(S.current.cloudAuthSuccess);
158+
}
159+
});
154160
}
155161
});
156162
if (showLoading) CustomLoadingDialog.dismissLoading();
@@ -174,7 +180,8 @@ class _GoogleDriveServiceScreenState extends State<GoogleDriveServiceScreen>
174180
padding: const EdgeInsets.symmetric(horizontal: 6),
175181
child: CheckboxItem(
176182
title: S.current.enable + S.current.cloudTypeGoogleDrive,
177-
description: S.current.cloudTypeGoogleDriveTip,
183+
description: S.current.cloudOAuthSafeTip(
184+
S.current.cloudTypeGoogleDrive, CloudService.serverEndpoint),
178185
value: _googledriveCloudServiceConfig?.enabled ?? false,
179186
onTap: () {
180187
setState(() {
@@ -222,7 +229,7 @@ class _GoogleDriveServiceScreenState extends State<GoogleDriveServiceScreen>
222229
padding: const EdgeInsets.symmetric(horizontal: 16),
223230
child: RoundIconTextButton(
224231
text: S.current.cloudSignin,
225-
background: Theme.of(context).primaryColor,
232+
background: ChewieTheme.primaryColor,
226233
fontSizeDelta: 2,
227234
onPressed: () async {
228235
try {
@@ -245,7 +252,7 @@ class _GoogleDriveServiceScreenState extends State<GoogleDriveServiceScreen>
245252
child: RoundIconTextButton(
246253
text: S.current.cloudPullBackup,
247254
padding: const EdgeInsets.symmetric(vertical: 12),
248-
color: Theme.of(context).primaryColor,
255+
color: ChewieTheme.primaryColor,
249256
fontSizeDelta: 2,
250257
onPressed: () async {
251258
CustomLoadingDialog.showLoading(title: S.current.cloudPulling);
@@ -300,7 +307,7 @@ class _GoogleDriveServiceScreenState extends State<GoogleDriveServiceScreen>
300307
Expanded(
301308
child: RoundIconTextButton(
302309
padding: const EdgeInsets.symmetric(horizontal: 12),
303-
background: Theme.of(context).primaryColor,
310+
background: ChewieTheme.primaryColor,
304311
text: S.current.cloudPushBackup,
305312
fontSizeDelta: 2,
306313
onPressed: () async {

0 commit comments

Comments
 (0)