Skip to content

Commit

Permalink
final commit (for now)
Browse files Browse the repository at this point in the history
- finished all screens
- added compilation info
  • Loading branch information
maximoospital committed Jun 25, 2024
1 parent 971d39c commit 00f66f2
Show file tree
Hide file tree
Showing 13 changed files with 514 additions and 86 deletions.
28 changes: 8 additions & 20 deletions lib/components/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ class GlobalVariables {
static List<Map<String, dynamic>> games = [
{'name': 'Test', 'path': 'Testpath'},
];
static List gamesList = games.sublist(1);
// variable List of games excluding the test game (games[0])
static bool get gamesEmpty => games.length == 1;
static List<Map<String, dynamic>> get gamesList => games.sublist(1);
static int index = 0;


static bool gamesEmpty = games[1].isEmpty;
static Future<void> loadConfig() async {
final appDirectory = await getApplicationCacheDirectory();
final configFile = File('${appDirectory.path}/config.json');
Expand Down Expand Up @@ -76,23 +75,13 @@ void copyB2Exe() async {
}
}

Future<void> testAdd(String name, String path) async {
print("Adding test game");
print("Name: $name");
print("Path: $path");
final batName = path.split('/').last.split('.').first;
// Create a .bat file with the following content:
// @echo off
// start "$path"
// and save it as $name.bata in the cache directory
Future<void> testAdd(String name, String gamepath) async {
final batName = gamepath.split('/').last.split('.').first;
final appDirectory = await getApplicationCacheDirectory();
final batFile = File('${appDirectory.path}/$batName.bat');
final batContent = '@echo off\nstart "" "$path"';
final batFile = File('${appDirectory.path}/$name.$batName.bat');
final batContent = '@echo off\nstart "" "$gamepath"';
await batFile.writeAsString(batContent);
// Run b2exe.exe with the following arguments: /bat $batFile.bat /exe $batFile.exe /invisible
final process = await Process.run('${appDirectory.path}/b2exe.exe', ['/bat', '${appDirectory.path}/$batName.bat', '/exe', '${appDirectory.path}/$batName.exe', '/invisible']);
print(process.stdout);
print(process.stderr);
await Process.run('${appDirectory.path}/b2exe.exe', ['/bat', '${appDirectory.path}/$name.$batName.bat', '/exe', '${appDirectory.path}/$name.$batName.exe', '/invisible']);
}

void bitFiestaCleanup() async {
Expand Down Expand Up @@ -128,7 +117,6 @@ void bitFiestaCleanup() async {
Directory('${destinationDir.path}/$filename').create(recursive: true);
}
}
print('Unzip successful');
} catch (e) {
print('Failed to unzip: $e');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/components/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void WindowSetup() async {
size: Size(800, 600),
center: true,
backgroundColor: Colors.transparent,
title: "Maxi's Steam Remote Play Launcher",
title: "Maxi's Remote Play Launcher",
);

windowManager.waitUntilReadyToShow(windowOptions, () async {
Expand Down
4 changes: 4 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'screens/config.dart';
import 'screens/error.dart';
import 'screens/main.dart';
import 'screens/tutorial.dart';
import 'screens/add.dart';
import 'screens/edit.dart';
import 'package:path/path.dart' as path;

void main() async {
Expand Down Expand Up @@ -41,6 +43,8 @@ class App extends StatelessWidget {
'/error': (context) => const Error(),
'/main': (context) => const Main(),
'/config': (context) => const Config(),
'/add': (context) => const Add(),
'/edit': (context) => const Edit(),
},
);
}
Expand Down
147 changes: 147 additions & 0 deletions lib/screens/add.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import 'package:flutter/material.dart';
import 'package:introduction_screen/introduction_screen.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:file_picker/file_picker.dart';
import '../components/global.dart';

class Add extends StatefulWidget {
const Add({super.key});

@override
AddScreen createState() => AddScreen();

}
class AddScreen extends State<Add> {
String name = '';
String gamepath = '';
int screenValue = 0;
late TextEditingController nameController;

@override
void initState() {
super.initState();
nameController = TextEditingController(text: name);
}

List<PageViewModel> getPages() {
return [
PageViewModel(
title: "Adding a game",
body: "First off, type the game's name.",
footer: Container (
margin: const EdgeInsets.only(left: 200.0, right: 200.0, top: 25.0),
child: Column(
children: [
TextField(
controller: nameController,
onChanged: (value) {
setState(() {
name = value;
});
},
decoration: const InputDecoration(
prefixIcon: Icon(FontAwesomeIcons.gamepad),
filled: false,
labelText: "Game name",
hintText: "Write the game's name here.",
),
),
],
),
),
image: const Center(child: Icon(FontAwesomeIcons.edit, size: 50.0)),
),
PageViewModel(
title: "Adding a game",
body: "Please specify the game's executable's path.",
footer: Container (
margin: const EdgeInsets.only(left: 200.0, right: 200.0, top: 25.0),
child: Column(
children: [
ElevatedButton(
onPressed: () async {
// Open file picker to select 8 Bit Fiesta's nw.exe
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['exe'],
);
if (result != null) {
setState(() {
gamepath = result.files.single.path!;
// Replace all backslashes with forward slashes for compatibility
gamepath = gamepath.replaceAll('\\', '/');
});
}
},
style: ElevatedButton.styleFrom(
fixedSize: const Size(200, 50),
),
child: const Text("Find the executable.", style: TextStyle(fontSize: 15.0)),
),
Container(
margin: const EdgeInsets.only(top: 10.0),
child: Text(gamepath, style: const TextStyle(fontSize: 10.0)),
),
],
),
),
image: const Center(child: Icon(FontAwesomeIcons.edit, size: 50.0)),
),
PageViewModel(
title: "And that's it!",
body: "Let's get started!",
image: const Center(child: Icon(FontAwesomeIcons.checkCircle, size: 100.0)),
),
];
}

@override
Widget build(BuildContext context) {
return IntroductionScreen(
pages: getPages(),
onDone: () async {

if(name != '' && gamepath != ''){
testAdd(name, gamepath.toString());
GlobalVariables.addGame(name, gamepath.toString());
}
Navigator.pushNamedAndRemoveUntil(context, '/main', (route) => false);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Game $name added!'),
animation: CurvedAnimation(parent: const AlwaysStoppedAnimation(1), curve: Curves.easeInOut),
behavior: SnackBarBehavior.floating,
),
);
},
showSkipButton: screenValue == 0 ? true : false,
showNextButton: true,
showBackButton: screenValue == 0 ? false : true,
back: const Text("Go Back"),
overrideSkip: screenValue == 0 ? ElevatedButton(
onPressed: () {
Navigator.pushNamedAndRemoveUntil(context, '/main', (route) => false);
},
style: ElevatedButton.styleFrom(
fixedSize: const Size(100, 25),
),
// If screenValue is 0, the skip button will be "Skip", else it will be "Cancel"
child: Text(screenValue == 0 ? "Cancel" : "Go Back"),
) : null,
onChange: (value) {
setState(() {
screenValue = value;
});
},
next: const Text("Next"),
done: const Text("Done!", style: TextStyle(fontWeight: FontWeight.w600)),
);
}

@override
void dispose() {
// Dispose of the TextEditingController when the widget is disposed
nameController.dispose();
super.dispose();
}
}
11 changes: 8 additions & 3 deletions lib/screens/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ class ConfigScreen extends State<Config> {
Center(
child: Container(
margin: const EdgeInsets.only(top: 10.0),
child: ElevatedButton(
child: Tooltip(
message: '500mb required.',
child: ElevatedButton(
onPressed: () async {
await launchUrl(Uri.parse('https://store.steampowered.com/about/download'));
},
Expand All @@ -50,12 +52,14 @@ class ConfigScreen extends State<Config> {
),
child: const Text("Install Steam"),
)
)
))
),
Center(
child: Container(
margin: const EdgeInsets.only(top: 10.0),
child: ElevatedButton(
child: Tooltip(
message: '200mb required for initial download.',
child: ElevatedButton(
onPressed: () async {
await launchUrl(Uri.parse('steam://install/382260'));
},
Expand All @@ -64,6 +68,7 @@ class ConfigScreen extends State<Config> {
),
child: const Text("Install 8 Bit Fiesta"),
)
)
)
),
],)),
Expand Down
Empty file removed lib/screens/delete.dart
Empty file.
Loading

0 comments on commit 00f66f2

Please sign in to comment.