diff --git a/README.md b/README.md index c6b5b0d..62d2b75 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ A simple and user-friendly Matrix client made with Flutter and the Matrix Dart S - [x] Using a text/uri/link - [x] Plain text - [x] `matrix:` Uri - - [ ] Matrix.to link: I just need to fix my regex, I should do this next. + - [ ] Matrix.to link: I just need to fix my regex - [ ] From space - [ ] Exploring - [x] Leaving @@ -108,7 +108,7 @@ A simple and user-friendly Matrix client made with Flutter and the Matrix Dart S - [ ] About - [x] Log Out -## Build Instructions +## Development First, clone and open the repo: @@ -122,13 +122,13 @@ cd nexus #### Linux - With Nix: Either use direnv, or `nix flake develop` -- Without Nix: Install Flutter, Go, Olm, Git, Clang, and GLibc. +- Without Nix: Install Flutter, Rust, the libsecret dev package for your distro (must be in `PKG_CONFIG_PATH`), and sqlite (must be in `LD_LIBRARY_PATH`). #### Windows / MacOS -I don't really know. You will need Flutter, Git, Olm, Go, and Visual Studio tools, and otherwise I guess just keep installing stuff until there aren't any errors. I will look into this sometimeTM. +I don't really know. You will need Flutter and Rust, and otherwise I guess just keep installing stuff until there aren't any errors. -### Set up Flutter +### Get dependencies: @@ -136,18 +136,6 @@ Get dependencies: flutter pub get ``` -Get dependencies: - -```sh -flutter pub get -``` - -Clone Gomuks and generate bindings: - -```sh -scripts/generate.sh -``` - Build generated files, and watch for new changes: ```sh diff --git a/flake.nix b/flake.nix index 860d010..0e5e7c8 100644 --- a/flake.nix +++ b/flake.nix @@ -29,6 +29,22 @@ ... }: + let + src = ./.; + + # from https://discourse.nixos.org/t/is-there-a-way-to-read-a-yaml-file-and-get-back-a-set/18385/5 + importYAML = + file: + lib.importJSON ( + pkgs.runCommand "converted-yaml.json" { } ''${pkgs.yj}/bin/yj < "${file}" > "$out"'' + ); + + package = importYAML "${src}/pubspec.yaml"; + + usedFlutter = (pkgs.flutter.override { extraPkgConfigPackages = [ pkgs.libsecret ]; }); + + buildInputs = [ pkgs.sqlite ]; + in { _module.args.pkgs = import nixpkgs { inherit system; @@ -45,14 +61,35 @@ olm git clang - flutter + usedFlutter + + (pkgs.writeShellScriptBin "rustup" (builtins.readFile ./nix/fake-rustup.sh)) ]; env = { - LD_LIBRARY_PATH = "./build/native_assets/linux"; + LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}:./build/native_assets/linux"; CPATH = lib.makeSearchPath "include" [ pkgs.glibc.dev ]; }; }; + + packages.default = usedFlutter.buildFlutterApplication { + inherit src buildInputs; + pname = package.name; + version = package.version; + + pubspecLock = importYAML "${src}/pubspec.lock"; + gitHashes = { + flutter_chat_ui = "sha256-4fuag7lRH5cMBFD3fUzj2K541JwXLoz8HF/4OMr3uhk="; + flutter_link_previewer = "sha256-4fuag7lRH5cMBFD3fUzj2K541JwXLoz8HF/4OMr3uhk="; + flyer_chat_text_message = "sha256-4fuag7lRH5cMBFD3fUzj2K541JwXLoz8HF/4OMr3uhk="; + window_size = "sha256-XelNtp7tpZ91QCEcvewVphNUtgQX7xrp5QP0oFo6DgM="; + }; + + patchPhase = /* sh */ '' + patchShebangs ./scripts/generate.sh + ./scripts/generate.sh # note: this doesn't quit the build on fail + ''; + }; }; }; } diff --git a/lib/controllers/secure_storage_controller.dart b/lib/controllers/secure_storage_controller.dart new file mode 100644 index 0000000..4a5781b --- /dev/null +++ b/lib/controllers/secure_storage_controller.dart @@ -0,0 +1,19 @@ +import "package:flutter_riverpod/flutter_riverpod.dart"; +import "package:flutter_secure_storage/flutter_secure_storage.dart"; + +class SecureStorageController extends Notifier { + @override + FlutterSecureStorage build() => FlutterSecureStorage(); + + Future get(String key) => state.read(key: key); + + Future set(String key, String value) => + state.write(key: key, value: value); + + Future clear() => state.deleteAll(); + + static final provider = + NotifierProvider( + SecureStorageController.new, + ); +} diff --git a/lib/pages/settings_page.dart b/lib/pages/settings_page.dart index 505904c..b348aac 100644 --- a/lib/pages/settings_page.dart +++ b/lib/pages/settings_page.dart @@ -1,11 +1,18 @@ import "package:flutter/material.dart"; import "package:flutter_riverpod/flutter_riverpod.dart"; +import "package:nexus/controllers/secure_storage_controller.dart"; class SettingsPage extends ConsumerWidget { const SettingsPage({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { - return Placeholder(); + return Scaffold( + appBar: AppBar(title: Text("Settings")), + body: ElevatedButton( + onPressed: ref.watch(SecureStorageController.provider.notifier).clear, + child: Text("Log out"), + ), + ); } } diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index f70fb6e..dffacff 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -20,6 +21,9 @@ void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) file_selector_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin"); file_selector_plugin_register_with_registrar(file_selector_linux_registrar); + g_autoptr(FlPluginRegistrar) flutter_secure_storage_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterSecureStorageLinuxPlugin"); + flutter_secure_storage_linux_plugin_register_with_registrar(flutter_secure_storage_linux_registrar); g_autoptr(FlPluginRegistrar) screen_retriever_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverLinuxPlugin"); screen_retriever_linux_plugin_register_with_registrar(screen_retriever_linux_registrar); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 78dcf40..8b658f4 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -5,6 +5,7 @@ list(APPEND FLUTTER_PLUGIN_LIST dynamic_system_colors file_selector_linux + flutter_secure_storage_linux screen_retriever_linux url_launcher_linux window_manager diff --git a/nix/fake-rustup.sh b/nix/fake-rustup.sh new file mode 100644 index 0000000..7884c05 --- /dev/null +++ b/nix/fake-rustup.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# Fake rustup for nix-managed Rust toolchains + +case "$1" in + run) + if [[ "$2" == "stable" ]]; then + shift 2 + if [[ $# -eq 0 ]]; then + echo "fake rustup: no command given" >&2 + exit 1 + fi + exec "$@" + exit 0 + fi + ;; + + toolchain) + if [[ "$2" == "list" ]]; then + echo "stable (default)" + exit 0 + fi + ;; + + target) + if [[ "$2" == "list" && "$3" == "--toolchain" && "$4" == "stable" && "$5" == "--installed" ]]; then + echo "x86_64-unknown-linux-gnu" + exit 0 + fi + ;; +esac + +echo "fake rustup: the command:" >&2 +echo " rustup $*" >&2 +echo "…is not mocked yet" >&2 +exit 1 \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index aec6fdc..222e779 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -533,6 +533,54 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.0" + flutter_secure_storage: + dependency: "direct main" + description: + name: flutter_secure_storage + sha256: da922f2aab2d733db7e011a6bcc4a825b844892d4edd6df83ff156b09a9b2e40 + url: "https://pub.dev" + source: hosted + version: "10.0.0" + flutter_secure_storage_darwin: + dependency: transitive + description: + name: flutter_secure_storage_darwin + sha256: "8878c25136a79def1668c75985e8e193d9d7d095453ec28730da0315dc69aee3" + url: "https://pub.dev" + source: hosted + version: "0.2.0" + flutter_secure_storage_linux: + dependency: transitive + description: + name: flutter_secure_storage_linux + sha256: "2b5c76dce569ab752d55a1cee6a2242bcc11fdba927078fb88c503f150767cda" + url: "https://pub.dev" + source: hosted + version: "3.0.0" + flutter_secure_storage_platform_interface: + dependency: transitive + description: + name: flutter_secure_storage_platform_interface + sha256: "8ceea1223bee3c6ac1a22dabd8feefc550e4729b3675de4b5900f55afcb435d6" + url: "https://pub.dev" + source: hosted + version: "2.0.1" + flutter_secure_storage_web: + dependency: transitive + description: + name: flutter_secure_storage_web + sha256: "6a1137df62b84b54261dca582c1c09ea72f4f9a4b2fcee21b025964132d5d0c3" + url: "https://pub.dev" + source: hosted + version: "2.1.0" + flutter_secure_storage_windows: + dependency: transitive + description: + name: flutter_secure_storage_windows + sha256: "3b7c8e068875dfd46719ff57c90d8c459c87f2302ed6b00ff006b3c9fcad1613" + url: "https://pub.dev" + source: hosted + version: "4.1.0" flutter_svg: dependency: "direct main" description: @@ -880,6 +928,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.11.1" + mention_tag_text_field: + dependency: "direct main" + description: + name: mention_tag_text_field + sha256: ba7b9d8003e0f340a65c6dcdb7770f4340f653ae1612a9e31e11d12f7f1dd80f + url: "https://pub.dev" + source: hosted + version: "0.0.9" meta: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 3c50656..7893653 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -59,7 +59,9 @@ dependencies: flutter_svg: ^2.2.2 json_annotation: ^4.9.0 shared_preferences: ^2.5.3 + mention_tag_text_field: ^0.0.9 fluttertagger: ^2.3.1 + flutter_secure_storage: ^10.0.0 dynamic_polls: ^0.0.6 flutter_hooks: ^0.21.3+1 cross_cache: ^1.1.0 diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 55fb066..b12edca 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -18,6 +19,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("DynamicColorPluginCApi")); FileSelectorWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("FileSelectorWindows")); + FlutterSecureStorageWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin")); ScreenRetrieverWindowsPluginCApiRegisterWithRegistrar( registry->GetRegistrarForPlugin("ScreenRetrieverWindowsPluginCApi")); UrlLauncherWindowsRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 9333a2f..8967b80 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -5,6 +5,7 @@ list(APPEND FLUTTER_PLUGIN_LIST dynamic_system_colors file_selector_windows + flutter_secure_storage_windows screen_retriever_windows url_launcher_windows window_manager