FileConfigJSONNodeSettings constructor

FileConfigJSONNodeSettings({
  1. Directory? directory,
  2. bool reloadable = true,
})

Implementation

FileConfigJSONNodeSettings({Directory? directory, this.reloadable = true}) {
  configDirectory = directory ??
      Directory("${Directory.current.path}${Platform.pathSeparator}config");
  logger.info("Using config directory ${configDirectory.path}");
  if (!configDirectory.existsSync()) {
    configDirectory.createSync(recursive: true);
    logger.verbose("Created config directory ${configDirectory.path}");
  }
  if (reloadable) {
    watcher = Watcher(configDirectory.path);
    watcher.events.listen((event) {
      String path = event.path.replaceAll("\\", "/");
      if (event.type == ChangeType.MODIFY) {
        if (ignore.contains(path)) {
          ignore.remove(path);
          return;
        }

        logger.verbose("Config Change detected at $path");
        onChangeAt(path);
      } else if (event.type == ChangeType.REMOVE) {
        logger.verbose("Config removed at $path");
      }
    });
  }
}