Skip to content

Commit

Permalink
refactor: apply new lint suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Merrit committed Jan 16, 2023
1 parent 4d671d8 commit d3e8a40
Show file tree
Hide file tree
Showing 22 changed files with 98 additions and 92 deletions.
16 changes: 8 additions & 8 deletions lib/active_window/src/active_window.dart
Expand Up @@ -90,45 +90,45 @@ class ActiveWindow {
Future<bool> _suspend() async {
log.v('Suspending');

final _window = await _nativePlatform.activeWindow();
final window = await _nativePlatform.activeWindow();

log.v('Active window: $_window');
log.v('Active window: $window');

if (defaultTargetPlatform == TargetPlatform.windows) {
// Once in a blue moon on Windows we get "explorer.exe" as the active
// window, even when no file explorer windows are open / the desktop
// is not the active element, etc. So we filter it just in case.
if (_window.process.executable == 'explorer.exe') {
if (window.process.executable == 'explorer.exe') {
log.e('Only got explorer as active window!');
return false;
}
}

await _minimize(_window.id);
await _minimize(window.id);

// Small delay on Windows to ensure the window actually minimizes.
// Doesn't seem to be necessary on Linux.
if (defaultTargetPlatform == TargetPlatform.windows) {
await Future.delayed(const Duration(milliseconds: 500));
}

final suspended = await _processRepository.suspend(_window.process.pid);
final suspended = await _processRepository.suspend(window.process.pid);
if (!suspended) {
log.e('Failed to suspend active window.');
return false;
}

await _storageRepository.saveValue(
key: 'pid',
value: _window.process.pid,
value: window.process.pid,
storageArea: 'activeWindow',
);
await _storageRepository.saveValue(
key: 'windowId',
value: _window.id,
value: window.id,
storageArea: 'activeWindow',
);
log.v('Suspended ${_window.process.pid} successfully');
log.v('Suspended ${window.process.pid} successfully');

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/app/cubit/app_cubit.dart
@@ -1,6 +1,6 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../logs/logs.dart';
import '../../storage/storage_repository.dart';
Expand Down
6 changes: 3 additions & 3 deletions lib/app_version/app_version.dart
Expand Up @@ -18,9 +18,9 @@ class AppVersion {
String running() => _packageInfo.version;

Future<bool> updateAvailable() async {
final _runningVersion = semver.Version.parse(_packageInfo.version);
final _latestVersion = semver.Version.parse(await latest());
return (_runningVersion < _latestVersion) ? true : false;
final runningVersion = semver.Version.parse(_packageInfo.version);
final latestVersion = semver.Version.parse(await latest());
return (runningVersion < latestVersion) ? true : false;
}

/// Cached variable for `latest()`.
Expand Down
2 changes: 1 addition & 1 deletion lib/apps_list/cubit/apps_list_cubit.dart
@@ -1,10 +1,10 @@
import 'dart:async';
import 'dart:io' as io;

import 'package:bloc/bloc.dart';
import 'package:collection/collection.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../../settings/cubit/settings_cubit.dart';
import '../../../settings/settings_service.dart';
Expand Down
7 changes: 4 additions & 3 deletions lib/apps_list/widgets/custom_app_bar.dart
Expand Up @@ -43,7 +43,7 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
final currentVersion = state.runningVersion;
final latestVersion = state.updateVersion;
const url = 'https://nyrna.merritt.codes/download';
final _message = 'An update for Nyrna is available!\n\n'
final message = 'An update for Nyrna is available!\n\n'
'Current version: $currentVersion\n'
'Latest version: $latestVersion';

Expand All @@ -52,14 +52,15 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
builder: (context) {
return AlertDialog(
title: const Text('Update available'),
content: Text(_message),
content: Text(message),
actions: [
TextButton(
onPressed: () async {
final scaffoldMessenger = ScaffoldMessenger.of(context);
final launched = await AppCubit.instance.launchURL(url);

if (!launched) {
ScaffoldMessenger.of(context).showSnackBar(
scaffoldMessenger.showSnackBar(
const SnackBar(
content: Text('Error launching browser'),
),
Expand Down
10 changes: 5 additions & 5 deletions lib/apps_list/widgets/window_tile.dart
Expand Up @@ -33,17 +33,17 @@ class _WindowTileState extends State<WindowTile> {
@override
Widget build(BuildContext context) {
final window = widget.window;
Color _statusColor;
Color statusColor;

switch (window.process.status) {
case ProcessStatus.normal:
_statusColor = Colors.green;
statusColor = Colors.green;
break;
case ProcessStatus.suspended:
_statusColor = Colors.orange[700]!;
statusColor = Colors.orange[700]!;
break;
case ProcessStatus.unknown:
_statusColor = Colors.grey;
statusColor = Colors.grey;
}

return BlocProvider(
Expand All @@ -57,7 +57,7 @@ class _WindowTileState extends State<WindowTile> {
width: 25,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: (loading) ? null : _statusColor,
color: (loading) ? null : statusColor,
),
child: (loading) ? const CircularProgressIndicator() : null,
),
Expand Down
6 changes: 3 additions & 3 deletions lib/hotkey/hotkey_service.dart
Expand Up @@ -17,7 +17,7 @@ class HotkeyService {
await hotKeyManager.unregisterAll();
}

Future<void> updateHotkey(HotKey _hotKey) async {
Future<void> updateHotkey(HotKey hotKey) async {
// Hotkey service not working properly on Linux..
// - The method channel doesn't seem able to register `Pause` at all.
// - Hotkeys don't seem to work on Wayland.
Expand All @@ -26,11 +26,11 @@ class HotkeyService {
await hotKeyManager.unregisterAll();

await hotKeyManager.register(
_hotKey,
hotKey,
keyDownHandler: (hotKey) => _toggleActiveWindow(),
);

log.v('Registered hotkey: ${_hotKey.toStringHelper()}');
log.v('Registered hotkey: ${hotKey.toStringHelper()}');
}

Future<bool> _toggleActiveWindow() async {
Expand Down
2 changes: 1 addition & 1 deletion lib/loading/cubit/loading_cubit.dart
@@ -1,5 +1,5 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../native_platform/native_platform.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/logs/cubit/log_cubit.dart
@@ -1,5 +1,5 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../logs.dart';

Expand Down
4 changes: 3 additions & 1 deletion lib/logs/log_page.dart
Expand Up @@ -26,11 +26,13 @@ class LogPage extends StatelessWidget {
builder: (context, state) {
return ElevatedButton(
onPressed: () async {
final scaffoldMessenger = ScaffoldMessenger.of(context);
// Copy the visible logs to user's clipboard.
await Clipboard.setData(
ClipboardData(text: state.logsText),
);
ScaffoldMessenger.of(context).showSnackBar(

scaffoldMessenger.showSnackBar(
const SnackBar(
content: Text('Logs copied to clipboard'),
),
Expand Down
10 changes: 5 additions & 5 deletions lib/main.dart
Expand Up @@ -66,7 +66,7 @@ Future<void> main(List<String> args) async {
final nyrnaWindow = NyrnaWindow();

// Created outside runApp so it can be accessed for window settings below.
final _settingsCubit = await SettingsCubit.init(
final settingsCubit = await SettingsCubit.init(
assetToTempDir: assetToTempDir,
getWindowInfo: window.getWindowInfo,
prefs: settingsService,
Expand All @@ -88,7 +88,7 @@ Future<void> main(List<String> args) async {
),
lazy: false,
),
BlocProvider.value(value: _settingsCubit),
BlocProvider.value(value: settingsCubit),
BlocProvider(
create: (context) => ThemeCubit(settingsService),
),
Expand Down Expand Up @@ -185,16 +185,16 @@ Used with the `toggle` flag, `no-minimize` instructs Nyrna not to automatically
help: 'Output verbose logs for troubleshooting and debugging.',
);

final _helpText = _helpTextGreeting + _parser.usage + '\n\n';
final helpText = '$_helpTextGreeting${_parser.usage}\n\n';

try {
final result = _parser.parse(args);
if (result.rest.isNotEmpty) {
stdout.writeln(_helpText);
stdout.writeln(helpText);
exit(0);
}
} on ArgParserException {
stdout.writeln(_helpText);
stdout.writeln(helpText);
exit(0);
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/native_platform/src/linux/linux.dart
Expand Up @@ -118,17 +118,17 @@ class Linux implements NativePlatform {
// Returns the unique hex ID of the active window as reported by xdotool.
Future<int> _activeWindowId() async {
final result = await _run('xdotool', ['getactivewindow']);
final _windowId = int.tryParse(result.stdout.toString().trim());
return _windowId ?? 0;
final windowId = int.tryParse(result.stdout.toString().trim());
return windowId ?? 0;
}

Future<int> _activeWindowPid(int windowId) async {
final result = await _run(
'xdotool',
['getwindowpid', '$windowId'],
);
final _pid = int.tryParse(result.stdout.toString().trim());
return _pid ?? 0;
final pid = int.tryParse(result.stdout.toString().trim());
return pid ?? 0;
}

Future<String> _activeWindowTitle() async {
Expand Down
Expand Up @@ -50,7 +50,7 @@ class Win32ProcessRepository extends ProcessRepository {

// Pull the value from the pointer.
// Discard all of path except the executable name.
final _executable = path.toDartString().split('\\').last;
final executable = path.toDartString().split('\\').last;

// Free the pointer's memory.
calloc.free(path);
Expand All @@ -60,7 +60,7 @@ class Win32ProcessRepository extends ProcessRepository {
log.e('get executable failed to close the process handle.');
}

return _executable;
return executable;
}

@override
Expand All @@ -77,7 +77,7 @@ class Win32ProcessRepository extends ProcessRepository {
],
);

ProcessStatus _status;
ProcessStatus status;

if (result.stderr != '') {
log.w('Unable to get process status', result.stderr);
Expand All @@ -100,11 +100,11 @@ class Win32ProcessRepository extends ProcessRepository {
}

// If every thread has the `Suspended` status, process is suspended.
_status = suspended.contains(false)
status = suspended.contains(false)
? ProcessStatus.normal
: ProcessStatus.suspended;

return _status;
return status;
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/native_platform/src/win32/ffi/user32.dart
Expand Up @@ -2,7 +2,7 @@
///
/// https://docs.microsoft.com/en-us/windows/win32/api/winuser/
// ignore_for_file: non_constant_identifier_names
// ignore_for_file: non_constant_identifier_names, no_leading_underscores_for_local_identifiers

import 'dart:ffi';

Expand Down
4 changes: 2 additions & 2 deletions lib/native_platform/src/win32/win32.dart
Expand Up @@ -135,7 +135,7 @@ class Win32 implements NativePlatform {

// Pull the value from the pointer.
// Discard all of path except the executable name.
final _executable = path.toDartString().split('\\').last;
final executable = path.toDartString().split('\\').last;

// Free the pointer's memory.
calloc.free(path);
Expand All @@ -145,7 +145,7 @@ class Win32 implements NativePlatform {
log.e('Failed to close the process handle.');
}

return _executable;
return executable;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/settings/cubit/settings_cubit.dart
Expand Up @@ -2,10 +2,10 @@ import 'dart:convert';
import 'dart:io';
import 'dart:ui';

import 'package:bloc/bloc.dart';
import 'package:desktop_integration/desktop_integration.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hotkey_manager/hotkey_manager.dart';
import 'package:window_size/window_size.dart' show PlatformWindow;

Expand Down
3 changes: 2 additions & 1 deletion lib/settings/widgets/behaviour_section.dart
Expand Up @@ -135,6 +135,7 @@ class RecordHotKeyDialog extends StatefulWidget {
}) : super(key: key);

@override
// ignore: library_private_types_in_public_api
_RecordHotKeyDialogState createState() => _RecordHotKeyDialogState();
}

Expand Down Expand Up @@ -196,13 +197,13 @@ class _RecordHotKeyDialogState extends State<RecordHotKeyDialog> {
},
),
TextButton(
child: const Text('OK'),
onPressed: _hotKey == null
? null
: () {
settingsCubit.updateHotkey(_hotKey!);
Navigator.of(context).pop();
},
child: const Text('OK'),
),
],
);
Expand Down
10 changes: 5 additions & 5 deletions lib/system_tray/system_tray_manager.dart
Expand Up @@ -17,11 +17,6 @@ class SystemTrayManager {

await trayManager.setIcon(iconPath);

Future<void> _showWindow() async {
await _window.show();
await appsListCubit.manualRefresh();
}

final Menu menu = Menu(
items: [
MenuItem(label: 'Show', onClick: (menuItem) => _showWindow()),
Expand All @@ -32,4 +27,9 @@ class SystemTrayManager {

await trayManager.setContextMenu(menu);
}

Future<void> _showWindow() async {
await _window.show();
await appsListCubit.manualRefresh();
}
}
2 changes: 1 addition & 1 deletion lib/theme/cubit/theme_cubit.dart
@@ -1,6 +1,6 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

import '../../settings/settings_service.dart';
import '../theme.dart';
Expand Down

0 comments on commit d3e8a40

Please sign in to comment.