diff options
author | Scott Murray <scott.murray@konsulko.com> | 2023-12-17 15:48:21 -0500 |
---|---|---|
committer | Jan-Simon Moeller <jsmoeller@linuxfoundation.org> | 2023-12-18 13:28:28 +0000 |
commit | 4ae68f5be11d110f2df10d54377d970921e30a21 (patch) | |
tree | b37b5cb3c6964fbaeaa95edc1edeb44d615912e9 /lib/data/data_providers/app_config_provider.dart | |
parent | dda6c8502a3fa1e50654c4cca934b4b846bbca98 (diff) |
Implement audio settings
Changes:
- Rework KUKSA.val "VAL" gRPC API implementation to separate it
from the vehicle model + notifier, and more easily allow using
it from other notifiers.
- Move volume handling from the vehicle model + notifier to the
audio set for clarity.
- Wire up the new VSS audio signals in the audio notifier. The
"rearFront" variable naming has been changed to "fade" in
several places to match expected terminology.
- Add a balance slider to the audio settings page.
- Change the min/max labels on the fade slider to be Text instead
of Icon's since we do not have the equivalent to use with the
balance slider, and text seems like it'd be what you would want
for any potential future internationalization.
- Rework configuration file to be usable from anywhere via a
RiverPod Provider instead of tied to the vehicle notifier code,
and shifted the background and hybrid animation flags to be handled
with it. This change removes the built-in asset with defaults in
favor of maintaining the defaults for the ICS environment in the
AppConfig and KuksaConfig classes, with a goal of avoiding the need
for using async methods in the config provider.
- Change some notifiers from using StateNotifier to the RiverPod
2.0 Notifier class for improved flexibility. The other notifiers
will be updated in future work.
- Added select's to several ref.watches in the new hybrid animation
code to avoid unnecessary repaints.
- Fix several spelling issues in method and parameter names
across the codebase.
Bug-AGL: SPEC-5001
Change-Id: Iefae417fa870405d659303497d96e519e6b6d1de
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Diffstat (limited to 'lib/data/data_providers/app_config_provider.dart')
-rw-r--r-- | lib/data/data_providers/app_config_provider.dart | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/lib/data/data_providers/app_config_provider.dart b/lib/data/data_providers/app_config_provider.dart new file mode 100644 index 0000000..7e0ddc6 --- /dev/null +++ b/lib/data/data_providers/app_config_provider.dart @@ -0,0 +1,162 @@ +import 'dart:io'; +import 'package:flutter/foundation.dart'; +import 'package:flutter_ics_homescreen/core/constants/constants.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:yaml/yaml.dart'; + +class KuksaConfig { + final String hostname; + final int port; + final String authorization; + final bool use_tls; + final List<int> ca_certificate; + final String tls_server_name; + + static String defaultHostname = 'localhost'; + static int defaultPort = 55555; + static String defaultCaCertPath = '/etc/kuksa-val/CA.pem'; + + KuksaConfig( + {required this.hostname, + required this.port, + required this.authorization, + required this.use_tls, + required this.ca_certificate, + required this.tls_server_name}); + + static KuksaConfig defaultConfig() { + return KuksaConfig( + hostname: KuksaConfig.defaultHostname, + port: KuksaConfig.defaultPort, + authorization: "", + use_tls: false, + ca_certificate: [], + tls_server_name: ""); + } +} + +class AppConfig { + final bool disableBkgAnimation; + final bool randomHybridAnimation; + final KuksaConfig kuksaConfig; + + static String configFilePath = '/etc/xdg/AGL/ics-homescreen.yaml'; + + AppConfig({required this.disableBkgAnimation, required this.randomHybridAnimation, required this.kuksaConfig}); + + static KuksaConfig parseKuksaConfig(YamlMap kuksaMap) { + try { + String hostname = KuksaConfig.defaultHostname; + if (kuksaMap.containsKey('hostname')) { + hostname = kuksaMap['hostname']; + } + + int port = KuksaConfig.defaultPort; + if (kuksaMap.containsKey('port')) { + port = kuksaMap['port']; + } + + String token = ""; + if (kuksaMap.containsKey('authorization')) { + String s = kuksaMap['authorization']; + if (s.isNotEmpty) { + if (s.startsWith("/")) { + debugPrint("Reading authorization token $s"); + try { + token = File(s).readAsStringSync(); + } on Exception catch (_) { + print("ERROR: Could not read authorization token file $token"); + token = ""; + } + } else { + token = s; + } + } + } + //debugPrint("authorization = $token"); + + bool use_tls = false; + if (kuksaMap.containsKey('use-tls')) { + var value = kuksaMap['use-tls']; + if (value is bool) use_tls = value; + } + //debugPrint("Use TLS = $use_tls"); + + List<int> ca_cert = []; + String ca_path = KuksaConfig.defaultCaCertPath; + if (kuksaMap.containsKey('ca-certificate')) { + ca_path = kuksaMap['ca-certificate']; + } + try { + ca_cert = File(ca_path).readAsBytesSync(); + } on Exception catch (_) { + print("ERROR: Could not read CA certificate file $ca_path"); + ca_cert = []; + } + //debugPrint("CA cert = $ca_cert"); + + String tls_server_name = ""; + if (kuksaMap.containsKey('tls-server-name')) { + tls_server_name = kuksaMap['tls_server_name']; + } + + return KuksaConfig( + hostname: hostname, + port: port, + authorization: token, + use_tls: use_tls, + ca_certificate: ca_cert, + tls_server_name: tls_server_name); + } on Exception catch (_) { + return KuksaConfig.defaultConfig(); + } + } +} + +final appConfigProvider = Provider((ref) { + final configFile = File(AppConfig.configFilePath); + try { + print("Reading configuration ${AppConfig.configFilePath}"); + String content = configFile.readAsStringSync(); + final dynamic yamlMap = loadYaml(content); + + KuksaConfig kuksaConfig; + if (yamlMap.containsKey('kuksa')) { + kuksaConfig = AppConfig.parseKuksaConfig(yamlMap['kuksa']); + } else { + kuksaConfig = KuksaConfig( + hostname: KuksaConfig.defaultHostname, + port: KuksaConfig.defaultPort, + authorization: "", + use_tls: false, + ca_certificate: [], + tls_server_name: ""); + } + + bool disableBkgAnimation = disableBkgAnimationDefault; + if (yamlMap.containsKey('disable-bg-animation')) { + var value = yamlMap['disable-bg-animation']; + if (value is bool) { + disableBkgAnimation = value; + } + } + + bool randomHybridAnimation = randomHybridAnimationDefault; + if (yamlMap.containsKey('random-hybrid-animation')) { + var value = yamlMap['random-hybrid-animation']; + if (value is bool) { + randomHybridAnimation = value; + } + } + + return AppConfig( + disableBkgAnimation: disableBkgAnimation, + randomHybridAnimation: randomHybridAnimation, + kuksaConfig: kuksaConfig); + } on Exception catch (_) { + return AppConfig( + disableBkgAnimation: false, + randomHybridAnimation: false, + kuksaConfig: KuksaConfig.defaultConfig()); + } +}); |