diff --git a/lib/cwtch/cwtch.dart b/lib/cwtch/cwtch.dart index b19d0f72..3976bfb9 100644 --- a/lib/cwtch/cwtch.dart +++ b/lib/cwtch/cwtch.dart @@ -14,6 +14,8 @@ abstract class Cwtch { // ignore: non_constant_identifier_names Future ReconnectCwtchForeground(); + String getAssetsDir(); + // ignore: non_constant_identifier_names void CreateProfile(String nick, String pass, bool autostart); diff --git a/lib/cwtch/ffi.dart b/lib/cwtch/ffi.dart index 059ff55d..1ccc4817 100644 --- a/lib/cwtch/ffi.dart +++ b/lib/cwtch/ffi.dart @@ -134,6 +134,7 @@ class CwtchFfi implements Cwtch { late Isolate cwtchIsolate; ReceivePort _receivePort = ReceivePort(); bool _isL10nInit = false; + String _assetsDir = path.join(Directory.current.path, "data", "flutter_assets"); static String getLibraryPath() { if (Platform.isWindows) { @@ -183,8 +184,10 @@ class CwtchFfi implements Cwtch { bundledTor = "lib/Tor/tor"; } else if (await File(path.join(home, ".local/lib/cwtch/Tor/tor")).exists()) { bundledTor = path.join(home, ".local/lib/cwtch/Tor/tor"); + _assetsDir = path.join(home, ".local", "share", "cwtch", "data", "flutter_assets"); } else if (await File("/usr/lib/cwtch/Tor/tor").exists()) { bundledTor = "/usr/lib/cwtch/Tor/tor"; + _assetsDir = path.join("usr", "share", "cwtch", "data", "flutter_assets"); } else { bundledTor = "tor"; } @@ -193,14 +196,18 @@ class CwtchFfi implements Cwtch { String currentTor = path.join(Directory.current.absolute.path, "Tor\\Tor\\tor.exe"); if (await File(currentTor).exists()) { bundledTor = currentTor; + _assetsDir = path.join(Directory.current.absolute.path, "data", "flutter_assets"); } else { String exeDir = path.dirname(Platform.resolvedExecutable); bundledTor = path.join(exeDir, "Tor\\Tor\\tor.exe"); + _assetsDir = path.join(exeDir, "data", "flutter_assets"); } } else if (Platform.isMacOS) { cwtchDir = envVars['CWTCH_HOME'] ?? path.join(envVars['HOME']!, "Library/Application Support/Cwtch"); + _assetsDir = "/Applications/Cwtch.app/Contents/Frameworks/App.framework/Versions/Current/Resources/flutter_assets/"; if (await File("Cwtch.app/Contents/MacOS/Tor/tor").exists()) { bundledTor = "Cwtch.app/Contents/MacOS/Tor/tor"; + _assetsDir = "Cwtch.app/Contents/Frameworks/App.framework/Versions/Current/Resources/flutter_assets/"; } else if (await File("/Applications/Cwtch.app/Contents/MacOS/Tor/tor").exists()) { bundledTor = "/Applications/Cwtch.app/Contents/MacOS/Tor/tor"; } else if (await File("/Volumes/Cwtch/Cwtch.app/Contents/MacOS/Tor/tor").exists()) { @@ -257,6 +264,10 @@ class CwtchFfi implements Cwtch { }); } + String getAssetsDir() { + return _assetsDir; + } + // ignore: non_constant_identifier_names Future ReconnectCwtchForeground() async { var reconnectCwtch = library.lookup>("c_ReconnectCwtchForeground"); diff --git a/lib/cwtch/gomobile.dart b/lib/cwtch/gomobile.dart index 3eca7ecd..7d28fcd3 100644 --- a/lib/cwtch/gomobile.dart +++ b/lib/cwtch/gomobile.dart @@ -62,6 +62,11 @@ class CwtchGomobile implements Cwtch { appbusEventChannel.setMethodCallHandler(this._handleAppbusEvent); } + String getAssetsDir() { + // TODO + return ""; + } + // ignore: non_constant_identifier_names Future Start() async { print("gomobile.dart: Start()..."); diff --git a/lib/themes/opaque.dart b/lib/themes/opaque.dart index 4a598989..1fb8a2a1 100644 --- a/lib/themes/opaque.dart +++ b/lib/themes/opaque.dart @@ -123,7 +123,7 @@ abstract class OpaqueThemeType { get chatImage => null; - ImageProvider loadImage(String key) { return AssetImage(""); } + ImageProvider loadImage(String key, {BuildContext? context}) { return AssetImage(""); } // Sizes double contactOnionTextSize() { diff --git a/lib/themes/yamltheme.dart b/lib/themes/yamltheme.dart index 3171f9ca..e5be331a 100644 --- a/lib/themes/yamltheme.dart +++ b/lib/themes/yamltheme.dart @@ -7,9 +7,12 @@ import 'package:cwtch/themes/cwtch.dart'; import 'package:cwtch/themes/opaque.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:provider/provider.dart'; import 'package:yaml/yaml.dart'; import 'package:path/path.dart' as path; +import '../main.dart'; + Future>> loadYamlThemes() async { final manifestJson = await rootBundle.loadString('AssetManifest.json'); final themesList = json.decode(manifestJson).keys.where((String key) => key.startsWith('assets/themes')); @@ -139,13 +142,22 @@ class YmlTheme extends OpaqueThemeType { get chatImage => getImage("chatImage") ?? fallbackTheme.chatImage; - - ImageProvider loadImage(String key) { + ImageProvider loadImage(String key, {BuildContext? context}) { File f = File(key); if (f.existsSync()) { return FileImage(f); - } else { - return AssetImage(key); } + + if (context != null) { + File af = File(path.join(Provider + .of(context, listen: false) + .cwtch + .getAssetsDir(), key)); + if (af.existsSync()) { + return FileImage(af); + } + } + + return AssetImage(key); } } diff --git a/lib/widgets/messagelist.dart b/lib/widgets/messagelist.dart index 65a13c15..a2d262bd 100644 --- a/lib/widgets/messagelist.dart +++ b/lib/widgets/messagelist.dart @@ -120,7 +120,7 @@ class _MessageListState extends State { ? (Provider.of(context).theme.chatImage != null) ? DecorationImage( repeat: ImageRepeat.repeat, - image: Provider.of(context).theme.loadImage(Provider.of(context).theme.chatImage), + image: Provider.of(context).theme.loadImage(Provider.of(context).theme.chatImage, context: context), colorFilter: ColorFilter.mode(Provider.of(context).theme.hilightElementColor.withOpacity(0.15), BlendMode.srcIn)) : null : DecorationImage(