-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
/* | ||
** Copyright (C) 2024 Victron Energy B.V. | ||
** See LICENSE.txt for license information. | ||
*/ | ||
|
||
import QtQuick | ||
import Victron.VenusOS | ||
|
||
Page { | ||
id: root | ||
|
||
readonly property string tailscaleServiceUid: BackendConnection.serviceUidForType("tailscale") | ||
|
||
VeQuickItem { | ||
id: commandItem | ||
uid: root.tailscaleServiceUid + "/GuiCommand" | ||
} | ||
VeQuickItem { | ||
id: loginItem | ||
uid: root.tailscaleServiceUid + "/LoginLink" | ||
} | ||
VeQuickItem { | ||
id: loginItemQrCode | ||
uid: root.tailscaleServiceUid + "/LoginLinkQrCode" | ||
} | ||
VeQuickItem { | ||
id: stateItem | ||
uid: root.tailscaleServiceUid + "/State" | ||
} | ||
|
||
property int connectState: stateItem.isValid ? stateItem.value : 0 | ||
property string loginLink: loginItem.isValid ? loginItem.value : "" | ||
property string loginLinkQrCode: loginItemQrCode.isValid ? loginItemQrCode.value : "" | ||
|
||
property bool isRunning: stateItem.isValid | ||
property bool isEnabled: switchTailscaleEnabled.checked | ||
property bool isEnabledAndRunning: isEnabled && isRunning | ||
property bool isConnected: connectState == 100 && isEnabledAndRunning | ||
|
||
function getState(){ | ||
let returnValue; | ||
|
||
if (!isRunning){ | ||
//% "Tailscale control service not running" | ||
returnValue = qsTrId("settings_tailscale_tailscale_control_service_not_running") | ||
} else if (!isEnabledAndRunning){ | ||
returnValue = "" | ||
} else if (isConnected){ | ||
returnValue = "" | ||
} else if (connectState == 0){ | ||
returnValue = "" | ||
} else if (connectState == 1){ | ||
//% "Starting..." | ||
returnValue = qsTrId("settings_tailscale_starting") | ||
} else if (connectState == 2 || connectState == 3){ | ||
//% "Tailscale starting..." | ||
returnValue = qsTrId("settings_tailscale_tailscale_starting") | ||
} else if (connectState == 4){ | ||
//% "This GX device is logged out of Tailscale.\n\nPlease check your internet connection and try again." | ||
returnValue = qsTrId("settings_tailscale_logged_out") | ||
} else if (connectState == 5){ | ||
//% "Waiting for a response from Tailscale..."{ | ||
returnValue = qsTrId("settings_tailscale_waiting_for_a_response") | ||
} else if (connectState == 6){ | ||
//% "Connect this GX device to your Tailscale account by opening this link:" | ||
returnValue = qsTrId("settings_tailscale_connect_to_tailscale_account") + "\n\n" + loginLink | ||
} else { | ||
//% "Unknown state:" | ||
returnValue = qsTrId("settings_tailscale_unknown_state") + " " + connectState | ||
} | ||
|
||
return (returnValue) | ||
} | ||
|
||
property string serviceState: getState() | ||
|
||
GradientListView { | ||
id: settingsListView | ||
|
||
model: ObjectModel { | ||
|
||
ListSwitch { | ||
id: switchTailscaleEnabled | ||
//% "Enable Tailscale" | ||
text: qsTrId("settings_tailscale_enable") | ||
dataItem.uid: Global.systemSettings.serviceUid + "/Settings/Services/Tailscale/Enabled" | ||
writeAccessLevel: VenusOS.User_AccessType_Installer | ||
enabled: isRunning | ||
} | ||
|
||
ListLabel { | ||
text: serviceState | ||
allowed: serviceState !== "" | ||
horizontalAlignment: Text.AlignHCenter | ||
} | ||
|
||
Rectangle { | ||
id: qrCodeRect | ||
color: Theme.color_page_background | ||
width: 200 | ||
height: visible ? (200 + Theme.geometry_listItem_content_verticalMargin) : 0 | ||
visible: loginLink !== "" && isEnabled && connectState == 6 | ||
anchors.horizontalCenter: parent.horizontalCenter | ||
|
||
Image { | ||
id: qrCodeImage | ||
// NOTE: wait for https://github.com/victronenergy/gui-v2/issues/1350 to be fixed | ||
// source: loginLink !== "" ? "https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=" + encodeURIComponent(loginLink) : "" | ||
|
||
// Temporary solution | ||
source: loginLinkQrCode !== "" ? "data:image/png;base64," + loginLinkQrCode : "" | ||
|
||
width: 200 | ||
height: 200 | ||
} | ||
} | ||
|
||
ListTextField { | ||
//% "Hostname" | ||
text: qsTrId("settings_tailscale_hostname") | ||
dataItem.uid: Global.systemSettings.serviceUid + "/Settings/Services/Tailscale/Hostname" | ||
placeholderText: "--" | ||
enabled: !isEnabled | ||
writeAccessLevel: VenusOS.User_AccessType_Installer | ||
} | ||
|
||
ListTextItem { | ||
//% "IPv4" | ||
text: qsTrId("settings_tailscale_ipv4") | ||
dataItem.uid: root.tailscaleServiceUid + "/IPv4" | ||
allowed: dataItem.isValid && dataItem.value !== "" && isConnected | ||
} | ||
|
||
ListTextItem { | ||
//% "IPv6" | ||
text: qsTrId("settings_tailscale_ipv6") | ||
dataItem.uid: root.tailscaleServiceUid + "/IPv6" | ||
allowed: dataItem.isValid && dataItem.value !== "" && isConnected | ||
} | ||
|
||
ListButton { | ||
//% "Logout from Tailscale account" | ||
text: qsTrId("settings_tailscale_logout_from_tailscale_account") | ||
//% "Logout" | ||
button.text: qsTrId("settings_tailscale_logout") | ||
allowed: isConnected | ||
showAccessLevel: VenusOS.User_AccessType_Installer | ||
onClicked: commandItem.setValue ('logout') | ||
} | ||
|
||
ListNavigationItem { | ||
//% "Advanced" | ||
text: qsTrId("settings_tailscale_advanced") | ||
onClicked: { | ||
Global.pageManager.pushPage(tailscaleAdvanced, {"title": text}) | ||
} | ||
|
||
Component { | ||
id: tailscaleAdvanced | ||
|
||
Page { | ||
GradientListView { | ||
model: ObjectModel { | ||
|
||
ListTextField { | ||
//% "Advertise routes" | ||
text: qsTrId("settings_tailscale_advertise_routes") | ||
dataItem.uid: Global.systemSettings.serviceUid + "/Settings/Services/Tailscale/AdvertiseRoutes" | ||
//% "e.g. 192.168.1.0/24" | ||
placeholderText: qsTrId("settings_tailscale_advertise_routes_placeholder") | ||
enabled: !isEnabled | ||
writeAccessLevel: VenusOS.User_AccessType_Installer | ||
} | ||
|
||
ListTextField { | ||
//% "Custom server URL (Headscale)" | ||
text: qsTrId("settings_tailscale_custom_server_url") | ||
dataItem.uid: Global.systemSettings.serviceUid + "/Settings/Services/Tailscale/CustomServerUrl" | ||
placeholderText: "--" | ||
enabled: !isEnabled | ||
writeAccessLevel: VenusOS.User_AccessType_Installer | ||
} | ||
|
||
ListTextField { | ||
//% "Custom Tailscale up arguments" | ||
text: qsTrId("settings_tailscale_custom_tailscale_up_arguments") | ||
dataItem.uid: Global.systemSettings.serviceUid + "/Settings/Services/Tailscale/CustomArguments" | ||
placeholderText: "--" | ||
enabled: !isEnabled | ||
writeAccessLevel: VenusOS.User_AccessType_Installer | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |