Skip to content

Commit

Permalink
Bring in changes that make login and token retrieval use WebEngineVie…
Browse files Browse the repository at this point in the history
…w by default
  • Loading branch information
streetpea committed Nov 29, 2024
2 parents 4c5b0bf + a15b78f commit 5f8341f
Show file tree
Hide file tree
Showing 16 changed files with 489 additions and 55 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build-appimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ jobs:
submodules: 'recursive'
path: 'chiaki-ng'

- name: Add QmlWebEngine Import
working-directory: chiaki-ng
run: |
echo "import QtWebEngine; WebEngineView {}" > "$PWD/gui/src/qml/qtwebengine_import.qml"
- name: Run build script
working-directory: chiaki-ng/scripts
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-macos-x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
- name: Deploy chiaki-ng
run: |
cp -a build/gui/chiaki.app chiaki-ng.app
echo "import QtWebEngine; WebEngineView {}" > "$PWD/gui/src/qml/qtwebengine_import.qml"
$(brew --prefix)/opt/qt@6/bin/macdeployqt chiaki-ng.app -qmldir="$PWD/gui/src/qml" -libpath=$(brew --prefix)/lib
mkdir -p chiaki-ng.app/Contents/Resources/vulkan/icd.d
wget https://github.com/KhronosGroup/MoltenVK/releases/download/v1.2.9/MoltenVK-macos.tar && tar xf MoltenVK-macos.tar
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
- name: Deploy chiaki-ng
run: |
cp -a build/gui/chiaki.app chiaki-ng.app
echo "import QtWebEngine; WebEngineView {}" > "$PWD/gui/src/qml/qtwebengine_import.qml"
$(brew --prefix)/opt/qt@6/bin/macdeployqt chiaki-ng.app -qmldir="$PWD/gui/src/qml" -libpath=$(brew --prefix)/lib
mkdir -p chiaki-ng.app/Contents/Resources/vulkan/icd.d
wget https://github.com/KhronosGroup/MoltenVK/releases/download/v1.2.9/MoltenVK-macos.tar && tar xf MoltenVK-macos.tar
Expand Down Expand Up @@ -79,6 +80,7 @@ jobs:
- name: Deploy chiaki-ng
run: |
cp -a build/gui/chiaki.app chiaki-ng.app
echo "import QtWebEngine; WebEngineView {}" > "$PWD/gui/src/qml/qtwebengine_import.qml"
$(brew --prefix)/opt/qt@6/bin/macdeployqt chiaki-ng.app -qmldir="$PWD/gui/src/qml" -libpath=$(brew --prefix)/lib
mkdir -p chiaki-ng.app/Contents/Resources/vulkan/icd.d
wget https://github.com/KhronosGroup/MoltenVK/releases/download/v1.2.9/MoltenVK-macos.tar && tar xf MoltenVK-macos.tar
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-msys2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ jobs:
cp /mingw64/bin/libpsl-*.dll chiaki-ng-Win/
cp /mingw64/bin/libjson-c-*.dll chiaki-ng-Win/
cp /mingw64/bin/swresample-*.dll chiaki-ng-Win/
echo "import QtWebEngine; WebEngineView {}" > "$PWD/gui/src/qml/qtwebengine_import.qml"
/mingw64/bin/windeployqt6.exe --no-translations --qmldir=$PWD/gui/src/qml --release chiaki-ng-Win/chiaki.exe
cp -R /mingw64/share/qt6/qml/QtQuick chiaki-ng-Win/qml/
cp -R /mingw64/share/qt6/qml/QtQml/WorkerScript/ chiaki-ng-Win/qml/QtQml/
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/build-weekly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ jobs:
cp "${{ github.workspace }}\${{ env.dep_folder }}\bin\libplacebo-*.dll" chiaki-ng-Win
cp "${{ github.workspace }}\${{ env.dep_folder }}\bin\shaderc_shared.dll" chiaki-ng-Win
cp "${{ github.workspace }}\${{ env.dep_folder }}\bin\spirv-cross-c-shared.dll" chiaki-ng-Win
echo "import QtWebEngine; WebEngineView {}" > "$PWD/gui/src/qml/qtwebengine_import.qml"
windeployqt.exe --no-translations --qmldir=gui/src/qml/ chiaki-ng-Win\chiaki.exe
- name: Compile .ISS to .EXE Installer
Expand Down Expand Up @@ -245,6 +246,7 @@ jobs:
- name: Deploy chiaki-ng
run: |
cp -a build/gui/chiaki.app chiaki-ng.app
echo "import QtWebEngine; WebEngineView {}" > "$PWD/gui/src/qml/qtwebengine_import.qml"
$(brew --prefix)/opt/qt@6/bin/macdeployqt chiaki-ng.app -qmldir="$PWD/gui/src/qml" -libpath=$(brew --prefix)/lib
mkdir -p chiaki-ng.app/Contents/Resources/vulkan/icd.d
wget https://github.com/KhronosGroup/MoltenVK/releases/download/v1.2.9/MoltenVK-macos.tar && tar xf MoltenVK-macos.tar
Expand Down Expand Up @@ -284,6 +286,11 @@ jobs:
submodules: 'recursive'
path: 'chiaki-ng'

