diff --git a/devel/704.md b/devel/704.md new file mode 100644 index 0000000000..e24a495b78 --- /dev/null +++ b/devel/704.md @@ -0,0 +1,7 @@ +# [704] 补充 OAuth 相关的 WASM 条件编译 + +# What +补充了 OAuth 相关的 WASM 条件编译,在 WASM 构建中不使用 QNetworkAuth + +# Why? +Qt WASM 不支持 QNetworkAuth 模块 diff --git a/src/Plugins/Qt/QTMOAuth.hpp b/src/Plugins/Qt/QTMOAuth.hpp index fd85462a2b..c366b3a7fe 100644 --- a/src/Plugins/Qt/QTMOAuth.hpp +++ b/src/Plugins/Qt/QTMOAuth.hpp @@ -12,11 +12,11 @@ #ifndef QTMOAUTH_H #define QTMOAUTH_H -#include - +#ifndef OS_WASM #include +#include #include - +#endif #include #include #include @@ -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 diff --git a/src/Plugins/Qt/qt_tm_widget.cpp b/src/Plugins/Qt/qt_tm_widget.cpp index 51cdd45ba3..02bf385ef6 100644 --- a/src/Plugins/Qt/qt_tm_widget.cpp +++ b/src/Plugins/Qt/qt_tm_widget.cpp @@ -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" @@ -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; @@ -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 (get_server ().operator->()); @@ -485,6 +488,7 @@ qt_tm_widget_rep::qt_tm_widget_rep (int mask, command _quit) checkLocalTokenAndLogin (); } } +#endif }); // 初始设置VIP按钮可见性:商业版且(未登录或普通用户/体验会员)时显示 @@ -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 (get_server ().operator->()); @@ -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 () { @@ -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 @@ -3213,6 +3221,7 @@ qt_tm_widget_rep::logout () { syncScmMembershipNotification (false); // 通过tm_server获取QTMOAuth实例并调用clearInvalidTokens +#ifndef OS_WASM if (is_server_started ()) { tm_server_rep* server= dynamic_cast (get_server ().operator->()); @@ -3220,6 +3229,7 @@ qt_tm_widget_rep::logout () { server->getAccount ()->clearInvalidTokens (); } } +#endif } void diff --git a/src/System/Boot/init_texmacs.cpp b/src/System/Boot/init_texmacs.cpp index 8d8e5e1f6d..eb2993d8c0 100644 --- a/src/System/Boot/init_texmacs.cpp +++ b/src/System/Boot/init_texmacs.cpp @@ -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" @@ -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; @@ -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 guardedDialog (dialog); auto observer= std::make_shared> (); @@ -1022,6 +1032,7 @@ 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) { @@ -1029,11 +1040,13 @@ attach_startup_login_success_observer (QWK::StartupLoginDialog* dialog) { guardedDialog->notifyLoginSucceeded (); } }); +#endif if (account->isLoggedIn ()) guardedDialog->notifyLoginSucceeded (); }; QTimer::singleShot (0, dialog, *observer); +#endif } bool @@ -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; diff --git a/src/Texmacs/Server/tm_server.cpp b/src/Texmacs/Server/tm_server.cpp index 0b2a58c5cc..2179d7d59e 100644 --- a/src/Texmacs/Server/tm_server.cpp +++ b/src/Texmacs/Server/tm_server.cpp @@ -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" @@ -34,7 +32,7 @@ #include #include -#ifdef QTTEXMACS +#if defined(QTTEXMACS) && !defined(OS_WASM) #include #include #include @@ -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 @@ -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 (app)) {} server_rep* tm_server_rep::get_server () { @@ -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 buffers= get_all_buffers (); QStringList args = QApplication::arguments (); @@ -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 } /****************************************************************************** diff --git a/src/Texmacs/tm_server.hpp b/src/Texmacs/tm_server.hpp index 2d3706bb85..8231d8d55b 100644 --- a/src/Texmacs/tm_server.hpp +++ b/src/Texmacs/tm_server.hpp @@ -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" @@ -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