Send NPPN_READY notification to loaded plugins after their installation by Plugin Admin

This commit is contained in:
Don HO 2018-10-25 20:48:36 +02:00
parent ef5d07771a
commit c531a4d42a
4 changed files with 41 additions and 22 deletions

View File

@ -605,23 +605,20 @@ void PluginsManager::runPluginCommand(const TCHAR *pluginName, int commandID)
} }
} }
// send the notification to a specific plugin
void PluginsManager::notify(const SCNotification *notification) void PluginsManager::notify(size_t indexPluginInfo, const SCNotification *notification)
{ {
if (_noMoreNotification) // this boolean should be enabled after NPPN_SHUTDOWN has been sent if (indexPluginInfo >= _pluginInfos.size())
return; return;
_noMoreNotification = notification->nmhdr.code == NPPN_SHUTDOWN;
for (size_t i = 0, len = _pluginInfos.size() ; i < len ; ++i) if (_pluginInfos[indexPluginInfo]->_hLib)
{
if (_pluginInfos[i]->_hLib)
{ {
// To avoid the plugin change the data in SCNotification // To avoid the plugin change the data in SCNotification
// Each notification to pass to a plugin is a copy of SCNotification instance // Each notification to pass to a plugin is a copy of SCNotification instance
SCNotification scNotif = *notification; SCNotification scNotif = *notification;
try try
{ {
_pluginInfos[i]->_pBeNotified(&scNotif); _pluginInfos[indexPluginInfo]->_pBeNotified(&scNotif);
} }
catch (std::exception& e) catch (std::exception& e)
{ {
@ -632,10 +629,22 @@ void PluginsManager::notify(const SCNotification *notification)
TCHAR funcInfo[256]; TCHAR funcInfo[256];
generic_sprintf(funcInfo, TEXT("notify(SCNotification *notification) : \r notification->nmhdr.code == %d\r notification->nmhdr.hwndFrom == %p\r notification->nmhdr.idFrom == %" PRIuPTR), \ generic_sprintf(funcInfo, TEXT("notify(SCNotification *notification) : \r notification->nmhdr.code == %d\r notification->nmhdr.hwndFrom == %p\r notification->nmhdr.idFrom == %" PRIuPTR), \
scNotif.nmhdr.code, scNotif.nmhdr.hwndFrom, scNotif.nmhdr.idFrom); scNotif.nmhdr.code, scNotif.nmhdr.hwndFrom, scNotif.nmhdr.idFrom);
pluginCrashAlert(_pluginInfos[i]->_moduleName.c_str(), funcInfo); pluginCrashAlert(_pluginInfos[indexPluginInfo]->_moduleName.c_str(), funcInfo);
} }
} }
} }
// broadcast the notification to all plugins
void PluginsManager::notify(const SCNotification *notification)
{
if (_noMoreNotification) // this boolean should be enabled after NPPN_SHUTDOWN has been sent
return;
_noMoreNotification = notification->nmhdr.code == NPPN_SHUTDOWN;
for (size_t i = 0, len = _pluginInfos.size() ; i < len ; ++i)
{
notify(i, notification);
}
} }

View File

@ -113,7 +113,8 @@ public:
bool getShortcutByCmdID(int cmdID, ShortcutKey *sk); bool getShortcutByCmdID(int cmdID, ShortcutKey *sk);
bool removeShortcutByCmdID(int cmdID); bool removeShortcutByCmdID(int cmdID);
void notify(const SCNotification *notification); void notify(size_t indexPluginInfo, const SCNotification *notification); // to a plugin
void notify(const SCNotification *notification); // broadcast
void relayNppMessages(UINT Message, WPARAM wParam, LPARAM lParam); void relayNppMessages(UINT Message, WPARAM wParam, LPARAM lParam);
bool relayPluginMessages(UINT Message, WPARAM wParam, LPARAM lParam); bool relayPluginMessages(UINT Message, WPARAM wParam, LPARAM lParam);

View File

@ -552,6 +552,13 @@ DWORD WINAPI PluginsAdminDlg::launchPluginInstallerThread(void* params)
int index = lwp->_pPluginsManager->loadPlugin(installedPluginPath.c_str(), dll2Remove); int index = lwp->_pPluginsManager->loadPlugin(installedPluginPath.c_str(), dll2Remove);
lwp->_pPluginsManager->addInMenuFromPMIndex(index); lwp->_pPluginsManager->addInMenuFromPMIndex(index);
// Notify plugin that Notepad++ is ready
SCNotification scnN;
scnN.nmhdr.code = NPPN_READY;
scnN.nmhdr.hwndFrom = lwp->_hwnd;
scnN.nmhdr.idFrom = 0;
lwp->_pPluginsManager->notify(index, &scnN);
// End of Critical section // End of Critical section
ReleaseMutex(lwp->_mutex); ReleaseMutex(lwp->_mutex);
} }
@ -609,6 +616,7 @@ bool PluginsAdminDlg::installPlugins()
lwp->_updaterDir = _updaterDir; lwp->_updaterDir = _updaterDir;
lwp->_updaterFullPath = _updaterFullPath; lwp->_updaterFullPath = _updaterFullPath;
lwp->_updaterParams = updaterParams; lwp->_updaterParams = updaterParams;
lwp->_hwnd = _hSelf;
lwp->_mutex = mutex; lwp->_mutex = mutex;
_lwps.push_back(lwp); _lwps.push_back(lwp);

View File

@ -168,6 +168,7 @@ struct LaunchWingupParams
PluginsManager *_pPluginsManager; PluginsManager *_pPluginsManager;
HWND _hwnd = nullptr;
HANDLE _mutex; HANDLE _mutex;
}; };