1 import 'package:flutter_ics_homescreen/export.dart';
2 import 'package:protos/applauncher-api.dart';
3 import 'package:protos/agl-shell-api.dart';
8 late ClientChannel aglShellChannel;
9 late AglShellManagerServiceClient aglShell;
10 late ClientChannel appLauncherChannel;
11 late AppLauncherClient appLauncher;
13 List<String> appStack = ['homescreen'];
15 AppLauncher({required this.ref}) {
16 aglShellChannel = ClientChannel('localhost',
18 options: ChannelOptions(credentials: ChannelCredentials.insecure()));
20 aglShell = AglShellManagerServiceClient(aglShellChannel);
22 appLauncherChannel = ClientChannel('localhost',
24 options: ChannelOptions(credentials: ChannelCredentials.insecure()));
25 appLauncher = AppLauncherClient(appLauncherChannel);
32 var response = appLauncher.getStatusEvents(StatusRequest());
33 await for (var event in response) {
35 AppStatus app_status = event.app;
36 debugPrint("Got app status:");
37 debugPrint("$app_status");
38 if (app_status.hasId() && app_status.hasStatus()) {
39 if (app_status.status == "started") {
40 activateApp(app_status.id);
41 } else if (app_status.status == "terminated") {
42 deactivateApp(app_status.id);
54 var response = await appLauncher.listApplications(ListRequest());
55 List<AppLauncherInfo> apps = [];
56 for (AppInfo info in response.apps) {
57 debugPrint("Got app:");
59 // Existing icons are currently not usable, so leave blank for now
60 apps.add(AppLauncherInfo(
61 id: info.id, name: info.name, icon: "", internal: false));
63 apps.sort((a, b) => a.name.compareTo(b.name));
65 // Add built-in app widgets
69 id: "clock", name: "Clock", icon: "clock.svg", internal: true));
78 ref.read(appLauncherListProvider.notifier).update(apps);
84 void startApp(String id) async {
85 await appLauncher.startApplication(StartRequest(id: id));
88 addAppToStack(String id) {
89 if (!appStack.contains(id)) {
92 int current = appStack.indexOf(id);
93 if (current != (appStack.length - 1)) {
94 appStack.removeAt(current);
100 activateApp(String id) async {
101 if (appStack.last != id) {
102 var req = ActivateRequest(appId: id);
103 var response = aglShell.activateApp(req);
108 deactivateApp(String id) async {
109 if (appStack.contains(id)) {
111 if (appStack.isNotEmpty) {
112 activateApp(appStack.last);