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

Commit

Permalink
feat: add lock ability
Browse files Browse the repository at this point in the history
  • Loading branch information
RossComputerGuy committed May 2, 2024
1 parent fffe8e3 commit c9bbef8
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 27 deletions.
20 changes: 18 additions & 2 deletions lib/views/lock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ class LockView extends StatefulWidget {
}

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

TextEditingController passcodeController = TextEditingController();
String? passwordHint = null;
String? errorText = null;

void _onSubmitted(BuildContext context, String input) {
setState(() {
errorText = null;
});

platform.invokeMethod<void>('auth', <String, dynamic>{
authChannel.invokeMethod<void>('auth', <String, dynamic>{
'password': input,
}).then((_) {
setState(() {
Expand All @@ -57,6 +59,17 @@ class _LockViewState extends State<LockView> {
}));
}

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

accChannel.invokeMethod('get', null).then((user) => setState(() {
passwordHint = user['passwordHint'];
})).catchError((err) {
print(err);
});
}

@override
void dispose() {
super.dispose();
Expand All @@ -66,6 +79,8 @@ class _LockViewState extends State<LockView> {
@override
Widget build(BuildContext context) =>
SystemLayout(
userMode: true,
isLocked: true,
body: Container(
decoration: BoxDecoration(
image: getWallpaper(
Expand Down Expand Up @@ -131,6 +146,7 @@ class _LockViewState extends State<LockView> {
decoration: InputDecoration(
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(horizontal: 4.0),
hintText: passwordHint,
errorMaxLines: 5,
errorText: errorText,
),
Expand Down
5 changes: 3 additions & 2 deletions lib/widgets/account_profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class _AccountProfileState extends State<AccountProfile> {
platform.invokeMethod('get', _getData()).then((user) => setState(() {
displayName = user['displayName'];
icon = user['icon'];
print(user);
})).catchError((err) {
print(err);
});
Expand All @@ -43,13 +42,15 @@ class _AccountProfileState extends State<AccountProfile> {
Row(
children: [
icon == null
? Icon(Icons.account_circle, size: 40)
? const Icon(Icons.account_circle, size: 40)
: ClipRRect(
borderRadius: BorderRadius.circular(360.0),
child: Image.file(
File(icon!),
width: 40,
height: 40,
errorBuilder: (context, err, stackTrace) =>
const Icon(Icons.account_circle, size: 40),
),
),
Padding(
Expand Down
82 changes: 82 additions & 0 deletions lib/widgets/power.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,88 @@ import 'dart:async';
import 'package:flutter/material.dart';
import '../logic/power.dart';

class PowerDialog extends StatelessWidget {
const PowerDialog({
super.key,
this.isLocked = false,
});

final bool isLocked;

@override
Widget build(BuildContext context) =>
Dialog(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
!isLocked
? Row(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.all(8),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
onPressed: () => Navigator.of(context).pushNamed('/lock'),
icon: Icon(Icons.lock),
),
Text('Lock'),
],
),
),
Padding(
padding: const EdgeInsets.all(8),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
onPressed: () {},
icon: Icon(Icons.logout),
),
Text('Log Out'),
],
),
),
],
) : null,
Row(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.all(8),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
onPressed: () {},
icon: Icon(Icons.restart_alt),
),
Text('Restart'),
],
),
),
Padding(
padding: const EdgeInsets.all(8),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
onPressed: () {},
icon: Icon(Icons.power),
),
Text('Shutdown'),
],
),
),
],
),
].where((e) => e != null).toList().cast<Widget>(),
),
);
}

