Showing
3 changed files
with
26 additions
and
31 deletions
| @@ -14,17 +14,12 @@ | @@ -14,17 +14,12 @@ | ||
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | import { FlutterAbility } from '@ohos/flutter_ohos' | 16 | import { FlutterAbility } from '@ohos/flutter_ohos' |
| 17 | -import { FlutterPlugin } from '@ohos/flutter_ohos/src/main/ets/embedding/engine/plugins/FlutterPlugin'; | ||
| 18 | import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant'; | 17 | import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant'; |
| 19 | -import List from '@ohos.util.List'; | ||
| 20 | import FlutterEngine from '@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterEngine'; | 18 | import FlutterEngine from '@ohos/flutter_ohos/src/main/ets/embedding/engine/FlutterEngine'; |
| 21 | 19 | ||
| 22 | export default class EntryAbility extends FlutterAbility { | 20 | export default class EntryAbility extends FlutterAbility { |
| 23 | configureFlutterEngine(flutterEngine: FlutterEngine) { | 21 | configureFlutterEngine(flutterEngine: FlutterEngine) { |
| 24 | super.configureFlutterEngine(flutterEngine) | 22 | super.configureFlutterEngine(flutterEngine) |
| 25 | - let plugins = GeneratedPluginRegistrant.getPlugins() as List<FlutterPlugin>; | ||
| 26 | - plugins.forEach((plugin) => { | ||
| 27 | - this.addPlugin(plugin); | ||
| 28 | - }) | 23 | + GeneratedPluginRegistrant.registerWith(flutterEngine) |
| 29 | } | 24 | } |
| 30 | } | 25 | } |
| @@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
| 13 | * limitations under the License. | 13 | * limitations under the License. |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | -import { BasicMessageChannel, BinaryMessenger, ByteBuffer, Log, MessageCodec } from '@ohos/flutter_ohos'; | 16 | +import { BasicMessageChannel, BinaryMessenger, ByteBuffer, Log, MessageCodec, Any } from '@ohos/flutter_ohos'; |
| 17 | import { Reply } from '@ohos/flutter_ohos/src/main/ets/plugin/common/BasicMessageChannel'; | 17 | import { Reply } from '@ohos/flutter_ohos/src/main/ets/plugin/common/BasicMessageChannel'; |
| 18 | import StandardMessageCodec from '@ohos/flutter_ohos/src/main/ets/plugin/common/StandardMessageCodec'; | 18 | import StandardMessageCodec from '@ohos/flutter_ohos/src/main/ets/plugin/common/StandardMessageCodec'; |
| 19 | import ArrayList from '@ohos.util.ArrayList'; | 19 | import ArrayList from '@ohos.util.ArrayList'; |
| @@ -24,13 +24,13 @@ const TAG = "wakelock.Messages"; | @@ -24,13 +24,13 @@ const TAG = "wakelock.Messages"; | ||
| 24 | export class ToggleMessage { | 24 | export class ToggleMessage { |
| 25 | enable: Boolean = false; | 25 | enable: Boolean = false; |
| 26 | 26 | ||
| 27 | - toMap(): Map<String, ESObject> { | ||
| 28 | - let toMapResult: Map<String, ESObject> = new Map<String, ESObject>(); | 27 | + toMap(): Map<String, Any> { |
| 28 | + let toMapResult: Map<String, Any> = new Map<String, Any>(); | ||
| 29 | toMapResult.set("enable", this.enable); | 29 | toMapResult.set("enable", this.enable); |
| 30 | return toMapResult; | 30 | return toMapResult; |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | - static fromMap(map: Map<String, ESObject>): ToggleMessage { | 33 | + static fromMap(map: Map<String, Any>): ToggleMessage { |
| 34 | let fromMapResult = new ToggleMessage(); | 34 | let fromMapResult = new ToggleMessage(); |
| 35 | let enable: Boolean = map.get("enable") ?? false; | 35 | let enable: Boolean = map.get("enable") ?? false; |
| 36 | fromMapResult.enable = enable; | 36 | fromMapResult.enable = enable; |
| @@ -41,13 +41,13 @@ export class ToggleMessage { | @@ -41,13 +41,13 @@ export class ToggleMessage { | ||
| 41 | export class IsEnabledMessage { | 41 | export class IsEnabledMessage { |
| 42 | enabled: Boolean = false; | 42 | enabled: Boolean = false; |
| 43 | 43 | ||
| 44 | - toMap(): Map<String, ESObject> { | ||
| 45 | - let toMapResult: Map<String, ESObject> = new Map<String, ESObject>(); | 44 | + toMap(): Map<String, Any> { |
| 45 | + let toMapResult: Map<String, Any> = new Map<String, Any>(); | ||
| 46 | toMapResult.set("enabled", this.enabled); | 46 | toMapResult.set("enabled", this.enabled); |
| 47 | return toMapResult; | 47 | return toMapResult; |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | - static fromMap(map: Map<String, ESObject>): IsEnabledMessage { | 50 | + static fromMap(map: Map<String, Any>): IsEnabledMessage { |
| 51 | let fromMapResult = new IsEnabledMessage(); | 51 | let fromMapResult = new IsEnabledMessage(); |
| 52 | let enabled: Boolean = map.get("enabled") ?? false; | 52 | let enabled: Boolean = map.get("enabled") ?? false; |
| 53 | fromMapResult.enabled = enabled; | 53 | fromMapResult.enabled = enabled; |
| @@ -62,21 +62,21 @@ class WakelockApiCodec extends StandardMessageCodec { | @@ -62,21 +62,21 @@ class WakelockApiCodec extends StandardMessageCodec { | ||
| 62 | super(); | 62 | super(); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | - readValueOfType(type: number, buffer: ByteBuffer): ESObject { | 65 | + readValueOfType(type: number, buffer: ByteBuffer): Any { |
| 66 | // Log.i(TAG, "readValueOfType type=" + type + ", buffer=" + buffer); | 66 | // Log.i(TAG, "readValueOfType type=" + type + ", buffer=" + buffer); |
| 67 | switch (type) { | 67 | switch (type) { |
| 68 | case 128: | 68 | case 128: |
| 69 | - return IsEnabledMessage.fromMap(this.readValue(buffer) as Map<String, ESObject>); | 69 | + return IsEnabledMessage.fromMap(this.readValue(buffer) as Map<String, Any>); |
| 70 | 70 | ||
| 71 | case 129: | 71 | case 129: |
| 72 | - return ToggleMessage.fromMap(this.readValue(buffer) as Map<String, ESObject>); | 72 | + return ToggleMessage.fromMap(this.readValue(buffer) as Map<String, Any>); |
| 73 | 73 | ||
| 74 | default: | 74 | default: |
| 75 | return super.readValueOfType(type, buffer); | 75 | return super.readValueOfType(type, buffer); |
| 76 | } | 76 | } |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | - writeValue(stream: ByteBuffer, value: ESObject): ESObject { | 79 | + writeValue(stream: ByteBuffer, value: Any): Any { |
| 80 | if (value instanceof IsEnabledMessage) { | 80 | if (value instanceof IsEnabledMessage) { |
| 81 | stream.writeUint8(128); | 81 | stream.writeUint8(128); |
| 82 | this.writeValue(stream, value.toMap()); | 82 | this.writeValue(stream, value.toMap()); |
| @@ -90,21 +90,21 @@ class WakelockApiCodec extends StandardMessageCodec { | @@ -90,21 +90,21 @@ class WakelockApiCodec extends StandardMessageCodec { | ||
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | export class Messages { | 92 | export class Messages { |
| 93 | - static getCodec(): MessageCodec<ESObject> { | 93 | + static getCodec(): MessageCodec<Any> { |
| 94 | return WakelockApiCodec.INSTANCE; | 94 | return WakelockApiCodec.INSTANCE; |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | static setup(binaryMessenger: BinaryMessenger, api: WakelockApi): void { | 97 | static setup(binaryMessenger: BinaryMessenger, api: WakelockApi): void { |
| 98 | { | 98 | { |
| 99 | - const channel: BasicMessageChannel<ESObject> = new BasicMessageChannel<ESObject>( | 99 | + const channel: BasicMessageChannel<Any> = new BasicMessageChannel<Any>( |
| 100 | binaryMessenger, "dev.flutter.pigeon.WakelockApi.toggle", Messages.getCodec()); | 100 | binaryMessenger, "dev.flutter.pigeon.WakelockApi.toggle", Messages.getCodec()); |
| 101 | if (api != null) { | 101 | if (api != null) { |
| 102 | channel.setMessageHandler({ | 102 | channel.setMessageHandler({ |
| 103 | - onMessage(message: ESObject, reply: Reply<ESObject>): void { | 103 | + onMessage(message: Any, reply: Reply<Any>): void { |
| 104 | // Log.d(TAG, 'onMessage reply:' + reply) | 104 | // Log.d(TAG, 'onMessage reply:' + reply) |
| 105 | - let wrapped: Map<String, ESObject> = new Map<String, ESObject>(); | 105 | + let wrapped: Map<String, Any> = new Map<String, Any>(); |
| 106 | try { | 106 | try { |
| 107 | - let args: ArrayList<ESObject> = message as ArrayList<ESObject>; | 107 | + let args: ArrayList<Any> = message as ArrayList<Any>; |
| 108 | let msgArg: ToggleMessage = args[0] as ToggleMessage; | 108 | let msgArg: ToggleMessage = args[0] as ToggleMessage; |
| 109 | 109 | ||
| 110 | Log.i(TAG, "received msgArg=" + JSON.stringify(msgArg)); | 110 | Log.i(TAG, "received msgArg=" + JSON.stringify(msgArg)); |
| @@ -115,7 +115,7 @@ export class Messages { | @@ -115,7 +115,7 @@ export class Messages { | ||
| 115 | Log.i(TAG, "toggle success"); | 115 | Log.i(TAG, "toggle success"); |
| 116 | wrapped.set("result", null); | 116 | wrapped.set("result", null); |
| 117 | reply.reply(wrapped); | 117 | reply.reply(wrapped); |
| 118 | - }).catch((err: ESObject) => { | 118 | + }).catch((err: Any) => { |
| 119 | Log.i(TAG, "toggle failed: " + JSON.stringify(err)); | 119 | Log.i(TAG, "toggle failed: " + JSON.stringify(err)); |
| 120 | wrapped.set("error", Messages.wrapError(err)); | 120 | wrapped.set("error", Messages.wrapError(err)); |
| 121 | reply.reply(wrapped); | 121 | reply.reply(wrapped); |
| @@ -132,13 +132,13 @@ export class Messages { | @@ -132,13 +132,13 @@ export class Messages { | ||
| 132 | } | 132 | } |
| 133 | } | 133 | } |
| 134 | { | 134 | { |
| 135 | - const channel: BasicMessageChannel<ESObject> = new BasicMessageChannel<ESObject>( | 135 | + const channel: BasicMessageChannel<Any> = new BasicMessageChannel<Any>( |
| 136 | binaryMessenger, "dev.flutter.pigeon.WakelockApi.isEnabled", Messages.getCodec()); | 136 | binaryMessenger, "dev.flutter.pigeon.WakelockApi.isEnabled", Messages.getCodec()); |
| 137 | if (api != null) { | 137 | if (api != null) { |
| 138 | channel.setMessageHandler({ | 138 | channel.setMessageHandler({ |
| 139 | - onMessage(message: ESObject, reply: Reply<ESObject>): void { | 139 | + onMessage(message: Any, reply: Reply<Any>): void { |
| 140 | // Log.d(TAG, 'onMessage reply:' + reply) | 140 | // Log.d(TAG, 'onMessage reply:' + reply) |
| 141 | - let wrapped: Map<String, ESObject> = new Map<String, ESObject>(); | 141 | + let wrapped: Map<String, Any> = new Map<String, Any>(); |
| 142 | try { | 142 | try { |
| 143 | let output: IsEnabledMessage = api.isEnabled(); | 143 | let output: IsEnabledMessage = api.isEnabled(); |
| 144 | wrapped.set("result", output); | 144 | wrapped.set("result", output); |
| @@ -154,8 +154,8 @@ export class Messages { | @@ -154,8 +154,8 @@ export class Messages { | ||
| 154 | } | 154 | } |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | - static wrapError(error: Error): Map<String, ESObject> { | ||
| 158 | - let errorMap: Map<String, ESObject> = new Map(); | 157 | + static wrapError(error: Error): Map<String, Any> { |
| 158 | + let errorMap: Map<String, Any> = new Map(); | ||
| 159 | errorMap.set("message", error.message); | 159 | errorMap.set("message", error.message); |
| 160 | errorMap.set("code", error.name); | 160 | errorMap.set("code", error.name); |
| 161 | errorMap.set("details", null); | 161 | errorMap.set("details", null); |
| @@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
| 13 | * limitations under the License. | 13 | * limitations under the License. |
| 14 | */ | 14 | */ |
| 15 | 15 | ||
| 16 | -import { Log } from '@ohos/flutter_ohos'; | 16 | +import { Log, Any } from '@ohos/flutter_ohos'; |
| 17 | import { IsEnabledMessage, ToggleMessage } from './Messages'; | 17 | import { IsEnabledMessage, ToggleMessage } from './Messages'; |
| 18 | import common from '@ohos.app.ability.common'; | 18 | import common from '@ohos.app.ability.common'; |
| 19 | import window from '@ohos.window'; | 19 | import window from '@ohos.window'; |
| @@ -50,12 +50,12 @@ export class Wakelock implements WakelockApi { | @@ -50,12 +50,12 @@ export class Wakelock implements WakelockApi { | ||
| 50 | Log.i(TAG, "setWindowKeepScreenOn success"); | 50 | Log.i(TAG, "setWindowKeepScreenOn success"); |
| 51 | this.enabled = isKeepScreenOn; | 51 | this.enabled = isKeepScreenOn; |
| 52 | resolve(); | 52 | resolve(); |
| 53 | - }).catch((err: ESObject) => { | 53 | + }).catch((err: Any) => { |
| 54 | this.enabled = false; | 54 | this.enabled = false; |
| 55 | reject(err); | 55 | reject(err); |
| 56 | Log.e(TAG, "setWindowKeepScreenOn error: " + JSON.stringify(err)); | 56 | Log.e(TAG, "setWindowKeepScreenOn error: " + JSON.stringify(err)); |
| 57 | }) | 57 | }) |
| 58 | - }).catch((err: ESObject) => { | 58 | + }).catch((err: Any) => { |
| 59 | this.enabled = false; | 59 | this.enabled = false; |
| 60 | reject(err); | 60 | reject(err); |
| 61 | Log.i(TAG, "setWindowKeepScreenOn other error: " + JSON.stringify(err)); | 61 | Log.i(TAG, "setWindowKeepScreenOn other error: " + JSON.stringify(err)); |
-
Please register or login to post a comment