From 9814f25696f6136996550dcfd03c43f26fc75bd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 30 Jul 2023 20:18:45 -0300 Subject: [PATCH] Added flatpak warning. --- include/eepp/system/time.hpp | 8 +- src/tools/ecode/ecode.cpp | 152 ++++++++++++++++++++++------------- src/tools/ecode/ecode.hpp | 2 +- 3 files changed, 103 insertions(+), 59 deletions(-) diff --git a/include/eepp/system/time.hpp b/include/eepp/system/time.hpp index a8398edd1..aa03465ba 100644 --- a/include/eepp/system/time.hpp +++ b/include/eepp/system/time.hpp @@ -39,10 +39,10 @@ class EE_API Time { std::string toString() const; private: - friend EE_API constexpr Time Minutes( double ); - friend EE_API constexpr Time Seconds( double ); - friend EE_API constexpr Time Milliseconds( double ); - friend EE_API constexpr Time Microseconds( Int64 ); + friend constexpr Time Minutes( double ); + friend constexpr Time Seconds( double ); + friend constexpr Time Milliseconds( double ); + friend constexpr Time Microseconds( Int64 ); /** @brief Construct from a number of microseconds ** This function is internal. To construct time values, diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 6f0247d21..f682b3baa 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -170,9 +170,7 @@ void App::setAppTitle( const std::string& title ) { if ( mBenchmarkMode ) fullTitle += " - " + String::toString( mWindow->getFPS() ) + " FPS"; - mUISceneNode->runOnMainThread( [this, fullTitle] { - mWindow->setTitle( fullTitle ); - } ); + mUISceneNode->runOnMainThread( [this, fullTitle] { mWindow->setTitle( fullTitle ); } ); } void App::onDocumentModified( UICodeEditor* editor, TextDocument& ) { @@ -435,11 +433,14 @@ void App::initPluginManager() { mPluginManager->registerPlugin( XMLToolsPlugin::Definition() ); } -void App::loadConfig( const LogLevel& logLevel, const Sizeu& displaySize, bool sync, +bool App::loadConfig( const LogLevel& logLevel, const Sizeu& displaySize, bool sync, bool stdOutLogs, bool disableFileLogs ) { mConfigPath = Sys::getConfigPath( "ecode" ); - if ( !FileSystem::fileExists( mConfigPath ) ) + bool firstRun = false; + if ( !FileSystem::fileExists( mConfigPath ) ) { FileSystem::makeDir( mConfigPath ); + firstRun = true; + } FileSystem::dirAddSlashAtEnd( mConfigPath ); mPluginsPath = mConfigPath + "plugins"; mLanguagesPath = mConfigPath + "languages"; @@ -481,6 +482,8 @@ void App::loadConfig( const LogLevel& logLevel, const Sizeu& displaySize, bool s mConfig.load( mConfigPath, mKeybindingsPath, mInitColorScheme, mRecentFiles, mRecentFolders, mResPath, mPluginManager.get(), displaySize.asInt(), sync ); + + return firstRun; } void App::saveConfig() { @@ -600,15 +603,16 @@ void App::onFileDropped( String file ) { } } - loadFileFromPath( file, false, codeEditor, [this, tab]( UICodeEditor* editor, const std::string& ) { - if ( tab ) - tab->setTabSelected(); - else { - UITab* tab = mSplitter->tabFromEditor( editor ); - if ( tab ) - tab->setTabSelected(); - } - } ); + loadFileFromPath( file, false, codeEditor, + [this, tab]( UICodeEditor* editor, const std::string& ) { + if ( tab ) + tab->setTabSelected(); + else { + UITab* tab = mSplitter->tabFromEditor( editor ); + if ( tab ) + tab->setTabSelected(); + } + } ); } void App::onTextDropped( String text ) { @@ -1642,7 +1646,8 @@ void App::loadFileDelayed() { editor->goToLine( fileAndPos.second ); mSplitter->addEditorPositionToNavigationHistory( editor ); UITab* tab = mSplitter->tabFromEditor( editor ); - if (tab) tab->setTabSelected(); + if ( tab ) + tab->setTabSelected(); } ); } ); } @@ -1796,41 +1801,48 @@ std::map App::getDefaultKeybindings() { std::map App::getLocalKeybindings() { return { { { KEY_RETURN, KEYMOD_LALT | KEYMOD_LCTRL }, "fullscreen-toggle" }, - { { KEY_F3, KEYMOD_NONE }, "repeat-find" }, - { { KEY_F3, KEYMOD_SHIFT }, "find-prev" }, - { { KEY_F12, KEYMOD_NONE }, "console-toggle" }, - { { KEY_F, KeyMod::getDefaultModifier() }, "find-replace" }, - { { KEY_Q, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "close-app" }, - { { KEY_O, KeyMod::getDefaultModifier() }, "open-file" }, - { { KEY_W, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "download-file-web" }, - { { KEY_O, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "open-folder" }, - { { KEY_F11, KEYMOD_NONE }, "debug-widget-tree-view" }, - { { KEY_K, KeyMod::getDefaultModifier() }, "open-locatebar" }, - { { KEY_P, KeyMod::getDefaultModifier() }, "open-command-palette" }, - { { KEY_F, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "open-global-search" }, - { { KEY_L, KeyMod::getDefaultModifier() }, "go-to-line" }, + { { KEY_F3, KEYMOD_NONE }, "repeat-find" }, { { KEY_F3, KEYMOD_SHIFT }, "find-prev" }, + { { KEY_F12, KEYMOD_NONE }, "console-toggle" }, + { { KEY_F, KeyMod::getDefaultModifier() }, "find-replace" }, + { { KEY_Q, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "close-app" }, + { { KEY_O, KeyMod::getDefaultModifier() }, "open-file" }, + { { KEY_W, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "download-file-web" }, + { { KEY_O, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "open-folder" }, + { { KEY_F11, KEYMOD_NONE }, "debug-widget-tree-view" }, + { { KEY_K, KeyMod::getDefaultModifier() }, "open-locatebar" }, + { { KEY_P, KeyMod::getDefaultModifier() }, "open-command-palette" }, + { { KEY_F, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "open-global-search" }, + { { KEY_L, KeyMod::getDefaultModifier() }, "go-to-line" }, #if EE_PLATFORM == EE_PLATFORM_MACOSX - { { KEY_M, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "menu-toggle" }, + { { KEY_M, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "menu-toggle" }, #else - { { KEY_M, KeyMod::getDefaultModifier() }, "menu-toggle" }, + { { KEY_M, KeyMod::getDefaultModifier() }, "menu-toggle" }, #endif - { { KEY_S, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "save-all" }, - { { KEY_F9, KEYMOD_LALT }, "switch-side-panel" }, - { { KEY_J, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT }, "terminal-split-left" }, - { { KEY_L, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT }, "terminal-split-right" }, - { { KEY_I, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT }, "terminal-split-top" }, - { { KEY_K, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT }, "terminal-split-bottom" }, - { { KEY_S, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT }, "terminal-split-swap" }, - { { KEY_T, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT }, "reopen-closed-tab" }, - { { KEY_1, KEYMOD_LALT }, "toggle-status-locate-bar" }, - { { KEY_2, KEYMOD_LALT }, "toggle-status-global-search-bar" }, - { { KEY_3, KEYMOD_LALT }, "toggle-status-terminal" }, - { { KEY_4, KEYMOD_LALT }, "toggle-status-build-output" }, - { { KEY_B, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "project-build-start" }, - { { KEY_C, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "project-build-cancel" }, - { { KEY_O, KEYMOD_LALT | KEYMOD_SHIFT }, "show-open-documents" }, - { { KEY_K, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "open-workspace-symbol-search" }, - { { KEY_P, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "open-document-symbol-search" }, + { { KEY_S, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "save-all" }, + { { KEY_F9, KEYMOD_LALT }, "switch-side-panel" }, + { { KEY_J, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT }, + "terminal-split-left" }, + { { KEY_L, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT }, + "terminal-split-right" }, + { { KEY_I, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT }, + "terminal-split-top" }, + { { KEY_K, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT }, + "terminal-split-bottom" }, + { { KEY_S, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT }, + "terminal-split-swap" }, + { { KEY_T, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT }, + "reopen-closed-tab" }, + { { KEY_1, KEYMOD_LALT }, "toggle-status-locate-bar" }, + { { KEY_2, KEYMOD_LALT }, "toggle-status-global-search-bar" }, + { { KEY_3, KEYMOD_LALT }, "toggle-status-terminal" }, + { { KEY_4, KEYMOD_LALT }, "toggle-status-build-output" }, + { { KEY_B, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "project-build-start" }, + { { KEY_C, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "project-build-cancel" }, + { { KEY_O, KEYMOD_LALT | KEYMOD_SHIFT }, "show-open-documents" }, + { { KEY_K, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, + "open-workspace-symbol-search" }, + { { KEY_P, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, + "open-document-symbol-search" }, }; } @@ -1839,13 +1851,13 @@ std::map App::getLocalKeybindings() { std::map App::getMigrateKeybindings() { return { { "fullscreen-toggle", "alt+return" }, { "switch-to-tab-1", "alt+1" }, - { "switch-to-tab-2", "alt+2" }, { "switch-to-tab-3", "alt+3" }, - { "switch-to-tab-4", "alt+4" }, { "switch-to-tab-5", "alt+5" }, - { "switch-to-tab-6", "alt+6" }, { "switch-to-tab-7", "alt+7" }, - { "switch-to-tab-8", "alt+8" }, { "switch-to-tab-9", "alt+9" }, - { "switch-to-last-tab", "alt+0" }, + { "switch-to-tab-2", "alt+2" }, { "switch-to-tab-3", "alt+3" }, + { "switch-to-tab-4", "alt+4" }, { "switch-to-tab-5", "alt+5" }, + { "switch-to-tab-6", "alt+6" }, { "switch-to-tab-7", "alt+7" }, + { "switch-to-tab-8", "alt+8" }, { "switch-to-tab-9", "alt+9" }, + { "switch-to-last-tab", "alt+0" }, #if EE_PLATFORM == EE_PLATFORM_MACOSX - { "menu-toggle", "mod+shift+m" }, + { "menu-toggle", "mod+shift+m" }, #endif }; } @@ -3043,7 +3055,8 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe mResPath += "assets"; FileSystem::dirAddSlashAtEnd( mResPath ); - loadConfig( logLevel, currentDisplay->getSize(), health, stdOutLogs, disableFileLogs ); + bool firstRun = + loadConfig( logLevel, currentDisplay->getSize(), health, stdOutLogs, disableFileLogs ); if ( health ) { Sys::windowAttachConsole(); @@ -3094,6 +3107,9 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe mConfig.context = engine->createContextSettings( &mConfig.ini, "window", false ); #endif + if ( firstRun ) + mConfig.context.FrameRateLimit = currentDisplay->getRefreshRate(); + mConfig.context.SharedGLContext = true; mWindow = engine->createWindow( winSettings, mConfig.context ); @@ -3383,6 +3399,34 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe }, Seconds( 60.f ) ); +#if EE_PLATFORM == EE_PLATFORM_LINUX + // Is the process running from flatpak isolation for the first time? + if ( firstRun && getenv( "FLATPAK_ISOLATION" ) != NULL ) { + static const auto FLATPAK_WARN = R"xml( + + + + You are running flatpak version of ecode. This version is running inside of a container and is therefore not able to access tools on your host system. + Please read carefully the following guide at: + https://github.com/flathub/dev.ensoft.ecode/blob/master/ECODE_FIRST_RUN.md + + + + + )xml"; + + UIWindow* flatpakWarnWindow = + static_cast( mUISceneNode->loadLayoutFromString( FLATPAK_WARN ) ); + flatpakWarnWindow->find( "win_flatpak_warning_ok" ) + ->onClick( [flatpakWarnWindow]( auto ) { flatpakWarnWindow->closeWindow(); } ); + flatpakWarnWindow->on( Event::KeyDown, [flatpakWarnWindow]( const Event* event ) { + if ( event->asKeyEvent()->getKeyCode() == KEY_ESCAPE ) + flatpakWarnWindow->closeWindow(); + } ); + flatpakWarnWindow->center(); + } +#endif + mWindow->runMainLoop( &appLoop, mBenchmarkMode ? 0 : mConfig.context.FrameRateLimit ); } } diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index e20a43020..a6f473c7c 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -61,7 +61,7 @@ class App : public UICodeEditorSplitter::Client { void runCommand( const std::string& command ); - void loadConfig( const LogLevel& logLevel, const Sizeu& displaySize, bool sync, bool stdOutLogs, + bool loadConfig( const LogLevel& logLevel, const Sizeu& displaySize, bool sync, bool stdOutLogs, bool disableFileLogs ); void saveConfig();