connect method
Connects to the Liquid Galaxy system
Returns true
if the connection is successful, false
otherwise.
Implementation
Future<bool> connect() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
if (!prefs.containsKey('lg_ip') ||
!prefs.containsKey('lg_port') ||
!prefs.containsKey('lg_username') ||
!prefs.containsKey('lg_password')) {
return false;
}
try {
final socket = await SSHSocket.connect(
prefs.getString('lg_ip')!,
int.parse(prefs.getString('lg_port')!),
).timeout(const Duration(seconds: 8));
client = SSHClient(
socket,
username: prefs.getString('lg_username')!,
onPasswordRequest: () => prefs.getString('lg_password')!,
);
await client!.authenticated;
final screenAmountString = prefs.getString('lg_screen_amount') ??
(await getScreenAmount()).toString();
screenAmount = int.parse(screenAmountString);
prefs.setString('lg_screen_amount', screenAmountString);
} catch (e) {
return false;
}
return true;
}