| 241 | } |
| 242 | |
| 243 | MainWindow::MainWindow(QWidget *parent) |
| 244 | : QMainWindow(parent), localServer(nullptr) { |
| 245 | |
| 246 | // Initial fallback before widgets are wired; the canonical title comes |
| 247 | // from updateWindowTitle() at the end of the ctor and on every active- |
| 248 | // viewport / current-tab change thereafter. |
| 249 | setWindowTitle(QStringLiteral("SpeedyNote")); |
| 250 | |
| 251 | // Phase 3.1: Always using new DocumentViewport architecture |
| 252 | |
| 253 | #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) |
| 254 | // Setup signal handlers for proper cleanup on Linux (not Android) |
| 255 | setupLinuxSignalHandlers(); |
| 256 | #endif |
| 257 | |
| 258 | #if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) |
| 259 | // On Android/iOS, auto-save all modified documents when app goes to background |
| 260 | // This is critical because the app may be killed without closeEvent() |
| 261 | // when user swipes from recents. Without this: |
| 262 | // 1. Unsaved changes would be lost |
| 263 | // 2. New documents wouldn't appear in Launcher |
| 264 | // |
| 265 | // Note: This connect is set up early in constructor, but m_documentManager |
| 266 | // is initialized just after. The lambda captures 'this' and checks for null. |
| 267 | connect(qApp, &QGuiApplication::applicationStateChanged, |
| 268 | this, [this](Qt::ApplicationState state) { |
| 269 | #ifdef SPEEDYNOTE_DEBUG |
| 270 | qDebug() << "[MainWindow] Application state changed to:" |
| 271 | << (state == Qt::ApplicationActive ? "Active" : |
| 272 | state == Qt::ApplicationSuspended ? "Suspended" : |
| 273 | state == Qt::ApplicationInactive ? "Inactive" : "Hidden"); |
| 274 | #endif |
| 275 | if (state == Qt::ApplicationSuspended || state == Qt::ApplicationInactive) { |
| 276 | // Sync positions for all documents before auto-save |
| 277 | // This ensures lastAccessedPage/edgeless position is saved |
| 278 | syncAllDocumentPositions(); |
| 279 | |
| 280 | if (m_documentManager) { |
| 281 | // autoSaveModifiedDocuments() also saves NotebookLibrary internally |
| 282 | #ifdef SPEEDYNOTE_DEBUG |
| 283 | qDebug() << "[MainWindow] Triggering auto-save, document count:" << m_documentManager->documentCount(); |
| 284 | #endif |
| 285 | int saved = m_documentManager->autoSaveModifiedDocuments(); |
| 286 | #ifdef SPEEDYNOTE_DEBUG |
| 287 | qDebug() << "[MainWindow] Auto-saved" << saved << "documents"; |
| 288 | #endif |
| 289 | } else { |
| 290 | #ifdef SPEEDYNOTE_DEBUG |
| 291 | qDebug() << "[MainWindow] m_documentManager is null, only saving NotebookLibrary"; |
| 292 | #endif |
| 293 | // Fallback: save NotebookLibrary directly if DocumentManager not ready |
| 294 | NotebookLibrary::instance()->save(); |
| 295 | } |
| 296 | } |
| 297 | }); |
| 298 | #endif |
| 299 | |
| 300 | // Enable IME support for multi-language input |
nothing calls this directly
no test coverage detected