Skip to content

Commit

Permalink
wip: Migrate apiClient to biyi_api_client package
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed Jun 22, 2024
1 parent 9935223 commit cd68210
Show file tree
Hide file tree
Showing 67 changed files with 488 additions and 453 deletions.
2 changes: 1 addition & 1 deletion apps/biyi_app/lib/app/available_ocr_engines/page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/generated/locale_keys.g.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/states/settings.dart';
import 'package:biyi_app/widgets/customized_app_bar/customized_app_bar.dart';
import 'package:biyi_app/widgets/widgets.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/generated/locale_keys.g.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/states/settings.dart';
import 'package:biyi_app/widgets/customized_app_bar/customized_app_bar.dart';
import 'package:biyi_app/widgets/widgets.dart';
Expand Down
3 changes: 1 addition & 2 deletions apps/biyi_app/lib/app/home/desktop_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/app/home/limited_functionality_banner.dart';
import 'package:biyi_app/app/home/new_version_found_banner.dart';
import 'package:biyi_app/app/home/toolbar_item_always_on_top.dart';
Expand All @@ -15,6 +14,7 @@ import 'package:biyi_app/app/home/translation_results_view.dart';
import 'package:biyi_app/app/home/translation_target_select_view.dart';
import 'package:biyi_app/generated/locale_keys.g.dart';
import 'package:biyi_app/models/models.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/services/services.dart';
import 'package:biyi_app/states/settings.dart';
import 'package:biyi_app/utils/utils.dart';
Expand Down Expand Up @@ -904,7 +904,6 @@ class _DesktopPopupPageState extends State<DesktopPopupPage>
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((_) => _windowResize());
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
appBar: _buildAppBar(context),
body: _buildBody(context),
);
Expand Down
2 changes: 1 addition & 1 deletion apps/biyi_app/lib/app/home/new_version_found_banner.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/generated/locale_keys.g.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/utils/utils.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/gestures.dart';
Expand Down
2 changes: 1 addition & 1 deletion apps/biyi_app/lib/app/settings/general/page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:biyi_advanced_features/models/models.dart';
import 'package:biyi_app/app/router_config.dart';
import 'package:biyi_app/generated/locale_keys.g.dart';
import 'package:biyi_app/models/translation_target.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/states/settings.dart';
import 'package:biyi_app/widgets/customized_app_bar/customized_app_bar.dart';
import 'package:biyi_app/widgets/widgets.dart';
Expand Down
2 changes: 1 addition & 1 deletion apps/biyi_app/lib/app/settings/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class _SettingsLayoutState extends State<SettingsLayout> with WindowListener {
Widget _buildSidebar(BuildContext context) {
return Container(
decoration: BoxDecoration(
color: Theme.of(context).scaffoldBackgroundColor,
color: Theme.of(context).colorScheme.surfaceContainerLow,
border: Border(
right: BorderSide(
color: Theme.of(context).dividerColor,
Expand Down
2 changes: 1 addition & 1 deletion apps/biyi_app/lib/app/settings/ocr_engines/new/page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/app/router_config.dart';
import 'package:biyi_app/generated/locale_keys.g.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/services/ocr_client/ocr_client.dart';
import 'package:biyi_app/states/settings.dart';
import 'package:biyi_app/widgets/customized_app_bar/customized_app_bar.dart';
Expand Down
2 changes: 1 addition & 1 deletion apps/biyi_app/lib/app/settings/ocr_engines/page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:biyi_advanced_features/models/models.dart';
import 'package:biyi_app/app/router_config.dart';
import 'package:biyi_app/generated/locale_keys.g.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/states/settings.dart';
import 'package:biyi_app/widgets/customized_app_bar/customized_app_bar.dart';
import 'package:biyi_app/widgets/widgets.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/app/router_config.dart';
import 'package:biyi_app/generated/locale_keys.g.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/services/translate_client/translate_client.dart';
import 'package:biyi_app/states/settings.dart';
import 'package:biyi_app/widgets/customized_app_bar/customized_app_bar.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:biyi_advanced_features/models/models.dart';
import 'package:biyi_app/app/router_config.dart';
import 'package:biyi_app/generated/locale_keys.g.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/states/settings.dart';
import 'package:biyi_app/widgets/customized_app_bar/customized_app_bar.dart';
import 'package:biyi_app/widgets/widgets.dart';
Expand Down
4 changes: 3 additions & 1 deletion apps/biyi_app/lib/models/ext_ocr_engine_config.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/services/api_client.dart' show OcrEngineConfig;
import 'package:easy_localization/easy_localization.dart';

export 'package:biyi_app/services/api_client.dart' show OcrEngineConfig;

extension ExtOcrEngineConfig on OcrEngineConfig {
String get typeName {
String key = 'ocr_engine.$type';
Expand Down
4 changes: 3 additions & 1 deletion apps/biyi_app/lib/models/ext_translation_engine_config.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/services/api_client.dart' show TranslationEngineConfig;
import 'package:easy_localization/easy_localization.dart';

export 'package:biyi_app/services/api_client.dart' show TranslationEngineConfig;

extension ExtTranslationEngineConfig on TranslationEngineConfig {
String get typeName {
String key = 'engine.$type';
Expand Down
3 changes: 1 addition & 2 deletions apps/biyi_app/lib/models/settings_base.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:biyi_advanced_features/models/ocr_engine_config.dart';
import 'package:biyi_advanced_features/models/translation_engine_config.dart';
import 'package:biyi_api_client/biyi_api_client.dart';
import 'package:biyi_app/models/translation_target.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart' show ThemeMode;
Expand Down
4 changes: 4 additions & 0 deletions apps/biyi_app/lib/services/api_client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import 'package:biyi_api_client/biyi_api_client.dart';
export 'package:biyi_api_client/biyi_api_client.dart' hide ApiClient;

ApiClient apiClient = ApiClient();
3 changes: 2 additions & 1 deletion apps/biyi_app/lib/services/local_db/configuration.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';

import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_advanced_features/models/user_preference.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/services/local_db/local_db.dart';
import 'package:biyi_app/utils/language_util.dart';
import 'package:flutter/services.dart';
Expand Down
28 changes: 0 additions & 28 deletions apps/biyi_app/lib/services/local_db/local_db.dart
Original file line number Diff line number Diff line change
@@ -1,59 +1,31 @@
import 'dart:io';

import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/services/local_db/configuration.dart';
import 'package:biyi_app/services/local_db/init_data_if_need.dart';
import 'package:biyi_app/services/local_db/local_db_listener.dart';
import 'package:biyi_app/services/local_db/modifiers/engines_modifier.dart';
import 'package:biyi_app/services/local_db/modifiers/ocr_engines_modifier.dart';
import 'package:biyi_app/services/local_db/modifiers/preferences_modifier.dart';
import 'package:biyi_app/services/local_db/modifiers/translation_targets_modifier.dart';
import 'package:biyi_app/utils/utils.dart';
import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';
import 'package:path/path.dart' as path;
import 'package:uni_platform/uni_platform.dart';

export 'configuration.dart';
export 'local_db_listener.dart';
export 'modifiers/engines_modifier.dart';
export 'modifiers/ocr_engines_modifier.dart';
export 'modifiers/preferences_modifier.dart';
export 'modifiers/translation_targets_modifier.dart';

@Deprecated('Use Settings instead.')
class LocalDb {
User user = User(id: -1);
Configuration configuration = Configuration();

EnginesModifier? _enginesModifier;
OcrEnginesModifier? _ocrEnginesModifier;
PreferencesModifier? _preferencesModifier;
TranslationTargetsModifier? _translationTargetsModifier;

final ObserverList<LocalDbListener> _listeners =
ObserverList<LocalDbListener>();

List<LocalDbListener> get listeners {
final List<LocalDbListener> localListeners =
List<LocalDbListener>.from(_listeners);
return localListeners;
}

bool get hasListeners {
return _listeners.isNotEmpty;
}

@Deprecated('No longer used.')
void addListener(LocalDbListener listener) {
_listeners.add(listener);
}

@Deprecated('No longer used.')
void removeListener(LocalDbListener listener) {
_listeners.remove(listener);
}

@Deprecated('No longer used.')
EnginesModifier get engines {
return engine(null);
Expand Down
6 changes: 0 additions & 6 deletions apps/biyi_app/lib/services/local_db/local_db_listener.dart

This file was deleted.

5 changes: 2 additions & 3 deletions apps/biyi_app/lib/services/local_db/migrate_old_settings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// ignore_for_file: deprecated_member_use_from_same_package, deprecated_member_use
// ignore_for_file: deprecated_member_use_from_same_package

import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/models/settings_base.dart';
import 'package:biyi_app/services/local_db/local_db.dart';

Expand All @@ -14,7 +13,7 @@ Future<SettingsBase> migrateOldSettings(SettingsBase settings) async {
settings.defaultDetectLanguageEngineId = c.defaultEngineId;
settings.translationTargets = localDb.translationTargets.list();
settings.doubleClickCopyResult = c.doubleClickCopyResult;
settings.inputSubmitMode = c.inputSetting == kInputSettingSubmitWithEnter
settings.inputSubmitMode = c.inputSetting == 'submit-with-enter'
? InputSubmitMode.enter
: InputSubmitMode.metaEnter;
settings.themeMode = c.themeMode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:flutter/foundation.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:shortid/shortid.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:flutter/foundation.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:shortid/shortid.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_advanced_features/models/user_preference.dart';
import 'package:flutter/foundation.dart';
import 'package:hive_flutter/hive_flutter.dart';

Expand Down
3 changes: 2 additions & 1 deletion apps/biyi_app/lib/services/ocr_client/ocr_client.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/states/settings.dart';
import 'package:ocr_engine_builtin/ocr_engine_builtin.dart';
import 'package:ocr_engine_youdao/ocr_engine_youdao.dart';
Expand All @@ -20,7 +21,7 @@ OcrEngine? createOcrEngine(
) {
OcrEngine? ocrEngine;
if (Settings.instance.proOcrEngine(ocrEngineConfig.id).exists()) {
ocrEngine = ProOcrEngine(ocrEngineConfig);
ocrEngine = ProOcrEngine(ocrEngineConfig, apiClient: apiClient);
if (ocrEngineConfig.id == kDefaultBuiltInOcrEngine.identifier) {
ocrEngine = kDefaultBuiltInOcrEngine;
}
Expand Down
8 changes: 4 additions & 4 deletions apps/biyi_app/lib/services/services.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export './local_db/local_db.dart';
export './ocr_client/ocr_client.dart';
export './shortcut_service/shortcut_service.dart';
export './translate_client/translate_client.dart';
export 'local_db/local_db.dart';
export 'ocr_client/ocr_client.dart';
export 'shortcut_service/shortcut_service.dart';
export 'translate_client/translate_client.dart';
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/states/settings.dart';
import 'package:translation_engine_baidu/translation_engine_baidu.dart';
import 'package:translation_engine_caiyun/translation_engine_caiyun.dart';
Expand Down Expand Up @@ -36,7 +37,7 @@ TranslationEngine? createTranslationEngine(
TranslationEngineConfig engineConfig,
) {
if (Settings.instance.proTranslationEngine(engineConfig.id).exists()) {
return ProTranslationEngine(engineConfig);
return ProTranslationEngine(engineConfig, apiClient: apiClient);
} else {
switch (engineConfig.type) {
case kEngineTypeBaidu:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:biyi_advanced_features/models/ocr_engine_config.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/states/settings.dart';
import 'package:collection/collection.dart';
import 'package:shortid/shortid.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/states/settings.dart';
import 'package:collection/collection.dart';
import 'package:shortid/shortid.dart';
Expand Down
5 changes: 2 additions & 3 deletions apps/biyi_app/lib/states/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:biyi_advanced_features/models/ocr_engine_config.dart';
import 'package:biyi_advanced_features/models/translation_engine_config.dart';
import 'package:biyi_advanced_features/networking/api_client/api_client.dart';
import 'package:biyi_app/models/settings_base.dart';
import 'package:biyi_app/models/translation_target.dart';
import 'package:biyi_app/services/api_client.dart';
import 'package:biyi_app/services/local_db/migrate_old_settings.dart';
import 'package:biyi_app/services/ocr_client/ocr_client.dart';
import 'package:biyi_app/states/modifiers/ocr_engines_modifier.dart';
Expand Down Expand Up @@ -140,6 +138,7 @@ class Settings extends SettingsBase with ChangeNotifier {
.firstWhere((e) => e.type == 'built_in' || e.type == 'tesseract')
.id;
}
await _writeToLocalFile();
}

Locale get locale => languageToLocale(displayLanguage ?? 'en');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class CustomizedAppBar extends StatelessWidget implements PreferredSizeWidget {
right: 16,
),
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainerLow,
border: Border(
bottom: BorderSide(
color: Theme.of(context).dividerColor,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/models/ext_ocr_engine_config.dart';
import 'package:influxui/influxui.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/models/ext_translation_engine_config.dart';
import 'package:influxui/influxui.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:biyi_advanced_features/biyi_advanced_features.dart';
import 'package:biyi_app/models/ext_translation_engine_config.dart';
import 'package:biyi_app/models/translation_result_record.dart';
import 'package:biyi_app/states/settings.dart';
Expand Down
23 changes: 17 additions & 6 deletions apps/biyi_app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ packages:
relative: true
source: path
version: "0.1.0"
biyi_api_client:
dependency: "direct main"
description:
path: "../../packages/biyi_api_client"
relative: true
source: path
version: "0.1.0"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -527,9 +534,11 @@ packages:
influxui:
dependency: "direct main"
description:
path: "../../../../leanflutter/influxui/packages/influxui"
relative: true
source: path
path: "packages/influxui"
ref: HEAD
resolved-ref: "30ea962d4d58e0a43dfed7dd02171cd57e2c5d0a"
url: "https://github.com/leanflutter/influxui.git"
source: git
version: "0.0.1"
intl:
dependency: transitive
Expand Down Expand Up @@ -822,9 +831,11 @@ packages:
preference_list:
dependency: "direct main"
description:
path: "../../../../leanflutter/influxui/packages/preference_list"
relative: true
source: path
path: "packages/preference_list"
ref: HEAD
resolved-ref: "30ea962d4d58e0a43dfed7dd02171cd57e2c5d0a"
url: "https://github.com/leanflutter/influxui.git"
source: git
version: "0.0.2"
protocol_handler:
dependency: "direct main"
Expand Down
2 changes: 2 additions & 0 deletions apps/biyi_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ dependencies:
audioplayers: ^5.2.1
biyi_advanced_features:
path: ../../packages/biyi_advanced_features
biyi_api_client:
path: ../../packages/biyi_api_client
bot_toast: ^4.1.3
collection: ^1.18.0
easy_localization: ^3.0.3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library biyi_advanced_features;

export './models/models.dart';
export './networking/networking.dart';
export 'src/pro_ocr_engine.dart';
export 'src/pro_translation_engine.dart';
6 changes: 0 additions & 6 deletions packages/biyi_advanced_features/lib/models/models.dart

This file was deleted.

Loading

0 comments on commit cd68210

Please sign in to comment.