Files
BiLauncher/MicrosoftLoginDialog.qml
T
2026-10-09 12:29:21 +03:00

121 lines
2.7 KiB
QML

pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Controls 2.15
import QtWebEngine
Dialog {
id: msLogin
required property var backend
signal failed(string message)
property bool codeTaken: false
anchors.centerIn: parent
modal: true
width: 560
height: 680
padding: 0
closePolicy: Popup.NoAutoClose
function openAt(url) {
codeTaken = false
web.url = url
open()
}
function handleUrl(url) {
if (codeTaken)
return
const info = backend.inspectMicrosoftRedirect(String(url))
if (!info.matched)
return
codeTaken = true
close()
if (info.code !== "") {
backend.finishMicrosoftLogin(info.code)
} else {
backend.cancelMicrosoftLogin()
msLogin.failed(info.error !== "" ? info.error : Loc.t.auth.msa.error.incomplete)
}
}
background: Rectangle {
color: "#1e1e1e"
radius: 10
border.color: "#91B315"
border.width: 1
}
header: Item {
implicitHeight: 52
Text {
anchors.centerIn: parent
text: Loc.t.auth.msa.title.signIn
color: "#ffffff"
font.pixelSize: 17
font.bold: true
}
Rectangle {
anchors.bottom: parent.bottom
width: parent.width
height: 1
color: "#333333"
}
}
contentItem: Item {
WebEngineProfilePrototype {
id: msProfile
}
WebEngineView {
id: web
anchors.fill: parent
anchors.margins: 12
profile: msProfile.instance()
onUrlChanged: msLogin.handleUrl(url)
}
BusyIndicator {
anchors.centerIn: parent
running: web.loading
visible: running
}
}
footer: Item {
implicitHeight: 60
Rectangle {
anchors.top: parent.top
width: parent.width
height: 1
color: "#333333"
}
Button {
anchors.centerIn: parent
text: Loc.t.common.button.cancel
width: 110; height: 36
contentItem: Text {
text: parent.text
color: "#ffffff"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
background: Rectangle {
color: parent.pressed ? "#444444" : "#333333"
radius: 6
}
onClicked: {
msLogin.codeTaken = true
msLogin.close()
msLogin.backend.cancelMicrosoftLogin()
}
}
}
}