refactor(updates): pass typed runtime policy to deskup
This commit is contained in:
1 parent
1ef8edc8bc
commit
d83f94afd5
13 files changed
+158
-102
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import '../diagnostics/app_diagnostics.dart';
|
||||
import 'app_update_configuration.dart';
|
||||
|
||||
import 'package:deskup/deskup.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
@@ -26,7 +27,11 @@ AppUpdateBridge appUpdateBridge(Ref ref) {
|
||||
// Application adapter: Riverpod ownership and the macOS workspace quit gate.
|
||||
class AppUpdateBridge {
|
||||
AppUpdateBridge([MethodChannel channel = appUpdatesChannel])
|
||||
: _updater = Deskup(channel: channel);
|
||||
: _updater = Deskup(
|
||||
channel: channel,
|
||||
windows: windowsUpdateConfiguration(),
|
||||
macos: macosUpdateConfiguration(),
|
||||
);
|
||||
|
||||
final Deskup _updater;
|
||||
Stream<UpdateStatus> get events => _updater.events;
|
||||
@@ -65,7 +70,7 @@ class AppUpdateBridge {
|
||||
Future<void> check() => _updater.check();
|
||||
Future<void> download() => _updater.download();
|
||||
Future<void> validateInstall() => _updater.validateInstall();
|
||||
Future<void> install() => _updater.install();
|
||||
Future<void> install() => _updater.install(silent: true, restart: true);
|
||||
Future<void> setAutomaticChecks(bool enabled) =>
|
||||
_updater.setAutomaticChecks(enabled);
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import 'package:deskup/deskup.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
// Values are compiled from Dart defines; process environment does not redirect production.
|
||||
MacOSUpdateConfiguration macosUpdateConfiguration() =>
|
||||
const MacOSUpdateConfiguration(
|
||||
allowLocalHttp:
|
||||
appFlavor == 'development' &&
|
||||
bool.fromEnvironment('CUTDEX_UPDATE_TEST_HTTP'),
|
||||
);
|
||||
|
||||
WindowsUpdateConfiguration? windowsUpdateConfiguration({
|
||||
String? flavor,
|
||||
String developmentUrl = const String.fromEnvironment(
|
||||
'CUTDEX_WINDOWS_UPDATE_URL',
|
||||
),
|
||||
String developmentSource = const String.fromEnvironment(
|
||||
'CUTDEX_WINDOWS_UPDATE_SOURCE',
|
||||
defaultValue: 'gitea',
|
||||
),
|
||||
bool allowLocalHttp = const bool.fromEnvironment('CUTDEX_UPDATE_TEST_HTTP'),
|
||||
}) {
|
||||
final development = (flavor ?? appFlavor) == 'development';
|
||||
if (development && developmentUrl.isEmpty) return null;
|
||||
final WindowsUpdateSource source;
|
||||
if (!development) {
|
||||
source = GiteaUpdateSource(
|
||||
repositoryUrl: Uri.parse('https://git.orangraph.com/lingjhf/cutdex'),
|
||||
);
|
||||
} else if (developmentSource == 'gitea') {
|
||||
source = GiteaUpdateSource(
|
||||
repositoryUrl: Uri.parse(developmentUrl),
|
||||
allowLocalHttp: allowLocalHttp,
|
||||
);
|
||||
} else if (developmentSource == 'web') {
|
||||
source = WebUpdateSource(
|
||||
url: Uri.parse(developmentUrl),
|
||||
allowLocalHttp: allowLocalHttp,
|
||||
);
|
||||
} else {
|
||||
throw ArgumentError.value(developmentSource, 'developmentSource');
|
||||
}
|
||||
return WindowsUpdateConfiguration(
|
||||
source: source,
|
||||
expectedPackageId: development ? 'Cutdex.Dev' : 'Cutdex',
|
||||
preferenceNamespace: 'Cutdex',
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user