Skip to content

Commit 5419909

Browse files
authored
[tizen_app_manager] Deprecate AppRunningContext.dispose (#405)
* Implement a finalizer for AppRunningContext * Update the example app * Version bump and update README
1 parent 5e566a6 commit 5419909

File tree

5 files changed

+42
-35
lines changed

5 files changed

+42
-35
lines changed

packages/tizen_app_manager/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.1.2
2+
3+
* Implement a Dart finalizer for `AppRunningContext`.
4+
* Deprecate `AppRunningContext.dispose`.
5+
* Clean up README.
6+
17
## 0.1.1
28

39
* Add the main exporter file `tizen_app_manager.dart`.

packages/tizen_app_manager/README.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,51 @@
22

33
[![pub package](https://img.shields.io/pub/v/tizen_app_manager.svg)](https://pub.dev/packages/tizen_app_manager)
44

5-
Tizen application manager API. Used for getting installed app info and getting running context info of specific app.
5+
Tizen application manager APIs. Used for getting app info and getting app running context on a Tizen device.
66

77
## Usage
88

99
To use this package, add `tizen_app_manager` as a dependency in your `pubspec.yaml` file.
1010

1111
```yaml
1212
dependencies:
13-
tizen_app_manager: ^0.1.1
13+
tizen_app_manager: ^0.1.2
1414
```
1515
1616
### Retrieving current app info
1717
18-
To retrieve information of the current app, get app ID with `currentAppId` and then get `AppInfo` with `getAppInfo` method.
18+
To retrieve information of the current app, get app ID with `AppManager.currentAppId` and then get `AppInfo` with `AppManager.getAppInfo`.
1919

2020
```dart
21-
var appId = await AppManager.currentAppId;
22-
var appInfo = await AppManager.getAppInfo(appId);
21+
import 'package:tizen_app_manager/tizen_app_manager.dart';
22+
23+
String appId = await AppManager.currentAppId;
24+
AppInfo appInfo = await AppManager.getAppInfo(appId);
2325
```
2426

2527
### Retrieving all apps info
2628

27-
To retrieve information of all apps installed on a Tizen device, use `getInstalledApps` method.
29+
To retrieve information of all installed apps, use `AppManager.getInstalledApps`.
2830

2931
```dart
30-
var apps = await AppManager.getInstalledApps();
31-
for (var app in apps) {
32+
List<AppInfo> apps = await AppManager.getInstalledApps();
33+
for (AppInfo app in apps) {
3234
// Handle each app's info.
3335
}
3436
```
3537

3638
### Getting app running context
3739

38-
To get specific app running context, create `AppRunningContext` instance.
40+
To get a specific app's running context, create an `AppRunningContext` instance with the target app ID.
3941

4042
```dart
41-
var appId = await AppManager.currentAppId;
42-
var appContext = AppRunningContext(appId: appId);
43+
String appId = await AppManager.currentAppId;
44+
AppRunningContext appContext = AppRunningContext(appId: appId);
4345
```
4446

4547
### Monitoring app events
4648

47-
You can listen for app state change by subscribing to the stream.
49+
You can listen for app state changes by subscribing to `AppManager.onAppLaunched` and `AppManager.onAppTerminated`.
4850

4951
```dart
5052
final List<StreamSubscription<AppRunningContext>> _subscriptions =
@@ -54,25 +56,22 @@ final List<StreamSubscription<AppRunningContext>> _subscriptions =
5456
void initState() {
5557
super.initState();
5658
57-
_subscriptions.add(AppManager.onAppLaunched
58-
.listen((AppRunningContext event) {
59-
// Handle the launched event.
60-
...
61-
event.dispose();
59+
_subscriptions
60+
.add(AppManager.onAppLaunched.listen((AppRunningContext context) {
61+
...
6262
}));
63-
_subscriptions.add(AppManager.onAppTerminated
64-
.listen((AppRunningContext event) {
65-
// Handle the terminated event.
66-
...
67-
event.dispose();
63+
_subscriptions
64+
.add(AppManager.onAppTerminated.listen((AppRunningContext context) {
65+
...
6866
}));
6967
}
7068
7169
@override
7270
void dispose() {
7371
super.dispose();
7472
75-
_subscriptions.forEach((StreamSubscription subscription) => subscription.cancel());
73+
_subscriptions
74+
.forEach((StreamSubscription subscription) => subscription.cancel());
7675
_subscriptions.clear();
7776
}
7877
```

packages/tizen_app_manager/example/lib/main.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,10 @@ class _CurrentAppScreenState extends State<_CurrentAppScreen> {
173173
_infoTile('Application type', _appInfo.appType),
174174
_infoTile('Execuatable path', _appInfo.executablePath),
175175
_infoTile('Shared res path', _appInfo.sharedResourcePath),
176-
_infoTile('App meta data', _appInfo.metadata.toString()),
177-
_infoTile(
178-
'App is terminated', _currentAppContext.isTerminated.toString()),
179-
_infoTile('process id', _currentAppContext.processId.toString()),
180-
_infoTile('state', _currentAppContext.appState.toString()),
176+
_infoTile('Metadata', _appInfo.metadata.toString()),
177+
_infoTile('Terminated', _currentAppContext.isTerminated.toString()),
178+
_infoTile('Process ID', _currentAppContext.processId.toString()),
179+
_infoTile('State', _currentAppContext.appState.toString()),
181180
],
182181
),
183182
);
@@ -279,7 +278,6 @@ class _AppsEventScreenState extends State<_AppsEventScreen> {
279278
appId: event.appId,
280279
processId: event.processId,
281280
));
282-
event.dispose();
283281
});
284282
}));
285283
_subscriptions
@@ -290,7 +288,6 @@ class _AppsEventScreenState extends State<_AppsEventScreen> {
290288
appId: event.appId,
291289
processId: event.processId,
292290
));
293-
event.dispose();
294291
});
295292
}));
296293
}

packages/tizen_app_manager/lib/app_manager.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,15 @@ class AppRunningContext {
164164
/// Creates an instance of [AppRunningContext] with application ID and handle address.
165165
AppRunningContext({required this.appId, int handleAddress = 0}) {
166166
_context = AppContext(appId, handleAddress);
167+
168+
_finalizer.attach(this, _context, detach: this);
167169
}
168170

169171
late AppContext _context;
170172

173+
static final Finalizer<AppContext> _finalizer =
174+
Finalizer<AppContext>((AppContext context) => context.destroy());
175+
171176
/// The ID of the application.
172177
final String appId;
173178

@@ -191,11 +196,11 @@ class AppRunningContext {
191196
}
192197

193198
/// Releases all resources associated with this object.
194-
///
195-
/// Note that [dispose] must be called on an instance of [AppRunningContext]
196-
/// after use.
199+
@Deprecated('Automatically disposed on GC')
197200
void dispose() {
198201
_context.destroy();
202+
203+
_finalizer.detach(this);
199204
}
200205

201206
/// Sends a resume request to the application if it is not running.

packages/tizen_app_manager/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: tizen_app_manager
2-
description: Tizen application manager APIs. Used to get application info and app running context on a Tizen device.
2+
description: Tizen application manager APIs. Used for getting app info and getting app running context on a Tizen device.
33
homepage: https://github.com/flutter-tizen/plugins
44
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/tizen_app_manager
5-
version: 0.1.1
5+
version: 0.1.2
66

77
environment:
88
sdk: ">=2.15.1 <3.0.0"

0 commit comments

Comments
 (0)