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,7 +605,36 @@ void PluginsManager::runPluginCommand(const TCHAR *pluginName, int commandID)
}
}
// send the notification to a specific plugin
void PluginsManager::notify(size_t indexPluginInfo, const SCNotification *notification)
{
if (indexPluginInfo >= _pluginInfos.size())
return;
if (_pluginInfos[indexPluginInfo]->_hLib)
{
// To avoid the plugin change the data in SCNotification
// Each notification to pass to a plugin is a copy of SCNotification instance
SCNotification scNotif = *notification;
try
{
_pluginInfos[indexPluginInfo]->_pBeNotified(&scNotif);
}
catch (std::exception& e)
{
::MessageBoxA(NULL, e.what(), "Exception", MB_OK);
}
catch (...)
{
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), \
scNotif.nmhdr.code, scNotif.nmhdr.hwndFrom, scNotif.nmhdr.idFrom);
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
@ -614,27 +643,7 @@ void PluginsManager::notify(const SCNotification *notification)
for (size_t i = 0, len = _pluginInfos.size() ; i < len ; ++i)
{
if (_pluginInfos[i]->_hLib)
{
// To avoid the plugin change the data in SCNotification
// Each notification to pass to a plugin is a copy of SCNotification instance
SCNotification scNotif = *notification;
try
{
_pluginInfos[i]->_pBeNotified(&scNotif);
}
catch (std::exception& e)
{
::MessageBoxA(NULL, e.what(), "Exception", MB_OK);
}
catch (...)
{
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),\
scNotif.nmhdr.code, scNotif.nmhdr.hwndFrom, scNotif.nmhdr.idFrom);
pluginCrashAlert(_pluginInfos[i]->_moduleName.c_str(), funcInfo);
}
}
notify(i, notification);
}
}

View File

@ -113,7 +113,8 @@ public:
bool getShortcutByCmdID(int cmdID, ShortcutKey *sk);
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);
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);
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
ReleaseMutex(lwp->_mutex);
}
@ -609,6 +616,7 @@ bool PluginsAdminDlg::installPlugins()
lwp->_updaterDir = _updaterDir;
lwp->_updaterFullPath = _updaterFullPath;
lwp->_updaterParams = updaterParams;
lwp->_hwnd = _hSelf;
lwp->_mutex = mutex;
_lwps.push_back(lwp);

View File

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