diff --git a/include/eepp/ui/uimessagebox.hpp b/include/eepp/ui/uimessagebox.hpp index 6b4898417..569089950 100644 --- a/include/eepp/ui/uimessagebox.hpp +++ b/include/eepp/ui/uimessagebox.hpp @@ -43,7 +43,9 @@ class EE_API UIMessageBox : public UIWindow { UITextInput* getTextInput() const; - protected: + UILayout* getLayoutCont() const; + + protected: Type mMsgBoxType; UITextView* mTextBox; UIPushButton* mButtonOK; diff --git a/src/eepp/scene/node.cpp b/src/eepp/scene/node.cpp index 90bdf6042..7157a1b28 100644 --- a/src/eepp/scene/node.cpp +++ b/src/eepp/scene/node.cpp @@ -648,9 +648,8 @@ void Node::childAddAt( Node* node, Uint32 index ) { } else { Uint32 i = 0; - while ( NULL != nodeLoop->mNext && i < index ) { + while ( NULL != nodeLoop->mNext && ++i < index ) { nodeLoop = nodeLoop->mNext; - i++; } Node* ChildTmp = nodeLoop->mNext; diff --git a/src/eepp/ui/uimessagebox.cpp b/src/eepp/ui/uimessagebox.cpp index 7cc5e9025..239c7fe26 100644 --- a/src/eepp/ui/uimessagebox.cpp +++ b/src/eepp/ui/uimessagebox.cpp @@ -13,6 +13,8 @@ UIMessageBox* UIMessageBox::New( const Type& type, const String& message, UIMessageBox::UIMessageBox( const Type& type, const String& message, const Uint32& windowFlags ) : UIWindow(), mMsgBoxType( type ), mTextInput( NULL ), mCloseShortcut( KEY_UNKNOWN ) { + mVisible = false; + mStyleConfig.WinFlags = windowFlags; updateWinFlags(); @@ -179,6 +181,10 @@ UITextInput* UIMessageBox::getTextInput() const { return mTextInput; } +UILayout* UIMessageBox::getLayoutCont() const { + return mLayoutCont; +} + void UIMessageBox::onWindowReady() { forcedApplyStyle(); diff --git a/src/tools/ecode/appconfig.cpp b/src/tools/ecode/appconfig.cpp index 95691bb62..0a1cf2bec 100644 --- a/src/tools/ecode/appconfig.cpp +++ b/src/tools/ecode/appconfig.cpp @@ -136,6 +136,8 @@ void AppConfig::load( const std::string& confPath, std::string& keybindingsPath, term.colorScheme = ini.getValue( "terminal", "colorscheme", "eterm" ); workspace.restoreLastSession = ini.getValueB( "workspace", "restore_last_session", false ); + workspace.checkForUpdatesAtStartup = + ini.getValueB( "workspace", "check_for_updates_at_startup", false ); std::map pluginsEnabled; const auto& creators = pluginManager->getDefinitions(); @@ -241,6 +243,8 @@ void AppConfig::save( const std::vector& recentFiles, ini.setValueI( "window", "frameratelimit", context.FrameRateLimit ); ini.setValueB( "workspace", "restore_last_session", workspace.restoreLastSession ); + ini.setValueB( "workspace", "check_for_updates_at_startup", + workspace.checkForUpdatesAtStartup ); const auto& pluginsEnabled = pluginManager->getPluginsEnabled(); for ( const auto& plugin : pluginsEnabled ) diff --git a/src/tools/ecode/appconfig.hpp b/src/tools/ecode/appconfig.hpp index ca9adbea3..7e786134c 100644 --- a/src/tools/ecode/appconfig.hpp +++ b/src/tools/ecode/appconfig.hpp @@ -106,6 +106,7 @@ struct TerminalConfig { struct WorkspaceConfig { bool restoreLastSession{ false }; + bool checkForUpdatesAtStartup{ false }; }; struct AppConfig { diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index fcda8301c..480c703c4 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -664,8 +664,10 @@ void App::setUIColorScheme( const ColorSchemePreference& colorScheme ) { mUISceneNode->setColorSchemePreference( colorScheme ); } -void App::checkForUpdatesResponse( Http::Response response ) { - auto updatesError = [&]() { +void App::checkForUpdatesResponse( Http::Response response, bool fromStartup ) { + auto updatesError = [&, fromStartup]() { + if ( fromStartup ) + return; UIMessageBox* msg = UIMessageBox::New( UIMessageBox::OK, i18n( "error_checking_version", "Failed checking for updates." ) ); msg->setTitle( "Error" ); @@ -678,6 +680,31 @@ void App::checkForUpdatesResponse( Http::Response response ) { return; } + auto addStartUpCheckbox = [this]( UIMessageBox* msg ) { + msg->setId( "check_for_updates" ); + msg->addEventListener( Event::OnWindowReady, [this, msg]( const Event* ) { + msg->setVisible( false ); + UICheckBox* cbox = UICheckBox::New(); + cbox->addClass( "check_at_startup" ); + cbox->setParent( msg->getLayoutCont()->getFirstChild() ); + cbox->setLayoutSizePolicy( SizePolicy::WrapContent, SizePolicy::WrapContent ); + cbox->setText( i18n( "check_for_new_updates_at_startup", + "Always check for new updates at startup." ) ); + cbox->setChecked( mConfig.workspace.checkForUpdatesAtStartup ); + cbox->toPosition( 1 ); + cbox->runOnMainThread( [msg]() { + msg->setMinWindowSize( msg->getLayoutCont()->getSize() ); + msg->center(); + msg->runOnMainThread( [msg]() { + msg->show(); + } ); + } ); + cbox->addEventListener( Event::OnValueChange, [this, cbox]( const Event* ) { + mConfig.workspace.checkForUpdatesAtStartup = cbox->isChecked(); + } ); + } ); + }; + json j; try { j = json::parse( response.getBody(), nullptr, true, true ); @@ -692,6 +719,7 @@ void App::checkForUpdatesResponse( Http::Response response ) { name + i18n( "ecode_updates_available", " is available!\nDo you want to download it now?" ) .unescape() ); + auto url( j.value( "html_url", "https://github.com/SpartanJ/ecode/releases/" ) ); msg->addEventListener( Event::MsgBoxConfirmClick, [&, url, msg]( const Event* ) { Engine::instance()->openURI( url ); @@ -699,8 +727,10 @@ void App::checkForUpdatesResponse( Http::Response response ) { } ); msg->setTitle( "ecode" ); msg->setCloseShortcut( { KEY_ESCAPE, 0 } ); - msg->showWhenReady(); + addStartUpCheckbox( msg ); } else if ( versionNum < ecode::Version::getVersionNum() ) { + if ( fromStartup ) + return; UIMessageBox* msg = UIMessageBox::New( UIMessageBox::OK, i18n( "ecode_unreleased_version", @@ -709,14 +739,16 @@ void App::checkForUpdatesResponse( Http::Response response ) { ecode::Version::getVersionNumString() ); msg->setTitle( "ecode" ); msg->setCloseShortcut( { KEY_ESCAPE, 0 } ); - msg->showWhenReady(); + addStartUpCheckbox( msg ); } else { + if ( fromStartup ) + return; UIMessageBox* msg = UIMessageBox::New( UIMessageBox::OK, i18n( "ecode_no_updates_available", "There are currently no updates available." ) ); msg->setTitle( "ecode" ); msg->setCloseShortcut( { KEY_ESCAPE, 0 } ); - msg->showWhenReady(); + addStartUpCheckbox( msg ); } } else { updatesError(); @@ -726,11 +758,11 @@ void App::checkForUpdatesResponse( Http::Response response ) { } } -void App::checkForUpdates() { +void App::checkForUpdates( bool fromStartup ) { Http::getAsync( - [&]( const Http&, Http::Request&, Http::Response& response ) { + [&, fromStartup]( const Http&, Http::Request&, Http::Response& response ) { mUISceneNode->runOnMainThread( - [&, response]() { checkForUpdatesResponse( response ); } ); + [&, response]() { checkForUpdatesResponse( response, fromStartup ); } ); }, "https://api.github.com/repos/SpartanJ/ecode/releases/latest", Seconds( 30 ) ); } @@ -752,7 +784,7 @@ UIMenu* App::createHelpMenu() { ecode::Version::getCodename() + "\")" ); UIMessageBox* msgBox = UIMessageBox::New( UIMessageBox::OK, msg ); msgBox->setTitle( i18n( "about_ecode", "About ecode..." ) ); - msgBox->show(); + msgBox->showWhenReady(); } else if ( "check-for-updates" == id ) { checkForUpdates(); } @@ -3860,6 +3892,9 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe margin-left: 0dp; margin-right: 0dp; } + #check_for_updates .check_at_startup { + margin: 6dp 0dp 6p 0dp; + } @@ -4223,6 +4258,9 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe downloadFileWeb( "https://raw.githubusercontent.com/SpartanJ/eepp/develop/README.md" ); #endif + if ( mConfig.workspace.checkForUpdatesAtStartup ) + checkForUpdates( true ); + mWindow->runMainLoop( &appLoop, mBenchmarkMode ? 0 : mConfig.context.FrameRateLimit ); } } diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index b16587abd..bd8ce1b5b 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -233,7 +233,7 @@ class App : public UICodeEditorSplitter::Client { void setCursorBlinkingTime(); - void checkForUpdates(); + void checkForUpdates( bool fromStartup = false ); protected: EE::Window::Window* mWindow{ nullptr }; @@ -436,7 +436,7 @@ class App : public UICodeEditorSplitter::Client { void onPluginEnabled( UICodeEditorPlugin* plugin ); - void checkForUpdatesResponse( Http::Response response ); + void checkForUpdatesResponse( Http::Response response, bool fromStartup ); }; } // namespace ecode