mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-30 01:56:31 +03:00
eepp: Some code refactoring regarding the TextureFactory. Also renamed some functions with incorrect naming.
ecode: Plugins are now hot-reloaded when a its configuration file is being written.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "pluginmanager.hpp"
|
||||
#include "../filesystemlistener.hpp"
|
||||
#include <eepp/system/filesystem.hpp>
|
||||
#include <eepp/ui/uicheckbox.hpp>
|
||||
#include <eepp/ui/uitableview.hpp>
|
||||
@@ -56,6 +57,16 @@ bool PluginManager::isEnabled( const std::string& id ) const {
|
||||
return mPluginsEnabled.find( id ) != mPluginsEnabled.end() ? mPluginsEnabled.at( id ) : false;
|
||||
}
|
||||
|
||||
bool PluginManager::reload( const std::string& id ) {
|
||||
if ( isEnabled( id ) ) {
|
||||
Log::warning( "PluginManager reloading plugin: %s", id.c_str() );
|
||||
setEnabled( id, false );
|
||||
setEnabled( id, true );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string& PluginManager::getResourcesPath() const {
|
||||
return mResourcesPath;
|
||||
}
|
||||
@@ -218,6 +229,14 @@ void PluginManager::setSplitter( UICodeEditorSplitter* splitter ) {
|
||||
mSplitter = splitter;
|
||||
}
|
||||
|
||||
void PluginManager::setFileSystemListener( FileSystemListener* listener ) {
|
||||
if ( listener == mFileSystemListener )
|
||||
return;
|
||||
mFileSystemListener = listener;
|
||||
sendBroadcast( PluginMessageType::FileSystemListenerReady, PluginMessageFormat::Empty,
|
||||
nullptr );
|
||||
}
|
||||
|
||||
void PluginManager::sendBroadcast( const PluginMessageType& notification,
|
||||
const PluginMessageFormat& format, void* data ) {
|
||||
if ( mClosing )
|
||||
@@ -412,4 +431,52 @@ UIWindow* UIPluginManager::New( UISceneNode* sceneNode, PluginManager* manager,
|
||||
return win;
|
||||
}
|
||||
|
||||
Plugin::Plugin( PluginManager* manager ) :
|
||||
mManager( manager ), mThreadPool( manager->getThreadPool() ) {}
|
||||
|
||||
void Plugin::subscribeFileSystemListener() {
|
||||
if ( mFileSystemListenerCb != 0 || mManager->getFileSystemListener() == nullptr )
|
||||
return;
|
||||
|
||||
mConfigFileInfo = FileInfo( mConfigPath );
|
||||
|
||||
mFileSystemListenerCb = mManager->getFileSystemListener()->addListener(
|
||||
[this]( const FileEvent& ev, const FileInfo& file ) {
|
||||
if ( ev.type != FileSystemEventType::Modified )
|
||||
return;
|
||||
if ( !mShuttingDown && file.getFilepath() == mConfigPath &&
|
||||
file.getModificationTime() != mConfigFileInfo.getModificationTime() ) {
|
||||
mConfigFileInfo = file;
|
||||
mManager->getFileSystemListener()->removeListener( mFileSystemListenerCb );
|
||||
mFileSystemListenerCb = 0;
|
||||
mManager->reload( getId() );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
void Plugin::unsubscribeFileSystemListener() {
|
||||
if ( mFileSystemListenerCb != 0 && mManager->getFileSystemListener() )
|
||||
mManager->getFileSystemListener()->removeListener( mFileSystemListenerCb );
|
||||
}
|
||||
|
||||
bool Plugin::isReady() const {
|
||||
return mReady;
|
||||
}
|
||||
|
||||
bool Plugin::isShuttingDown() const {
|
||||
return mShuttingDown;
|
||||
}
|
||||
|
||||
bool Plugin::hasFileConfig() {
|
||||
return !mConfigPath.empty();
|
||||
}
|
||||
|
||||
std::string Plugin::getFileConfigPath() {
|
||||
return mConfigPath;
|
||||
}
|
||||
|
||||
PluginManager* Plugin::getManager() const {
|
||||
return mManager;
|
||||
}
|
||||
|
||||
} // namespace ecode
|
||||
|
||||
Reference in New Issue
Block a user