hlwhl / webview_cef

WebView for Flutter Desktop Apps using CEF(Chromium Embedded Framework) [Work in Progress]
Apache License 2.0
184 stars 54 forks source link

Better way to distribute prebuilt packages for macOS #36

Open ghost opened 1 year ago

ghost commented 1 year ago

You can implement something icons_launcher implemented to change icons.

flutter pub get
# create a function that can be passed in terminal and download binaries directly
flutter pub run icons_launcher:create

Create a installer_cli.dart and implement something like:

flutter pub get
flutter pub run webview_cef:download

Example for installer_cli.dart:

// ignore_for_file: avoid_print
import 'dart:io';

void downloadPrequisitesForMac() async {
  if (Platform.isMacOS) {
    if (await File('../macos/third/cef/libcef_dll_wrapper.a').exists()) {
      return;
    } else {
      const url =
          'https://github.com/hlwhl/webview_cef/releases/download/pods/mac103.0.12-universal.zip';
      final file = File('../mac103.0.12-universal.zip');
      final request = await HttpClient().getUrl(Uri.parse(url));
      final response = await request.close();
      final contentLength = response.contentLength;
      var bytes = <int>[];
      var total = 0;

      await for (var data in response) {
        bytes.addAll(data);
        total += data.length;

        stdout.write('\x1B[2J\x1B[0;0H');

        print('Downloading ${(total / contentLength * 100).toInt()}%');
      }

      await file.writeAsBytes(bytes);
      print('Download complete.');

      print('Extracting files...');
      await Process.run('unzip', [
        '../mac103.0.12-universal.zip',
        '-d',
        '../macos/third/cef/',
      ]);
      print('Files successfully extracted.');

      print('Cleaning up...');
      file.delete();

      print('Done.');
    }
  } else {
    return;
  }
}
bahricanyesil commented 10 months ago

@SinyimZhi Better macOS binary distribution can be the next thing to improve for the package. It's a bit hard to manage package code manually with the repo. You may prioritize it, take it as a suggestion. The real problem is the fact that being have to download the whole zip and unzip it to the repo folder and preserve the source code. We should remove this requirement.