| 954 | } |
| 955 | |
| 956 | void SC::PluginRegistry::getPluginsToReloadBecauseOf(StringSpan relativePath, TimeMs tolerance, |
| 957 | Function<void(const PluginIdentifier&)> onPlugin) |
| 958 | { |
| 959 | const size_t numberOfPlugins = getNumberOfEntries(); |
| 960 | const bool reloadAll = relativePath.isEmpty(); |
| 961 | for (size_t idx = 0; idx < numberOfPlugins; ++idx) |
| 962 | { |
| 963 | const PluginDynamicLibrary& library = getPluginDynamicLibraryAt(idx); |
| 964 | bool shouldReload = false; |
| 965 | for (const PluginFile& file : library.definition.files) |
| 966 | { |
| 967 | StringSpan filePath = file.absolutePath.view(); |
| 968 | if (reloadAll or PluginString::pathEndsWith(filePath, relativePath)) |
| 969 | { |
| 970 | shouldReload = true; |
| 971 | break; |
| 972 | } |
| 973 | } |
| 974 | if (shouldReload) |
| 975 | { |
| 976 | const int64_t elapsed = PluginNow().milliseconds - library.lastLoadTime.milliseconds; |
| 977 | if (elapsed > tolerance.milliseconds) |
| 978 | { |
| 979 | // Only reload if at least tolerance ms have passed, as sometimes FSEvents on |
| 980 | // macOS likes to send multiple events that are difficult to filter properly |
| 981 | onPlugin(getIdentifierAt(idx)); |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | SC::Result SC::PluginRegistry::loadPlugin(StringSpan identifier, const PluginCompiler& compiler, |
| 988 | const PluginSysroot& sysroot, StringSpan executablePath, LoadMode loadMode) |