From 8979811de7c6c3e6f2e35b44f447dba9d5f57059 Mon Sep 17 00:00:00 2001 From: cyan Date: Thu, 28 May 2026 17:10:48 +0200 Subject: [PATCH] linux fixes (#3262) * linux fixes fix: use ints instead of bools in SQLite to prevent crashes on linux fix: disable lightning if it's unsupported ui: start linux app in portrait mode instead of landscape so it looks nicer * minor cleanup --------- Co-authored-by: Omar --- cw_bitcoin/lib/electrum_wallet.dart | 11 +++++- cw_core/lib/node.dart | 60 +++++++++++++++++------------ lib/new-ui/pages/receive_page.dart | 2 +- lib/new-ui/pages/send_page.dart | 2 +- linux/my_application.cc | 6 +-- 5 files changed, 47 insertions(+), 34 deletions(-) diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index ec5492116..842fe7e38 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -4,6 +4,7 @@ import 'dart:io'; import 'dart:isolate'; import 'package:bitcoin_base/bitcoin_base.dart'; +import 'package:cw_bitcoin/lightning/lightning_wallet.dart'; import 'package:cw_core/hardware/hardware_wallet_service.dart'; import 'package:cw_core/root_dir.dart'; import 'package:cw_core/utils/proxy_wrapper.dart'; @@ -76,7 +77,7 @@ abstract class ElectrumWalletBase ElectrumBalance? initialBalance, CryptoCurrency? currency, bool? alwaysScan, - this.useLightning = true, + bool useLightning = true, }) : _masterHD = getMasterHD(seedBytes, network, walletInfo.hardwareWalletType), accountHD = getAccountHDWallet( currency, network, seedBytes, xpub, derivationInfo, walletInfo.hardwareWalletType), @@ -102,6 +103,7 @@ abstract class ElectrumWalletBase this.unspentCoinsInfo = unspentCoinsInfo, this.isTestnet = !network.isMainnet, this._mnemonic = mnemonic, + _useLightning = useLightning, super(walletInfo, derivationInfo) { this.electrumClient = electrumClient ?? electrum.ElectrumClient(); this.walletInfo = walletInfo; @@ -305,8 +307,13 @@ abstract class ElectrumWalletBase @observable bool? alwaysScan; + @computed + bool get useLightning => _useLightning && LightningWallet.isAvailable; + + set useLightning(bool val) => _useLightning = val && LightningWallet.isAvailable; + @observable - bool useLightning; + bool _useLightning; final Bip32Slip10Secp256k1? _masterHD; final Bip32Slip10Secp256k1 accountHD; diff --git a/cw_core/lib/node.dart b/cw_core/lib/node.dart index 818286a2d..7550fc626 100644 --- a/cw_core/lib/node.dart +++ b/cw_core/lib/node.dart @@ -92,15 +92,25 @@ class Node { login = map['login'] as String?, label = map['label'] as String?, password = map['password'] as String?, - isPow = (map["isPow"] != null && map['isPow'] != 0) as bool? ?? false, - useSSL = (map['useSSL'] != 0) as bool?, + isPow = _getBoolFromDB(map['isPow']), + useSSL = _getBoolFromDB(map['useSSL']), typeRaw = (map["typeRaw"] ?? 0) as int, - trusted = (map['trusted'] != 0) as bool? ?? false, + trusted = _getBoolFromDB(map['trusted']), socksProxyAddress = map['socksProxyAddress'] as String?, - isEnabledForAutoSwitching = (map['isEnabledForAutoSwitching'] != 0) as bool? ?? false, - isOfficial = (map['isOfficial'] != 0) as bool? ?? false, - isBuiltin = (map['isBuiltin'] != 0) as bool? ?? false, - isDefault = (map['isDefault'] != 0) as bool? ?? false; + isEnabledForAutoSwitching = _getBoolFromDB(map['isEnabledForAutoSwitching']), + isOfficial = _getBoolFromDB(map['isOfficial']), + isBuiltin = _getBoolFromDB(map['isBuiltin']), + isDefault = _getBoolFromDB(map['isDefault']); + + static bool _getBoolFromDB(value, {bool? defaultValue}) { + if (value is bool) { + return value; + } else if (value is int) { + return value == 1; + } else { + return defaultValue ?? false; + } + } Map toMap() { return { @@ -110,15 +120,15 @@ class Node { 'login': login, "label": label, 'password': password, - "isPow": isPow, - 'useSSL': useSSL, + "isPow": isPow ? 1 : 0, + 'useSSL': (useSSL??false) ? 1 : 0, "typeRaw": typeRaw, - 'trusted': trusted, + 'trusted': trusted ? 1 : 0, 'socksProxyAddress': socksProxyAddress, - 'isEnabledForAutoSwitching': isEnabledForAutoSwitching, - "isOfficial": isOfficial, - "isBuiltin": isBuiltin, - "isDefault": isDefault + 'isEnabledForAutoSwitching': isEnabledForAutoSwitching ? 1 : 0, + "isOfficial": isOfficial ? 1 : 0, + "isBuiltin": isBuiltin ? 1 : 0, + "isDefault": isDefault ? 1 : 0 }; } @@ -127,11 +137,11 @@ class Node { } static Future deleteAll() async { - return await db!.delete(tableName, where: "isPow = ?", whereArgs: [false]); + return await db!.delete(tableName, where: "isPow = ?", whereArgs: [0]); } static Future deleteAllPow() async { - return await db!.delete(tableName, where: "isPow = ?", whereArgs: [true]); + return await db!.delete(tableName, where: "isPow = ?", whereArgs: [1]); } Future save() async { @@ -173,35 +183,35 @@ class Node { static Future> getAll() async { - return selectList("isPow = ?", [false]); + return selectList("isPow = ?", [0]); } static Future> getAllBuiltin() async { - return selectList("isPow = ? AND isBuiltin = ?", [false, true]); + return selectList("isPow = ? AND isBuiltin = ?", [0, 1]); } static Future> getAllPowBuiltin() async { - return selectList("isPow = ? AND isBuiltin = ?", [true, true]); + return selectList("isPow = ? AND isBuiltin = ?", [1, 1]); } static Future> getAllForWalletType(WalletType type) async { - return selectList("typeRaw = ? AND isPow = ?", [serializeToInt(type), false]); + return selectList("typeRaw = ? AND isPow = ?", [serializeToInt(type), 0]); } static Future getDefaultForWalletType(WalletType type) async { - return (await selectList("typeRaw = ? AND isPow = ? AND isDefault = ?", [serializeToInt(type), false, true])).firstOrNull; + return (await selectList("typeRaw = ? AND isPow = ? AND isDefault = ?", [serializeToInt(type), 0, 1])).firstOrNull; } static Future getDefaultPowForWalletType(WalletType type) async { - return (await selectList("typeRaw = ? AND isPow = ? AND isDefault = ?", [serializeToInt(type), true, true])).firstOrNull; + return (await selectList("typeRaw = ? AND isPow = ? AND isDefault = ?", [serializeToInt(type), 1, 1])).firstOrNull; } static Future> getAllForWalletTypePow(WalletType type) async { - return selectList("typeRaw = ? AND isPow = ?", [serializeToInt(type), true]); + return selectList("typeRaw = ? AND isPow = ?", [serializeToInt(type), 1]); } static Future> getAllPow() async { - return selectList("isPow = ?", [true]); + return selectList("isPow = ?", [1]); } static Future get(int id) async { @@ -475,7 +485,7 @@ class Node { }, ), ); - + final data = jsonDecode(response.body); if (response.statusCode != 200 || data["error"] != null || diff --git a/lib/new-ui/pages/receive_page.dart b/lib/new-ui/pages/receive_page.dart index 764393e3b..9ad2d7d2f 100644 --- a/lib/new-ui/pages/receive_page.dart +++ b/lib/new-ui/pages/receive_page.dart @@ -342,7 +342,7 @@ class _NewReceivePageState extends State { setState(() { _addressItemWithLabel = widget.addressListViewModel.forceRecomputeItems.firstWhereOrNull( (item) => (item is WalletAddressListItem && item.address == newAddress.address)) - as WalletAddressListItem; + as WalletAddressListItem?; }); } } diff --git a/lib/new-ui/pages/send_page.dart b/lib/new-ui/pages/send_page.dart index 1fd28fc9b..c3f5da957 100644 --- a/lib/new-ui/pages/send_page.dart +++ b/lib/new-ui/pages/send_page.dart @@ -972,7 +972,7 @@ class _NewSendPageState extends State { onNext: (PaymentFlowResult newResult) { final selectedChainId = newResult.chainId; final isCompatible = - selectedChainId == evm!.getSelectedChainId(widget.sendViewModel.wallet); + selectedChainId == evm?.getSelectedChainId(widget.sendViewModel.wallet); if (isCompatible) { widget.sendViewModel.setSelectedCryptoCurrency( diff --git a/linux/my_application.cc b/linux/my_application.cc index 49f9ae139..5038b3c5f 100644 --- a/linux/my_application.cc +++ b/linux/my_application.cc @@ -46,11 +46,7 @@ static void my_application_activate(GApplication* application) { } else { gtk_window_set_title(window, "Cake Wallet"); } - if (getenv("DESKTOP_FORCE_MOBILE")) { - gtk_window_set_default_size(window, 720, 1280); - } else { - gtk_window_set_default_size(window, 1280, 720); - } + gtk_window_set_default_size(window, 480, 800); gtk_widget_show(GTK_WIDGET(window)); g_autoptr(FlDartProject) project = fl_dart_project_new();