diff --git a/lib/src/proxmox_lister/proxmox_lister_list_view.dart b/lib/src/proxmox_lister/proxmox_lister_list_view.dart index f1efa51..2a5d8bd 100644 --- a/lib/src/proxmox_lister/proxmox_lister_list_view.dart +++ b/lib/src/proxmox_lister/proxmox_lister_list_view.dart @@ -5,7 +5,6 @@ import 'package:pi_dashboard/src/proxmox_webservice/model.dart'; import 'package:pi_dashboard/src/proxmox_webservice/service.dart'; import 'package:pi_dashboard/src/screen_helper.dart'; import 'package:pi_dashboard/src/settings/settings_controller.dart'; -import 'package:pi_dashboard/src/settings/settings_service.dart'; import '../settings/settings_view.dart'; import 'vm_card.dart'; @@ -69,60 +68,74 @@ class _ProxmoxListerState extends State { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text("Proxmox VMs"), - actions: [ - IconButton( - icon: const Icon(Icons.nightlight), - onPressed: () { - toggleScreen(); - }, - ), - IconButton( - icon: const Icon(Icons.sync), - onPressed: () { - syncVMs(); - }, - ), - IconButton( - icon: const Icon(Icons.settings), - onPressed: () { - Navigator.restorablePushNamed(context, SettingsView.routeName); - }, - ), - ], + // infinite touch container to turn screen back on + return Stack( + children: [ + Scaffold( + appBar: appbar(context), + body: bodyBuilder(context), ), - body: FutureBuilder( - future: nodes, - builder: (ctx, snapshot) { - if (snapshot.hasData) { - if (snapshot.requireData.isEmpty) { - return const Center(child: Icon(Icons.block)); - } - - final nodeEntry = snapshot.requireData.entries.first; - return ListView.builder( - restorationId: "proxmoxVMLister", - itemCount: nodeEntry.value.length, - itemBuilder: (BuildContext ctx, int index) { - return ProxmoxVmCard( - node: nodeEntry.key, - vm: nodeEntry.value[index], - pm_service: _service, - ); - }, - ); - } else if (snapshot.hasError) { - return AlertDialog( - title: const Text("error"), - content: Text(snapshot.error.toString()), - ); - } else { - return const Center(child: CircularProgressIndicator()); - } + screenActivator(), + ], + ); + } + + PreferredSizeWidget? appbar(BuildContext context) { + return AppBar( + title: const Text("Proxmox VMs"), + actions: [ + IconButton( + icon: const Icon(Icons.nightlight), + onPressed: () { + toggleScreen(); + }, + ), + IconButton( + icon: const Icon(Icons.sync), + onPressed: () { + syncVMs(); + }, + ), + IconButton( + icon: const Icon(Icons.settings), + onPressed: () { + Navigator.restorablePushNamed(context, SettingsView.routeName); }, - )); + ), + ], + ); + } + + Widget bodyBuilder(BuildContext context) { + return FutureBuilder( + future: nodes, + builder: (ctx, snapshot) { + if (snapshot.hasData) { + if (snapshot.requireData.isEmpty) { + return const Center(child: Icon(Icons.block)); + } + + final nodeEntry = snapshot.requireData.entries.first; + return ListView.builder( + restorationId: "proxmoxVMLister", + itemCount: nodeEntry.value.length, + itemBuilder: (BuildContext ctx, int index) { + return ProxmoxVmCard( + node: nodeEntry.key, + vm: nodeEntry.value[index], + pm_service: _service, + ); + }, + ); + } else if (snapshot.hasError) { + return AlertDialog( + title: const Text("error"), + content: Text(snapshot.error.toString()), + ); + } else { + return const Center(child: CircularProgressIndicator()); + } + }, + ); } - } diff --git a/lib/src/screen_helper.dart b/lib/src/screen_helper.dart index 404e020..580af19 100644 --- a/lib/src/screen_helper.dart +++ b/lib/src/screen_helper.dart @@ -1,34 +1,50 @@ import 'dart:io'; +import 'package:flutter/material.dart'; const _off = "1"; const _on = "0"; +bool _screenStatus = true; + Future toggleScreen() async { - if (await isScreenOff()) { - turnOncreen(); - } else { + if (_screenStatus) { turnOffScreen(); + } else { + turnOncreen(); } } Future turnOffScreen() async { await setBlFile(_off); + _screenStatus = false; } Future turnOncreen() async { await setBlFile(_on); + _screenStatus = true; } File blFile() { return File("/sys/class/backlight/10-0045/bl_power"); } -Future isScreenOff() async { - final status = await blFile().readAsString(); - if (status.startsWith(_on)) return false; - return true; -} - Future setBlFile(String content) async { await blFile().writeAsString(content); } + +Widget screenActivator() { + // only show when screen is dark + return Visibility( + visible: !_screenStatus, + child: SizedBox( + height: double.infinity, + width: double.infinity, + child: Material( + color: Colors.black, + child: InkWell(onTap: () async { + await turnOncreen(); + }), + ), + ), + ); +}