Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions devel/704.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# [704] 补充 OAuth 相关的 WASM 条件编译

# What
补充了 OAuth 相关的 WASM 条件编译,在 WASM 构建中不使用 QNetworkAuth

# Why?
Qt WASM 不支持 QNetworkAuth 模块
20 changes: 11 additions & 9 deletions src/Plugins/Qt/QTMOAuth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
#ifndef QTMOAUTH_H
#define QTMOAUTH_H

#include <QtNetworkAuth/qoauth2authorizationcodeflow.h>

#ifndef OS_WASM
#include <QtNetwork/qnetworkrequestfactory.h>
#include <QtNetworkAuth/qoauth2authorizationcodeflow.h>
#include <QtNetworkAuth/qoauthhttpserverreplyhandler.h>

#endif
#include <QtCore/qabstractitemmodel.h>
#include <QtCore/qjsonobject.h>
#include <QtCore/qpointer.h>
Expand Down Expand Up @@ -52,15 +52,17 @@ private slots:
public:
void clearInvalidTokens ();

#ifndef OS_WASM
QRestAccessManager* network= nullptr;
QOAuth2AuthorizationCodeFlow oauth2;
QOAuthHttpServerReplyHandler* m_reply;
QTimer* m_tokenCheckTimer;
QString m_refreshToken;
qint64 m_tokenExpiryTime= 0;
QString m_codeVerifier;
QString m_codeChallenge;
int m_port;
#endif
QTimer* m_tokenCheckTimer;
QString m_refreshToken;
qint64 m_tokenExpiryTime= 0;
QString m_codeVerifier;
QString m_codeChallenge;
int m_port;
};

#endif
12 changes: 11 additions & 1 deletion src/Plugins/Qt/qt_tm_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ bool in_presentation_mode ();
#include "QTMGuiHelper.hpp" // needed to connect()
#include "QTMInteractiveInputHelper.hpp"
#include "QTMInteractivePrompt.hpp"
#ifndef OS_WASM
#include "QTMOAuth.hpp"
#include "QTMStartupTabWidget.hpp"
#endif
#include "QTMStyle.hpp" // qtstyle()
#include "QTMTabPage.hpp"
#include "QTMWindow.hpp"
Expand Down Expand Up @@ -309,7 +311,7 @@ qt_tm_widget_rep::qt_tm_widget_rep (int mask, command _quit)

windowAgent->setSystemButtonArea (sysBtnArea);
}
#elif defined(Q_OS_WIN) || defined(Q_OS_LINUX)
#elif defined(Q_OS_WIN) || defined(Q_OS_LINUX) || defined(Q_OS_WASM)
// 无边框布局(Windows / Linux),并使用 /styles 资源中的图标
Q_INIT_RESOURCE (styles);
QWK::WindowBar* windowBar= nullptr;
Expand Down Expand Up @@ -471,6 +473,7 @@ qt_tm_widget_rep::qt_tm_widget_rep (int mask, command _quit)
return;
}

#ifndef OS_WASM
if (is_server_started ()) {
tm_server_rep* server=
dynamic_cast<tm_server_rep*> (get_server ().operator->());
Expand All @@ -485,6 +488,7 @@ qt_tm_widget_rep::qt_tm_widget_rep (int mask, command _quit)
checkLocalTokenAndLogin ();
}
}
#endif
});

// 初始设置VIP按钮可见性:商业版且(未登录或普通用户/体验会员)时显示
Expand Down Expand Up @@ -911,6 +915,7 @@ qt_tm_widget_rep::qt_tm_widget_rep (int mask, command _quit)
update_visibility ();

// 连接登录状态变化信号
#ifndef OS_WASM
if (is_server_started ()) {
tm_server_rep* server=
dynamic_cast<tm_server_rep*> (get_server ().operator->());
Expand Down Expand Up @@ -944,6 +949,7 @@ qt_tm_widget_rep::qt_tm_widget_rep (int mask, command _quit)
else {
std_error << "qt_tm_widget_rep: server not started, cannot connect ";
}
#endif
}

