void (@NotNull RegistryManager registryManager) { int idleTimeout = getAutomakeWhileIdleTimeout(registryManager); int listenerTimeout = idleTimeout > 0 ? idleTimeout : 60000; Ref<AccessToken> idleListenerHandle = new Ref<>(); idleListenerHandle.set(IdleTracker.getInstance().addIdleListener(listenerTimeout, () -> { int currentTimeout = getAutomakeWhileIdleTimeout(registryManager); if (idleTimeout != currentTimeout) { // re-schedule with a changed period AccessToken removeListener = idleListenerHandle.get(); if (removeListener != null) { removeListener.close(); } configureIdleAutomake(registryManager); } if (currentTimeout > 0 /*is enabled*/ && !myAutoMakeTask.myInProgress.get()) { boolean hasChanges = false; synchronized (myProjectDataMap) { for (ProjectData data : myProjectDataMap.values()) { if (data.hasChanges()) { hasChanges = true; break; } } } if (hasChanges) { // only schedule automake if the feature is enabled, no automake is running at the moment, // and there is at least one watched project with pending changes scheduleAutoMake(); } } })); }