initiateUpdate static method

Future<void> initiateUpdate({
  1. required String url,
  2. required String versionName,
  3. required UpdateCenterConfig config,
  4. required DownloadState downloadState,
  5. required Future<void> launchUrl(
    1. String url
    ),
  6. String? sourceUrl,
})

Implementation

static Future<void> initiateUpdate({
  required String url,
  required String versionName,
  required UpdateCenterConfig config,
  required DownloadState downloadState,
  required Future<void> Function(String url) launchUrl,
  String? sourceUrl,
}) async {
  if (config.globalConfig.isOpenFile) {
    File localFile;
    if (Platform.isWindows) {
      localFile = await MemoryProvider.getLocalFileWindows(url);
    } else if (Platform.isAndroid) {
      localFile = await MemoryProvider.getLocalFileAndroid(url);
    } else {
      // Handle other platforms if necessary
      return;
    }

    if (await localFile.exists()) {
      log(localFile.path);

      // Optionally, open the file directly
      await OpenFilex.open(localFile.path);
      return;
    }
  }

  // Next, check if the source URL should be launched instead of downloading
  if (config.globalConfig.isSourceUrl && sourceUrl != null) {
    await launchUrl(sourceUrl);
    return;
  }

  // Based on the platform, initiate the appropriate download method
  if (Platform.isWindows) {
    await DownloadProvider.downloadUpdateWindows(
      url,
      versionName,
      (progress) {},
      config,
      downloadState,
    );
  } else if (Platform.isAndroid) {
    await DownloadProvider.downloadUpdateAndroid(
      url,
      versionName,
      (progress) {},
      config,
      downloadState,
    );
  }
}