Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
feat: adding login
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed May 2, 2024
1 parent 2d8ad4b commit 1feea75
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 13 deletions.
13 changes: 12 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import 'package:system_theme/system_theme.dart';
import 'logic/theme.dart' show buildThemeData;
import 'views/desktop.dart';
import 'views/lock.dart';
import 'views/login.dart';

void main(List<String> argsList) async {
final argsParser = ArgParser()
..addFlag('init-locked', help: 'Adding this option will start Genesis Shell in a locked state')
..addFlag('display-manager', help: 'Start as a display manager')
..addFlag('help', abbr: 'h', negatable: false);

final args = argsParser.parse(argsList);
Expand All @@ -20,11 +22,17 @@ void main(List<String> argsList) async {
exit(0);
}

if (args.flag('display-manager') && args.flag('init-locked')) {
print('Cannot run as a display manager and start locked');
exit(1);
}

WidgetsFlutterBinding.ensureInitialized();
await SystemTheme.accentColor.load();

runApp(GenesisShellApp(
initLocked: args.flag('init-locked'),
displayManager: args.flag('display-manager'),
));

doWhenWindowReady(() {
Expand All @@ -39,9 +47,11 @@ class GenesisShellApp extends StatelessWidget {
const GenesisShellApp({
super.key,
this.initLocked = false,
this.displayManager = false,
});

final bool initLocked;
final bool displayManager;

@override
Widget build(BuildContext context) {
Expand All @@ -61,8 +71,9 @@ class GenesisShellApp extends StatelessWidget {
routes: {
'/': (_) => const DesktopView(),
'/lock': (_) => const LockView(),
'/login': (_) => const LoginView(),
},
initialRoute: initLocked ? '/lock' : '/',
initialRoute: initLocked ? '/lock' : (displayManager ? '/login' : '/'),
),
);
}
Expand Down
99 changes: 99 additions & 0 deletions lib/views/login.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_adaptive_scaffold/flutter_adaptive_scaffold.dart';
import 'package:intl/intl.dart';

import '../logic/wallpaper.dart';

import '../widgets/account_profile.dart';
import '../widgets/clock.dart';
import '../widgets/draggable.dart';
import '../widgets/keypad.dart';
import '../widgets/system_layout.dart';

class LoginView extends StatefulWidget {
const LoginView({
super.key,
this.wallpaper = null,
this.desktopWallpaper = null,
this.mobileWallpaper = null,
});

final String? wallpaper;
final String? desktopWallpaper;
final String? mobileWallpaper;

@override
State<LoginView> createState() => _LoginViewState();
}

class _LoginViewState extends State<LoginView> {
static const authChannel = MethodChannel('com.expidusos.genesis.shell/auth');
static const accChannel = MethodChannel('com.expidusos.genesis.shell/account');

List<String> users = List.empty(growable: true);

@override
void initState() {
super.initState();

accChannel.invokeListMethod('list').then((values) => setState(() {
users.clear();
users.addAll(values!.map((value) => value['name']));
})).catchError((err) {
print(err);
});
}

@override
Widget build(BuildContext context) =>
SystemLayout(
userMode: false,
isLocked: true,
body: Container(
decoration: BoxDecoration(
image: getWallpaper(
path: (Breakpoints.small.isActive(context) ? widget.mobileWallpaper : widget.desktopWallpaper) ?? widget.wallpaper,
fallback: AssetImage('assets/wallpaper/${Breakpoints.small.isActive(context) ? 'mobile' : 'desktop'}/default.jpg'),
),
),
child: Center(
child: Card(
margin: const EdgeInsets.all(36),
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Log In',
style: Theme.of(context).textTheme.displayLarge,
),
],
),
const Spacer(),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: users.map(
(name) =>
AccountProfile.name(
name: name,
direction: Axis.vertical,
iconSize: 140,
textStyle: Theme.of(context).textTheme.displaySmall,
),
).toList(),
),
),
const Spacer(),
],
),
),
),
),
),
);
}
41 changes: 32 additions & 9 deletions lib/widgets/account_profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,34 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class AccountProfile extends StatefulWidget {
const AccountProfile({ super.key }) : uid = null, name = null;
const AccountProfile.uid({ super.key, required this.uid }) : name = null;
const AccountProfile.name({ super.key, required this.name }) : uid = null;
const AccountProfile({
super.key,
this.direction = Axis.horizontal,
this.iconSize = 40,
this.textStyle,
}) : uid = null, name = null;

const AccountProfile.uid({
super.key,
required this.uid,
this.direction = Axis.horizontal,
this.iconSize = 40,
this.textStyle,
}) : name = null;

const AccountProfile.name({
super.key,
required this.name,
this.direction = Axis.horizontal,
this.iconSize = 40,
this.textStyle,
}) : uid = null;

final int? uid;
final String? name;
final Axis direction;
final double iconSize;
final TextStyle? textStyle;

@override
State<AccountProfile> createState() => _AccountProfileState();
Expand Down Expand Up @@ -39,25 +61,26 @@ class _AccountProfileState extends State<AccountProfile> {
}

Widget build(BuildContext context) =>
Row(
Flex(
direction: widget.direction,
children: [
icon == null
? const Icon(Icons.account_circle, size: 40)
? Icon(Icons.account_circle, size: widget.iconSize)
: ClipRRect(
borderRadius: BorderRadius.circular(360.0),
child: Image.file(
File(icon!),
width: 40,
height: 40,
width: widget.iconSize,
height: widget.iconSize,
errorBuilder: (context, err, stackTrace) =>
const Icon(Icons.account_circle, size: 40),
Icon(Icons.account_circle, size: widget.iconSize),
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: Text(
displayName ?? '',
style: Theme.of(context).textTheme.titleLarge,
style: widget.textStyle ?? Theme.of(context).textTheme.titleLarge,
),
),
],
Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/system_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class _SystemDrawerState extends State<SystemDrawer> {
shrinkWrap: true,
children: [
widget.userMode && !Breakpoints.small.isActive(context) ? const AccountProfile() : null,
widget.userMode ? Row(
Row(
children: [
Expanded(
child: ButtonBar(),
Expand Down Expand Up @@ -68,7 +68,7 @@ class _SystemDrawerState extends State<SystemDrawer> {
),
),
],
) : null,
),
StatefulBuilder(
builder: (context, setState) =>
PowerBar(
Expand Down
2 changes: 1 addition & 1 deletion nix/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
services = {
cage = {
enable = true;
program = "${lib.getExe pkgs.expidus.genesis-shell} --init-locked";
program = "${lib.getExe pkgs.expidus.genesis-shell} --display-manager";
};
accounts-daemon.enable = true;
};
Expand Down

0 comments on commit 1feea75

Please sign in to comment.