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

Commit

Permalink
feat: adding app launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed May 10, 2024
1 parent 53d3f06 commit dda1c1d
Show file tree
Hide file tree
Showing 17 changed files with 447 additions and 46 deletions.
63 changes: 63 additions & 0 deletions lib/logic/applications.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'dart:async';
import 'dart:collection';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

class ApplicationsManager {
static const channel = MethodChannel('com.expidusos.genesis.shell/applications');

ApplicationsManager() {
channel.setMethodCallHandler((call) async {
switch (call.method) {
case 'sync':
_sync();
break;
default:
throw MissingPluginException();
}
});

_sync();
}

List<Application> _applications = [];
UnmodifiableListView<Application> get applications => UnmodifiableListView(_applications);

void _sync() {
channel.invokeListMethod('list').then((list) {
_applications.clear();
_applications.addAll(list!.map(
(app) =>
Application(
id: app['id'],
name: app['name'],
displayName: app['displayName'],
description: app['description'],
isHidden: app['isHidden'],
icon: app['icon'],
)
));
}).catchError((err) {
print(err);
});
}
}

class Application {
const Application({
this.id,
this.name,
this.displayName,
this.description,
this.isHidden = false,
this.icon,
});

final String? id;
final String? name;
final String? displayName;
final String? description;
final bool isHidden;
final String? icon;
}
2 changes: 1 addition & 1 deletion lib/logic/wm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class WindowManager extends ChangeNotifier {
this.mode = WindowManagerMode.stacking,
});

final WindowManagerMode mode;
WindowManagerMode mode;
List<Window> _wins = [];

void dispose() {}
Expand Down
4 changes: 4 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:libtokyo/libtokyo.dart' hide TokyoApp;
import 'package:provider/provider.dart';

