generateMacosCode function

Future<bool> generateMacosCode({
  1. required DesktopSplashConfig config,
  2. required String flavor,
  3. required Directory outputDir,
})

Generates Macos platform-specific code for the native splash screen

Takes a config object containing splash screen configuration, a flavor string to support multiple build flavors, and an output outputDir to override the default location.

Returns true if generation was successful, false otherwise.

Implementation

Future<bool> generateMacosCode({
  required DesktopSplashConfig config,
  required String flavor,
  required Directory outputDir,
}) async {
  if (!File(config.imagePath).existsSync()) {
    logger.e('Image file not found: ${config.imagePath}');
    return false;
  }

  // --- High-Quality Asset Generation ---
  // To ensure maximum quality, we generate both 1x and 2x assets directly
  // from the original source image, preventing any quality loss from upscaling.

// 1. Determine the final LOGICAL canvas dimensions.
  //    Fall back to window size if image size is not specified.
  final int logicalWidth =
      config.imageWidth > 0 ? config.imageWidth : config.windowWidth;
  final int logicalHeight =
      config.imageHeight > 0 ? config.imageHeight : config.windowHeight;

  // 2. Generate the 1x asset using the logical dimensions.
  final BGRAImage? processedImage1x =
      await _loadAndProcessImage(config, logicalWidth, logicalHeight);
  if (processedImage1x == null) return false;

  // 3. Generate the 2x asset using doubled logical dimensions.
  final BGRAImage? processedImage2x = await _loadAndProcessImage(
      config, logicalWidth * 2, logicalHeight * 2,
      scale: 2.0);
  if (processedImage2x == null) return false;

  // Save the generated high-quality assets to the xcassets bundle.
  final imageFileName = await _generateMacosAssets(
    outputDir: outputDir.path,
    flavor: flavor,
    processedImage1x: processedImage1x,
    processedImage2x: processedImage2x,
  );
  if (imageFileName == null) {
    return false;
  }

  // Generate the Swift source file.
  return _generateSourceFile(
    outputDir: outputDir.path,
    flavor: flavor,
    config: config,
    imageFileName: imageFileName,
    logicalWidth: logicalWidth,
    logicalHeight: logicalHeight,
  );
}