exec function

dynamic exec()

Executes the static_shortcuts package

Implementation

exec() {
  log("Start static_shortcuts", color: PrintColor.blue);

  final Map<String, dynamic> config = loadConfigFile();
  final Map<String, Map<String, String>> labels = {};
  final List<Shortcut> shortcuts = [];

  for (String shortcut in config.keys) {
    log("Build static shortcut '$shortcut'...", color: PrintColor.blue);
    String? iconPath = config[shortcut]["icon"];
    String intent = config[shortcut]["intent"];
    String targetClass =
        config[shortcut]["targetClass"]; // todo iwie herausfinden
    String targetPackage =
        config[shortcut]["targetPackage"]; // todo iwie herausfinden
    dynamic label = config[shortcut]["label"];
    String shortcutId = formatSecure(intent);

    String iconName = "";
    if (iconPath != null) {
      log("Generating Android mipmaps...");
      iconName = "ic_ssc_$shortcutId";
      ImageResizer.createAndroidMipmaps(iconPath, iconName);
      log("Mipmap icons generated.", color: PrintColor.green);
    } else {
      iconName = "ic_launcher";
      log("No icon specified. Using default icon 'ic_launcher' instead.");
    }

    // Strings
    String stringName = "ssc_$shortcutId";
    if (label is String) {
      if (labels[""] == null) {
        labels[""] = {};
      }
      labels[""]![stringName] = label;
    } else {
      for (String key in (label as yaml.YamlMap).keys) {
        String language = key == "default" ? "" : key;
        if (labels[language] == null) {
          labels[language] = {};
        }
        labels[language]![stringName] = label[key]!;
      }
    }

    shortcuts.add(
      Shortcut(
        "@mipmap/$iconName",
        shortcutId,
        "@string/$stringName",
        targetClass,
        targetPackage,
        intent,
      ),
    );
  }

  log("Generating Strings for all shortcuts...");
  for (String lang in labels.keys) {
    XmlGenerator.generateStrings(labels[lang]!, languageCode: lang);
  }
  log("All strings created.", color: PrintColor.green);

  log("Generating shortcuts.xml...");
  XmlGenerator.generateShortcutsXml(shortcuts);
  log("shortcuts.xml generated.", color: PrintColor.green);

  log("You have just now ${config.length} shortcut(s).");

  log("Exit static_shortcuts", color: PrintColor.blue);
}