import 'logic/account.dart';
import 'logic/applications.dart';
import 'logic/display.dart';
import 'logic/outputs.dart';
import 'logic/power.dart';
Expand Down Expand Up @@ -64,6 +65,7 @@ class GenesisShellApp extends StatefulWidget {

class _GenesisShellAppState extends State<GenesisShellApp> {
late AccountManager _accountManager;
late ApplicationsManager _applicationsManager;
late DisplayManager _displayManager;
late OutputManager _outputManager;
late PowerManager _powerManager;
Expand All @@ -73,6 +75,7 @@ class _GenesisShellAppState extends State<GenesisShellApp> {
super.initState();

_accountManager = AccountManager();
_applicationsManager = ApplicationsManager();
_displayManager = DisplayManager();
_outputManager = OutputManager();
_powerManager = PowerManager.auto();
Expand All @@ -90,6 +93,7 @@ class _GenesisShellAppState extends State<GenesisShellApp> {
MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => _accountManager),
Provider(create: (_) => _applicationsManager),
ChangeNotifierProvider(create: (_) => _displayManager),
ChangeNotifierProvider(create: (_) => _outputManager),
Provider(create: (_) => _powerManager),
Expand Down
7 changes: 6 additions & 1 deletion lib/views/desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class _DesktopViewState extends State<DesktopView> {
String? sessionName = null;
DisplayServer? _displayServer = null;
GlobalKey _key = GlobalKey();
GlobalKey<WindowManagerViewState> _wmKey = GlobalKey();

void _syncOutputs() {
final outputs = Provider.of<OutputManager>(_key.currentContext!, listen: false);
Expand Down Expand Up @@ -117,6 +118,7 @@ class _DesktopViewState extends State<DesktopView> {
constraints: BoxConstraints.expand(),
child: _displayServer != null
? WindowManagerView(
key: _wmKey,
displayServer: _displayServer!,
mode: Breakpoints.small.isActive(context) ? WindowManagerMode.stacking : WindowManagerMode.floating,
) : null,
Expand All @@ -128,7 +130,10 @@ class _DesktopViewState extends State<DesktopView> {
if (_displayServer != null) {
value = ChangeNotifierProvider<DisplayServer>.value(
value: _displayServer!,
child: value,
child: ChangeNotifierProvider<WindowManager>(
create: (context) => _wmKey!.currentState!.instance,
child: value,
),
);
}
return value;
Expand Down
11 changes: 10 additions & 1 deletion lib/widgets/system_layout.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:backdrop/backdrop.dart';
import 'package:flutter/material.dart' as material;
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart';
import 'package:libtokyo_flutter/libtokyo.dart' hide ColorScheme;
import 'package:libtokyo/libtokyo.dart' hide TokyoApp, Scaffold;
Expand Down Expand Up @@ -100,6 +101,7 @@ class SystemLayout extends StatelessWidget {
? Padding(
padding: const EdgeInsets.all(8.0),
child: Drawer(
width: double.infinity,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
Expand All @@ -111,7 +113,14 @@ class SystemLayout extends StatelessWidget {
backgroundColor: Theme.of(context).colorScheme.surface,
),
),
child: UserDrawer(),
child: Builder(
builder: (context) =>
UserDrawer(
onClose: () {
material.Scaffold.of(context).closeDrawer();
},
),
),
),
),
),
Expand Down
26 changes: 24 additions & 2 deletions lib/widgets/system_navbar.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import 'package:flutter/material.dart' as material;
import 'package:libtokyo_flutter/libtokyo.dart' hide ColorScheme;
import 'package:libtokyo/libtokyo.dart' hide TokyoApp, Scaffold;

class SystemNavbar extends StatelessWidget {
import 'user_drawer.dart';

class SystemNavbar extends StatefulWidget {
const SystemNavbar({ super.key });

@override
State<SystemNavbar> createState() => _SystemNavbarState();
}

class _SystemNavbarState extends State<SystemNavbar> {
PersistentBottomSheetController? _controller;

@override
Widget build(BuildContext context) =>
BottomAppBar(
Expand All @@ -17,7 +27,19 @@ class SystemNavbar extends StatelessWidget {
icon: Icon(Icons.chevronLeft),
),
IconButton(
onPressed: () {},
onPressed: () {
if (_controller != null) {
_controller!.close();
_controller = null;
} else {
_controller = material.Scaffold.of(context).showBottomSheet((context) =>
UserDrawer(
onClose: () {
_controller!.close();
},
));
}
},
icon: Icon(Icons.circleDot),
),
IconButton(
Expand Down
59 changes: 32 additions & 27 deletions lib/widgets/toplevel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,25 @@ class ToplevelDecor extends StatelessWidget {
final VoidCallback? onClose;

@override
Widget build(BuildContext context) =>
AppBar(
Widget build(BuildContext context) {
final actions = [
onMinimize != null
? IconButton(
onPressed: onMinimize!,
icon: Icon(Icons.windowMinimize),
) : null,
onMaximize != null
? IconButton(
onPressed: onMaximize!,
icon: Icon(Icons.windowMaximize),
) : null,
onClose != null
? IconButton(
onPressed: onClose!,
icon: Icon(Icons.circleXmark),
) : null,
].where((e) => e != null).toList().cast<Widget>();
return AppBar(
automaticallyImplyLeading: false,
primary: false,
title: Text(toplevel.title ?? 'Untitled Window'),
Expand All @@ -32,24 +49,12 @@ class ToplevelDecor extends StatelessWidget {
topRight: Radius.circular(12),
),
),
actions: [
onMinimize != null
? IconButton(
onPressed: onMinimize!,
icon: Icon(Icons.windowMinimize),
) : null,
onMaximize != null
? IconButton(
onPressed: onMaximize!,
icon: Icon(Icons.windowMaximize),
) : null,
onClose != null
? IconButton(
onPressed: onClose!,
icon: Icon(Icons.circleXmark),
) : null,
].where((e) => e != null).toList().cast<Widget>(),
actions: actions.isEmpty
? [
const SizedBox()
] : actions,
);
}
}

class ToplevelView extends StatefulWidget {
Expand Down Expand Up @@ -91,13 +96,10 @@ class _ToplevelViewState extends State<ToplevelView> {

@override
Widget _buildContent(BuildContext context, DisplayServerToplevel toplevel) {
Widget content = ConstrainedBox(
constraints: toplevel.buildBoxConstraints(),
child: toplevel.texture == null
? SizedBox() : Texture(
textureId: toplevel.texture!,
),
);
Widget content = toplevel.texture == null
? SizedBox() : Texture(
textureId: toplevel.texture!,
);

if (widget.isFocusable) {
content = Focus(
Expand All @@ -116,7 +118,10 @@ class _ToplevelViewState extends State<ToplevelView> {
return true;
},
child: SizeChangedLayoutNotifier(
child: content,
child: ConstrainedBox(
constraints: toplevel.buildBoxConstraints(),
child: content,
),
),
);
}
Expand Down
Loading

0 comments on commit dda1c1d

Please sign in to comment.