Skip to content

Commit

Permalink
style: Resolve all dart analyzer issues
Browse files Browse the repository at this point in the history
Converted some variables to final, added missing trailing commas, fixed some typing, etc.
  • Loading branch information
ashuntu committed Oct 9, 2024
1 parent f284696 commit ef4629d
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 84 deletions.
10 changes: 5 additions & 5 deletions packages/game_center/lib/app/app_pages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,34 @@ final pages = <AppPage>[
leading: Icon(LauncherPage.icon(selected)),
title: Text(LauncherPage.label(context)),
),
pageBuilder: (_) => LauncherPage()
pageBuilder: (_) => const LauncherPage()
),
(
titleBuilder: (context, selected) => YaruMasterTile(
leading: Icon(SteamPage.icon(selected)),
title: Text(SteamPage.label(context)),
),
pageBuilder: (_) => SteamPage(),
pageBuilder: (_) => const SteamPage(),
),
(
titleBuilder: (context, selected) => YaruMasterTile(
leading: Icon(SystemPage.icon(selected)),
title: Text(SystemPage.label(context)),
),
pageBuilder: (_) => SystemPage()
pageBuilder: (_) => const SystemPage()
),
(
titleBuilder: (context, selected) => YaruMasterTile(
leading: Icon(SettingsPage.icon(selected)),
title: Text(SettingsPage.label(context)),
),
pageBuilder: (_) => SettingsPage()
pageBuilder: (_) => const SettingsPage()
),
(
titleBuilder: (context, selected) => YaruMasterTile(
leading: Icon(AboutPage.icon(selected)),
title: Text(AboutPage.label(context)),
),
pageBuilder: (_) => AboutPage()
pageBuilder: (_) => const AboutPage()
),
];
2 changes: 1 addition & 1 deletion packages/game_center/lib/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension TextStyleToMono on TextStyle {
}

