| 639 | } |
| 640 | |
| 641 | void App::run() |
| 642 | { |
| 643 | // Run the GUI |
| 644 | if (isGui()) { |
| 645 | #if _DEBUG |
| 646 | // On OS X, when we compile LibreSprite on Debug mode, we're using it |
| 647 | // outside an app bundle, so we must active the app explicitly. |
| 648 | she::instance()->activateApp(); |
| 649 | #endif |
| 650 | |
| 651 | app::SendCrash sendCrash; |
| 652 | sendCrash.search(); |
| 653 | |
| 654 | // Run the GUI main message loop |
| 655 | ui::Manager::getDefault()->run(); |
| 656 | } |
| 657 | |
| 658 | // Start shell to execute scripts. |
| 659 | if (m_isShell) { |
| 660 | script::EngineDelegate::setDefault("stdout"); |
| 661 | script::Engine::setDefault("js"); |
| 662 | AppScripting engine; |
| 663 | engine.printLastResult(); |
| 664 | Shell shell; |
| 665 | shell.run(engine); |
| 666 | } |
| 667 | |
| 668 | // Destroy all documents in the UIContext. |
| 669 | const doc::Documents& docs = m_modules->m_ui_context.documents(); |
| 670 | while (!docs.empty()) { |
| 671 | doc::Document* doc = docs.back(); |
| 672 | |
| 673 | // First we close the document. In this way we receive recent |
| 674 | // notifications related to the document as an app::Document. If |
| 675 | // we delete the document directly, we destroy the app::Document |
| 676 | // too early, and then doc::~Document() call |
| 677 | // DocumentsObserver::onRemoveDocument(). In this way, observers |
| 678 | // could think that they have a fully created app::Document when |
| 679 | // in reality it's a doc::Document (in the middle of a |
| 680 | // destruction process). |
| 681 | // |
| 682 | // TODO: This problem is because we're extending doc::Document, |
| 683 | // in the future, we should remove app::Document. |
| 684 | doc->close(); |
| 685 | delete doc; |
| 686 | } |
| 687 | |
| 688 | if (isGui()) { |
| 689 | // Destroy the window. |
| 690 | m_mainWindow.reset(nullptr); |
| 691 | } |
| 692 | |
| 693 | // Delete backups (this is a normal shutdown, we are not handling |
| 694 | // exceptions, and we are not in a destructor). |
| 695 | m_modules->deleteDataRecovery(); |
| 696 | } |
| 697 | |
| 698 | // Finishes the LibreSprite application. |
no test coverage detected