Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/account/account_key_value.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class AccountKeyValue extends HiveKeyValue {
static const _primarySessionId = 'primarySessionId';
static const _hasNewAlbum = 'hasNewAlbum';
static const _keyRecentUsedEmoji = 'recentUsedEmoji';
static const _deviceId = 'deviceId';

String? get deviceId => box.get(_deviceId) as String?;

Future<void> setDeviceId(String value) => box.put(_deviceId, value);

bool get hasSyncCircle =>
box.get(_hasSyncCircle, defaultValue: false) as bool;
Expand Down
30 changes: 30 additions & 0 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';
import 'package:tuple/tuple.dart';

import 'account/account_key_value.dart';
import 'account/account_server.dart';
import 'account/notification_service.dart';
import 'bloc/bloc_converter.dart';
Expand All @@ -29,6 +30,7 @@ import 'ui/landing/landing.dart';
import 'utils/extension/extension.dart';
import 'utils/hook.dart';
import 'utils/logger.dart';
import 'utils/platform.dart';
import 'utils/system/system_fonts.dart';
import 'utils/system/text_input.dart';
import 'utils/system/tray.dart';
Expand Down Expand Up @@ -263,6 +265,34 @@ class _Home extends HookWidget {
}
}, [signed]);

useEffect(() {
Future<void> effect() async {
if (!signed || accountServer == null) return;

try {
final currentDeviceId = await getDeviceId();
if (currentDeviceId == 'unknown') return;

final deviceId = AccountKeyValue.instance.deviceId;

if (deviceId == null) {
await AccountKeyValue.instance.setDeviceId(currentDeviceId);
return;
}

if (deviceId != currentDeviceId) {
final multiAuthCubit = context.multiAuthCubit;
await accountServer.signOutAndClear();
multiAuthCubit.signOut();
}
} catch (e) {
w('checkDeviceId error: $e');
}
}

effect();
}, [signed]);

