diff --git a/.github/install-dep/action.yml b/.github/install-dep/action.yml index fbb6d410f..50747441e 100644 --- a/.github/install-dep/action.yml +++ b/.github/install-dep/action.yml @@ -46,7 +46,7 @@ runs: # ================ Platform-specific Initialization (Linux) ================ - name: Install dependencies (Ubuntu) - if: inputs.platform == 'ubuntu-latest' + if: contains(inputs.platform, 'ubuntu') shell: bash run: | echo "deb http://gb.archive.ubuntu.com/ubuntu jammy main" | sudo tee -a /etc/apt/sources.list @@ -70,13 +70,13 @@ runs: # ================ Platform-specific Initialization (macOS) ================ - name: Set up Homebrew - if: inputs.platform == 'macos-latest' + if: contains(inputs.platform, 'macos') id: set-up-homebrew uses: Homebrew/actions/setup-homebrew@master # fuse not available on macOS - name: Install dependencies (macOS) - if: inputs.platform == 'macos-latest' + if: contains(inputs.platform, 'macos') shell: bash run: | export HOMEBREW_NO_AUTO_UPDATE=1 @@ -90,7 +90,7 @@ runs: # According to https://github.com/actions/runner-images/blob/main/images/windows/toolsets/toolset-2025.json # OpenSSL, cmake and some other build tools have been embedded into the windows-latest image. - name: Install dependencies (Windows) - if: inputs.platform == 'windows-latest' + if: contains(inputs.platform, 'windows') shell: pwsh run: | choco config set cacheLocation ./.choco-cache @@ -100,12 +100,12 @@ runs: # Required by monobean, performing this step would take about 5s. # Won't caching it, for compression and decompression are MUCH slower than downloading it directly. - name: Load GTK and libadwaita - if: inputs.platform == 'windows-latest' && inputs.use-gtk == 'true' + if: contains(inputs.platform, 'windows') && inputs.use-gtk == 'true' shell: pwsh run: python ./monobean/setup.py - name: Manually set env vars and export - if: inputs.platform == 'windows-latest' + if: contains(inputs.platform, 'windows') shell: pwsh run: | $env:Path = "$env:Path;${{ github.workspace }}\monobean\resources\lib\bin;C:\Program Files\NASM;C:\Program Files\CMake\bin" @@ -124,7 +124,7 @@ runs: # =============== Save cache for speeding up =============== - name: Cache dependencies - if: inputs.platform != 'windows-latest' || steps.cache-restore.outputs.cache-hit == 'false' + if: ${{ ! contains(inputs.platform, 'windows') && steps.cache-restore.outputs.cache-hit == 'false' }} uses: actions/cache/save@v4 with: path: | diff --git a/.github/workflows/base.yml b/.github/workflows/base.yml index b7e92d881..88078b103 100644 --- a/.github/workflows/base.yml +++ b/.github/workflows/base.yml @@ -20,6 +20,7 @@ on: - 'scripts/**' - 'third-party/**' - 'toolchains/**' + - '.github/workflows/release.yml' pull_request: paths-ignore: - 'alfs/**' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 061c8d06a..c3c95d6a1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,31 +4,24 @@ on: workflow_dispatch: push: tags: - - "v*" + - "v*.*.*" permissions: contents: write jobs: - create-release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: taiki-e/create-gh-release-action@v1 - with: - # (required) GitHub token for creating GitHub Releases. - token: ${{ secrets.GITHUB_TOKEN }} - upload-assets: - needs: create-release strategy: matrix: include: - target: x86_64-unknown-linux-gnu + arch: amd64 os: ubuntu-latest - target: aarch64-apple-darwin + arch: aarch64 os: macos-latest - target: x86_64-pc-windows-msvc + arch: x64 os: windows-latest runs-on: ${{ matrix.os }} steps: @@ -44,19 +37,59 @@ jobs: cache-key: sysdeps platform: ${{ matrix.os }} - - name: Upload libra binary - uses: taiki-e/upload-rust-binary-action@v1 + - name: Building + run: | + cargo install --locked cargo-packager + cargo build --release --manifest-path libra/Cargo.toml + cargo packager --release --manifest-path monobean/Cargo.toml --config monobean/resources/packager_${{ matrix.target}}.toml + + - name: Prepare Linux + if: contains(matrix.os, 'ubuntu') + run: | + # makepkg monobean/target/build/ + mv target/release/libra ${{ github.workspace }}/libra_${{ github.ref_name }}_${{ matrix.target }} + # mv monobean/target/build/Monobean__${{ matrix.arch }}.tar.gz.zst ${{ github.workspace }}/Monobean_${{ github.ref_name }}_${{ matrix.target }}.tar.gz.zst + mv monobean/target/build/monobean__${{ matrix.arch }}.deb ${{ github.workspace }}/Monobean_${{ github.ref_name }}_${{ matrix.target }}.deb + + - name: Prepare Windows + if: contains(matrix.os, 'windows') + run: | + mv target/release/libra.exe ${{ github.workspace }}/libra_${{ github.ref_name }}_${{ matrix.target }}.exe + mv monobean/target/build/monobean_0.0.1_${{ matrix.arch }}-setup.exe ${{ github.workspace }}/Monobean_${{ github.ref_name }}_${{ matrix.target }}.exe + + - name: Prepare MacOS + if: contains(matrix.os, 'macos') + run: | + mv target/release/libra ${{ github.workspace }}/libra_${{ github.ref_name }}_${{ matrix.target }} + mv monobean/target/build/Monobean__${{ matrix.arch }}.dmg ${{ github.workspace }}/Monobean_${{ github.ref_name }}_${{ matrix.target }}.dmg + + - name: Release Linux + if: contains(matrix.os, 'ubuntu') + uses: softprops/action-gh-release@v2 with: - bin: libra - target: ${{ matrix.target }} - archive: libra-${{ matrix.target }} token: ${{ secrets.GITHUB_TOKEN }} + draft: true + files: | + libra_${{ github.ref_name }}_${{ matrix.target }} + # Monobean_${{ github.ref_name }}_${{ matrix.target }}.tar.gz.zst + Monobean_${{ github.ref_name }}_${{ matrix.target }}.deb - - name: Upload monobean binary - uses: taiki-e/upload-rust-binary-action@v1 + - name: Release Windows + if: contains(matrix.os, 'windows') + uses: softprops/action-gh-release@v2 with: - bin: monobean - manifest-path: monobean/Cargo.toml - target: ${{ matrix.target }} - archive: monobean-${{ matrix.target }} - token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + token: ${{ secrets.GITHUB_TOKEN }} + draft: true + files: | + libra_${{ github.ref_name }}_${{ matrix.target }}.exe + Monobean_${{ github.ref_name }}_${{ matrix.target }}.exe + + - name: Release MacOS + if: contains(matrix.os, 'macos') + uses: softprops/action-gh-release@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + draft: true + files: | + libra_${{ github.ref_name }}_${{ matrix.target }} + Monobean_${{ github.ref_name }}_${{ matrix.target }}.dmg \ No newline at end of file diff --git a/monobean/Cargo.toml b/monobean/Cargo.toml index 73b1fc143..e89764176 100644 --- a/monobean/Cargo.toml +++ b/monobean/Cargo.toml @@ -38,6 +38,7 @@ gix-config = "0.43.0" home = "0.5.11" smallvec = "1.14.0" directories = "6.0.0" +tracing-appender = "0.2.3" [build-dependencies] glib-build-tools = "0.20.0" @@ -47,6 +48,3 @@ tempfile = "3.19.1" [profile.dev] panic = "abort" # glib panics are not human friendly, just leave them alone - -[profile.release] -lto = "fat" diff --git a/monobean/resources/gtk/hello_page.ui b/monobean/resources/gtk/hello_page.ui index 71ce7a852..b3754f43b 100644 --- a/monobean/resources/gtk/hello_page.ui +++ b/monobean/resources/gtk/hello_page.ui @@ -42,7 +42,7 @@ - Welcome to MonoBean + Welcome to Monobean True word-char center @@ -297,7 +297,7 @@ vertical - <a href="https://os.gnome.org/">MonoBean Docs</a> + <a href="https://os.gnome.org/">Monobean Docs</a> True word-char True @@ -325,7 +325,7 @@ 24 - MonoBean + Monobean True word-char 1.0 diff --git a/monobean/resources/icons/scalable/apps/mono-black-logo.ico b/monobean/resources/icons/scalable/apps/mono-black-logo.ico new file mode 100644 index 000000000..5f2c4e611 Binary files /dev/null and b/monobean/resources/icons/scalable/apps/mono-black-logo.ico differ diff --git a/monobean/resources/icons/scalable/apps/mono-white-logo.ico b/monobean/resources/icons/scalable/apps/mono-white-logo.ico new file mode 100644 index 000000000..1f230f2b7 Binary files /dev/null and b/monobean/resources/icons/scalable/apps/mono-white-logo.ico differ diff --git a/monobean/resources/packager_aarch64-apple-darwin.toml b/monobean/resources/packager_aarch64-apple-darwin.toml new file mode 100644 index 000000000..ccd80eb41 --- /dev/null +++ b/monobean/resources/packager_aarch64-apple-darwin.toml @@ -0,0 +1,25 @@ +name = "Monobean" +product_name = "Monobean" +identifier = "org.Web3Infrastructure.Monobean" +category = "DeveloperTool" +formats = ["dmg"] +before-packaging-command = "cargo build --release" +out_dir = "../target/build" +binaries_dir = "../target/release" +binaries = [{ path = "monobean", main = true }] +resources = [ + "../Monobean.gresource", + "lib/bin/*.dll", + "lib/bin/gdbus.exe", +] +icons = [ + "icons/scalable/apps/mono-white-logo.ico", + "icons/scalable/apps/mono-black-logo.ico", +] +authors = ["Neon "] +description = "Monobean is a simple and easy-to-use wallet for the Monero blockchain, built with GTK4 and Rust. It provides a user-friendly interface for managing your monorepo code." + +[macos] + +[dmg] +background = "icons/scalable/apps/mono-white-logo.ico" diff --git a/monobean/resources/packager_x86_64-pc-windows-msvc.toml b/monobean/resources/packager_x86_64-pc-windows-msvc.toml new file mode 100644 index 000000000..b9747e9f7 --- /dev/null +++ b/monobean/resources/packager_x86_64-pc-windows-msvc.toml @@ -0,0 +1,24 @@ +name = "Monobean" +product_name = "Monobean" +version = "0.0.1" +identifier = "org.Web3Infrastructure.Monobean" +category = "DeveloperTool" +formats = ["nsis"] +before-packaging-command = "cargo build --release" +out_dir = "../target/build" +binaries_dir = "../target/release" +binaries = [{ path = "monobean", main = true }] +resources = [ + "../Monobean.gresource", + "lib/bin/*.dll", + "lib/bin/gdbus.exe", +] +authors = ["Neon "] +description = "Monobean is a simple and easy-to-use wallet for the Monero blockchain, built with GTK4 and Rust. It provides a user-friendly interface for managing your monorepo code." + +[windows] +allow_downgrades = true + +[nsis] +appdata_paths = ["$PROGRAMFILES64/$IDENTIFIER"] +installer_icon = "icons/scalable/apps/mono-white-logo.ico" diff --git a/monobean/resources/packager_x86_64-unknown-linux-gnu.toml b/monobean/resources/packager_x86_64-unknown-linux-gnu.toml new file mode 100644 index 000000000..3a71be11e --- /dev/null +++ b/monobean/resources/packager_x86_64-unknown-linux-gnu.toml @@ -0,0 +1,35 @@ +name = "Monobean" +product_name = "Monobean" +identifier = "org.Web3Infrastructure.Monobean" +category = "DeveloperTool" +formats = ["deb", "pacman"] +before-packaging-command = "cargo build --release" +out_dir = "../target/build" +binaries_dir = "../target/release" +binaries = [{ path = "monobean", main = true }] +icons = [ + "icons/scalable/apps/mono-white-logo.ico", + "icons/scalable/apps/mono-black-logo.ico", +] +authors = ["Neon "] +description = "Monobean is a simple and easy-to-use wallet for the Monero blockchain, built with GTK4 and Rust. It provides a user-friendly interface for managing your monorepo code." + +[linux] +generate_desktop_entry = true + +[deb] +depends = ["libgtk-4-dev", "libgtksourceview-5-0", "libadwaita-1-0"] +section = "rust" + +[deb.files] +"../Monobean.gresource" = "usr/share/monobean/monobean.gresource" +"icons/scalable/apps/mono-white-logo.ico" = "usr/share/icons/hicolor/scalable/apps/mono-white-logo.ico" +"icons/scalable/apps/mono-black-logo.ico" = "usr/share/icons/hicolor/scalable/apps/mono-black-logo.ico" + +# [pacman] +# depends = ["gtk4", "libadwaita", "gtksourceview5"] + +# [pacman.files] +# "../Monobean.gresource" = "usr/share/monobean/monobean.gresource" +# "icons/scalable/apps/mono-white-logo.ico" = "usr/share/icons/hicolor/scalable/apps/mono-white-logo.ico" +# "icons/scalable/apps/mono-black-logo.ico" = "usr/share/icons/hicolor/scalable/apps/mono-black-logo.ico" diff --git a/monobean/setup.py b/monobean/setup.py index 049e42237..15d85e0c6 100644 --- a/monobean/setup.py +++ b/monobean/setup.py @@ -1,5 +1,6 @@ import os import requests +import argparse import zipfile from tqdm import tqdm @@ -70,13 +71,17 @@ def setup_environmental_variables(): print("This script is only for Windows!") exit() + parser = argparse.ArgumentParser(description="Setup GTK4 for Gvsbuild") + parser.add_argument("--upgrade", "-u", action="store_true", help="Upgrade GTK4 to the latest version") + args = parser.parse_args() + cwd = os.getcwd() cur = os.path.dirname(os.path.abspath(__file__)) os.chdir(cur) try: # Check if the setup is already done - if os.path.exists("resources/lib/DONE"): + if os.path.exists("resources/lib/DONE") and not args.upgrade: print("Setup already done!") setup_environmental_variables() exit() @@ -86,7 +91,26 @@ def setup_environmental_variables(): gtk_ver = get_redirected_url(GTK_PKG).split("/")[-1] gtk_url = f"https://github.com/wingtk/gvsbuild/releases/download/{gtk_ver}/GTK4_Gvsbuild_{gtk_ver}_x64.zip" + if os.path.exists("resources/lib/DONE"): + with open ("resources/lib/DONE", "r") as f: + try: + installed = f.read().strip().split(".") + except: + installed = ["0", "0", "0"] + installed = [int(i) for i in installed] + remote = [int(i) for i in gtk_ver.strip().split(".")] + + if installed >= remote: + print("Already up to date!") + exit() + elif args.upgrade: + print(f"Upgrading GTK4 {installed} -> {remote}...") + else: + print("GTK4 is outdated!") + exit() + # download the GTK4 package + print(f"Downloading GTK4 package with version {gtk_ver}...") download_file_with_resume(gtk_url, "GTK4_Gvsbuild.zip") with zipfile.ZipFile("GTK4_Gvsbuild.zip", "r") as zip_ref: @@ -97,7 +121,7 @@ def setup_environmental_variables(): setup_environmental_variables() with open("resources/lib/DONE", "w") as f: - f.write("Setup complete!") + f.write(gtk_ver) print("Setup complete!") diff --git a/monobean/src/application.rs b/monobean/src/application.rs index 04e42b549..857f2c1f1 100644 --- a/monobean/src/application.rs +++ b/monobean/src/application.rs @@ -25,9 +25,7 @@ use std::fmt::Debug; use std::net::{IpAddr, SocketAddr}; use std::path::PathBuf; use tokio::sync::oneshot; -use tracing_subscriber::fmt; -use tracing_subscriber::layer::SubscriberExt; -use tracing_subscriber::util::SubscriberInitExt; +use tracing_subscriber::fmt::writer::MakeWriterExt; glib::wrapper! { pub struct MonobeanApplication(ObjectSubclass) @@ -258,11 +256,29 @@ impl MonobeanApplication { fn setup_log(&self) { // TODO: Use gtk settings for log level. // FIXME: currently not working for glib logs. + let file_appender = + tracing_appender::rolling::hourly(monobean_cache(), "monobean-logs.txt"); let filter = tracing_subscriber::EnvFilter::new("info,monobean=debug"); - tracing_subscriber::registry() - .with(fmt::layer()) - .with(filter) - .init(); + + if cfg!(debug_assertions) { + tracing_subscriber::fmt() + .with_writer(file_appender.and(std::io::stdout)) + .with_env_filter(filter) + .with_target(false) + .with_line_number(true) + .with_file(true) + .without_time() + .compact() + .init(); + } else { + tracing_subscriber::fmt() + .with_writer(file_appender) + .with_env_filter(filter) + .with_target(false) + .without_time() + .compact() + .init(); + } glib::log_set_handler( None, diff --git a/monobean/src/main.rs b/monobean/src/main.rs index 9966825b1..01b31d709 100644 --- a/monobean/src/main.rs +++ b/monobean/src/main.rs @@ -1,3 +1,4 @@ +#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] extern crate gtk; use std::sync::LazyLock; @@ -23,7 +24,11 @@ fn main() -> glib::ExitCode { std::env::set_current_dir(cargo_dir).expect("Failed to set workspace dir"); } - let resources = gio::Resource::load("Monobean.gresource").expect("Failed to load resources"); + let resources = { + gio::Resource::load("Monobean.gresource").unwrap_or_else(|_| { + gio::Resource::load("/usr/share/monobean/monobean.gresource").expect("Failed to load resources") + }) + }; gio::resources_register(&resources); glib::set_application_name(APP_NAME);