Skip to content

Hello, Can I use the "prepareUpdateApp" function to customize the update logic? #24

@lishangjing-spec

Description

@lishangjing-spec
void updateApp() async {
    updateStatus.value = 'updating...';

    String remoteUpdateFolder =
        ProjectManager().appInitModel?.appUpdates?.downloadUrl ?? '';

    if (remoteUpdateFolder.isEmpty) {
      closeDialog();
      return;
    }

    List<FileHashModel?> changedFiles = await updater.prepareUpdateApp(
      remoteUpdateFolder: remoteUpdateFolder,
    );

    if (changedFiles.isNotEmpty) {
      final progressStream = await updater.updateApp(
        remoteUpdateFolder: remoteUpdateFolder,
        changedFiles: changedFiles,
      );

      progressStream.listen(
        (progress) {
          logger.i('download progress: ${progress.receivedBytes}/${progress.totalBytes} KB');
          updateStatus.value = 'downloading...';
          updateProgress.value = progress.receivedBytes / progress.totalBytes;
        },
        onDone: () {
          updateStatus.value = 'restart...';
          updateProgress.value = 1.0;
          updater.restartApp();
        },
        onError: (error) {
          updateStatus.value = 'error: $error';
          closeDialog();
        },
      );
    } else {
      logger.e('empty update');
      closeDialog();
    }
  }

I didn't see any relevant documents or source code using prepareUpdateApp. Although it causes errors when overriding installation in the development environment and makes the application unable to open, in the release environment, it seems to be able to perform the override normally.

I don't know if it can be used.

I hope to receive a reply from the author.

thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions