Skip to content

Commit

Permalink
feat: Screen lock (#1276)
Browse files Browse the repository at this point in the history
* Feat: Screen lock

* update

* update

* l10n

* update

* update

* update

* update
  • Loading branch information
YeungKC authored Jul 6, 2023
1 parent d660a8c commit 544328f
Show file tree
Hide file tree
Showing 38 changed files with 690 additions and 23 deletions.
8 changes: 8 additions & 0 deletions assets/images/lock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/images/proxy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions assets/images/shield.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions lib/account/security_key_value.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import 'package:rxdart/rxdart.dart';

import '../utils/hive_key_values.dart';

class SecurityKeyValue extends HiveKeyValue {
SecurityKeyValue._() : super(_hiveSecurity);

static SecurityKeyValue? _instance;

static SecurityKeyValue get instance => _instance ??= SecurityKeyValue._();

static const _hiveSecurity = 'security_box';
static const _passcode = 'passcode';
static const _biometric = 'biometric';

String? get passcode => box.get(_passcode) as String?;

set passcode(String? value) {
if (value != null && value.length != 6) {
throw ArgumentError('Passcode must be 6 digits');
}
box.put(_passcode, value);
}

bool get biometric => box.get(_biometric, defaultValue: false) as bool;

set biometric(bool value) => box.put(_biometric, value);

bool get hasPasscode => passcode != null;

Stream<bool> watchHasPasscode() => box
.watch(key: _passcode)
.map((event) => event.value != null)
.startWith(passcode != null);

Stream<bool> watchBiometric() =>
box.watch(key: _biometric).map((event) => (event.value ?? false) as bool);
}
5 changes: 4 additions & 1 deletion lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import 'utils/platform.dart';
import 'utils/system/system_fonts.dart';
import 'utils/system/text_input.dart';
import 'utils/system/tray.dart';
import 'widgets/auth.dart';
import 'widgets/brightness_observer.dart';
import 'widgets/focus_helper.dart';
import 'widgets/message/item/text/mention_builder.dart';
Expand Down Expand Up @@ -243,7 +244,9 @@ class _App extends StatelessWidget {
),
child: SystemTrayWidget(
child: TextInputActionHandler(
child: child!,
child: AuthGuard(
child: child!,
),
),
),
),
Expand Down
9 changes: 9 additions & 0 deletions lib/constants/resources.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ class MessageLookup extends MessageLookupByLibrary {
"combineAndForward":
MessageLookupByLibrary.simpleMessage("Combine and forward"),
"confirm": MessageLookupByLibrary.simpleMessage("Confirm"),
"confirmPasscodeDesc": MessageLookupByLibrary.simpleMessage(
"Enter again to confirm the passcode"),
"confirmSyncChatsFromPhone": MessageLookupByLibrary.simpleMessage(
"Are you sure to sync the chat history from the phone?"),
"confirmSyncChatsToPhone": MessageLookupByLibrary.simpleMessage(
Expand Down Expand Up @@ -487,6 +489,7 @@ class MessageLookup extends MessageLookupByLibrary {
"System time is unusual, please continue to use again after correction"),
"locateToChat": MessageLookupByLibrary.simpleMessage("locate to chat"),
"location": MessageLookupByLibrary.simpleMessage("Location"),
"lock": MessageLookupByLibrary.simpleMessage("Lock"),
"logIn": MessageLookupByLibrary.simpleMessage("Log in"),
"loginAndAbortAccountDeletion": MessageLookupByLibrary.simpleMessage(
"Continue to log in and abort account deletion"),
Expand Down Expand Up @@ -563,6 +566,8 @@ class MessageLookup extends MessageLookupByLibrary {
"originalImage": MessageLookupByLibrary.simpleMessage("Original"),
"owner": MessageLookupByLibrary.simpleMessage("Owner"),
"participantsCount": m35,
"passcodeIncorrect":
MessageLookupByLibrary.simpleMessage("Passcode incorrect"),
"password": MessageLookupByLibrary.simpleMessage("Password"),
"pendingConfirmation": m36,
"phoneNumber": MessageLookupByLibrary.simpleMessage("Phone Number"),
Expand Down Expand Up @@ -620,6 +625,8 @@ class MessageLookup extends MessageLookupByLibrary {
"sayHi": MessageLookupByLibrary.simpleMessage("Say Hi"),
"scamWarning": MessageLookupByLibrary.simpleMessage(
"Warning: Many users reported this account as a scam. Please be careful, especially if it asks you for money"),
"screenPasscode":
MessageLookupByLibrary.simpleMessage("Screen Passcode"),
"search": MessageLookupByLibrary.simpleMessage("Search"),
"searchContact": MessageLookupByLibrary.simpleMessage("Search contact"),
"searchConversation":
Expand All @@ -632,6 +639,7 @@ class MessageLookup extends MessageLookupByLibrary {
"searchUnread": MessageLookupByLibrary.simpleMessage("Search Unread"),
"secretUrl": MessageLookupByLibrary.simpleMessage(
"https://mixin.one/pages/1000007"),
"security": MessageLookupByLibrary.simpleMessage("Security"),
"select": MessageLookupByLibrary.simpleMessage("Select"),
"send": MessageLookupByLibrary.simpleMessage("Send"),
"sendArchived": MessageLookupByLibrary.simpleMessage(
Expand All @@ -645,6 +653,8 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Send Without Sound"),
"set": MessageLookupByLibrary.simpleMessage("Set"),
"setDisappearingMessageTimeTo": m40,
"setPasscodeDesc": MessageLookupByLibrary.simpleMessage(
"Set Passcode to unlock Mixin Messenger"),
"settingAuthSearchHint":
MessageLookupByLibrary.simpleMessage("Mixin ID, Name"),
"settingBackupTips": MessageLookupByLibrary.simpleMessage(
Expand Down Expand Up @@ -729,6 +739,8 @@ class MessageLookup extends MessageLookupByLibrary {
"unitSecond": m48,
"unitWeek": m49,
"unknowError": MessageLookupByLibrary.simpleMessage("Unknow error"),
"unlockWithWasscode": MessageLookupByLibrary.simpleMessage(
"Enter Passcode to unlock Mixin Messenger"),
"unmute": MessageLookupByLibrary.simpleMessage("Unmute"),
"unpin": MessageLookupByLibrary.simpleMessage("Unpin"),
"unpinAllMessages":
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_es.dart
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ class MessageLookup extends MessageLookupByLibrary {
"searchUnread": MessageLookupByLibrary.simpleMessage("Buscar no leído"),
"secretUrl": MessageLookupByLibrary.simpleMessage(
"https://mixin.one/pages/1000007"),
"security": MessageLookupByLibrary.simpleMessage("Seguridad"),
"select": MessageLookupByLibrary.simpleMessage("Seleccionar"),
"send": MessageLookupByLibrary.simpleMessage("Enviar"),
"sendArchived": MessageLookupByLibrary.simpleMessage(
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_in.dart
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ class MessageLookup extends MessageLookupByLibrary {
"searchRelatedMessage": m39,
"secretUrl": MessageLookupByLibrary.simpleMessage(
"https://mixin.one/pages/1000007"),
"security": MessageLookupByLibrary.simpleMessage("Keamanan"),
"select": MessageLookupByLibrary.simpleMessage("Pilih"),
"send": MessageLookupByLibrary.simpleMessage("Kirim"),
"settingAuthSearchHint":
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_ja.dart
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ class MessageLookup extends MessageLookupByLibrary {
"searchRelatedMessage": m39,
"secretUrl": MessageLookupByLibrary.simpleMessage(
"https://mixin.one/pages/1000007"),
"security": MessageLookupByLibrary.simpleMessage("セキュリティ"),
"select": MessageLookupByLibrary.simpleMessage("選択"),
"send": MessageLookupByLibrary.simpleMessage("送る"),
"sendArchived":
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_ms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ class MessageLookup extends MessageLookupByLibrary {
"searchRelatedMessage": m39,
"secretUrl": MessageLookupByLibrary.simpleMessage(
"https://mixin.one/pages/1000007"),
"security": MessageLookupByLibrary.simpleMessage("Keselamatan"),
"select": MessageLookupByLibrary.simpleMessage("Pilih"),
"send": MessageLookupByLibrary.simpleMessage("Hantar"),
"settingAuthSearchHint":
Expand Down
1 change: 1 addition & 0 deletions lib/generated/intl/messages_ru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ class MessageLookup extends MessageLookupByLibrary {
"searchRelatedMessage": m39,
"secretUrl": MessageLookupByLibrary.simpleMessage(
"https://mixin.one/pages/1000007"),
"security": MessageLookupByLibrary.simpleMessage("Безопасность"),
"select": MessageLookupByLibrary.simpleMessage("Выбрать"),
"send": MessageLookupByLibrary.simpleMessage("Отправить"),
"sendArchived": MessageLookupByLibrary.simpleMessage(
Expand Down
8 changes: 8 additions & 0 deletions lib/generated/intl/messages_zh-HK.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class MessageLookup extends MessageLookupByLibrary {
"collapse": MessageLookupByLibrary.simpleMessage("摺疊"),
"combineAndForward": MessageLookupByLibrary.simpleMessage("合併轉發"),
"confirm": MessageLookupByLibrary.simpleMessage("確認"),
"confirmPasscodeDesc": MessageLookupByLibrary.simpleMessage("再次確認密碼"),
"confirmSyncChatsFromPhone":
MessageLookupByLibrary.simpleMessage("確認從手機端同步聊天記錄嗎?"),
"confirmSyncChatsToPhone":
Expand Down Expand Up @@ -428,6 +429,7 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("檢測到系統時間異常,請校正後再繼續使用"),
"locateToChat": MessageLookupByLibrary.simpleMessage("定位到聊天"),
"location": MessageLookupByLibrary.simpleMessage("位置"),
"lock": MessageLookupByLibrary.simpleMessage("鎖定"),
"logIn": MessageLookupByLibrary.simpleMessage("登錄"),
"loginAndAbortAccountDeletion":
MessageLookupByLibrary.simpleMessage("繼續登錄並放棄刪除賬户"),
Expand Down Expand Up @@ -494,6 +496,7 @@ class MessageLookup extends MessageLookupByLibrary {
"originalImage": MessageLookupByLibrary.simpleMessage("原圖"),
"owner": MessageLookupByLibrary.simpleMessage("羣主"),
"participantsCount": m35,
"passcodeIncorrect": MessageLookupByLibrary.simpleMessage("密碼不正確"),
"password": MessageLookupByLibrary.simpleMessage("密碼"),
"pendingConfirmation": m36,
"phoneNumber": MessageLookupByLibrary.simpleMessage("手機號碼"),
Expand Down Expand Up @@ -543,6 +546,7 @@ class MessageLookup extends MessageLookupByLibrary {
"sayHi": MessageLookupByLibrary.simpleMessage("打招呼"),
"scamWarning": MessageLookupByLibrary.simpleMessage(
"警告:此賬號被大量用户舉報,請謹防網絡詐騙,注意個人財產安全"),
"screenPasscode": MessageLookupByLibrary.simpleMessage("鎖屏密碼"),
"search": MessageLookupByLibrary.simpleMessage("搜索"),
"searchContact": MessageLookupByLibrary.simpleMessage("搜索用户"),
"searchConversation": MessageLookupByLibrary.simpleMessage("搜索聊天記錄"),
Expand All @@ -551,6 +555,7 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("搜索 Mixin ID 或手機號碼:"),
"searchRelatedMessage": m39,
"searchUnread": MessageLookupByLibrary.simpleMessage("搜索未讀會話"),
"security": MessageLookupByLibrary.simpleMessage("安全"),
"select": MessageLookupByLibrary.simpleMessage("選擇"),
"send": MessageLookupByLibrary.simpleMessage("發送"),
"sendArchived": MessageLookupByLibrary.simpleMessage("打包成 zip 發送"),
Expand All @@ -561,6 +566,7 @@ class MessageLookup extends MessageLookupByLibrary {
"sendWithoutSound": MessageLookupByLibrary.simpleMessage("靜音發送"),
"set": MessageLookupByLibrary.simpleMessage("設置"),
"setDisappearingMessageTimeTo": m40,
"setPasscodeDesc": MessageLookupByLibrary.simpleMessage("設置解鎖密碼"),
"settingAuthSearchHint":
MessageLookupByLibrary.simpleMessage("Mixin ID, 暱稱"),
"settingBackupTips": MessageLookupByLibrary.simpleMessage(
Expand Down Expand Up @@ -627,6 +633,8 @@ class MessageLookup extends MessageLookupByLibrary {
"unitSecond": m48,
"unitWeek": m49,
"unknowError": MessageLookupByLibrary.simpleMessage("未知錯誤"),
"unlockWithWasscode":
MessageLookupByLibrary.simpleMessage("輸入密碼解鎖 Mixin Messenger"),
"unmute": MessageLookupByLibrary.simpleMessage("取消靜音"),
"unpin": MessageLookupByLibrary.simpleMessage("取消置頂"),
"unpinAllMessages": MessageLookupByLibrary.simpleMessage("取消所有置頂消息"),
Expand Down
Loading

0 comments on commit 544328f

Please sign in to comment.