Skip to content

Commit

Permalink
Upgrade Runtime (#416)
Browse files Browse the repository at this point in the history
* chore: bump runtime

* fix: remove getDeviceInfo

* chore: update config stuff

* chore: update handler

* chore: remove unused lib
  • Loading branch information
jkoenig134 authored Jan 29, 2025
1 parent d4193fc commit 41ac8d8
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 235 deletions.
24 changes: 0 additions & 24 deletions apps/enmeshed/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.10"
device_info_plus:
dependency: transitive
description:
name: device_info_plus
sha256: "4fa68e53e26ab17b70ca39f072c285562cfc1589df5bb1e9295db90f6645f431"
url: "https://pub.dev"
source: hosted
version: "11.2.0"
device_info_plus_platform_interface:
dependency: transitive
description:
name: device_info_plus_platform_interface
sha256: "0b04e02b30791224b31969eb1b50d723498f402971bff3630bca2ba839bd1ed2"
url: "https://pub.dev"
source: hosted
version: "7.0.2"
enmeshed_runtime_bridge:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1389,14 +1373,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.10.0"
win32_registry:
dependency: transitive
description:
name: win32_registry
sha256: "21ec76dfc731550fd3e2ce7a33a9ea90b828fdf19a5c3bcf556fa992cfa99852"
url: "https://pub.dev"
source: hosted
version: "1.1.5"
wolt_modal_sheet:
dependency: "direct main"
description:
Expand Down
9 changes: 1 addition & 8 deletions packages/enmeshed_runtime_bridge/assets/index.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.10"
device_info_plus:
dependency: transitive
description:
name: device_info_plus
sha256: "4fa68e53e26ab17b70ca39f072c285562cfc1589df5bb1e9295db90f6645f431"
url: "https://pub.dev"
source: hosted
version: "11.2.0"
device_info_plus_platform_interface:
dependency: transitive
description:
name: device_info_plus_platform_interface
sha256: "0b04e02b30791224b31969eb1b50d723498f402971bff3630bca2ba839bd1ed2"
url: "https://pub.dev"
source: hosted
version: "7.0.2"
enmeshed_runtime_bridge:
dependency: "direct main"
description:
Expand Down Expand Up @@ -530,22 +514,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.4"
win32:
dependency: transitive
description:
name: win32
sha256: "154360849a56b7b67331c21f09a386562d88903f90a1099c5987afc1912e1f29"
url: "https://pub.dev"
source: hosted
version: "5.10.0"
win32_registry:
dependency: transitive
description:
name: win32_registry
sha256: "21ec76dfc731550fd3e2ce7a33a9ea90b828fdf19a5c3bcf556fa992cfa99852"
url: "https://pub.dev"
source: hosted
version: "1.1.5"
xdg_directories:
dependency: transitive
description:
Expand Down
11 changes: 4 additions & 7 deletions packages/enmeshed_runtime_bridge/lib/src/enmeshed_runtime.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ class EnmeshedRuntime {
RegExp(r'handleRuntimeEvent'),
RegExp(r'runtimeReady'),
RegExp(r'onReceivedServerTrustAuthRequest'),
RegExp(r'getDeviceInfo'),
RegExp(r'getDefaultConfig'),
RegExp(r'getRuntimeConfig'),
RegExp(r'uibridge_'),
RegExp(r'notifications_'),
RegExp(r'.*File'),
Expand Down Expand Up @@ -143,14 +142,13 @@ class EnmeshedRuntime {
);

controller.addJavaScriptHandler(
handlerName: 'getDefaultConfig',
handlerName: 'getRuntimeConfig',
callback: (_) => {
'applicationId': runtimeConfig.applicationId,
if (Platform.isIOS || Platform.isMacOS) 'applePushEnvironment': runtimeConfig.useAppleSandbox ? 'Development' : 'Production',
'transport': {
if (Platform.isIOS || Platform.isMacOS) 'pushService': 'apns' else if (Platform.isAndroid) 'pushService': 'fcm' else 'pushService': 'none',
'transportLibrary': {
'baseUrl': runtimeConfig.baseUrl,
'logLevel': 'warn',
'datawalletEnabled': true,
'platformClientId': runtimeConfig.clientId,
'platformClientSecret': runtimeConfig.clientSecret,
},
Expand All @@ -159,7 +157,6 @@ class EnmeshedRuntime {
},
);

controller.addDeviceInfoJavaScriptHandler();
controller.addLocalNotificationsJavaScriptHandlers();
}

Expand Down
43 changes: 0 additions & 43 deletions packages/enmeshed_runtime_bridge/lib/src/javascript_handlers.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:enmeshed_types/enmeshed_types.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
Expand Down Expand Up @@ -136,46 +133,6 @@ Future<dynamic> handleRuntimeEventCallback(List<dynamic> args, EventBus eventBus
eventBus.publish(event);
}

extension DeviceInfo on InAppWebViewController {
void addDeviceInfoJavaScriptHandler() => addJavaScriptHandler(handlerName: 'getDeviceInfo', callback: _getDeviceInfo);
}

Future<Map<String, dynamic>> _getDeviceInfo(List<dynamic> args) async {
final deviceInfoPlugin = DeviceInfoPlugin();

if (Platform.isAndroid) {
final deviceInfo = await deviceInfoPlugin.androidInfo;

return {
'model': deviceInfo.model,
'platform': 'Android',
'uuid': deviceInfo.id,
'manufacturer': deviceInfo.manufacturer,
'isVirtual': !deviceInfo.isPhysicalDevice,
'languageCode': Platform.localeName,
'version': deviceInfo.version.release,
'pushService': 'fcm',
};
}

if (Platform.isIOS) {
final deviceInfo = await deviceInfoPlugin.iosInfo;

return {
'model': deviceInfo.model,
'platform': 'IOS',
'uuid': deviceInfo.identifierForVendor ?? '',
'manufacturer': 'Apple',
'isVirtual': !deviceInfo.isPhysicalDevice,
'languageCode': Platform.localeName,
'version': deviceInfo.systemVersion,
'pushService': 'apns',
};
}

throw Exception('Unsupported platform');
}

class JsToUIBridge {
late final InAppWebViewController _controller;
set controller(InAppWebViewController controller) => _controller = controller;
Expand Down
72 changes: 31 additions & 41 deletions packages/enmeshed_runtime_bridge/natives/package-lock.json

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

6 changes: 3 additions & 3 deletions packages/enmeshed_runtime_bridge/natives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
},
"dependencies": {
"@js-soft/logging-abstractions": "^1.0.1",
"@js-soft/simple-logger": "^1.0.5",
"@js-soft/ts-utils": "^2.3.3",
"@js-soft/web-logger": "^1.0.4",
"@nmshd/app-runtime": "6.24.0",
"@nmshd/runtime": "6.24.0",
"@nmshd/app-runtime": "6.24.2",
"@nmshd/runtime": "6.24.2",
"js-logger": "^1.6.1",
"json-stringify-safe": "^5.0.1",
"lodash": "^4.17.21"
Expand Down
33 changes: 14 additions & 19 deletions packages/enmeshed_runtime_bridge/natives/src/ConfigAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,34 @@ export class ConfigAccess implements INativeConfigAccess {
public constructor(
private fileAccess: FileAccess,
private logger: ILogger,
private runtimeConfigPath: string
private configPath: string
) {}

private config: any = {};

public async initDefaultConfig(): Promise<Result<void>> {
const result: any = await window.flutter_inappwebview.callHandler("getDefaultConfig");
this.config = _.defaultsDeep(this.config, result);

return Result.ok(undefined);
}

public async initRuntimeConfig(): Promise<Result<void>> {
const runtimeConfigExistsResult = await this.fileAccess.existsFile(this.runtimeConfigPath);
if (runtimeConfigExistsResult.isError) {
public async init(): Promise<Result<void>> {
const configExistsResult = await this.fileAccess.existsFile(this.configPath);
if (configExistsResult.isError) {
return Result.fail(new ApplicationError("CONFIG_INIT", "Unable to check if runtime config exists!"));
}

if (!runtimeConfigExistsResult.value) {
this.logger.info("No runtime config found!");
if (!configExistsResult.value) {
this.logger.info("No config found!");
return Result.ok(undefined);
}

const runtimeConfigResult = await this.fileAccess.readFileAsText(this.runtimeConfigPath);
if (runtimeConfigResult.isError) {
const configResult = await this.fileAccess.readFileAsText(this.configPath);
if (configResult.isError) {
return Result.fail(new ApplicationError("CONFIG_INIT", "Unable to read runtime config file!"));
} else if (!runtimeConfigResult.value) {
} else if (!configResult.value) {
return Result.fail(new ApplicationError("CONFIG_INIT", "Unable to read runtime config file!"));
}

try {
const runtimeConfig = JSON.parse(runtimeConfigResult.value);
this.config = _.defaultsDeep(this.config, runtimeConfig);
const config = JSON.parse(configResult.value);
this.config = _.defaultsDeep(this.config, config);

await this.save();
} catch (err) {
return Result.fail(new ApplicationError("CONFIG_INIT", "Unable to parse runtime config data!"));
}
Expand All @@ -51,7 +46,7 @@ export class ConfigAccess implements INativeConfigAccess {

public async save(): Promise<Result<void>> {
const configAsString = stringifySafe(this.config);
const result = await this.fileAccess.writeFile(this.runtimeConfigPath, configAsString);
const result = await this.fileAccess.writeFile(this.configPath, configAsString);
if (result.isError) {
return Result.fail(new ApplicationError("CONFIG_SAVE", "Unable to save runtime config!"));
}
Expand Down
Loading

0 comments on commit 41ac8d8

Please sign in to comment.