Skip to content

Commit

Permalink
Cleanup unused code & code comments (mainly)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechAurelian committed Dec 4, 2024
1 parent b185fd3 commit 9b90b4b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 43 deletions.
6 changes: 3 additions & 3 deletions lib/common/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ AppPreference<int> testColorIndex = AppPreference<int>(
);

/// The app preference for showing the tip on the test screen.
AppPreference<bool> showTip = AppPreference<bool>(
AppPreference<bool> showInspectionModeTip = AppPreference<bool>(
defaultValue: true,
key: 'showTip',
key: 'showInspectionModeTip',
);

/// Loads app settings from persistent storage.
Future<void> load() async {
try {
SharedPreferences preferences = await SharedPreferences.getInstance();
testColorIndex.loadValue(preferences);
showTip.loadValue(preferences);
showInspectionModeTip.loadValue(preferences);
} catch (e) {
// We can ignore errors here, as the default values will be used.
// ignore: avoid_print
Expand Down
9 changes: 1 addition & 8 deletions lib/common/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,12 @@ const String appName = 'InjuredPixels';
// -----------------------------------------------------------------------------------------------

const String inspectionModeButton = 'Inspection Mode';
String showTipMenuItem(bool show) => show ? 'Show tip' : 'Hide tip';
const String inspectionModeTipMenuItem = 'Inspection mode tip';
const String helpMenuItem = 'Online help';
const String supportMenuItem = 'Contact support';
const String supportUsMenuItem = 'Support us';

// String testScreenTip(bool mouseIsConnected) =>
// '<b>Long ${mouseIsConnected ? 'click' : 'tap'}</b> the color screen or press <b>Space</b> to toggle inspection mode. <b>Double ${mouseIsConnected ? 'click' : 'tap'}</b> or use <b>arrow keys</b> to cycle colors. <b>Go fullscreen</b> to inspect all pixels.';

// String testScreenTip(bool mouseIsConnected) =>
// '<b>Long ${mouseIsConnected ? 'click' : 'tap'}</b> the color screen or press <b>Space</b> to toggle inspection mode. <b>Double ${mouseIsConnected ? 'click' : 'tap'}</b> or use <b>arrow keys</b> to cycle colors. Make sure you are running the app in <b>fullscreen mode</b> to inspect all pixels.';

String testScreenTip(bool mouseIsConnected) =>
'<b>Long ${mouseIsConnected ? 'click' : 'tap'}</b> the color screen or press <b>Space</b> to toggle inspection mode. <b>Double ${mouseIsConnected ? 'click' : 'tap'}</b> or use <b>arrow keys</b> to cycle colors. Run the app <b>fullscreen</b> to inspect all pixels.';

const String okButton = 'OK';
const String dontShowAgainButton = 'Don\'t show again';
5 changes: 0 additions & 5 deletions lib/common/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,5 @@ ThemeData getAppTheme(Brightness brightness) {
dividerTheme: DividerThemeData(
color: contrastColor,
),
// appBarTheme: const AppBarTheme(
// actionsIconTheme: IconThemeData(
// size: 32.0,
// ),
// ),
);
}
38 changes: 20 additions & 18 deletions lib/screens/test_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class TestScreen extends StatefulWidget {
}

class _TestScreenState extends State<TestScreen> {
/// Whether the mouse is connected to the device. Used to update the tip text terminology
/// ("click" or "tap").
/// Whether a mouse is connected. Used to update the tip text terminology ("click" or "tap").
bool _mouseIsConnected = false;

/// The focus node for the body of the screen, used to capture key events.
Expand All @@ -39,6 +38,7 @@ class _TestScreenState extends State<TestScreen> {
/// Whether we are in inspection mode, which hides all UI elements except the color screen.
bool _inInspectionMode = false;

/// Whether to show the inspection mode tip.
bool _showInspectionModeTip = true;

@override
Expand Down Expand Up @@ -80,7 +80,7 @@ class _TestScreenState extends State<TestScreen> {
});
}

/// Handles the key events for changing colors and toggling the control panel visibility.
/// Handles the key events for changing colors and toggling the inspection mode.
void _handleKeys(KeyEvent event) {
if (event is! KeyDownEvent && event is! KeyRepeatEvent) {
return;
Expand All @@ -95,8 +95,7 @@ class _TestScreenState extends State<TestScreen> {
case LogicalKeyboardKey.arrowRight:
_nextColor();
break;
// Toggle the control panel visibility when the space key is pressed
// case LogicalKeyboardKey.space:
// Toggle the inspection mode when the space key is pressed
case LogicalKeyboardKey.space:
_toggleInspectionMode();
break;
Expand All @@ -112,7 +111,7 @@ class _TestScreenState extends State<TestScreen> {

// If entering inspection mode, show the tip if it was not hidden permanently
if (!_showInspectionModeTip) {
setState(() => _showInspectionModeTip = prefs.showTip.value);
setState(() => _showInspectionModeTip = prefs.showInspectionModeTip.value);
}

// Toggle the inspection mode state and update the UI by hiding or showing the controls
Expand All @@ -130,7 +129,7 @@ class _TestScreenState extends State<TestScreen> {
break;

case _AppBarActions.toggleTip:
setState(() => prefs.showTip.value = !prefs.showTip.value);
setState(() => prefs.showInspectionModeTip.value = !prefs.showInspectionModeTip.value);
break;

case _AppBarActions.help:
Expand All @@ -155,8 +154,7 @@ class _TestScreenState extends State<TestScreen> {
return Scaffold(
backgroundColor: currentColor,

// Use a KeyboardListener to capture key events for cycling through test colors and toggling
// the control panel visibility
// Capture key events for cycling through test colors and toggling the inspection mode
body: KeyboardListener(
focusNode: _bodyFocusNode,
autofocus: true,
Expand All @@ -165,12 +163,12 @@ class _TestScreenState extends State<TestScreen> {
alignment: Alignment.center,
children: <Widget>[
// Fill the screen with a gesture detector to detect gestures for cycling through test
// colors and toggling the control panel visibility
// colors and toggling the inspection mode
Positioned.fill(
child: GestureDetector(
// Go to the next color on double tap and hide the cycle part of the tip
onDoubleTap: () => _nextColor(),
// Toggle the control panel visibility on long press and hide the control panel part of the tip
// Toggle the inspection mode on long press
onLongPress: () => _toggleInspectionMode(),
),
),
Expand All @@ -185,6 +183,7 @@ class _TestScreenState extends State<TestScreen> {
right: 0.0,
child: _AppBar(
foregroundColor: contrastColor,
inspectionModeTipStatus: _showInspectionModeTip,
onAction: _onAction,
),
),
Expand All @@ -199,7 +198,7 @@ class _TestScreenState extends State<TestScreen> {
),
],

/// Show the tip text at the bottom of the screen
/// Show the inspection mode tip when in inspection mode and the tip is not hidden
if (_inInspectionMode && _showInspectionModeTip)
Container(
alignment: Alignment.center,
Expand All @@ -209,7 +208,7 @@ class _TestScreenState extends State<TestScreen> {
foregroundColor: contrastColor,
onOkPressed: () => setState(() => _showInspectionModeTip = false),
onDontShowAgainPressed: () => setState(() {
prefs.showTip.value = false;
prefs.showInspectionModeTip.value = false;
_showInspectionModeTip = false;
}),
),
Expand All @@ -234,19 +233,21 @@ class _AppBar extends StatelessWidget implements PreferredSizeWidget {
const _AppBar({
super.key, // ignore: unused_element
required this.foregroundColor,
required this.inspectionModeTipStatus,
required this.onAction,
});

/// The foreground color of the app bar used for the text and icons.
final Color foregroundColor;

/// The status of the inspection mode tip menu item (checked or unchecked).
final bool inspectionModeTipStatus;

/// The callback that is called when an app bar action is pressed.
final void Function(_AppBarActions action) onAction;

@override
Widget build(BuildContext context) {
// final bool isLargeScreen = MediaQuery.of(context).size.width > 600.0;

return AppBar(
forceMaterialTransparency: true,
foregroundColor: foregroundColor,
Expand All @@ -268,10 +269,11 @@ class _AppBar extends StatelessWidget implements PreferredSizeWidget {
PopupMenuButton<_AppBarActions>(
onSelected: onAction,
itemBuilder: (BuildContext context) => <PopupMenuEntry<_AppBarActions>>[
// The Toggle tip menu item
PopupMenuItem<_AppBarActions>(
// The Inspection mode tip menu item
CheckedPopupMenuItem<_AppBarActions>(
value: _AppBarActions.toggleTip,
child: Text(strings.showTipMenuItem(!prefs.showTip.value)),
checked: inspectionModeTipStatus,
child: const Text(strings.inspectionModeTipMenuItem),
),

const PopupMenuDivider(),
Expand Down
15 changes: 6 additions & 9 deletions lib/utils/web_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,24 @@
// See the LICENSE file in the project root for license information.
// @author TechAurelian <dev@techaurelian.com> (https://techaurelian.com)

import 'package:web/web.dart';
/// Web utilities for the InjuredPixels web app.
library;

/// Toggles the fullscreen mode of the web app.
void toggleFullscreen() async {
if (isDocumentFullscreen()) {
document.exitFullscreen();
} else {
document.documentElement?.requestFullscreen();
}
}
import 'package:web/web.dart';

/// Makes the web app go fullscreen.
void enterFullscreen() {
if (!isDocumentFullscreen()) {
document.documentElement?.requestFullscreen();
}
}

/// Makes the web app exit fullscreen.
void exitFullscreen() {
if (isDocumentFullscreen()) {
document.exitFullscreen();
}
}

/// Returns whether the web app is in fullscreen mode.
bool isDocumentFullscreen() => document.fullscreenElement != null;

0 comments on commit 9b90b4b

Please sign in to comment.