Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
feat: make apps launch
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed May 10, 2024
1 parent dda1c1d commit eae369e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 28 deletions.
4 changes: 4 additions & 0 deletions lib/logic/applications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ class Application {
final String? description;
final bool isHidden;
final String? icon;

Future<bool> launch() async {
return await ApplicationsManager.channel.invokeMethod('launch', id);
}
}
61 changes: 33 additions & 28 deletions lib/widgets/user_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,38 +75,43 @@ class UserDrawer extends StatelessWidget {
).toList(),
),
),
GridView.count(
crossAxisCount: 5,
shrinkWrap: true,
children: (Provider.of<ApplicationsManager>(context).applications.toList()..where((app) => !app.isHidden))
.map(
(app) =>
InkWell(
// TODO: launch app
child: Column(
children: [
app.icon != null
? (path.extension(app.icon!) == '.svg'
? SvgPicture.file(
File(app.icon!),
width: 40,
height: 40,
) : Image.file(
Padding(
padding: const EdgeInsets.all(8),
child: GridView.count(
crossAxisCount: 5,
shrinkWrap: true,
children: (Provider.of<ApplicationsManager>(context).applications.toList()..where((app) => !app.isHidden))
.map(
(app) =>
InkWell(
onTap: () {
app.launch();
},
child: Column(
children: [
app.icon != null
? (path.extension(app.icon!) == '.svg'
? SvgPicture.file(
File(app.icon!),
width: 40,
height: 40,
)) : Icon(Icons.tablet, size: 80),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: Text(
app.displayName ?? app.name ?? '',
overflow: TextOverflow.ellipsis,
) : Image.file(
File(app.icon!),
width: 40,
height: 40,
)) : Icon(Icons.tablet, size: 40),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: Text(
app.displayName ?? app.name ?? '',
overflow: TextOverflow.ellipsis,
),
),
),
],
),
)
).toList(),
],
),
)
).toList(),
),
),
],
);
Expand Down
24 changes: 24 additions & 0 deletions linux/channels/applications.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ static void method_call_handler(FlMethodChannel* channel, FlMethodCall* method_c
g_clear_list(&list, g_object_unref);

response = FL_METHOD_RESPONSE(fl_method_success_response_new(value));
} else if (strcmp(fl_method_call_get_name(method_call), "launch") == 0) {
FlValue* args = fl_method_call_get_args(method_call);
const gchar* name = fl_value_get_string(args);

GAppInfo* appinfo = nullptr;

GList* list = g_app_info_get_all();
for (GList* entry = list; entry != NULL; entry = entry->next) {
GAppInfo* i = G_APP_INFO(entry->data);
if (g_strcmp0(name, g_app_info_get_id(i)) == 0) {
appinfo = G_APP_INFO(g_object_ref(G_OBJECT(i)));
break;
}
}

g_clear_list(&list, g_object_unref);

if (appinfo == nullptr) {
fl_method_call_respond_error(method_call, "Gio", "Application does not exist", args, nullptr);
return;
}

response = FL_METHOD_RESPONSE(fl_method_success_response_new(fl_value_new_bool(g_app_info_launch(appinfo, nullptr, nullptr, nullptr))));
g_object_unref(G_OBJECT(appinfo));
} else {
response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
}
Expand Down

0 comments on commit eae369e

Please sign in to comment.