initialize method

Future<void> initialize({
  1. bool strictMode = false,
})

Initialize the code push client

Must be called before using checkForUpdates or downloadAndInstall.

Throws QuicUISDKIncompatibleException if running on standard Flutter SDK and strict mode is enabled.

Implementation

Future<void> initialize({bool strictMode = false}) async {
  if (_isInitialized) {
    return; // Already initialized
  }

  // Check SDK compatibility first
  final isQuicUiSdk = await CodePushMethodChannel.isQuicUiFlutterSdk();
  if (!isQuicUiSdk) {
    print('⚠️  WARNING: QuicUI Code Push requires the modified Flutter SDK!');
    print('   Standard Flutter SDK detected - Code Push features will be disabled.');
    print('   See: https://github.com/Ikolvi/QuicUIFlutterSDK for installation.');
    print('   Tag: quicui-v1.0.0-engine');

    if (strictMode) {
      throw QuicUISDKIncompatibleException();
    }
  }

  _storageService = StorageService();
  await _storageService.initialize();

  _verifier = SignatureVerifier(
    publicKeyHex: _config.publicKey ?? '0',
  );

  _patchService = PatchService(
    config: _config,
    storageService: _storageService,
    verifier: _verifier,
  );

  // Detect and cache SDK info if enabled
  if (_config.includeSDKInfo) {
    try {
      final sdkInfo = await getSDKInfo();
      _config = Config(
        appId: _config.appId,
        clientSecret: _config.clientSecret,
        appVersion: _config.appVersion,
        publicKey: _config.publicKey,
        maxPatchSize: _config.maxPatchSize,
        autoCheckOnStart: _config.autoCheckOnStart,
        checkIntervalSeconds: _config.checkIntervalSeconds,
        enableDebugLogging: _config.enableDebugLogging,
        includeSDKInfo: _config.includeSDKInfo,
        sdkInfo: sdkInfo,
      );

      if (_config.enableDebugLogging) {
        print('[QuicUI] SDK Info detected: ${_config.sdkInfo?.sdkStatus}');
      }
    } catch (e) {
      if (_config.enableDebugLogging) {
        print('[QuicUI] Failed to detect SDK info: $e');
      }
    }
  }

  _isInitialized = true;

  if (_config.enableDebugLogging) {
    print('[QuicUI] Initialized with appId: ${_config.appId}');
  }
}