fix wiring of loading files for yaml theme images
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Dan Ballard 2024-01-05 01:13:43 -08:00
parent 10195b78f8
commit 05b50638da
6 changed files with 36 additions and 6 deletions

View File

@ -14,6 +14,8 @@ abstract class Cwtch {
// ignore: non_constant_identifier_names
Future<void> ReconnectCwtchForeground();
String getAssetsDir();
// ignore: non_constant_identifier_names
void CreateProfile(String nick, String pass, bool autostart);

View File

@ -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<void> ReconnectCwtchForeground() async {
var reconnectCwtch = library.lookup<NativeFunction<Void Function()>>("c_ReconnectCwtchForeground");

View File

@ -62,6 +62,11 @@ class CwtchGomobile implements Cwtch {
appbusEventChannel.setMethodCallHandler(this._handleAppbusEvent);
}
String getAssetsDir() {
// TODO
return "";
}
// ignore: non_constant_identifier_names
Future<void> Start() async {
print("gomobile.dart: Start()...");

View File

@ -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() {

View File

@ -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<Map<String, Map<String, OpaqueThemeType>>> 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<FlwtchState>(context, listen: false)
.cwtch
.getAssetsDir(), key));
if (af.existsSync()) {
return FileImage(af);
}
}
return AssetImage(key);
}
}

View File

@ -120,7 +120,7 @@ class _MessageListState extends State<MessageList> {
? (Provider.of<Settings>(context).theme.chatImage != null)
? DecorationImage(
repeat: ImageRepeat.repeat,
image: Provider.of<Settings>(context).theme.loadImage(Provider.of<Settings>(context).theme.chatImage),
image: Provider.of<Settings>(context).theme.loadImage(Provider.of<Settings>(context).theme.chatImage, context: context),
colorFilter: ColorFilter.mode(Provider.of<Settings>(context).theme.hilightElementColor.withOpacity(0.15), BlendMode.srcIn))
: null
: DecorationImage(