package net.taehui.twilight.system import net.taehui.twilight.Logger import net.taehui.twilight.TwilightComponent import org.apache.commons.io.FilenameUtils import java.nio.file.* import java.util.concurrent.Executors import java.util.concurrent.ScheduledExecutorService object AutoLoadingSystem : Logger { private val ws = FileSystems.getDefault().newWatchService() fun handleSystem() { logFuture { ws.use { TwilightComponent.SYSTEM_ENTRY_PATH.register(ws, StandardWatchEventKinds.ENTRY_MODIFY) TwilightComponent.DEFAULT_NOTE_ENTRY.register(ws, StandardWatchEventKinds.ENTRY_MODIFY) TwilightComponent.DEFAULT_UI_ENTRY.register(ws, StandardWatchEventKinds.ENTRY_MODIFY) while (true) { val tws = ws.take() tws.pollEvents().forEach { val filePath = (tws.watchable() as Path).resolve(it.context() as Path) val fileName = filePath.fileName.toString() when (filePath.parent.fileName.toString()) { "Note", "UI" -> { if (FilenameUtils.isExtension(fileName, "zip") || FilenameUtils.isExtension( fileName, "rar" ) ) { Configure.loadDefaultDate() } } "System" -> { when (fileName) { "Awilight.py" -> AwilightHandler.loadAwilight() } } } } tws.reset() } } } } }