-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Kononov
committed
Apr 12, 2024
1 parent
6e6203e
commit f144497
Showing
13 changed files
with
208 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
## | ||
## 0.1.1 | ||
* Fix plugin crashes in background on Android. | ||
## 0.1.0 | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:managed_configurations/managed_configurations.dart'; | ||
import 'package:managed_configurations/managed_configurations_platform_interface.dart'; | ||
|
||
const String getManagedConfiguration = "getManagedConfigurations"; | ||
const String reportKeyedAppState = "reportKeyedAppState"; | ||
|
||
/// An implementation of [ManagedConfigurationsPlatform] that uses method channels. | ||
class MethodChannelManagedConfigurations extends ManagedConfigurationsPlatform { | ||
/// The method channel used to interact with the native platform. | ||
@visibleForTesting | ||
final methodChannel = const MethodChannel('managed_configurations'); | ||
|
||
static const MethodChannel _managedConfigurationMethodChannel = | ||
const MethodChannel('managed_configurations_method'); | ||
static const EventChannel _managedConfigurationEventChannel = | ||
const EventChannel('managed_configurations_event'); | ||
|
||
static StreamController<Map<String, dynamic>?> | ||
_mangedConfigurationsController = | ||
StreamController<Map<String, dynamic>?>.broadcast(); | ||
|
||
static Stream<Map<String, dynamic>?> _managedConfigurationsStream = | ||
_mangedConfigurationsController.stream.asBroadcastStream(); | ||
|
||
/// Returns a broadcast stream which calls on managed app configuration changes | ||
/// Json will be returned | ||
/// Call [dispose] when stream is not more necessary | ||
static Stream<Map<String, dynamic>?> get mangedConfigurationsStream { | ||
if (_actionApplicationRestrictionsChangedSubscription == null) { | ||
_actionApplicationRestrictionsChangedSubscription = | ||
_managedConfigurationEventChannel | ||
.receiveBroadcastStream() | ||
.listen((newManagedConfigurations) { | ||
if (newManagedConfigurations != null) { | ||
_mangedConfigurationsController | ||
.add(json.decode(newManagedConfigurations)); | ||
} | ||
}); | ||
} | ||
return _managedConfigurationsStream; | ||
} | ||
|
||
static StreamSubscription<dynamic>? | ||
_actionApplicationRestrictionsChangedSubscription; | ||
|
||
/// Returns managed app configurations as Json | ||
static Future<Map<String, dynamic>?> get getManagedConfigurations async { | ||
final String? rawJson = await _managedConfigurationMethodChannel | ||
.invokeMethod(getManagedConfiguration); | ||
if (rawJson != null) { | ||
return json.decode(rawJson); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
/// This method is only supported on Android Platform | ||
static Future<void> reportKeyedAppStates( | ||
String key, | ||
Severity severity, | ||
String? message, | ||
String? data, | ||
) async { | ||
if (Platform.isAndroid) { | ||
await _managedConfigurationMethodChannel.invokeMethod( | ||
reportKeyedAppState, | ||
{ | ||
'key': key, | ||
'severity': severity.toInteger(), | ||
'message': message, | ||
'data': data, | ||
}, | ||
); | ||
} | ||
} | ||
|
||
static dispose() { | ||
_actionApplicationRestrictionsChangedSubscription?.cancel(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'package:managed_configurations/managed_configurations.dart'; | ||
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
|
||
import 'managed_configurations_method_channel.dart'; | ||
|
||
abstract class ManagedConfigurationsPlatform extends PlatformInterface { | ||
/// Constructs a ManagedConfigurationsPlatform. | ||
ManagedConfigurationsPlatform() : super(token: _token); | ||
|
||
static final Object _token = Object(); | ||
|
||
static ManagedConfigurationsPlatform _instance = | ||
MethodChannelManagedConfigurations(); | ||
|
||
/// The default instance of [ManagedConfigurationsPlatform] to use. | ||
/// | ||
/// Defaults to [MethodChannelManagedConfigurations]. | ||
static ManagedConfigurationsPlatform get instance => _instance; | ||
|
||
/// Platform-specific implementations should set this with their own | ||
/// platform-specific class that extends [ManagedConfigurationsPlatform] when | ||
/// they register themselves. | ||
static set instance(ManagedConfigurationsPlatform instance) { | ||
PlatformInterface.verifyToken(instance, _token); | ||
_instance = instance; | ||
} | ||
|
||
Future<String?> getPlatformVersion() { | ||
throw UnimplementedError('platformVersion() has not been implemented.'); | ||
} | ||
|
||
static Stream<Map<String, dynamic>?> get mangedConfigurationsStream { | ||
throw UnimplementedError('platformVersion() has not been implemented.'); | ||
} | ||
|
||
static Future<Map<String, dynamic>?> get getManagedConfigurations async { | ||
throw UnimplementedError('platformVersion() has not been implemented.'); | ||
} | ||
|
||
/// This method is only supported on Android Platform | ||
static Future<void> reportKeyedAppStates( | ||
String key, | ||
Severity severity, | ||
String? message, | ||
String? data, | ||
) async { | ||
throw UnimplementedError('platformVersion() has not been implemented.'); | ||
} | ||
|
||
static void dispose() { | ||
throw UnimplementedError('platformVersion() has not been implemented.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters