Skip to content

Commit

Permalink
Window management
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelovila committed Sep 29, 2023
1 parent a8a33fd commit 3c0ff2d
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 32 deletions.
66 changes: 36 additions & 30 deletions client/lib/logic/game_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,40 +52,46 @@ Future startGame(String playerId) async {
// |- supertux2.exe / supertux.AppImage - - (game executables)
//

final String rootDir = p.dirname(Platform.resolvedExecutable);
final String userDir =
(await Directory(p.join(rootDir, "game_dir/user_dir")).create()).path;
final String saveFilePath = p.join(userDir, "profile1/world1.stsg");
try {
final String rootDir = p.dirname(Platform.resolvedExecutable);
final String userDir =
(await Directory(p.join(rootDir, "game_dir/user_dir")).create()).path;
final String saveFilePath = p.join(userDir, "profile1/world1.stsg");

final http.Response response = await getSaveFile(playerId);
if (response.statusCode == 200) {
await File(saveFilePath).create(recursive: true);
File(saveFilePath).writeAsBytesSync(response.bodyBytes);
}
final http.Response response = await getSaveFile(playerId);
if (response.statusCode == 200) {
await File(saveFilePath).create(recursive: true);
File(saveFilePath).writeAsBytesSync(response.bodyBytes);
}

String binName = "";
if (Platform.isLinux) {
binName = "supertux.AppImage";
} else if (Platform.isWindows) {
binName = "supertux2.exe";
} else {
// Unsupported platform;
}
final String binPath = p.join(rootDir, "game_dir/supertux/bin/$binName");
String binName = "";
if (Platform.isLinux) {
binName = "supertux.AppImage";
} else if (Platform.isWindows) {
binName = "supertux2.exe";
} else {
// Unsupported platform;
}
final String binPath = p.join(rootDir, "game_dir/supertux/bin/$binName");

var env = ShellEnvironment()..vars["SUPERTUX2_USER_DIR"] = userDir;
var cshell = Shell(environment: env);
cshell.run(binPath);
var env = ShellEnvironment()..vars["SUPERTUX2_USER_DIR"] = userDir;
var cshell = Shell(environment: env);
cshell.run(binPath);

FileWatcher fileWatcher = FileWatcher(
saveFilePath,
pollingDelay: const Duration(milliseconds: 500),
);
fileWatcher.events.listen((event) {
if (event.type == ChangeType.MODIFY) {
sendSaveFile(playerId, File(saveFilePath).readAsStringSync());
}
});
FileWatcher fileWatcher = FileWatcher(
saveFilePath,
pollingDelay: const Duration(milliseconds: 500),
);
fileWatcher.events.listen(
(event) {
if (event.type == ChangeType.MODIFY) {
sendSaveFile(playerId, File(saveFilePath).readAsStringSync());
}
},
);
} catch (e) {
print(e);
}
}

Future startTraining() async {
Expand Down
18 changes: 16 additions & 2 deletions client/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:client/widgets/ongame_page.dart';
import 'package:client/widgets/loading_page.dart';
import 'package:client/widgets/codeinput_page.dart';
import 'package:window_manager/window_manager.dart';
import 'package:client/widgets/onboarding_page.dart';
import 'package:client/widgets/nameverification_page.dart';

void main() {
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await windowManager.ensureInitialized();

WindowOptions windowOptions = const WindowOptions(
minimumSize: Size(700, 550),
title: "Torneio de Super Tux - GLUA",
center: true,
);
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();
await windowManager.focus();
});

runApp(const MyApp());
}

Expand Down Expand Up @@ -37,7 +51,7 @@ class PageHolder extends StatefulWidget {

class _PageHolderState extends State<PageHolder> {
final PageController controller = PageController(initialPage: 0);
// Guardar os dados aqui mesmo à porco :)

String playerName = "";
void updateName(String newName) {
setState(() {
Expand Down
8 changes: 8 additions & 0 deletions client/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

#include "generated_plugin_registrant.h"

#include <screen_retriever/screen_retriever_plugin.h>
#include <window_manager/window_manager_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);
}
2 changes: 2 additions & 0 deletions client/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
16 changes: 16 additions & 0 deletions client/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
screen_retriever:
dependency: transitive
description:
name: screen_retriever
sha256: "6ee02c8a1158e6dae7ca430da79436e3b1c9563c8cf02f524af997c201ac2b90"
url: "https://pub.dev"
source: hosted
version: "0.1.9"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -312,6 +320,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
window_manager:
dependency: "direct main"
description:
name: window_manager
sha256: "6ee795be9124f90660ea9d05e581a466de19e1c89ee74fc4bf528f60c8600edd"
url: "https://pub.dev"
source: hosted
version: "0.3.6"
xml:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
process_run: ^0.13.1
path: ^1.8.0
watcher: ^1.1.0
window_manager: ^0.3.6
dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
6 changes: 6 additions & 0 deletions client/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

#include "generated_plugin_registrant.h"

#include <screen_retriever/screen_retriever_plugin.h>
#include <window_manager/window_manager_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
ScreenRetrieverPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
}
2 changes: 2 additions & 0 deletions client/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
screen_retriever
window_manager
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down

0 comments on commit 3c0ff2d

Please sign in to comment.