class PowerBar extends StatefulWidget {
const PowerBar({
super.key,
Expand Down
43 changes: 31 additions & 12 deletions lib/widgets/system_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@ import '../logic/power.dart';
import 'account_profile.dart';
import 'power.dart';

class SystemDrawer extends StatelessWidget {
class SystemDrawer extends StatefulWidget {
const SystemDrawer({
super.key,
this.userMode = false,
this.isLocked = false,
});

final bool userMode;
final bool isLocked;

@override
State<SystemDrawer> createState() => _SystemDrawerState();
}

class _SystemDrawerState extends State<SystemDrawer> {
final GlobalKey _powerButtonKey = GlobalKey();

@override
Widget build(BuildContext context) =>
Expand All @@ -21,8 +30,8 @@ class SystemDrawer extends StatelessWidget {
child: ListView(
shrinkWrap: true,
children: [
userMode && !Breakpoints.small.isActive(context) ? const AccountProfile() : null,
userMode ? Row(
widget.userMode && !Breakpoints.small.isActive(context) ? const AccountProfile() : null,
widget.userMode ? Row(
children: [
Expanded(
child: ButtonBar(),
Expand All @@ -31,21 +40,31 @@ class SystemDrawer extends StatelessWidget {
alignment: Alignment.centerRight,
child: ButtonBar(
children: [
!widget.isLocked
? IconButton(
style: IconButton.styleFrom(
shape: const LinearBorder(),
),
onPressed: () {},
icon: Icon(Icons.settings),
) : null,
IconButton(
key: _powerButtonKey,
style: IconButton.styleFrom(
shape: const LinearBorder(),
),
onPressed: () {},
icon: Icon(Icons.settings),
),
IconButton(
style: IconButton.styleFrom(
shape: const LinearBorder(),
),
onPressed: () {},
// TODO: on desktop, align to the button.
onPressed: () =>
showDialog(
context: context,
builder: (context) =>
PowerDialog(
isLocked: widget.isLocked,
),
),
icon: Icon(Icons.power),
),
],
].where((e) => e != null).toList().cast<Widget>(),
),
),
],
Expand Down
30 changes: 20 additions & 10 deletions lib/widgets/system_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class SystemLayout extends StatelessWidget {
super.key,
required this.body,
this.userMode = false,
this.isLocked = false,
this.bottomSheet,
});

final Widget body;
final bool userMode;
final bool isLocked;
final Widget? bottomSheet;

Widget _buildMobile(BuildContext context) =>
Expand Down Expand Up @@ -64,6 +66,7 @@ class SystemLayout extends StatelessWidget {
) : null,
SystemDrawer(
userMode: userMode,
isLocked: isLocked,
),
].where((e) => e != null).toList().cast<Widget>(),
),
Expand All @@ -86,17 +89,24 @@ class SystemLayout extends StatelessWidget {
child: const SystemBar(),
),
),
endDrawer: Drawer(
child: ListTileTheme(
tileColor: Theme.of(context).colorScheme.inversePrimary,
child: IconButtonTheme(
data: IconButtonThemeData(
style: IconButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
endDrawer: Padding(
padding: const EdgeInsets.all(8.0),
child: Drawer(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.0),
),
child: ListTileTheme(
tileColor: Theme.of(context).colorScheme.inversePrimary,
child: IconButtonTheme(
data: IconButtonThemeData(
style: IconButton.styleFrom(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
),
child: SystemDrawer(
userMode: userMode,
isLocked: isLocked,
),
),
child: SystemDrawer(
userMode: userMode,
),
),
),
Expand Down
4 changes: 3 additions & 1 deletion linux/channels/account.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern "C" {
#include "../application-priv.h"

static FlValue* new_string(const gchar* str) {
if (str == nullptr) return fl_value_new_null();
if (str == nullptr || g_utf8_strlen(str, -1) == 0) return fl_value_new_null();
return fl_value_new_string(str);
}

Expand All @@ -22,6 +22,8 @@ static FlValue* from_user(ActUser* usr) {
fl_value_set(value, fl_value_new_string("name"), new_string(act_user_get_user_name(usr)));
fl_value_set(value, fl_value_new_string("displayName"), new_string(act_user_get_real_name(usr)));
fl_value_set(value, fl_value_new_string("icon"), new_string(act_user_get_icon_file(usr)));
fl_value_set(value, fl_value_new_string("home"), new_string(act_user_get_home_dir(usr)));
fl_value_set(value, fl_value_new_string("passwordHint"), new_string(act_user_get_password_hint(usr)));
return value;
}

Expand Down

0 comments on commit c9bbef8

Please sign in to comment.