浏览代码

speed up start

Le Tan 7 年之前
父节点
当前提交
d917c942d9
共有 7 个文件被更改,包括 40 次插入26 次删除
  1. 1 7
      src/main.cpp
  2. 5 1
      src/veditarea.cpp
  3. 1 1
      src/veditarea.h
  4. 19 3
      src/vmainwindow.cpp
  5. 5 1
      src/vmainwindow.h
  6. 8 12
      src/vmathjaxinplacepreviewhelper.cpp
  7. 1 1
      src/vmathjaxinplacepreviewhelper.h

+ 1 - 7
src/main.cpp

@@ -223,13 +223,7 @@ int main(int argc, char *argv[])
 
     w.show();
 
-    w.checkNotebooks();
-
-    w.promptNewNotebookIfEmpty();
-
-    w.openStartupPages();
-
-    w.openFiles(filePaths);
+    w.kickOffStartUpTimer(filePaths);
 
     return app.exec();
 }

+ 5 - 1
src/veditarea.cpp

@@ -811,7 +811,7 @@ bool VEditArea::handleKeyNavigation(int p_key, bool &p_succeed)
     return ret;
 }
 
-int VEditArea::openFiles(const QVector<VFileSessionInfo> &p_files)
+int VEditArea::openFiles(const QVector<VFileSessionInfo> &p_files, bool p_oneByOne)
 {
     VFile *curFile = NULL;
     int nrOpened = 0;
@@ -838,6 +838,10 @@ int VEditArea::openFiles(const QVector<VFileSessionInfo> &p_files)
         info.toEditTabInfo(&tabInfo);
 
         tab->tryRestoreFromTabInfo(tabInfo);
+
+        if (p_oneByOne) {
+            QCoreApplication::sendPostedEvents();
+        }
     }
 
     if (curFile) {

+ 1 - 1
src/veditarea.h

@@ -79,7 +79,7 @@ public:
     bool handleKeyNavigation(int p_key, bool &p_succeed) Q_DECL_OVERRIDE;
 
     // Open files @p_files.
-    int openFiles(const QVector<VFileSessionInfo> &p_files);
+    int openFiles(const QVector<VFileSessionInfo> &p_files, bool p_oneByOne = false);
 
     // Record a closed file in the stack.
     void recordClosedFile(const VFileSessionInfo &p_file);

+ 19 - 3
src/vmainwindow.cpp

@@ -2637,7 +2637,8 @@ bool VMainWindow::tryOpenInternalFile(const QString &p_filePath)
 void VMainWindow::openFiles(const QStringList &p_files,
                             bool p_forceOrphan,
                             OpenFileMode p_mode,
-                            bool p_forceMode)
+                            bool p_forceMode,
+                            bool p_oneByOne)
 {
     for (int i = 0; i < p_files.size(); ++i) {
         VFile *file = NULL;
@@ -2650,6 +2651,9 @@ void VMainWindow::openFiles(const QStringList &p_files,
         }
 
         m_editArea->openFile(file, p_mode, p_forceMode);
+        if (p_oneByOne) {
+            QCoreApplication::sendPostedEvents();
+        }
     }
 }
 
@@ -2744,7 +2748,7 @@ void VMainWindow::openStartupPages()
     {
         QVector<VFileSessionInfo> files = g_config->getLastOpenedFiles();
         qDebug() << "open" << files.size() << "last opened files";
-        m_editArea->openFiles(files);
+        m_editArea->openFiles(files, true);
         break;
     }
 
@@ -2752,7 +2756,7 @@ void VMainWindow::openStartupPages()
     {
         QStringList pagesToOpen = VUtils::filterFilePathsToOpen(g_config->getStartupPages());
         qDebug() << "open startup pages" << pagesToOpen;
-        openFiles(pagesToOpen);
+        openFiles(pagesToOpen, false, OpenFileMode::Read, false, true);
         break;
     }
 
@@ -3403,3 +3407,15 @@ void VMainWindow::postChangePanelView()
         m_mainSplitter->setSizes(sizes);
     }
 }
+
+void VMainWindow::kickOffStartUpTimer(const QStringList &p_files)
+{
+    QTimer::singleShot(300, [this, p_files]() {
+        checkNotebooks();
+        QCoreApplication::sendPostedEvents();
+        promptNewNotebookIfEmpty();
+        QCoreApplication::sendPostedEvents();
+        openStartupPages();
+        openFiles(p_files, false, OpenFileMode::Read, false, true);
+    });
+}

+ 5 - 1
src/vmainwindow.h

@@ -89,7 +89,8 @@ public:
     void openFiles(const QStringList &p_files,
                    bool p_forceOrphan = false,
                    OpenFileMode p_mode = OpenFileMode::Read,
-                   bool p_forceMode = false);
+                   bool p_forceMode = false,
+                   bool p_oneByOne = false);
 
     // Try to open @p_filePath as internal note.
     bool tryOpenInternalFile(const QString &p_filePath);
@@ -114,6 +115,9 @@ public:
 
     VNotebook *getCurrentNotebook() const;
 
+    // Kick off timer to do things after start.
+    void kickOffStartUpTimer(const QStringList &p_files);
+
 signals:
     // Emit when editor related configurations were changed by user.
     void editorConfigUpdated();

+ 8 - 12
src/vmathjaxinplacepreviewhelper.cpp

@@ -153,27 +153,23 @@ void VMathJaxInplacePreviewHelper::processForInplacePreview(int p_idx)
     if (vmb.m_text.isEmpty()) {
         updateInplacePreview();
     } else {
-        textToHtmlViaWebView(vmb.m_text, p_idx, m_timeStamp);
+        if (!textToHtmlViaWebView(vmb.m_text, p_idx, m_timeStamp)) {
+            updateInplacePreview();
+        }
     }
 }
 
-void VMathJaxInplacePreviewHelper::textToHtmlViaWebView(const QString &p_text,
+bool VMathJaxInplacePreviewHelper::textToHtmlViaWebView(const QString &p_text,
                                                         int p_id,
                                                         int p_timeStamp)
 {
-    int maxRetry = 50;
-    while (!m_document->isReadyToTextToHtml() && maxRetry > 0) {
-        qDebug() << "wait for web side ready to convert text to HTML";
-        VUtils::sleepWait(100);
-        --maxRetry;
-    }
-
-    if (maxRetry == 0) {
-        qWarning() << "web side is not ready to convert text to HTML";
-        return;
+    if (!m_document->isReadyToTextToHtml()) {
+        qDebug() << "web side is not ready to convert text to HTML";
+        return false;
     }
 
     m_document->textToHtmlAsync(m_documentID, p_id, p_timeStamp, p_text, false);
+    return true;
 }
 
 void VMathJaxInplacePreviewHelper::updateInplacePreview()

+ 1 - 1
src/vmathjaxinplacepreviewhelper.h

@@ -118,7 +118,7 @@ private:
     // Emit signal to update inplace preview.
     void updateInplacePreview();
 
-    void textToHtmlViaWebView(const QString &p_text,
+    bool textToHtmlViaWebView(const QString &p_text,
                               int p_id,
                               int p_timeStamp);