From deb9fded885f6159d7d443ef583fca73790f6496 Mon Sep 17 00:00:00 2001 From: huangxiaoyao <976125628@qq.com> Date: Thu, 1 Feb 2024 19:03:01 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8DFlutterEntry=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=8F=82=E6=95=B0=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ohos/FlutterAbilityLaunchConfigs.ets | 11 ++++++- .../main/ets/embedding/ohos/FlutterEntry.ets | 29 +++++++++---------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets index 996f455b9d..a1ae4bdb86 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets @@ -43,4 +43,13 @@ export default class FlutterAbilityLaunchConfigs { static DEFAULT_DART_ENTRYPOINT = "main"; static DEFAULT_INITIAL_ROUTE = "/"; static DEFAULT_BACKGROUND_MODE = BackgroundMode.opaque -} \ No newline at end of file +} + +export interface ParamsConfigs { + should_attach_engine_to_ability?: boolean; + dart_entrypoint?: string; + route?: string; + cached_engine_id?: string; + dart_entrypoint_args?: Array; + cached_engine_group_id?: string | null; +} diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets index e66095a173..6625c6c6ff 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets @@ -21,7 +21,7 @@ import ExclusiveAppComponent from './ExclusiveAppComponent'; import { FlutterPlugin } from '../engine/plugins/FlutterPlugin'; import List from '@ohos.util.List'; import { FlutterAbilityAndEntryDelegate, Host } from './FlutterAbilityAndEntryDelegate'; -import FlutterAbilityLaunchConfigs from './FlutterAbilityLaunchConfigs'; +import FlutterAbilityLaunchConfigs, { ParamsConfigs } from './FlutterAbilityLaunchConfigs'; import Log from '../../util/Log'; import { FlutterView } from '../../view/FlutterView'; import FlutterManager from './FlutterManager'; @@ -38,11 +38,10 @@ export default class FlutterEntry implements Host { private flutterView: FlutterView | null = null private context: Context; private windowStage: window.WindowStage | null = null - private parameters: ESObject = {}; + private parameters: ParamsConfigs; private engineConfigurator: FlutterEngineConfigurator | null = null - private hasInit: boolean = false; - constructor(context: Context, params: ESObject = {}) { + constructor(context: Context, params: ParamsConfigs) { this.context = context; this.uiAbility = FlutterManager.getInstance().getUIAbility(context); this.parameters = params; @@ -143,15 +142,15 @@ export default class FlutterEntry implements Host { } shouldAttachEngineToAbility(): boolean { - return this.parameters![FlutterEntry.ARG_SHOULD_ATTACH_ENGINE_TO_ABILITY] as boolean + return this.parameters!.should_attach_engine_to_ability as boolean } getCachedEngineId(): string { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] as string + return this.parameters!.cached_engine_id as string } getCachedEngineGroupId(): string | null { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_GROUP_ID] as string + return this.parameters!.cached_engine_group_id as string } shouldDestroyEngineWithHost(): boolean { @@ -167,8 +166,8 @@ export default class FlutterEntry implements Host { } getDartEntrypointArgs(): string[] { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS]) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS] as Array; + if (this.parameters!.dart_entrypoint_args) { + return this.parameters!.dart_entrypoint_args as Array; } return new Array() } @@ -182,15 +181,15 @@ export default class FlutterEntry implements Host { } getDartEntrypointFunctionName(): string { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT]) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT] as string; + if (this.parameters!.dart_entrypoint) { + return this.parameters!.dart_entrypoint as string; } return FlutterAbilityLaunchConfigs.DEFAULT_DART_ENTRYPOINT } getInitialRoute(): string { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_INITIAL_ROUTE]) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_INITIAL_ROUTE] as string + if (this.parameters!.route) { + return this.parameters!.route as string } return ""; } @@ -200,8 +199,8 @@ export default class FlutterEntry implements Host { } shouldRestoreAndSaveState(): boolean { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] != undefined) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] as boolean; + if (this.parameters!.cached_engine_id != undefined) { + return true; } if (this.getCachedEngineId() != null && this.getCachedEngineId().length > 0) { // Prevent overwriting the existing state in a cached engine with restoration state. -- Gitee From 6b3d917c9194828de244a5e47f145d37932102a5 Mon Sep 17 00:00:00 2001 From: huangxiaoyao <976125628@qq.com> Date: Thu, 1 Feb 2024 19:03:52 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8DFlutterEntry=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=8F=82=E6=95=B0=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangxiaoyao <976125628@qq.com> --- .../ohos/FlutterAbilityLaunchConfigs.ets | 11 ++++++- .../main/ets/embedding/ohos/FlutterEntry.ets | 29 +++++++++---------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets index 996f455b9d..a1ae4bdb86 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterAbilityLaunchConfigs.ets @@ -43,4 +43,13 @@ export default class FlutterAbilityLaunchConfigs { static DEFAULT_DART_ENTRYPOINT = "main"; static DEFAULT_INITIAL_ROUTE = "/"; static DEFAULT_BACKGROUND_MODE = BackgroundMode.opaque -} \ No newline at end of file +} + +export interface ParamsConfigs { + should_attach_engine_to_ability?: boolean; + dart_entrypoint?: string; + route?: string; + cached_engine_id?: string; + dart_entrypoint_args?: Array; + cached_engine_group_id?: string | null; +} diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets index e66095a173..6625c6c6ff 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets @@ -21,7 +21,7 @@ import ExclusiveAppComponent from './ExclusiveAppComponent'; import { FlutterPlugin } from '../engine/plugins/FlutterPlugin'; import List from '@ohos.util.List'; import { FlutterAbilityAndEntryDelegate, Host } from './FlutterAbilityAndEntryDelegate'; -import FlutterAbilityLaunchConfigs from './FlutterAbilityLaunchConfigs'; +import FlutterAbilityLaunchConfigs, { ParamsConfigs } from './FlutterAbilityLaunchConfigs'; import Log from '../../util/Log'; import { FlutterView } from '../../view/FlutterView'; import FlutterManager from './FlutterManager'; @@ -38,11 +38,10 @@ export default class FlutterEntry implements Host { private flutterView: FlutterView | null = null private context: Context; private windowStage: window.WindowStage | null = null - private parameters: ESObject = {}; + private parameters: ParamsConfigs; private engineConfigurator: FlutterEngineConfigurator | null = null - private hasInit: boolean = false; - constructor(context: Context, params: ESObject = {}) { + constructor(context: Context, params: ParamsConfigs) { this.context = context; this.uiAbility = FlutterManager.getInstance().getUIAbility(context); this.parameters = params; @@ -143,15 +142,15 @@ export default class FlutterEntry implements Host { } shouldAttachEngineToAbility(): boolean { - return this.parameters![FlutterEntry.ARG_SHOULD_ATTACH_ENGINE_TO_ABILITY] as boolean + return this.parameters!.should_attach_engine_to_ability as boolean } getCachedEngineId(): string { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] as string + return this.parameters!.cached_engine_id as string } getCachedEngineGroupId(): string | null { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_GROUP_ID] as string + return this.parameters!.cached_engine_group_id as string } shouldDestroyEngineWithHost(): boolean { @@ -167,8 +166,8 @@ export default class FlutterEntry implements Host { } getDartEntrypointArgs(): string[] { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS]) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT_ARGS] as Array; + if (this.parameters!.dart_entrypoint_args) { + return this.parameters!.dart_entrypoint_args as Array; } return new Array() } @@ -182,15 +181,15 @@ export default class FlutterEntry implements Host { } getDartEntrypointFunctionName(): string { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT]) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_DART_ENTRYPOINT] as string; + if (this.parameters!.dart_entrypoint) { + return this.parameters!.dart_entrypoint as string; } return FlutterAbilityLaunchConfigs.DEFAULT_DART_ENTRYPOINT } getInitialRoute(): string { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_INITIAL_ROUTE]) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_INITIAL_ROUTE] as string + if (this.parameters!.route) { + return this.parameters!.route as string } return ""; } @@ -200,8 +199,8 @@ export default class FlutterEntry implements Host { } shouldRestoreAndSaveState(): boolean { - if (this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] != undefined) { - return this.parameters![FlutterAbilityLaunchConfigs.EXTRA_CACHED_ENGINE_ID] as boolean; + if (this.parameters!.cached_engine_id != undefined) { + return true; } if (this.getCachedEngineId() != null && this.getCachedEngineId().length > 0) { // Prevent overwriting the existing state in a cached engine with restoration state. -- Gitee From 245b7ef1fa9d39ceba46820c4dcfa0578540d0e6 Mon Sep 17 00:00:00 2001 From: huangxiaoyao <976125628@qq.com> Date: Thu, 1 Feb 2024 19:50:22 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8DFlutterEntry=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=8F=82=E6=95=B0=E8=8E=B7=E5=8F=96=E4=B8=8D?= =?UTF-8?q?=E5=88=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huangxiaoyao <976125628@qq.com> --- .../flutter/src/main/ets/embedding/ohos/FlutterEntry.ets | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets index 6625c6c6ff..a9984b3f9e 100644 --- a/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets +++ b/shell/platform/ohos/flutter_embedding/flutter/src/main/ets/embedding/ohos/FlutterEntry.ets @@ -40,7 +40,8 @@ export default class FlutterEntry implements Host { private windowStage: window.WindowStage | null = null private parameters: ParamsConfigs; private engineConfigurator: FlutterEngineConfigurator | null = null - + private hasInit: boolean = false; + constructor(context: Context, params: ParamsConfigs) { this.context = context; this.uiAbility = FlutterManager.getInstance().getUIAbility(context); -- Gitee