qt_tm_widget_rep::~qt_tm_widget_rep () {
Expand Down Expand Up @@ -1078,11 +1084,13 @@ qt_tm_widget_rep::sync_startup_tab_mode () {

update_visibility ();

#ifndef OS_WASM
if (!startupContentWidget) {
startupContentWidget= new QTMStartupTabWidget (centralwidget ());
}
show_widget_in_layout (startupContentWidget, layout);
startupContentWidget->setFocus (Qt::OtherFocusReason);
#endif
}
else if (pdfTabMode) {
// Show PDF viewer
Expand Down Expand Up @@ -3213,13 +3221,15 @@ qt_tm_widget_rep::logout () {
syncScmMembershipNotification (false);

// 通过tm_server获取QTMOAuth实例并调用clearInvalidTokens
#ifndef OS_WASM
if (is_server_started ()) {
tm_server_rep* server=
dynamic_cast<tm_server_rep*> (get_server ().operator->());
if (server && server->getAccount ()) {
server->getAccount ()->clearInvalidTokens ();
}
}
#endif
}

void
Expand Down
18 changes: 18 additions & 0 deletions src/System/Boot/init_texmacs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
#endif
#ifdef QTTEXMACS
#include "Qt/QTMApplication.hpp"
#ifndef OS_WASM
#include "Qt/QTMOAuth.hpp"
#endif
#include "Qt/qt_gui.hpp"
#include "Qt/qt_guide_window.hpp"
#include "Qt/qt_utilities.hpp"
Expand Down Expand Up @@ -987,6 +989,10 @@ TeXmacs_main (int argc, char** argv) {

static void
perform_startup_login_request () {
#if defined(OS_WASM)
g_startup_login_requested= false;
return;
#else
if (!is_server_started ()) {
g_startup_login_requested= true;
return;
Expand All @@ -1001,10 +1007,14 @@ perform_startup_login_request () {
}

g_startup_login_requested= true;
#endif
}

static void
attach_startup_login_success_observer (QWK::StartupLoginDialog* dialog) {
#if defined(OS_WASM)
(void) dialog;
#else
QPointer<QWK::StartupLoginDialog> guardedDialog (dialog);
auto observer= std::make_shared<std::function<void ()>> ();

Expand All @@ -1022,18 +1032,21 @@ attach_startup_login_success_observer (QWK::StartupLoginDialog* dialog) {
return;
}

#ifndef OS_WASM
QTMOAuth* account= server->getAccount ();
QObject::connect (account, &QTMOAuth::loginStateChanged, guardedDialog,
[guardedDialog] (bool loggedIn) {
if (loggedIn && guardedDialog) {
guardedDialog->notifyLoginSucceeded ();
}
});
#endif

if (account->isLoggedIn ()) guardedDialog->notifyLoginSucceeded ();
};

QTimer::singleShot (0, dialog, *observer);
#endif
}

bool
Expand All @@ -1043,6 +1056,11 @@ show_startup_login_dialog () {
return true;
}

#if defined(OS_WASM)
// WASM builds do not use the startup login dialog.
return true;
#endif

if (!QWK::StartupLoginDialog::shouldShow ()) {
// Normal startup, no need to show login dialog
return true;
Expand Down
22 changes: 15 additions & 7 deletions src/Texmacs/Server/tm_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
#include "dictionary.hpp"
#include "file.hpp"
#include "glue.hpp"
#ifndef OS_WASM
#include "goldfish.hpp"
#endif
#include "lolly/system/subprocess.hpp"
#include "new_style.hpp"
#include "s7_blackbox.hpp"
Expand All @@ -34,7 +32,7 @@
#include <moebius/drd/drd_std.hpp>
#include <s7_tm.hpp>

#ifdef QTTEXMACS
#if defined(QTTEXMACS) && !defined(OS_WASM)
#include <QApplication>
#include <QProcess>
#include <QStringList>
Expand Down Expand Up @@ -154,14 +152,14 @@ tm_server_rep::tm_server_rep (app_type app) : def_zoomf (1.0) {
eval_scheme_root (init_prg);
initialize_smobs (initialize_scheme ());
initialize_glue ();
#ifndef OS_WASM
goldfish::glue_for_community_edition (tm_s7);
#endif
gui_interpose (texmacs_interpose_handler);
set_wait_handler (texmacs_wait_handler);

init_app (app);
#ifndef OS_WASM
m_account= new QTMOAuth ();
#endif

#ifdef OS_GNU_LINUX
return; // in order to avoid segmentation faults
Expand All @@ -170,7 +168,11 @@ tm_server_rep::tm_server_rep (app_type app) : def_zoomf (1.0) {
#endif
}

tm_server_rep::~tm_server_rep () { delete m_account; }
tm_server_rep::~tm_server_rep () {
#ifndef OS_WASM
delete m_account;
#endif
}
server::server (app_type app) : rep (tm_new<tm_server_rep> (app)) {}
server_rep*
tm_server_rep::get_server () {
Expand Down Expand Up @@ -327,7 +329,7 @@ tm_server_rep::restart () {
call ("quit-TeXmacs-scheme");
clear_pending_commands ();

#ifdef QTTEXMACS
#if defined(QTTEXMACS) && !defined(OS_WASM)
del_obj_qt_renderer ();
array<url> buffers= get_all_buffers ();
QStringList args = QApplication::arguments ();
Expand All @@ -347,12 +349,18 @@ tm_server_rep::restart () {

void
tm_server_rep::login () {
#ifndef OS_WASM
m_account->login ();
#endif
}

bool
tm_server_rep::is_logged_in () {
#ifdef OS_WASM
return false;
#else
return m_account->isLoggedIn ();
#endif
}

/******************************************************************************
Expand Down
4 changes: 4 additions & 0 deletions src/Texmacs/tm_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#define TM_SERVER_H

#include "../Mogan/app_type.hpp"
#ifndef OS_WASM
#include "QTMOAuth.hpp"
#endif
#include "tm_buffer.hpp"
#include "tm_config.hpp"
#include "tm_data.hpp"
Expand Down Expand Up @@ -53,10 +55,12 @@ class tm_server_rep : public tm_config_rep, public tm_frame_rep {
void login ();
bool is_logged_in ();

#ifndef OS_WASM
QTMOAuth* getAccount () const { return m_account; }

private:
QTMOAuth* m_account= nullptr;
#endif // OS_WASM
};

#endif // defined TM_SERVER_H
Loading