if (signed) {
BlocProvider.of<ConversationListBloc>(context)
..limit = MediaQuery.of(context).size.height ~/
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/setting/appearance_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class _ChatTextSizePreview extends HookWidget {
const EdgeInsets.only(left: 20, right: 20, top: 10, bottom: 20),
decoration: BoxDecoration(
color: context.theme.chatBackground,
borderRadius: BorderRadius.circular(8),
borderRadius: const BorderRadius.all(Radius.circular(8)),
image: DecorationImage(
image: const ExactAssetImage(
Resources.assetsImagesChatBackgroundPng,
Expand Down
42 changes: 8 additions & 34 deletions lib/utils/platform.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:convert';
import 'dart:io';

import 'package:android_id/android_id.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:platform_device_id/platform_device_id.dart';
import 'package:ui_device/ui_device.dart' as ui_device;

import '../crypto/uuid/uuid.dart';
Expand Down Expand Up @@ -45,41 +45,15 @@ Future<String> getPlatformVersion() async {

Future<String> getDeviceId() async {
try {
final deviceInfo = DeviceInfoPlugin();
if (Platform.isIOS) {
final iosInfo = await deviceInfo.iosInfo;
final id = iosInfo.identifierForVendor;
if (id != null) {
return id;
}
e('failed to get iOS device id');
}
if (Platform.isAndroid) {
final id = await const AndroidId().getId();
if (id != null) {
return nameUuidFromBytes(utf8.encode(id)).uuid;
}
e('failed to get Android device id');
}
if (Platform.isMacOS) {
final macOsInfo = await deviceInfo.macOsInfo;
final id = macOsInfo.systemGUID;
if (id != null) {
return nameUuidFromBytes(utf8.encode(id)).uuid;
}
e('failed to get MacOS device id');
final id = (await PlatformDeviceId.getDeviceId)?.trim();
if (id == null || id.isEmpty) {
throw Exception("${Platform.operatingSystem}'s device id is empty");
}
if (Platform.isLinux) {
final linuxInfo = await deviceInfo.linuxInfo;
final id = linuxInfo.machineId;
if (id != null) {
return nameUuidFromBytes(utf8.encode(id)).uuid;
}
e('failed to get Linux device id');
}
if (Platform.isWindows) {
assert(false, 'Windows is not supported');
if (Platform.isAndroid || kIsWeb) {
return nameUuidFromBytes(utf8.encode(id)).uuid;
}

return id;
} catch (error, stack) {
e('failed to get device id. $error $stack');
}
Expand Down
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <file_selector_linux/file_selector_plugin.h>
#include <flutter_app_icon_badge/flutter_app_icon_badge_plugin.h>
#include <pasteboard/pasteboard_plugin.h>
#include <platform_device_id_linux/platform_device_id_linux_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
Expand Down Expand Up @@ -41,6 +42,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) pasteboard_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "PasteboardPlugin");
pasteboard_plugin_register_with_registrar(pasteboard_registrar);
g_autoptr(FlPluginRegistrar) platform_device_id_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "PlatformDeviceIdLinuxPlugin");
platform_device_id_linux_plugin_register_with_registrar(platform_device_id_linux_registrar);
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
Expand Down
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
flutter_app_icon_badge
pasteboard
platform_device_id_linux
screen_retriever
sqlite3_flutter_libs
url_launcher_linux
Expand Down
4 changes: 4 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import ogg_opus_player
import package_info_plus
import pasteboard
import path_provider_macos
import platform_device_id
import platform_device_id_macos
import protocol_handler
import screen_retriever
import sqlite3_flutter_libs
Expand All @@ -35,6 +37,8 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
PasteboardPlugin.register(with: registry.registrar(forPlugin: "PasteboardPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
PlatformDeviceIdMacosPlugin.register(with: registry.registrar(forPlugin: "PlatformDeviceIdMacosPlugin"))
PlatformDeviceIdMacosPlugin.register(with: registry.registrar(forPlugin: "PlatformDeviceIdMacosPlugin"))
ProtocolHandlerPlugin.register(with: registry.registrar(forPlugin: "ProtocolHandlerPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
Sqlite3FlutterLibsPlugin.register(with: registry.registrar(forPlugin: "Sqlite3FlutterLibsPlugin"))
Expand Down
12 changes: 12 additions & 0 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ PODS:
- FlutterMacOS
- path_provider_macos (0.0.1):
- FlutterMacOS
- platform_device_id (0.0.1):
- FlutterMacOS
- platform_device_id_macos (0.0.1):
- FlutterMacOS
- protocol_handler (0.0.1):
- FlutterMacOS
- screen_retriever (0.0.1):
Expand Down Expand Up @@ -61,6 +65,8 @@ DEPENDENCIES:
- package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`)
- pasteboard (from `Flutter/ephemeral/.symlinks/plugins/pasteboard/macos`)
- path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)
- platform_device_id (from `Flutter/ephemeral/.symlinks/plugins/platform_device_id/macos`)
- platform_device_id_macos (from `Flutter/ephemeral/.symlinks/plugins/platform_device_id_macos/macos`)
- protocol_handler (from `Flutter/ephemeral/.symlinks/plugins/protocol_handler/macos`)
- screen_retriever (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever/macos`)
- sqlite3_flutter_libs (from `Flutter/ephemeral/.symlinks/plugins/sqlite3_flutter_libs/macos`)
Expand Down Expand Up @@ -97,6 +103,10 @@ EXTERNAL SOURCES:
:path: Flutter/ephemeral/.symlinks/plugins/pasteboard/macos
path_provider_macos:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos
platform_device_id:
:path: Flutter/ephemeral/.symlinks/plugins/platform_device_id/macos
platform_device_id_macos:
:path: Flutter/ephemeral/.symlinks/plugins/platform_device_id_macos/macos
protocol_handler:
:path: Flutter/ephemeral/.symlinks/plugins/protocol_handler/macos
screen_retriever:
Expand All @@ -123,6 +133,8 @@ SPEC CHECKSUMS:
package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce
pasteboard: 9b69dba6fedbb04866be632205d532fe2f6b1d99
path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19
platform_device_id: 3e414428f45df149bbbfb623e2c0ca27c545b763
platform_device_id_macos: f763bb55f088be804d61b96eb4710b8ab6598e94
protocol_handler: 587e1caf6c0b92ce351ab14081968dae49cb8cc6
screen_retriever: 59634572a57080243dd1bf715e55b6c54f241a38
sqlite3: 88dd99ef4ac3945f5a15facdd752933c52fd93bf
Expand Down
4 changes: 4 additions & 0 deletions macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@
"${BUILT_PRODUCTS_DIR}/package_info_plus/package_info_plus.framework",
"${BUILT_PRODUCTS_DIR}/pasteboard/pasteboard.framework",
"${BUILT_PRODUCTS_DIR}/path_provider_macos/path_provider_macos.framework",
"${BUILT_PRODUCTS_DIR}/platform_device_id/platform_device_id.framework",
"${BUILT_PRODUCTS_DIR}/platform_device_id_macos/platform_device_id_macos.framework",
"${BUILT_PRODUCTS_DIR}/protocol_handler/protocol_handler.framework",
"${BUILT_PRODUCTS_DIR}/screen_retriever/screen_retriever.framework",
"${BUILT_PRODUCTS_DIR}/sqlite3/sqlite3.framework",
Expand All @@ -361,6 +363,8 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/package_info_plus.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/pasteboard.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/path_provider_macos.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/platform_device_id.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/platform_device_id_macos.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/protocol_handler.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/screen_retriever.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sqlite3.framework",
Expand Down
64 changes: 64 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.1.6"
device_info:
dependency: transitive
description:
name: device_info
sha256: f4a8156cb7b7480d969cb734907d18b333c8f0bc0b1ad0b342cdcecf30d62c48
url: "https://pub.dev"
source: hosted
version: "2.0.3"
device_info_platform_interface:
dependency: transitive
description:
name: device_info_platform_interface
sha256: b148e0bf9640145d09a4f8dea96614076f889e7f7f8b5ecab1c7e5c2dbc73c1b
url: "https://pub.dev"
source: hosted
version: "2.0.1"
device_info_plus:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1194,6 +1210,54 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.1.0"
platform_device_id:
dependency: "direct main"
description:
name: platform_device_id
sha256: "7a12ec84de4a823bb10eba2f0e1ad29e2365abba17790489a0d78029904f562e"
url: "https://pub.dev"
source: hosted
version: "1.0.1"
platform_device_id_linux:
dependency: transitive
description:
name: platform_device_id_linux
sha256: "994b1608593e527a629af2d5aeb241c60d308d3434bc78b0f6fcb3c1a02dff43"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
platform_device_id_macos:
dependency: transitive
description:
name: platform_device_id_macos
sha256: "968db2a504c611294b12a031b3734432d6df10553a0d3ae3b33ed21abfdbaba0"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
platform_device_id_platform_interface:
dependency: transitive
description:
name: platform_device_id_platform_interface
sha256: c61607594252aaddacf3e4c4371ab08f2ef85ff427817fa6e48a169429610c46
url: "https://pub.dev"
source: hosted
version: "1.0.0"
platform_device_id_web:
dependency: transitive
description:
name: platform_device_id_web
sha256: "58e124594e1165db7f108395a780b1d1e1cd403021978e5228cf4289fbe736d5"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
platform_device_id_windows:
dependency: transitive
description:
name: platform_device_id_windows
sha256: dbf8dcf03ad8555320ebae2403a3081b79f137f37661874e161fe2de0a84eeeb
url: "https://pub.dev"
source: hosted
version: "1.0.0"
plugin_platform_interface:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ dependencies:
url: https://github.com/fireslime/photo_view.git
ref: 52685ab7beaf8a9107904bdb8a1590924015d016
pin_code_fields: ^7.4.0
platform_device_id: ^1.0.1
protocol_handler: ^0.1.4
provider: ^6.0.4
qr_flutter: ^4.0.0
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <file_selector_windows/file_selector_windows.h>
#include <flutter_app_icon_badge/flutter_app_icon_badge_plugin.h>
#include <pasteboard/pasteboard_plugin.h>
#include <platform_device_id_windows/platform_device_id_windows_plugin.h>
#include <protocol_handler/protocol_handler_plugin.h>
#include <quick_breakpad/quick_breakpad_plugin.h>
#include <screen_retriever/screen_retriever_plugin.h>
Expand All @@ -35,6 +36,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("FlutterAppIconBadgePlugin"));
PasteboardPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PasteboardPlugin"));
PlatformDeviceIdWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PlatformDeviceIdWindowsPlugin"));
ProtocolHandlerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ProtocolHandlerPlugin"));
QuickBreakpadPluginRegisterWithRegistrar(
Expand Down
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
file_selector_windows
flutter_app_icon_badge
pasteboard
platform_device_id_windows
protocol_handler
quick_breakpad
screen_retriever
Expand Down