<feat: New release>

This commit is contained in:
Alessandro Autiero
2023-09-09 19:37:05 +02:00
parent 485e757e83
commit 64b85e4f6e
32 changed files with 586 additions and 223 deletions

View File

@@ -1,7 +1,6 @@
import 'dart:collection';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:reboot_launcher/src/page/home_page.dart';
import 'package:sync/semaphore.dart';
@@ -18,7 +17,7 @@ void restoreMessage(int lastIndex) {
Overlay.of(pageKey.currentContext!).insert(overlay);
}
void showInfoBar(String text, {InfoBarSeverity severity = InfoBarSeverity.info, bool loading = false, Duration? duration = snackbarShortDuration, Widget? action}) {
void showInfoBar(dynamic text, {InfoBarSeverity severity = InfoBarSeverity.info, bool loading = false, Duration? duration = snackbarShortDuration, Widget? action}) {
try {
_semaphore.acquire();
var index = pageIndex.value;
@@ -29,12 +28,25 @@ void showInfoBar(String text, {InfoBarSeverity severity = InfoBarSeverity.info,
width: double.infinity,
child: Mica(
child: InfoBar(
title: Text(text),
isLong: action == null,
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
if(text is Widget)
text,
if(text is String)
Text(text),
if(action != null)
action
],
),
isLong: false,
isIconVisible: true,
content: action ?? SizedBox(
content: SizedBox(
width: double.infinity,
child: loading ? const ProgressBar() : const SizedBox()
child: loading ? const Padding(
padding: EdgeInsets.only(top: 8.0, bottom: 2.0),
child: ProgressBar(),
) : const SizedBox()
),
severity: severity
),

View File

@@ -1,7 +1,6 @@
import 'package:fluent_ui/fluent_ui.dart';
import 'package:reboot_launcher/src/page/home_page.dart';
import 'package:reboot_launcher/src/dialog/abstract/dialog.dart';
import 'package:reboot_launcher/src/page/home_page.dart';
String? lastError;

View File

@@ -1,20 +1,21 @@
import 'dart:async';
import 'package:clipboard/clipboard.dart';
import 'package:dart_ipify/dart_ipify.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/material.dart' show Icons;
import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:get/get_state_manager/src/rx_flutter/rx_obx_widget.dart';
import 'package:get/get.dart';
import 'package:reboot_common/common.dart';
import 'package:reboot_launcher/src/controller/hosting_controller.dart';
import 'package:reboot_launcher/src/controller/matchmaker_controller.dart';
import 'package:reboot_launcher/src/controller/server_controller.dart';
import 'package:reboot_launcher/src/dialog/abstract/dialog.dart';
import 'package:reboot_launcher/src/dialog/abstract/dialog_button.dart';
import 'package:reboot_launcher/src/dialog/abstract/info_bar.dart';
import 'package:reboot_common/common.dart';
import 'package:reboot_launcher/src/page/home_page.dart';
import 'package:reboot_launcher/src/util/cryptography.dart';
import 'package:reboot_launcher/src/util/matchmaker.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
extension ServerControllerDialog on ServerController {
Future<bool> restartInteractive() async {
@@ -165,7 +166,22 @@ extension ServerControllerDialog on ServerController {
}
extension MatchmakerControllerExtension on MatchmakerController {
Future<void> joinServer(Map<String, dynamic> entry) async {
void joinLocalHost() {
gameServerAddress.text = kDefaultGameServerHost;
gameServerOwner.value = null;
}
Future<void> joinServer(String uuid, Map<String, dynamic> entry) async {
var id = entry["id"];
if(uuid == id) {
showInfoBar(
"You can't join your own server",
duration: snackbarLongDuration,
severity: InfoBarSeverity.error
);
return;
}
var hashedPassword = entry["password"];
var hasPassword = hashedPassword != null;
var embedded = type.value == ServerType.embedded;
@@ -275,6 +291,7 @@ extension MatchmakerControllerExtension on MatchmakerController {
void _onSuccess(bool embedded, String decryptedIp, String author) {
if(embedded) {
gameServerAddress.text = decryptedIp;
gameServerOwner.value = author;
pageIndex.value = 0;
}else {
FlutterClipboard.controlC(decryptedIp);
@@ -285,4 +302,44 @@ extension MatchmakerControllerExtension on MatchmakerController {
severity: InfoBarSeverity.success
));
}
}
extension HostingControllerExtension on HostingController {
Future<void> publishServer(String author, String version) async {
var passwordText = password.text;
var hasPassword = passwordText.isNotEmpty;
var ip = await Ipify.ipv4();
if(hasPassword) {
ip = aes256Encrypt(ip, passwordText);
}
var supabase = Supabase.instance.client;
var hosts = supabase.from('hosts');
var payload = {
'name': name.text,
'description': description.text,
'author': author,
'ip': ip,
'version': version,
'password': hasPassword ? hashPassword(passwordText) : null,
'timestamp': DateTime.now().toIso8601String(),
'discoverable': discoverable.value
};
if(published()) {
await hosts.update(payload).eq("id", uuid);
}else {
payload["id"] = uuid;
await hosts.insert(payload);
}
published.value = true;
}
Future<void> discardServer() async {
var supabase = Supabase.instance.client;
await supabase.from('hosts')
.delete()
.match({'id': uuid});
published.value = false;
}
}