2021-11-02 02:29:58 +00:00
|
|
|
import 'package:cwtch/models/servers.dart';
|
|
|
|
import 'package:cwtch/views/addeditservers.dart';
|
2021-11-02 04:45:27 +00:00
|
|
|
import 'package:cwtch/widgets/passwordfield.dart';
|
2021-11-02 02:29:58 +00:00
|
|
|
import 'package:cwtch/widgets/serverrow.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:cwtch/torstatus.dart';
|
|
|
|
import 'package:cwtch/widgets/tor_icon.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
2021-11-02 04:45:27 +00:00
|
|
|
import '../cwtch_icons_icons.dart';
|
2021-11-02 02:29:58 +00:00
|
|
|
import '../main.dart';
|
2021-11-02 04:45:27 +00:00
|
|
|
import '../settings.dart';
|
2021-11-02 02:29:58 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
class ServersView extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_ServersView createState() => _ServersView();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ServersView extends State<ServersView> {
|
2021-11-02 04:45:27 +00:00
|
|
|
final ctrlrPassword = TextEditingController();
|
|
|
|
|
2021-11-02 02:29:58 +00:00
|
|
|
@override
|
|
|
|
void dispose() {
|
2021-11-02 04:45:27 +00:00
|
|
|
ctrlrPassword.dispose();
|
2021-11-02 02:29:58 +00:00
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
2021-12-18 18:51:52 +00:00
|
|
|
backgroundColor: Provider.of<Settings>(context, listen: false).theme.backgroundMainColor,
|
2021-11-25 23:59:54 +00:00
|
|
|
appBar: AppBar(
|
|
|
|
title: Text(MediaQuery.of(context).size.width > 600 ? AppLocalizations.of(context)!.serversManagerTitleLong : AppLocalizations.of(context)!.serversManagerTitleShort),
|
|
|
|
actions: getActions(),
|
2021-11-02 02:29:58 +00:00
|
|
|
),
|
2021-11-25 23:59:54 +00:00
|
|
|
floatingActionButton: FloatingActionButton(
|
|
|
|
onPressed: _pushAddServer,
|
|
|
|
tooltip: AppLocalizations.of(context)!.addServerTooltip,
|
|
|
|
child: Icon(
|
|
|
|
Icons.add,
|
|
|
|
semanticLabel: AppLocalizations.of(context)!.addServerTooltip,
|
2022-04-15 00:50:53 +00:00
|
|
|
color: Provider.of<Settings>(context).theme.defaultButtonTextColor,
|
2021-11-25 23:59:54 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
body: Consumer<ServerListState>(
|
|
|
|
builder: (context, svrs, child) {
|
|
|
|
final tiles = svrs.servers.map(
|
|
|
|
(ServerInfoState server) {
|
|
|
|
return ChangeNotifierProvider<ServerInfoState>.value(
|
|
|
|
value: server,
|
|
|
|
builder: (context, child) => RepaintBoundary(child: ServerRow()),
|
|
|
|
);
|
|
|
|
},
|
2021-11-02 02:29:58 +00:00
|
|
|
);
|
|
|
|
|
2021-11-25 23:59:54 +00:00
|
|
|
final divided = ListTile.divideTiles(
|
|
|
|
context: context,
|
|
|
|
tiles: tiles,
|
|
|
|
).toList();
|
2021-11-02 02:29:58 +00:00
|
|
|
|
2021-11-25 23:59:54 +00:00
|
|
|
if (tiles.isEmpty) {
|
|
|
|
return Center(
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context)!.unlockServerTip,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
));
|
|
|
|
}
|
2021-11-02 02:29:58 +00:00
|
|
|
|
2021-11-25 23:59:54 +00:00
|
|
|
return ListView(children: divided);
|
|
|
|
},
|
|
|
|
));
|
2021-11-02 02:29:58 +00:00
|
|
|
}
|
|
|
|
|
2021-11-02 04:45:27 +00:00
|
|
|
List<Widget> getActions() {
|
|
|
|
List<Widget> actions = new List<Widget>.empty(growable: true);
|
|
|
|
|
|
|
|
// Unlock Profiles
|
|
|
|
actions.add(IconButton(
|
|
|
|
icon: Icon(CwtchIcons.lock_open_24px),
|
2021-12-10 04:22:55 +00:00
|
|
|
color: Provider.of<ServerListState>(context).servers.isEmpty ? Provider.of<Settings>(context).theme.defaultButtonColor : Provider.of<Settings>(context).theme.mainTextColor,
|
2021-11-02 04:45:27 +00:00
|
|
|
tooltip: AppLocalizations.of(context)!.tooltipUnlockProfiles,
|
|
|
|
onPressed: _modalUnlockServers,
|
|
|
|
));
|
|
|
|
|
|
|
|
return actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _modalUnlockServers() {
|
|
|
|
showModalBottomSheet<void>(
|
|
|
|
context: context,
|
|
|
|
isScrollControlled: true,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return Padding(
|
|
|
|
padding: MediaQuery.of(context).viewInsets,
|
|
|
|
child: RepaintBoundary(
|
|
|
|
child: Container(
|
2021-11-25 23:59:54 +00:00
|
|
|
height: 200, // bespoke value courtesy of the [TextField] docs
|
|
|
|
child: Center(
|
|
|
|
child: Padding(
|
|
|
|
padding: EdgeInsets.all(10.0),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
Text(AppLocalizations.of(context)!.enterServerPassword),
|
|
|
|
SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
CwtchPasswordField(
|
|
|
|
autofocus: true,
|
|
|
|
controller: ctrlrPassword,
|
|
|
|
action: unlock,
|
|
|
|
validator: (value) {},
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [
|
|
|
|
Spacer(),
|
|
|
|
Expanded(
|
|
|
|
child: ElevatedButton(
|
|
|
|
child: Text(AppLocalizations.of(context)!.unlock, semanticsLabel: AppLocalizations.of(context)!.unlock),
|
|
|
|
onPressed: () {
|
|
|
|
unlock(ctrlrPassword.value.text);
|
|
|
|
},
|
|
|
|
)),
|
|
|
|
Spacer()
|
|
|
|
]),
|
|
|
|
],
|
|
|
|
))),
|
|
|
|
)));
|
2021-11-02 04:45:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void unlock(String password) {
|
|
|
|
Provider.of<FlwtchState>(context, listen: false).cwtch.LoadServers(password);
|
|
|
|
ctrlrPassword.text = "";
|
|
|
|
Navigator.pop(context);
|
|
|
|
}
|
|
|
|
|
2021-11-02 02:29:58 +00:00
|
|
|
void _pushAddServer() {
|
|
|
|
Navigator.of(context).push(MaterialPageRoute<void>(
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return MultiProvider(
|
2021-11-25 23:59:54 +00:00
|
|
|
providers: [
|
|
|
|
ChangeNotifierProvider<ServerInfoState>(
|
|
|
|
create: (_) => ServerInfoState(onion: "", serverBundle: "", description: "", autoStart: true, running: false, isEncrypted: true),
|
|
|
|
)
|
|
|
|
],
|
2021-11-02 02:29:58 +00:00
|
|
|
child: AddEditServerView(),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|