- name: Add QmlWebEngine Import
working-directory: chiaki-ng
run: |
echo "import QtWebEngine; WebEngineView {}" > "$PWD/gui/src/qml/qtwebengine_import.qml"
- name: Run build script
working-directory: chiaki-ng/scripts
run: |
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ jobs:
cp "${{ github.workspace }}\${{ env.dep_folder }}\bin\libplacebo-*.dll" chiaki-ng-Win
cp "${{ github.workspace }}\${{ env.dep_folder }}\bin\shaderc_shared.dll" chiaki-ng-Win
cp "${{ github.workspace }}\${{ env.dep_folder }}\bin\spirv-cross-c-shared.dll" chiaki-ng-Win
echo "import QtWebEngine; WebEngineView {}" > "$PWD/gui/src/qml/qtwebengine_import.qml"
windeployqt.exe --no-translations --qmldir=gui/src/qml/ chiaki-ng-Win\chiaki.exe
- name: Compile .ISS to .EXE Installer
Expand Down
1 change: 1 addition & 0 deletions gui/include/qmlbackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class QmlBackend : public QObject
Q_INVOKABLE void sessionGoHome();
Q_INVOKABLE void enterPin(const QString &pin);
Q_INVOKABLE QUrl psnLoginUrl() const;
Q_INVOKABLE bool checkPsnRedirectURL(const QUrl &url) const;
Q_INVOKABLE bool handlePsnLoginRedirect(const QUrl &url);
Q_INVOKABLE void stopAutoConnect();
Q_INVOKABLE void setConsolePin(int index, QString console_pin);
Expand Down
1 change: 0 additions & 1 deletion gui/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ int real_main(int argc, char *argv[])
}

QGuiApplication::setAttribute(Qt::AA_ShareOpenGLContexts);

QGuiApplication app(argc, argv);

#ifdef Q_OS_MACOS
Expand Down
2 changes: 1 addition & 1 deletion gui/src/qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Item {
Chiaki.settings.psnAuthToken = ""
Chiaki.settings.psnAuthTokenExpiry = ""
Chiaki.settings.psnAccountId = ""
root.showPSNTokenDialog(Chiaki.openPsnLink(), true);
root.showPSNTokenDialog(true);
}

