diff --git a/local_server/server.js b/local_server/server.js index 9f1117f..c15ac44 100644 --- a/local_server/server.js +++ b/local_server/server.js @@ -17,14 +17,15 @@ const server = http.createServer((req, res) => { const io = socketIo(server); // Track the number of connected clients -let clientCount = 0; +let clients = []; -io.on('connection', (socket) => { - console.log("user connected"); - // Increment the client count - clientCount++; +io.on('connect', (socket) => { + console.log(`user connected, ${clients.length}`); + // add client to the list of clients + let client = { 'name': socket.handshake.query.name, 'type': socket.handshake.query.type, 'id': socket.id } + clients.push(client) // Broadcast the updated client count - io.emit('room_clients', clientCount); + io.emit('room_clients', clients); // Relay any event received to all clients except the sender socket.onAny((event, ...args) => { @@ -32,10 +33,11 @@ io.on('connection', (socket) => { }); socket.on('disconnect', () => { - // Decrement the client count - clientCount--; + console.log(`user disconnected, ${clients.length}`); + // remove the disconnected client + clients = clients.filter(client => client.id !== socket.id); // Broadcast the updated client count - io.emit('room_clients', clientCount); + io.emit('room_clients', clients); }); }); diff --git a/zal_app/lib/Functions/models.dart b/zal_app/lib/Functions/models.dart index 7b8dad6..66d1df8 100644 --- a/zal_app/lib/Functions/models.dart +++ b/zal_app/lib/Functions/models.dart @@ -546,17 +546,14 @@ class ProgramTime { class SocketObject { late Socket socket; Timer? timer; - SocketObject(String? localSocketAddress, String? uid, String? idToken) { + SocketObject(String localSocketAddress, {Map extraQueries = const {}}) { socket = io( - localSocketAddress ?? (dotenv.env['SERVER'] == 'production' ? 'https://api.zalapp.com' : 'http://192.168.0.120:5000'), + localSocketAddress, { 'transports': ['websocket'], 'query': { - 'EIO': '3', - 'uid': uid, - 'idToken': idToken, - 'type': 1, - 'version': 1, + ...extraQueries, + 'EIO': '4', }, }, ); diff --git a/zal_app/lib/Screens/FpsScreen/Widgets/fps_screen_pc_widget.dart b/zal_app/lib/Screens/FpsScreen/Widgets/fps_screen_pc_widget.dart index dbd812d..2d08988 100644 --- a/zal_app/lib/Screens/FpsScreen/Widgets/fps_screen_pc_widget.dart +++ b/zal_app/lib/Screens/FpsScreen/Widgets/fps_screen_pc_widget.dart @@ -219,12 +219,12 @@ class FpsScreenPcWidget extends ConsumerWidget { text: "core speed", value: "${gpu.coreSpeed.round()}Mhz", icon: FontAwesomeIcons.gauge, - maxValue: "${data.highestValues['gpu.coreSpeed']?.round()}Mhz"), + maxValue: "${data.highestValues['gpu.coreSpeed']?.round() ?? 0}Mhz"), FpsPcStatWidget( text: "mem speed", value: "${gpu.memorySpeed.round()}Mhz", icon: Icons.memory, - maxValue: "${data.highestValues['gpu.memorySpeed']?.round()}Mhz"), + maxValue: "${data.highestValues['gpu.memorySpeed']?.round() ?? 0}Mhz"), FpsPcStatWidget( text: "mem usage", value: (gpu.dedicatedMemoryUsed * 1000 * 1000).toSize(), @@ -234,18 +234,18 @@ class FpsScreenPcWidget extends ConsumerWidget { text: "power", value: "${gpu.power.round()}W", icon: Icons.memory, - maxValue: "${data.highestValues['gpu.power']?.round()}W", + maxValue: "${data.highestValues['gpu.power']?.round() ?? 0}W", ), FpsPcStatWidget( text: "voltage", value: "${gpu.voltage.round()}V", icon: Icons.memory, - maxValue: "${data.highestValues['gpu.voltage']?.round()}V"), + maxValue: "${data.highestValues['gpu.voltage']?.round() ?? 0}V"), FpsPcStatWidget( text: "fan Speed", value: "${gpu.fanSpeedPercentage.round()}%", icon: Icons.memory, - maxValue: "${data.highestValues['gpu.fanSpeedPercentage']?.round()}%"), + maxValue: "${data.highestValues['gpu.fanSpeedPercentage']?.round() ?? 0}%"), FpsPcStatWidget( text: "temperature", value: getTemperatureText(gpu.temperature, ref), @@ -255,7 +255,7 @@ class FpsScreenPcWidget extends ConsumerWidget { text: "load", value: "${gpu.corePercentage.round()}%", icon: Icons.memory, - maxValue: "${data.highestValues['gpu.corePercentage']?.round()}%"), + maxValue: "${data.highestValues['gpu.corePercentage']?.round() ?? 0}%"), ], ), ], @@ -316,13 +316,13 @@ class FpsScreenPcWidget extends ConsumerWidget { ), Expanded( child: Text( - '${coreInfo.clock?.round()}MHZ', + '${coreInfo.clock?.round() ?? 0}MHZ', style: Theme.of(context).textTheme.labelMedium, textAlign: TextAlign.center, ), ), Text( - '${coreInfo.load?.round()}%', + '${coreInfo.load?.round() ?? 0}%', style: Theme.of(context).textTheme.labelMedium, textAlign: TextAlign.end, ), diff --git a/zal_app/lib/Screens/FpsScreen/fps_screen_providers.dart b/zal_app/lib/Screens/FpsScreen/fps_screen_providers.dart index 06387d0..5f5b1cf 100644 --- a/zal_app/lib/Screens/FpsScreen/fps_screen_providers.dart +++ b/zal_app/lib/Screens/FpsScreen/fps_screen_providers.dart @@ -135,7 +135,7 @@ final fpsTimeElapsedProvider = AsyncNotifierProvider.autoDispose>((ref) { +final gpuProcessesProvider = FutureProvider>((ref) async { final sub = ref.listen(socketStreamProvider, (prev, cur) { if (cur.valueOrNull?.type == SocketDataType.gpuProcesses) { final parsedData = Map.from(jsonDecode(cur.valueOrNull!.data)); @@ -148,7 +148,7 @@ final gpuProcessesProvider = FutureProvider>((ref) { } }); ref.onDispose(() => sub.close()); - return ref.future; + return ref.future.timeout(const Duration(seconds: 2), onTimeout: () => []); }); final selectedGpuProcessProvider = StateProvider.autoDispose((ref) => null); diff --git a/zal_app/lib/Screens/InitialConnectionScreen/Widgets/connect_manually_widget.dart b/zal_app/lib/Screens/InitialConnectionScreen/Widgets/connect_manually_widget.dart new file mode 100644 index 0000000..001b049 --- /dev/null +++ b/zal_app/lib/Screens/InitialConnectionScreen/Widgets/connect_manually_widget.dart @@ -0,0 +1,48 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:sizer/sizer.dart'; +import 'package:zal/Functions/utils.dart'; +import 'package:zal/Screens/MainScreen/main_screen_providers.dart'; +import 'package:zal/Screens/StorageScreen/Widgets/storage_information_widget.dart'; + +class ConnectManuallyWidget extends ConsumerWidget { + ConnectManuallyWidget({super.key}); + TextEditingController addressController = TextEditingController(text: "192.168."); + @override + Widget build(BuildContext context, WidgetRef ref) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Row( + children: [ + const Text("Computer Address:"), + IconButton( + onPressed: () { + showInformationDialog(null, "You can find this address by opening Zal on your Computer, and check the bottom left corner.", context); + }, + icon: Icon( + FontAwesomeIcons.question, + size: 2.h, + ), + ), + ], + ), + const SizedBox(height: 4), + TextField( + controller: addressController, + ), + const SizedBox(height: 8), + Align( + alignment: Alignment.bottomRight, + child: ElevatedButton( + onPressed: () { + ref.read(socketProvider.notifier).connect(null, manualAddress: addressController.text, forceConnect: true); + Navigator.pop(context); + }, + child: const Text("Connect"))), + ], + ); + } +} diff --git a/zal_app/lib/Screens/InitialConnectionScreen/initial_connection_screen.dart b/zal_app/lib/Screens/InitialConnectionScreen/initial_connection_screen.dart index 554b55f..a22a0dd 100644 --- a/zal_app/lib/Screens/InitialConnectionScreen/initial_connection_screen.dart +++ b/zal_app/lib/Screens/InitialConnectionScreen/initial_connection_screen.dart @@ -1,10 +1,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:google_fonts/google_fonts.dart'; import 'package:sizer/sizer.dart'; import 'package:zal/Functions/models.dart'; +import 'package:zal/Functions/theme.dart'; import 'package:zal/Screens/ConnectedScreen/connected_screen.dart'; import 'package:zal/Screens/InitialConnectionScreen/Widgets/choose_computer_widget.dart'; +import 'package:zal/Screens/InitialConnectionScreen/Widgets/connect_manually_widget.dart'; import 'package:zal/Screens/InitialConnectionScreen/Widgets/initial_connection_settings_screen.dart'; import 'package:zal/Screens/InitialConnectionScreen/initial_connection_screen_providers.dart'; import 'package:zal/Screens/MainScreen/SettingsScreen/settings_providers.dart'; @@ -85,7 +88,7 @@ class InitialConnectionScreen extends ConsumerWidget { alignment: Alignment.centerRight, child: TextButton( onPressed: () { - ref.read(socketProvider.notifier).connect(computers[index]); + ref.read(socketProvider.notifier).connect(computers[index], forceConnect: true); }, child: const Text("Connect"), ), @@ -97,6 +100,22 @@ class InitialConnectionScreen extends ConsumerWidget { ); }, ), + ElevatedButton( + onPressed: () { + AlertDialog alert = AlertDialog( + title: Text("Connect manually", style: GoogleFonts.bebasNeueTextTheme(AppTheme.darkTheme.textTheme).displayLarge), + content: ConnectManuallyWidget(), + ); + + // show the dialog + showDialog( + context: context, + builder: (BuildContext context) { + return alert; + }, + ); + }, + child: const Text("Connect Manually")), const Spacer(), const Divider(), Wrap( diff --git a/zal_app/lib/Screens/MainScreen/main_screen_providers.dart b/zal_app/lib/Screens/MainScreen/main_screen_providers.dart index 4eac43a..0c12715 100644 --- a/zal_app/lib/Screens/MainScreen/main_screen_providers.dart +++ b/zal_app/lib/Screens/MainScreen/main_screen_providers.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:firebase_database/firebase_database.dart'; import 'package:flutter/material.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; @@ -54,17 +55,38 @@ final contextProvider = StateProvider((ref) => null); class SocketObjectNotifier extends AsyncNotifier { ComputerAddress? currentAddress; + String mobileName = 'Default Mobile Name'; + + Future setMobileName() async { + if (Platform.isAndroid) { + final info = (await DeviceInfoPlugin().androidInfo); + mobileName = info.model; + } + if (Platform.isIOS) { + final info = (await DeviceInfoPlugin().iosInfo); + mobileName = info.model; + } + } + @override Future build() async { + await setMobileName(); return null; } - connect(ComputerAddress address) { - if (currentAddress == address) return; + connect(ComputerAddress? address, {String? manualAddress, bool forceConnect = false}) { + if (!forceConnect) { + if (currentAddress == address) return; + } + if (state.valueOrNull != null) { + state.valueOrNull!.socket.disconnect(); + state.valueOrNull!.socket.dispose(); + } currentAddress = address; - ref.read(settingsProvider.notifier).updateSettings('address', address.toJson()); - - state = AsyncData(SocketObject(address.ip, null, null)); + if (address != null) { + ref.read(settingsProvider.notifier).updateSettings('address', address.toJson()); + } + state = AsyncData(SocketObject(address?.ip ?? "http://$manualAddress/", extraQueries: {'name': mobileName, 'type': 'mobile'})); } sendMessage(String key, dynamic value) { @@ -73,6 +95,7 @@ class SocketObjectNotifier extends AsyncNotifier { disconnect() { currentAddress = null; + state.valueOrNull?.socket.disconnect(); state.valueOrNull?.socket.dispose(); ref.invalidateSelf(); } @@ -93,8 +116,10 @@ final socketStreamProvider = StreamProvider((ref) async* { if (socket != null) { socket.socket.onConnect((data) { ref.read(isConnectedToServerProvider.notifier).state = true; - - //showSnackbarLocal("Server Connected"); + showSnackbarLocal("Server Connected"); + }); + socket.socket.onConnectError((a) { + showSnackbarLocal("Connection error:${a.toString()}"); }); socket.socket.onDisconnect((data) { ref.read(isConnectedToServerProvider.notifier).state = false; @@ -105,7 +130,15 @@ final socketStreamProvider = StreamProvider((ref) async* { // ref.read(webrtcProvider.notifier).messageReceived(RTCDataChannelMessage(data)); }); socket.socket.on("room_clients", (data) { - ref.read(isConnectedToServerProvider.notifier).state = (data as int) > 1; + for (Map client in data) { + if (client['type'] == 'computer') { + showSnackbarLocal("Connected to ${client['name']}!"); + + ref.read(isConnectedToServerProvider.notifier).state = true; + return; + } + } + showSnackbarLocal("Connected to Server, but no PC is online!"); // stream.add(SocketData(type: SocketDataType.roomClients, data: data != 0 ? [0, 1] : [1])); }); socket.socket.on('pc_data', (data) { diff --git a/zal_app/pubspec.lock b/zal_app/pubspec.lock index 73a1fd7..255f4e3 100644 --- a/zal_app/pubspec.lock +++ b/zal_app/pubspec.lock @@ -207,21 +207,21 @@ packages: source: hosted version: "4.1.1" device_info_plus: - dependency: transitive + dependency: "direct main" description: name: device_info_plus - sha256: "77f757b789ff68e4eaf9c56d1752309bd9f7ad557cb105b938a7f8eb89e59110" + sha256: f545ffbadee826f26f2e1a0f0cbd667ae9a6011cc0f77c0f8f00a969655e6e95 url: "https://pub.dev" source: hosted - version: "9.1.2" + version: "11.1.1" device_info_plus_platform_interface: dependency: transitive description: name: device_info_plus_platform_interface - sha256: d3b01d5868b50ae571cd1dc6e502fc94d956b665756180f7b16ead09e836fd64 + sha256: "282d3cf731045a2feb66abfe61bbc40870ae50a3ed10a4d3d217556c35c8c2ba" url: "https://pub.dev" source: hosted - version: "7.0.0" + version: "7.0.1" dio: dependency: transitive description: diff --git a/zal_app/pubspec.yaml b/zal_app/pubspec.yaml index 5da4559..43c1590 100644 --- a/zal_app/pubspec.yaml +++ b/zal_app/pubspec.yaml @@ -74,6 +74,7 @@ dependencies: hive: ^2.2.3 hive_flutter: ^1.1.0 flutter_gemini: ^2.0.3 + device_info_plus: ^11.1.1 dev_dependencies: flutter_lints: ^4.0.0 diff --git a/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs b/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs index d651c6a..9fdcd32 100644 --- a/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs +++ b/zal_program/Zal/Backend/HelperFunctions/FpsDataGetter.cs @@ -52,18 +52,30 @@ public void disposeIt() public void stopPresentmon() { Logger.Log("stopping presentmon"); - foreach (var process in Process.GetProcessesByName("presentmon")) + try { - process.Kill(); - Logger.Log("presentmon killed"); + foreach (var process in Process.GetProcessesByName("presentmon")) + { + process.Kill(); + Logger.Log("presentmon killed"); + } + foreach (var process in Process.GetProcessesByName("PresentMon-x64")) + { + process.Kill(); + Logger.Log("presentmon killed"); + } + } + catch (Exception ex) + { + Logger.LogError("error killing presentmon", ex); } } public async void startPresentmon(int processId, bool logFps) { shouldLog = logFps; - //startFpsTimer(); //kill any presentmon process that might be running + stopPresentmon(); var filePath = GlobalClass.Instance.getFilepathFromResources("presentmon.exe"); var startInfo = new ProcessStartInfo { diff --git a/zal_program/Zal/Functions/MajorFunctions/FrontendGlobalClass.cs b/zal_program/Zal/Functions/MajorFunctions/FrontendGlobalClass.cs index 72c7bf4..0d6df53 100644 --- a/zal_program/Zal/Functions/MajorFunctions/FrontendGlobalClass.cs +++ b/zal_program/Zal/Functions/MajorFunctions/FrontendGlobalClass.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Zal.Constants.Models; using Zal.Functions.MajorFunctions; @@ -15,13 +16,14 @@ public class FrontendGlobalClass public bool shouldLogFpsData = false; private FrontendGlobalClass( EventHandler socketConnectionStateChanged, - EventHandler computerDataReceived + EventHandler computerDataReceived, + EventHandler>> roomClientsReceived ) { // Initialization code here backend = new BackendManager(); - localSocket = new LocalSocket(stateChanged: socketConnectionStateChanged); + localSocket = new LocalSocket(stateChanged: socketConnectionStateChanged, roomClientsReceived: roomClientsReceived); dataManager = new DataManager(computerDataReceived); @@ -29,11 +31,13 @@ EventHandler computerDataReceived public static async Task Initialize( EventHandler socketConnectionStateChanged, //invoked when we retrieve computerData - EventHandler computerDataReceived + EventHandler computerDataReceived, + EventHandler>> roomClientsReceived + ) { await LocalDatabase.Initialize(); - instance = new FrontendGlobalClass(socketConnectionStateChanged, computerDataReceived); + instance = new FrontendGlobalClass(socketConnectionStateChanged, computerDataReceived, roomClientsReceived); } diff --git a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs index 0af3d00..7902b7e 100644 --- a/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs +++ b/zal_program/Zal/Functions/MajorFunctions/LocalSocket.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using System.Threading.Tasks; using Zal.Functions.Models; using Zal.HelperFunctions.SpecificFunctions; @@ -15,15 +14,18 @@ namespace Zal.Functions.MajorFunctions public class LocalSocket { public event EventHandler connectionStateChanged; + public event EventHandler>> roomClientsReceived; + public SocketIOClient.SocketIO socketio; public bool isConnected; public bool isMobileConnected; private Process? serverProcess; public LocalSocket( EventHandler stateChanged - ) +, EventHandler>> roomClientsReceived) { connectionStateChanged = stateChanged; + this.roomClientsReceived = roomClientsReceived; setupSocketio(); } public async void restartSocketio() @@ -42,21 +44,10 @@ private async Task setupSocketio() await killSocketProcess(); //run the server var port = LocalDatabase.Instance.readKey("port")?.ToString() ?? "4920"; - var pcName = (string?)LocalDatabase.Instance.readKey("pcName"); - if (pcName == null) - { - try - { - pcName = System.Security.Principal.WindowsIdentity.GetCurrent().Name; - } - catch - { - pcName = "Default Computer"; - } - } - pcName = string.Concat(pcName.Where(char.IsLetterOrDigit)); + var filePath = GlobalClass.Instance.getFilepathFromResources("server.exe"); + var pcName = Utils.getPcName(); var startInfo = new ProcessStartInfo { FileName = filePath, @@ -90,20 +81,29 @@ private async Task setupSocketio() { Query = new List> { - //new KeyValuePair("uid", uid), + new KeyValuePair("name", pcName), + new KeyValuePair("type", "computer"), } }); socketio.On("room_clients", response => { + var parsedData = response.GetValue>>(); + this.roomClientsReceived.Invoke(this, parsedData); - var parsedData = response.GetValue(); - Logger.Log($"local socketio room_clients {parsedData}"); - // if the data is 1, that means w'ere the only one connected to this server. if it's more than 1, it means a mobile is connected to the server. - isMobileConnected = parsedData > 1; + Logger.Log($"received room_clients"); + // check if the clients contain a mobile. if so, change state to connected. + foreach (var client in parsedData) + { + Logger.Log($"client: {client["name"]},type:{client["type"]}"); + if (client["type"].ToString() == "mobile") + { + isMobileConnected = true; + } + } FrontendGlobalClass.Instance.dataManager.setMobileConnectionState(isMobileConnected); - connectionStateChanged.Invoke(null, isMobileConnected ? SocketConnectionState.Connected : SocketConnectionState.Disconnected); + connectionStateChanged.Invoke(this, isMobileConnected ? SocketConnectionState.Connected : SocketConnectionState.Disconnected); }); socketio.On("get_directory", response => { diff --git a/zal_program/Zal/Functions/Utils.cs b/zal_program/Zal/Functions/Utils.cs index 18f7409..c4fef8a 100644 --- a/zal_program/Zal/Functions/Utils.cs +++ b/zal_program/Zal/Functions/Utils.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; namespace Zal.Functions { @@ -9,5 +10,27 @@ public static TValue GetValueOrDefault(this IDictionary { - mobileConnectionText.Text = state == Functions.Models.SocketConnectionState.Connected ? "Mobile connected" : "Mobile not connected"; - mobileConnectionText.ForeColor = !(state == Functions.Models.SocketConnectionState.Connected) ? Color.FromKnownColor(KnownColor.IndianRed) : Color.FromKnownColor(KnownColor.ForestGreen); + // mobileConnectionText.Text = state == Functions.Models.SocketConnectionState.Connected ? "Mobile connected" : "Mobile not connected"; + // mobileConnectionText.ForeColor = !(state == Functions.Models.SocketConnectionState.Connected) ? Color.FromKnownColor(KnownColor.IndianRed) : Color.FromKnownColor(KnownColor.ForestGreen); })); }, computerDataReceived: (sender, data) => { @@ -116,7 +118,27 @@ await FrontendGlobalClass.Initialize(socketConnectionStateChanged: (sender, stat gpuDatas = data.gpuData; })); - }); + }, + roomClientsReceived: (sender, data) => + { + Invoke(new Action(() => + { + connectedClientsList.Items.Clear(); + var connectedClients = 0; + var currentPcName = Utils.getPcName(); + foreach (var client in data) + { + if (client["name"].ToString() == currentPcName) continue; + connectedClients++; + var name = client["name"]; + connectedClientsList.Items.Add($"{name}"); + } + connectedClientsLabel.Text = $"Connected Clients: {connectedClients}"; + })); + } + ); + var port = LocalDatabase.Instance.readKey("port")?.ToString() ?? "4920"; + ipAddressText.Text = $"Address: {IpGetter.getIp()}:{port}"; setupTrayMenu(); setupRunOnStartup(); checkForUpdates(); @@ -151,7 +173,8 @@ private async Task checkForUpdates() Console.WriteLine("File downloaded successfully."); var p = new Process(); - var pi = new ProcessStartInfo { + var pi = new ProcessStartInfo + { UseShellExecute = true, FileName = fileName, }; @@ -246,6 +269,8 @@ private void restartServerToolStripMenuItem_Click(object sender, EventArgs e) { FrontendGlobalClass.Instance.localSocket.restartSocketio(); } + + } } diff --git a/zal_program/Zal/Pages/ConfigurationsForm.cs b/zal_program/Zal/Pages/ConfigurationsForm.cs index cbe69aa..2fd8e46 100644 --- a/zal_program/Zal/Pages/ConfigurationsForm.cs +++ b/zal_program/Zal/Pages/ConfigurationsForm.cs @@ -19,7 +19,7 @@ private void ConfigurationsForm_Load(object sender, EventArgs e) { runOnStartupCheckbox.Checked = (LocalDatabase.Instance.readKey("runOnStartup")?.ToString() ?? "1") == "1"; startMinimizedCheckbox.Checked = (LocalDatabase.Instance.readKey("startMinimized")?.ToString() ?? "1") == "1"; - FrontendGlobalClass.Instance.shouldLogFpsData = logFpsDataCheckbox.Checked; + logFpsDataCheckbox.Checked = FrontendGlobalClass.Instance.shouldLogFpsData; if (gpusListbox.Items.Count == 0) { diff --git a/zal_program/Zal/Pages/ConnectionSettingsForm.cs b/zal_program/Zal/Pages/ConnectionSettingsForm.cs index 4d82fc3..69f1164 100644 --- a/zal_program/Zal/Pages/ConnectionSettingsForm.cs +++ b/zal_program/Zal/Pages/ConnectionSettingsForm.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Windows.Forms; +using Zal.Functions; using Zal.MajorFunctions; namespace Zal.Pages @@ -14,18 +15,7 @@ public ConnectionSettingsForm() private void ConnectionSettingsForm_Load(object sender, EventArgs e) { - var pcName = (string?)LocalDatabase.Instance.readKey("pcName"); - if (pcName == null) - { - try - { - pcName = System.Security.Principal.WindowsIdentity.GetCurrent().Name; - } - catch - { - pcName = "Default Computer"; - } - } + var pcName = Utils.getPcName(); pcName = string.Concat(pcName.Where(char.IsLetterOrDigit)); portTextBox.Text = LocalDatabase.Instance.readKey("port")?.ToString() ?? "4920"; pcNameTextBox.Text = pcName;