forked from cwtch.im/cwtch-ui
Merge pull request 'fix wiring of loading files for yaml theme images' (#799) from assetsPath into trunk
Reviewed-on: cwtch.im/cwtch-ui#799 Reviewed-by: Sarah Jamie Lewis <sarah@openprivacy.ca>
This commit is contained in:
commit
2abbf223b2
|
@ -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);
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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()...");
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue