Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
fdennis committed Nov 8, 2023
1 parent 4233707 commit ab476ef
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions lib/desktop/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ const String _keyLeft = 'DESKTOP_WINDOW_LEFT';
const String _keyTop = 'DESKTOP_WINDOW_TOP';
const String _keyWidth = 'DESKTOP_WINDOW_WIDTH';
const String _keyHeight = 'DESKTOP_WINDOW_HEIGHT';
const String _logLevel = 'log-level';
const String _logFile = 'log-file';
const String _hidden = 'hidden';
const String _shown = 'shown';

void _saveWindowBounds(WindowManagerHelper helper) async {
final bounds = await helper.getBounds();
Expand Down Expand Up @@ -111,12 +115,12 @@ class _WindowEventListener extends WindowListener {
}

Future<Widget> initialize(List<String> argv) async {
var parser = ArgParser();
parser.addOption('log-file');
parser.addOption('log-level');
parser.addFlag('hidden');
parser.addFlag('shown');
var args = parser.parse(argv);
final parser = ArgParser();
parser.addOption(_logFile);
parser.addOption(_logLevel);
parser.addFlag(_hidden);
parser.addFlag(_shown);
final args = parser.parse(argv);
_initLogging(args);

await windowManager.ensureInitialized();
Expand Down Expand Up @@ -276,15 +280,11 @@ Future<RpcSession> _initHelper(String exe) async {
}

void _initLogging(ArgResults args) {
final path = args[_logFile];
final levelName = args[_logLevel];

File? file;
String path;
if (args['log-file'] != null) {
try {
path = args['log-file'];
} catch (e) {
throw InitializationException(
'USAGE: Missing argument for option --log-file');
}
if (path != null) {
file = File(path);
}

Expand All @@ -305,9 +305,8 @@ void _initLogging(ArgResults args) {
}
});

if (args['log-level'] != null) {
if (levelName != null) {
try {
final levelName = args['log-level'];
Level level = Levels.LEVELS
.firstWhere((level) => level.name == levelName.toUpperCase());
Logger.root.level = level;
Expand Down Expand Up @@ -342,8 +341,8 @@ void _initLicenses() async {
}

bool _getIsHidden(ArgResults args, SharedPreferences prefs) {
if (args['hidden'] || args['shown']) {
final isHidden = args['hidden'] && !args['shown'];
if (args[_hidden] || args[_shown]) {
final isHidden = args[_hidden] && !args[_shown];
prefs.setBool(windowHidden, isHidden);
return isHidden;
} else {
Expand Down

0 comments on commit ab476ef

Please sign in to comment.