class AppScrollView extends StatelessWidget {
AppScrollView({required this.children});
const AppScrollView({required this.children, super.key});

final List<Widget> children;

Expand Down
5 changes: 3 additions & 2 deletions packages/game_center/lib/steam/proton_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ProtonModel extends _$ProtonModel {
late String installLocation;
late List<String> protonVersions;

@override
Future<List<String>> build({String? install}) async {
// default install location
if (install == null) {
Expand All @@ -27,12 +28,12 @@ class ProtonModel extends _$ProtonModel {

// directory isn't created by Steam by default, so ensure it exists
final protonDir = Directory(protonDirectory(installLocation));
protonDir.create(recursive: true);
await protonDir.create(recursive: true);

await updateProtonVersions();

final fileSystem = FileWatcher(protonDirectory(installLocation));
fileSystem.events.listen((event) async => await updateProtonVersions());
fileSystem.events.listen((event) async => updateProtonVersions());

return protonVersions;
}
Expand Down
102 changes: 55 additions & 47 deletions packages/game_center/lib/steam/steam_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'dart:io';

import 'package:game_center/steam/steam_data.dart';
import 'package:game_center/util.dart';
import 'package:path/path.dart' as path;
import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:vdf/vdf.dart';
import 'package:watcher/watcher.dart';
import 'package:path/path.dart' as path;

part 'steam_model.g.dart';

Expand All @@ -24,8 +24,9 @@ class SteamUser {
factory SteamUser.fromConfig(Map<String, dynamic> config) {
final id = config['UserLocalConfigStore']['friends'].keys.first;
return SteamUser(
id: id,
name: config['UserLocalConfigStore']['friends'][id]['NameHistory']['0'],
id: id as String,
name: config['UserLocalConfigStore']['friends'][id]['NameHistory']['0']
as String,
);
}

Expand Down Expand Up @@ -68,7 +69,7 @@ class SteamModel extends _$SteamModel {

// user configs
final users = await listUserDirs();
userConfigs = new Map();
userConfigs = {};
for (final steamID in users) {
final file = File(steamUserConfig(installLocation, steamID));
userConfigs[steamID] = vdfDecode(await file.readAsString());
Expand All @@ -92,40 +93,46 @@ class SteamModel extends _$SteamModel {
}

Future<List<String>> listUserDirs() async {
var userdata =
await Directory('$installLocation/$steamDataDir/userdata').list();
var directories =
final userdata =
Directory('$installLocation/$steamDataDir/userdata').list();
final directories =
userdata.where((x) => x is Directory).map((x) => x as Directory);
return directories.map((dir) => path.basename(dir.path)).toList();
}

Future<void> updateGlobalConfig() async {
final file = File(steamGlobalConfig(installLocation));
globalConfig = vdfDecode(await file.readAsString());
state = AsyncData((
globalConfig: globalConfig,
userConfigs: userConfigs,
activeUser: activeUser,
));
state = AsyncData(
(
globalConfig: globalConfig,
userConfigs: userConfigs,
activeUser: activeUser,
),
);
}

Future<void> updateUserConfig(String steamID) async {
final file = File(steamUserConfig(installLocation, steamID));
userConfigs[steamID] = vdfDecode(await file.readAsString());
state = AsyncData((
globalConfig: globalConfig,
userConfigs: userConfigs,
activeUser: activeUser,
));
state = AsyncData(
(
globalConfig: globalConfig,
userConfigs: userConfigs,
activeUser: activeUser,
),
);
}

Future<void> setActiveUser(String newActiveUserID) async {
activeUser = SteamUser.fromConfig(userConfigs[newActiveUserID]!);
state = AsyncData((
globalConfig: globalConfig,
userConfigs: userConfigs,
activeUser: activeUser,
));
state = AsyncData(
(
globalConfig: globalConfig,
userConfigs: userConfigs,
activeUser: activeUser,
),
);
}

/// Enable/disable Steam Play (Proton) for all titles globally. This is
Expand All @@ -135,7 +142,7 @@ class SteamModel extends _$SteamModel {
required bool enable,
String? protonVersion,
}) async {
Map<String, dynamic> config = Map.from(globalConfig);
var config = Map<String, dynamic>.from(globalConfig);
if (enable) {
config = Map.castFrom(
safePut(
Expand All @@ -146,7 +153,7 @@ class SteamModel extends _$SteamModel {
'Valve',
'Steam',
'CompatToolMapping',
'0'
'0',
],
{
'name': protonVersion ?? 'proton_experimental',
Expand All @@ -164,7 +171,7 @@ class SteamModel extends _$SteamModel {
'Software',
'Valve',
'Steam',
'CompatToolMapping'
'CompatToolMapping',
],
{},
),
Expand All @@ -173,21 +180,22 @@ class SteamModel extends _$SteamModel {

final file = File(steamGlobalConfig(installLocation));
await file.writeAsString(vdf.encode(config));
await updateGlobalConfig();
}

/// Check if Steam Play is enabled in the global config.
bool steamPlayEnabled() {
Map<String, dynamic> config = Map.from(globalConfig);
final config = Map.from(globalConfig);
final key = config['InstallConfigStore']?['Software']?['Valve']?['Steam']
?['CompatToolMapping'];
Map<String, dynamic> compat = Map.castFrom(key ?? new Map());
return compat.containsKey('0') && compat['0'].isNotEmpty;
final compat = Map.castFrom(key != null ? key as Map : {});
return compat.containsKey('0') && (compat['0'] as Map).isNotEmpty;
}

/// Get a map of installed Steam apps for the given user.
Map<String, dynamic> listApps({required String steamID}) {
Map<String, dynamic> config = Map.from(userConfigs[steamID]!);
var apps = config['UserLocalConfigStore']['Software']['Valve']['Steam']
final config = Map.from(userConfigs[steamID]!);
final apps = config['UserLocalConfigStore']['Software']['Valve']['Steam']
['apps'] as Map;
return apps.cast<String, dynamic>();
}
Expand All @@ -199,7 +207,7 @@ class SteamModel extends _$SteamModel {
final apps = listApps(steamID: steamID);
for (final app in apps.keys) {
final launchOptions = getGameLaunchOptions(steamID: steamID, appID: app);
List<String> options =
final options =
launchOptions.isEmpty ? [] : launchOptions.split(RegExp(r'\s+'));
if (!options.contains(option)) {
return false;
Expand All @@ -213,9 +221,9 @@ class SteamModel extends _$SteamModel {
required String steamID,
required String appID,
}) {
Map<String, dynamic> config = Map.from(userConfigs[steamID]!);
String? launchOptions = config['UserLocalConfigStore']['Software']['Valve']
['Steam']['apps'][appID]['LaunchOptions'];
final config = Map.from(userConfigs[steamID]!);
final launchOptions = config['UserLocalConfigStore']['Software']['Valve']
['Steam']['apps'][appID]['LaunchOptions'] as String?;
return launchOptions ?? '';
}

Expand All @@ -225,7 +233,7 @@ class SteamModel extends _$SteamModel {
required String appID,
required String options,
}) async {
Map<String, dynamic> config = Map.from(userConfigs[steamID]!);
final config = Map<String, dynamic>.from(userConfigs[steamID]!);
config['UserLocalConfigStore']['Software']['Valve']['Steam']['apps'][appID]
['LaunchOptions'] = options;
final file = File(steamUserConfig(installLocation, steamID));
Expand All @@ -237,14 +245,14 @@ class SteamModel extends _$SteamModel {
required String steamID,
required String option,
}) async {
Map<String, dynamic> config = Map.from(userConfigs[steamID]!);
final apps = await listApps(steamID: steamID);
final config = Map<String, dynamic>.from(userConfigs[steamID]!);
final apps = listApps(steamID: steamID);
for (final app in apps.keys) {
final launchOptions = await getGameLaunchOptions(
final launchOptions = getGameLaunchOptions(
steamID: steamID,
appID: app,
);
List<String> options =
final options =
launchOptions.isEmpty ? [] : launchOptions.split(RegExp(r'\s+'));
if (!options.contains(option)) {
options.insert(0, option);
Expand All @@ -266,14 +274,14 @@ class SteamModel extends _$SteamModel {
required String steamID,
required String option,
}) async {
Map<String, dynamic> config = Map.from(userConfigs[steamID]!);
final apps = await listApps(steamID: steamID);
final config = Map<String, dynamic>.from(userConfigs[steamID]!);
final apps = listApps(steamID: steamID);
for (final app in apps.keys) {
final launchOptions = await getGameLaunchOptions(
final launchOptions = getGameLaunchOptions(
steamID: steamID,
appID: app,
);
List<String> options =
final options =
launchOptions.isEmpty ? [] : launchOptions.split(RegExp(r'\s+'));
options.remove(option);
config['UserLocalConfigStore']['Software']['Valve']['Steam']['apps'][app]
Expand All @@ -292,11 +300,11 @@ class SteamModel extends _$SteamModel {
required String appID,
required String option,
}) async {
String launchOptions = await getGameLaunchOptions(
final launchOptions = getGameLaunchOptions(
steamID: steamID,
appID: appID,
);
List<String> options =
final options =
launchOptions.isEmpty ? [] : launchOptions.split(RegExp(r'\s+'));
if (!options.contains(option)) {
options.insert(0, option);
Expand All @@ -318,11 +326,11 @@ class SteamModel extends _$SteamModel {
required String appID,
required String option,
}) async {
String launchOptions = await getGameLaunchOptions(
final launchOptions = getGameLaunchOptions(
steamID: steamID,
appID: appID,
);
List<String> options =
final options =
launchOptions.isEmpty ? [] : launchOptions.split(RegExp(r'\s+'));
options.remove(option);
await setGameLaunchOptions(
Expand Down
20 changes: 12 additions & 8 deletions packages/game_center/lib/steam/steam_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SteamPage extends ConsumerWidget {
child: Text(data.activeUser.name),
itemBuilder: (context) => data.userConfigs.values.map(
(id) {
var user = SteamUser.fromConfig(id);
final user = SteamUser.fromConfig(id);
return PopupMenuItem(
child: Text(user.name),
onTap: () => notifier.setActiveUser(user.id),
Expand Down Expand Up @@ -75,7 +75,7 @@ class SteamPage extends ConsumerWidget {
child: Text(l10n.loadingLabel),
),
error: (error, stackTrace) => Center(
child: Text('${error.toString()}\n${stackTrace.toString()}'),
child: Text('$error\n$stackTrace'),
),
);
}
Expand All @@ -100,7 +100,9 @@ class _SteamSimpleSettings extends ConsumerWidget {
YaruSwitchListTile(
title: Text(l10n.steamEnableMangoHUD),
value: steam.allGamesHaveOption(
steamID: steam.activeUser.id, option: 'mangohud'),
steamID: steam.activeUser.id,
option: 'mangohud',
),
onChanged: (value) async {
value
? await steam.addAllGameLaunchOption(
Expand All @@ -116,7 +118,9 @@ class _SteamSimpleSettings extends ConsumerWidget {
YaruSwitchListTile(
title: Text(l10n.steamEnableGameMode),
value: steam.allGamesHaveOption(
steamID: steam.activeUser.id, option: 'gamemoderun'),
steamID: steam.activeUser.id,
option: 'gamemoderun',
),
onChanged: (value) async {
value
? await steam.addAllGameLaunchOption(
Expand Down Expand Up @@ -167,7 +171,7 @@ class _SteamGlobalConfigText extends ConsumerWidget {
Widget build(BuildContext context, WidgetRef ref) {
final l10n = AppLocalizations.of(context);
final steam = ref.watch(steamModelProvider());
final controller = new TextEditingController();
final controller = TextEditingController();

steam.whenData((data) async {
controller.text = vdf.encode(data.globalConfig).replaceAll('\t', ' ');
Expand Down Expand Up @@ -201,7 +205,7 @@ class _SteamUserConfigs extends ConsumerWidget {
children: [
for (final userID in data.userConfigs.keys) ...[
_SteamUserConfigText(userID: userID),
SizedBox(height: kPagePadding),
const SizedBox(height: kPagePadding),
],
],
),
Expand All @@ -216,15 +220,15 @@ class _SteamUserConfigs extends ConsumerWidget {
}

class _SteamUserConfigText extends ConsumerWidget {
_SteamUserConfigText({required this.userID});
const _SteamUserConfigText({required this.userID});

final String userID;

@override
Widget build(BuildContext context, WidgetRef ref) {
final l10n = AppLocalizations.of(context);
final steam = ref.watch(steamModelProvider());
final controller = new TextEditingController();
final controller = TextEditingController();

steam.whenData((data) async {
controller.text =
Expand Down
Loading

0 comments on commit ef4629d

Please sign in to comment.