function onError(title, text) {
Expand Down
2 changes: 1 addition & 1 deletion gui/src/qml/MainView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Pane {
if(!Chiaki.settings.psnRefreshToken || !Chiaki.settings.psnAuthToken || !Chiaki.settings.psnAuthTokenExpiry || !Chiaki.settings.psnAccountId)
{
Chiaki.settings.remotePlayAsk = false;
root.showConfirmDialog(qsTr("Remote Play via PSN"), qsTr("Would you like to connect to PSN to play outside of your home network without port forwarding?") + "\n\n" + qsTr("(Note: If you select no now and want to do this later, go to the Config section of the settings.)"), () => root.showPSNTokenDialog(Chiaki.openPsnLink(), false));
root.showConfirmDialog(qsTr("Remote Play via PSN"), qsTr("Would you like to connect to PSN to play outside of your home network without port forwarding?") + "\n\n" + qsTr("(Note: If you select no now and want to do this later, go to the Config section of the settings.)"), () => root.showPSNTokenDialog(false));
}
else
Chiaki.settings.remotePlayAsk = false;
Expand Down
254 changes: 221 additions & 33 deletions gui/src/qml/PSNLoginDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,11 @@ DialogView {
submitting = true;
Chiaki.handlePsnLoginRedirect(url.text.trim());
}

StackView.onActivated: {
if(login)
{
loginForm.visible = true
dialog.buttonVisible = true
psnurl = Chiaki.openPsnLink()
if(psnurl)
{
openurl.selectAll()
openurl.copy()
}
pasteUrl.forceActiveFocus(Qt.TabFocusReason)
nativeLoginForm.visible = true;
nativeLoginForm.forceActiveFocus(Qt.TabFocusReason);
}
else
{
Expand All @@ -45,6 +37,211 @@ DialogView {
}

Item {
Item {
id: nativeLoginForm
Keys.onPressed: (event) => {
if (event.modifiers)
return;
switch (event.key) {
case Qt.Key_PageUp:
reloadButton.clicked();
event.accepted = true;
break;
case Qt.Key_PageDown:
extBrowserButton.clicked();
event.accepted = true;
break;
}
}
anchors.fill: parent
visible: false
ToolBar {
id: psnLoginToolbar
anchors {
top: parent.top
left: parent.left
right: parent.right
}
height: 80

RowLayout {
anchors {
fill: parent
leftMargin: 10
rightMargin: 10
}
Button {
id: reloadButton
Layout.fillHeight: true
Layout.preferredWidth: 300
flat: true
text: "reload webpage"
Image {
anchors {
left: parent.left
verticalCenter: parent.verticalCenter
leftMargin: 12
}
width: 28
height: 28
sourceSize: Qt.size(width, height)
source: "qrc:/icons/l1.svg"
}
onClicked: reloadTimer.start()
Material.roundedScale: Material.SmallScale
focusPolicy: Qt.NoFocus
}
ProgressBar {
id: browserProgresss
Layout.fillHeight: true
Layout.preferredWidth: 300
from: 0
to: 100
value: webView.web.loadProgress
Material.roundedScale: Material.SmallScale
focusPolicy: Qt.NoFocus
}
Button {
id: extBrowserButton
Layout.fillHeight: true
Layout.preferredWidth: 300
flat: true
Image {
anchors {
left: parent.left
verticalCenter: parent.verticalCenter
leftMargin: 12
}
width: 28
height: 28
sourceSize: Qt.size(width, height)
source: "qrc:/icons/r1.svg"
}
focusPolicy: Qt.NoFocus
text: "Use external browser"
onClicked: {
nativeLoginForm.visible = false;
psnLoginToolbar.visible = false;
nativeErrorGrid.visible = false;
webView.visible = false;
loginForm.visible = true;
dialog.buttonVisible = true;
psnurl = Chiaki.openPsnLink();
if(psnurl)
{
openurl.selectAll();
openurl.copy();
}
pasteUrl.forceActiveFocus(Qt.TabFocusReason);
}
}
}
}
Timer {
id: reloadTimer
interval: 0
running: false
onTriggered: {
webView.web.reload();
}
}

GridLayout {
id: nativeErrorGrid
visible: false
anchors {
top: psnLoginToolbar.bottom
left: parent.left
right: parent.right
topMargin: 50
}
columns: 2
rowSpacing: 10
columnSpacing: 20
Label {
id: nativeErrorHeader
text: "Retrieving PSN account ID failed with error: "
Layout.fillHeight: true
Layout.preferredWidth: 400
Layout.leftMargin: 20
}

Label {
id: nativeErrorLabel
Layout.fillHeight: true
Layout.preferredWidth: 400
Layout.leftMargin: 20
}

Label {
id: retryButton
text: "Retry process"
Layout.fillHeight: true
Layout.preferredWidth: 300
Layout.leftMargin: 20
}
C.Button {
firstInFocusChain: true
lastInFocusChain: true
text: "Retry"
onClicked: {
nativeErrorGrid.visible = false;
nativeErrorLabel.text = "";
nativeErrorLabel.visible = false;
webView.visible = true;
webView.web.url = Chiaki.psnLoginUrl();
}
Layout.preferredWidth: 200
Layout.fillHeight: true
Layout.leftMargin: 20
}
}
Item {
id: webView
property Item web
anchors {
top: psnLoginToolbar.bottom
bottom: parent.bottom
left: parent.left
right: parent.right
leftMargin: 10
rightMargin: 10
}
Component.onCompleted: {
try {
web = Qt.createQmlObject("
import QtWebEngine
import org.streetpea.chiaking
WebEngineView {
profile {
offTheRecord: true
}
settings {
dnsPrefetchEnabled: true
// Load larger touch icons
touchIconsEnabled: true
}
onContextMenuRequested: (request) => request.accepted = true;
onNavigationRequested: (request) => {
if (Chiaki.checkPsnRedirectURL(request.url)) {
Chiaki.handlePsnLoginRedirect(request.url)
request.reject();
}
else
request.accept();
}
onCertificateError: console.error(error.description);
}", webView, "webView");
web.url = Chiaki.psnLoginUrl();
web.anchors.fill = webView;
} catch (error) {
console.error('Create webengine view failed with error:' + error);
extBrowserButton.clicked();
}
}
}
}
GridLayout {
id: loginForm
anchors {
Expand Down Expand Up @@ -193,25 +390,6 @@ DialogView {
}
}

Rectangle {
id: overlay
anchors.fill: loginForm
color: "grey"
opacity: 0.0
visible: opacity

MouseArea {
anchors.fill: parent
}

BusyIndicator {
anchors.centerIn: parent
layer.enabled: true
width: 80
height: width
}
}

Connections {
target: Chiaki

Expand All @@ -222,10 +400,20 @@ DialogView {
}

function onPsnLoginAccountIdError(error) {
errorHeader.visible = true;
errorLabel.text = error;
errorLabel.visible = true;
submitting = false;
if(nativeLoginForm.visible)
{
webView.visible = false;
nativeErrorLabel.text = error;
nativeErrorLabel.visible = true;
nativeErrorGrid.visible = true;
}
else
{
errorHeader.visible = true;
errorLabel.text = error;
errorLabel.visible = true;
submitting = false;
}
}
}
}
Expand Down
Loading

0 comments on commit 5f8341f

Please sign in to comment.