mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-04-29 22:24:26 +02:00
chore:add qr code support for login
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
564f120c22
commit
cb591ba52e
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -19,3 +19,6 @@
|
||||
[submodule "flatpak/shared-modules"]
|
||||
path = flatpak/shared-modules
|
||||
url = https://github.com/flathub/shared-modules.git
|
||||
[submodule "libraries/qt-qrcodegenerator/QR-Code-generator"]
|
||||
path = libraries/qt-qrcodegenerator/QR-Code-generator
|
||||
url = https://github.com/nayuki/QR-Code-generator
|
||||
|
@ -503,6 +503,7 @@ add_subdirectory(libraries/libnbtplusplus)
|
||||
add_subdirectory(libraries/systeminfo) # system information library
|
||||
add_subdirectory(libraries/launcher) # java based launcher part for Minecraft
|
||||
add_subdirectory(libraries/javacheck) # java compatibility checker
|
||||
add_subdirectory(libraries/qt-qrcodegenerator) # qr code generator
|
||||
if(FORCE_BUNDLED_ZLIB)
|
||||
message(STATUS "Using bundled zlib")
|
||||
|
||||
|
@ -403,3 +403,12 @@
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
## qt-qrcodegenerator (`libraries/qt-qrcodegenerator`)
|
||||
|
||||
Copyright © 2024 Project Nayuki. (MIT License)
|
||||
https://www.nayuki.io/page/qr-code-generator-library
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
- The Software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.
|
||||
|
19
flake.lock
generated
19
flake.lock
generated
@ -32,10 +32,27 @@
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"qt-qrcodegenerator": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1731907326,
|
||||
"narHash": "sha256-5+iYwsbX8wjKZPCy7ENj5HCYgOqzeSNLs/YrX2Vc7CQ=",
|
||||
"owner": "nayuki",
|
||||
"repo": "QR-Code-generator",
|
||||
"rev": "f40366c40d8d1956081f7ec643d240c02a81df52",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nayuki",
|
||||
"repo": "QR-Code-generator",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"libnbtplusplus": "libnbtplusplus",
|
||||
"nixpkgs": "nixpkgs"
|
||||
"nixpkgs": "nixpkgs",
|
||||
"qt-qrcodegenerator": "qt-qrcodegenerator"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -15,6 +15,11 @@
|
||||
url = "github:PrismLauncher/libnbtplusplus";
|
||||
flake = false;
|
||||
};
|
||||
|
||||
qt-qrcodegenerator = {
|
||||
url = "github:nayuki/QR-Code-generator";
|
||||
flake = false;
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
@ -22,6 +27,7 @@
|
||||
self,
|
||||
nixpkgs,
|
||||
libnbtplusplus,
|
||||
qt-qrcodegenerator,
|
||||
}:
|
||||
|
||||
let
|
||||
@ -167,6 +173,7 @@
|
||||
prismlauncher-unwrapped = prev.callPackage ./nix/unwrapped.nix {
|
||||
inherit
|
||||
libnbtplusplus
|
||||
qt-qrcodegenerator
|
||||
self
|
||||
;
|
||||
};
|
||||
|
@ -1289,6 +1289,7 @@ target_link_libraries(Launcher_logic
|
||||
qdcss
|
||||
BuildConfig
|
||||
Qt${QT_VERSION_MAJOR}::Widgets
|
||||
qrcode
|
||||
)
|
||||
|
||||
if (UNIX AND NOT CYGWIN AND NOT APPLE)
|
||||
|
@ -2,7 +2,6 @@
|
||||
<RCC version="1.0">
|
||||
<qresource prefix="/documents">
|
||||
<file>../../../COPYING.md</file>
|
||||
<file>login-qr.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
|
@ -1,8 +0,0 @@
|
||||
<svg width="33" height="33" version="1.1" viewBox="0 0 8.7312 8.7312" xmlns="http://www.w3.org/2000/svg">
|
||||
<g transform="scale(.26458)">
|
||||
<rect width="33" height="33" fill="#fff"/>
|
||||
<g>
|
||||
<path d="m29 29h-6v-1h1v-3h-1v2h-1v-1h-1v1h-2v-1h1v-2h-1v-1h1v-1h-1v-1h1v-1h1v-1h1v1h1v-1h1v-1h-5v3h-2v-1h1v-1h-1v1h-2v-1h1v-1h1v-1h-1v1h-1v1h-1v-2h1v-2h2v-2h1v2h2v1h-1v1h2v-2h-1v-3h-1v-1h1v-2h-2v-1h-1v-1h-1v2h-2v1h-1v-1h-1v-3h1v1h1v1h1v-2h2v-2h1v3h3v5h1v1h-1v1h2v-1h1v1h1v1h2v1h2v2h-1v-1h-2v-1h-1v4h3v-1h1v7h-1v1h-1v1h2zm-10 0h-5v-1h3v-1h1v1h1zm-6 0h-1v-4h3v-1h1v2h1v1h-2v-1h-2zm-2 0h-7v-7h7zm15-1v-2h-1v2zm-16 0v-5h-5v5zm-1-1h-3v-3h3zm9-1h-1v-1h1zm10-1v-1h-1v-1h-1v-2h-1v3h1v1zm-9 0h-1v-1h1zm5-1v-3h-3v3zm-7 0h-1v-2h-1v1h-2v-1h-1v-1h-3v-1h6v1h2v1h2v1h-2zm6-1h-1v-1h1zm5-1v-1h-1v1zm-21-1h-1v-2h1zm-2-1h-1v-1h1zm23-1h-2v-1h2zm-17 0h-4v-1h1v-1h1v1h2zm-5 0h-1v-3h1v-1h1v-1h-1v1h-2v-3h4v1h2v1h-2v1h2v1h2v-1h1v1h1v1h-5v-1h-1v1h-2zm18-2v-2h-2v1h1v1zm-13-2h-1v-1h1zm17-1h-1v-1h1zm-14 0h-1v-1h1zm-2 0h-1v-1h1zm17-1h-1v-1h1zm-2 0h-3v-1h3zm-8 0h-1v-1h1zm-6 0h-1v-1h1zm-2 0h-1v-1h1zm5-1h-1v-1h1zm-2 0h-1v-1h1zm15-1h-7v-7h7zm-10 0h-1v-1h1zm-2 0h-1v-2h1zm-2 0h-1v-1h1zm-2 0h-1v-1h1zm-2 0h-7v-7h7zm17-1v-5h-5v5zm-18 0v-5h-5v5zm17-1h-3v-3h3zm-18 0h-3v-3h3zm5-4h-2v-1h2z"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
Before Width: | Height: | Size: 1.2 KiB |
@ -36,6 +36,7 @@
|
||||
#include "MSALoginDialog.h"
|
||||
#include "Application.h"
|
||||
|
||||
#include "qr.h"
|
||||
#include "ui_MSALoginDialog.h"
|
||||
|
||||
#include "DesktopServices.h"
|
||||
@ -60,7 +61,6 @@ MSALoginDialog::MSALoginDialog(QWidget* parent) : QDialog(parent), ui(new Ui::MS
|
||||
ui->code->setFont(font);
|
||||
|
||||
connect(ui->copyCode, &QPushButton::clicked, this, [this] { QApplication::clipboard()->setText(ui->code->text()); });
|
||||
ui->qr->setPixmap(QIcon((":/documents/login-qr.svg")).pixmap(QSize(150, 150)));
|
||||
connect(ui->loginButton, &QPushButton::clicked, this, [this] {
|
||||
if (m_url.isValid()) {
|
||||
if (!DesktopServices::openUrl(m_url)) {
|
||||
@ -139,19 +139,27 @@ void MSALoginDialog::authorizeWithBrowser(const QUrl& url)
|
||||
m_url = url;
|
||||
}
|
||||
|
||||
void MSALoginDialog::authorizeWithBrowserWithExtra(QString url, QString code, int expiresIn)
|
||||
void MSALoginDialog::authorizeWithBrowserWithExtra(QString url, QString code, [[maybe_unused]] int expiresIn)
|
||||
{
|
||||
ui->stackedWidget->setCurrentIndex(1);
|
||||
|
||||
const auto linkString = QString("<a href=\"%1\">%2</a>").arg(url, url);
|
||||
ui->code->setText(code);
|
||||
auto isDefaultUrl = url == "https://www.microsoft.com/link";
|
||||
ui->qr->setVisible(isDefaultUrl);
|
||||
if (isDefaultUrl) {
|
||||
ui->qrMessage->setText(tr("Open %1 or scan the QR and enter the above code.").arg(linkString));
|
||||
} else {
|
||||
ui->qrMessage->setText(tr("Open %1 and enter the above code.").arg(linkString));
|
||||
if (url == "https://www.microsoft.com/link" && !code.isEmpty()) {
|
||||
url += QString("?otc=%1").arg(code);
|
||||
}
|
||||
ui->code->setText(code);
|
||||
|
||||
auto size = QSize(150, 150);
|
||||
QPixmap pixmap(size);
|
||||
pixmap.fill(Qt::white);
|
||||
|
||||
QPainter painter(&pixmap);
|
||||
paintQR(painter, size, url, Qt::black);
|
||||
|
||||
// Set the generated pixmap to the label
|
||||
ui->qr->setPixmap(pixmap);
|
||||
|
||||
ui->qrMessage->setText(tr("Open %1 or scan the QR and enter the above code if needed.").arg(linkString));
|
||||
}
|
||||
|
||||
void MSALoginDialog::onDeviceFlowStatus(QString status)
|
||||
|
@ -99,6 +99,14 @@ Canonical implementation of the murmur2 hash, taken from [SMHasher](https://gith
|
||||
|
||||
Public domain (the author disclaimed the copyright).
|
||||
|
||||
## qt-qrcodegenerator
|
||||
|
||||
A simple library for generating QR codes
|
||||
|
||||
See [github repo](https://github.com/nayuki/QR-Code-generator).
|
||||
|
||||
MIT
|
||||
|
||||
## quazip
|
||||
|
||||
A zip manipulation library.
|
||||
|
32
libraries/qt-qrcodegenerator/CMakeLists.txt
Normal file
32
libraries/qt-qrcodegenerator/CMakeLists.txt
Normal file
@ -0,0 +1,32 @@
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
|
||||
project(qrcode)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED true)
|
||||
set(CMAKE_C_STANDARD_REQUIRED true)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
|
||||
|
||||
if(QT_VERSION_MAJOR EQUAL 5)
|
||||
find_package(Qt5 COMPONENTS Core Gui REQUIRED)
|
||||
elseif(Launcher_QT_VERSION_MAJOR EQUAL 6)
|
||||
find_package(Qt6 COMPONENTS Core Gui Core5Compat REQUIRED)
|
||||
list(APPEND systeminfo_LIBS Qt${QT_VERSION_MAJOR}::Core5Compat)
|
||||
endif()
|
||||
|
||||
add_library(qrcode STATIC qr.h qr.cpp QR-Code-generator/cpp/qrcodegen.cpp QR-Code-generator/cpp/qrcodegen.hpp )
|
||||
|
||||
target_link_libraries(qrcode Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui ${systeminfo_LIBS})
|
||||
|
||||
|
||||
# needed for statically linked qrcode in shared libs on x86_64
|
||||
set_target_properties(qrcode
|
||||
PROPERTIES POSITION_INDEPENDENT_CODE TRUE
|
||||
)
|
||||
|
||||
target_include_directories(qrcode PUBLIC ./ PRIVATE QR-Code-generator/cpp/)
|
||||
|
1
libraries/qt-qrcodegenerator/QR-Code-generator
Submodule
1
libraries/qt-qrcodegenerator/QR-Code-generator
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit f40366c40d8d1956081f7ec643d240c02a81df52
|
29
libraries/qt-qrcodegenerator/qr.cpp
Normal file
29
libraries/qt-qrcodegenerator/qr.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
#include "qr.h"
|
||||
#include "qrcodegen.hpp"
|
||||
|
||||
void paintQR(QPainter& painter, const QSize sz, const QString& data, QColor fg)
|
||||
{
|
||||
// NOTE: At this point you will use the API to get the encoding and format you want, instead of my hardcoded stuff:
|
||||
qrcodegen::QrCode qr = qrcodegen::QrCode::encodeText(data.toUtf8().constData(), qrcodegen::QrCode::Ecc::LOW);
|
||||
const int s = qr.getSize() > 0 ? qr.getSize() : 1;
|
||||
const double w = sz.width();
|
||||
const double h = sz.height();
|
||||
const double aspect = w / h;
|
||||
const double size = ((aspect > 1.0) ? h : w);
|
||||
const double scale = size / (s + 2);
|
||||
// NOTE: For performance reasons my implementation only draws the foreground parts in supplied color.
|
||||
// It expects background to be prepared already (in white or whatever is preferred).
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(fg);
|
||||
for (int y = 0; y < s; y++) {
|
||||
for (int x = 0; x < s; x++) {
|
||||
const int color = qr.getModule(x, y); // 0 for white, 1 for black
|
||||
if (0 != color) {
|
||||
const double rx1 = (x + 1) * scale, ry1 = (y + 1) * scale;
|
||||
QRectF r(rx1, ry1, scale, scale);
|
||||
painter.drawRects(&r, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
8
libraries/qt-qrcodegenerator/qr.h
Normal file
8
libraries/qt-qrcodegenerator/qr.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <QColor>
|
||||
#include <QPainter>
|
||||
#include <QSize>
|
||||
|
||||
// https://stackoverflow.com/questions/21400254/how-to-draw-a-qr-code-with-qt-in-native-c-c
|
||||
void paintQR(QPainter& painter, const QSize sz, const QString& data, QColor fg);
|
@ -9,16 +9,15 @@
|
||||
jdk17,
|
||||
kdePackages,
|
||||
libnbtplusplus,
|
||||
qt-qrcodegenerator,
|
||||
ninja,
|
||||
self,
|
||||
stripJavaArchivesHook,
|
||||
tomlplusplus,
|
||||
zlib,
|
||||
|
||||
msaClientID ? null,
|
||||
gamemodeSupport ? stdenv.hostPlatform.isLinux,
|
||||
}:
|
||||
|
||||
assert lib.assertMsg (
|
||||
gamemodeSupport -> stdenv.hostPlatform.isLinux
|
||||
) "gamemodeSupport is only available on Linux.";
|
||||
@ -64,6 +63,9 @@ stdenv.mkDerivation {
|
||||
postUnpack = ''
|
||||
rm -rf source/libraries/libnbtplusplus
|
||||
ln -s ${libnbtplusplus} source/libraries/libnbtplusplus
|
||||
|
||||
rm -rf source/libraries/qt-qrcodegenerator/QR-Code-generator
|
||||
ln -s ${qt-qrcodegenerator} source/libraries/qt-qrcodegenerator/QR-Code-generator
|
||||
'';
|
||||
|
||||
nativeBuildInputs = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user