mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-10-27 00:28:34 +03:00
ecode: Added "Check for updates at startup." option.
This commit is contained in:
@@ -43,7 +43,9 @@ class EE_API UIMessageBox : public UIWindow {
|
||||
|
||||
UITextInput* getTextInput() const;
|
||||
|
||||
protected:
|
||||
UILayout* getLayoutCont() const;
|
||||
|
||||
protected:
|
||||
Type mMsgBoxType;
|
||||
UITextView* mTextBox;
|
||||
UIPushButton* mButtonOK;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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<std::string, bool> pluginsEnabled;
|
||||
const auto& creators = pluginManager->getDefinitions();
|
||||
@@ -241,6 +243,8 @@ void AppConfig::save( const std::vector<std::string>& 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 )
|
||||
|
||||
@@ -106,6 +106,7 @@ struct TerminalConfig {
|
||||
|
||||
struct WorkspaceConfig {
|
||||
bool restoreLastSession{ false };
|
||||
bool checkForUpdatesAtStartup{ false };
|
||||
};
|
||||
|
||||
struct AppConfig {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
</style>
|
||||
<MainLayout id="main_layout" layout_width="match_parent" layout_height="match_parent">
|
||||
<Splitter id="project_splitter" layout_width="match_parent" layout_height="match_parent">
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user