From 6989979d9ba55e7172a6af0c84070ee79b0f09fb Mon Sep 17 00:00:00 2001 From: MOZGIII Date: Fri, 18 Aug 2023 03:31:03 -0300 Subject: [PATCH] Add gtk (#139) * Add gtk * Add GTK to installers and CI * Fix Windows CI --- .github/actions/build-gtk-windows/action.yml | 77 ++++ .github/actions/common-setup/action.yml | 12 +- .github/scripts/build_env/linux.sh | 3 +- .github/scripts/build_env/macos.sh | 3 +- .github/scripts/packaging/windows.sh | 1 + .github/workflows/code.yml | 4 +- Cargo.lock | 394 +++++++++++++++++++ Cargo.toml | 1 + README.md | 1 + debian/control | 7 +- debian/rebootinto-gtk.install | 1 + debian/rules | 1 + gtk/Cargo.toml | 19 + gtk/build.rs | 6 + gtk/manifest.rc | 4 + gtk/rebootinto-gtk.exe.manifest | 23 ++ gtk/src/main.rs | 97 +++++ wix/main.wxs | 14 + 18 files changed, 659 insertions(+), 9 deletions(-) create mode 100644 .github/actions/build-gtk-windows/action.yml create mode 100644 debian/rebootinto-gtk.install create mode 100644 gtk/Cargo.toml create mode 100644 gtk/build.rs create mode 100644 gtk/manifest.rc create mode 100644 gtk/rebootinto-gtk.exe.manifest create mode 100644 gtk/src/main.rs diff --git a/.github/actions/build-gtk-windows/action.yml b/.github/actions/build-gtk-windows/action.yml new file mode 100644 index 0000000..70352d9 --- /dev/null +++ b/.github/actions/build-gtk-windows/action.yml @@ -0,0 +1,77 @@ +name: "Build GTK" +description: "Build GTK from source on Windows using msvc toolchain" +runs: + using: "composite" + steps: + - uses: actions/cache@v3 + id: cache + with: + path: c:/gnome + key: ${{ runner.os }}-gtk + restore-keys: | + ${{ runner.os }}-gtk + + - name: Set up the PATH environment + shell: bash + run: | + echo "C:\pkg-config-lite-0.28-1\bin" >>"$GITHUB_PATH" + echo "C:\gnome\bin" >>"$GITHUB_PATH" + echo "PKG_CONFIG_PATH=C:\gnome\lib\pkgconfig" >>"$GITHUB_ENV" + + - name: Install pkgconfig-lite + shell: pwsh + run: | + Invoke-WebRequest -Uri https://deac-fra.dl.sourceforge.net/project/pkgconfiglite/0.28-1/pkg-config-lite-0.28-1_bin-win32.zip -OutFile /pkg_config_lite.zip -MaximumRetryCount 5 + Expand-Archive /pkg_config_lite.zip -DestinationPath C:\ + ls C:\ + ls C:\pkg-config-lite-0.28-1 + ls C:\pkg-config-lite-0.28-1\bin + pkg-config --version + + - name: Clone GTK + shell: pwsh + working-directory: / + if: steps.cache.outputs.cache-hit != 'true' + run: | + git clone https://gitlab.gnome.org/GNOME/gtk.git --depth 1 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install Python Dependencies + shell: pwsh + run: pip install meson ninja + + - name: Prepare GTK build + shell: pwsh + working-directory: /gtk + if: steps.cache.outputs.cache-hit != 'true' + run: | + meson setup builddir ` + --prefix="C:/gnome" ` + --backend=ninja ` + -Dbackend_max_links=1 ` + -Dbuild-demos=false ` + -Dbuild-tests=false ` + -Dmedia-gstreamer=disabled ` + -Dbuild-examples=false ` + -Dglib:tests=false ` + -Dharfbuzz:tests=disabled ` + -Dharfbuzz:docs=disabled ` + -Dgraphene:tests=false ` + -Dgdk-pixbuf:tests=false ` + -Dcairo:tests=disabled + + - name: Build and install GTK + shell: pwsh + working-directory: /gtk + if: steps.cache.outputs.cache-hit != 'true' + run: | + meson install -C builddir + + - name: List the contents + shell: bash + run: | + ls -laR "C:/gnome" diff --git a/.github/actions/common-setup/action.yml b/.github/actions/common-setup/action.yml index 7d4a577..3e67269 100644 --- a/.github/actions/common-setup/action.yml +++ b/.github/actions/common-setup/action.yml @@ -36,15 +36,19 @@ runs: run: rustup show if: ${{ inputs.requiresRust == 'true' }} + - name: Set up Vistual Studio Command Prompt (Windows only) + uses: ilammy/msvc-dev-cmd@v1 + if: runner.os == 'Windows' + + - name: Build GTK (Windows only) + uses: ./.github/actions/build-gtk-windows + if: runner.os == 'Windows' + - name: Prepare the build environment run: ${{ inputs.buildEnvScript }} shell: bash if: ${{ inputs.buildEnvScript != 'skip' }} - - name: Set up Vistual Studio Command Prompt (Windows only) - uses: ilammy/msvc-dev-cmd@v1 - if: runner.os == 'Windows' - - name: Print build environment info shell: bash run: | diff --git a/.github/scripts/build_env/linux.sh b/.github/scripts/build_env/linux.sh index f50793f..cf348ee 100755 --- a/.github/scripts/build_env/linux.sh +++ b/.github/scripts/build_env/linux.sh @@ -10,6 +10,7 @@ sudo apt-get install -y \ python3-setuptools \ python3-wheel \ ninja-build \ - llvm + llvm \ + libgtk-4-dev sudo pip3 install meson diff --git a/.github/scripts/build_env/macos.sh b/.github/scripts/build_env/macos.sh index d1bf7e1..5bd22bf 100755 --- a/.github/scripts/build_env/macos.sh +++ b/.github/scripts/build_env/macos.sh @@ -4,4 +4,5 @@ set -euo pipefail brew install \ ninja \ meson \ - llvm + llvm \ + gtk4 diff --git a/.github/scripts/packaging/windows.sh b/.github/scripts/packaging/windows.sh index 7df0d1c..8831e59 100755 --- a/.github/scripts/packaging/windows.sh +++ b/.github/scripts/packaging/windows.sh @@ -17,6 +17,7 @@ ARTIFACTS=( target/release/rebootinto-tui.exe target/release/rebootinto-iui.exe target/release/rebootinto-iced.exe + target/release/rebootinto-gtk.exe ) cp -t "$ARTIFACTS_DIR" "${ARTIFACTS[@]}" diff --git a/.github/workflows/code.yml b/.github/workflows/code.yml index a09d41c..4835be9 100644 --- a/.github/workflows/code.yml +++ b/.github/workflows/code.yml @@ -68,7 +68,7 @@ jobs: with: platformCacheKey: ${{ matrix.platform.cacheKey }} buildEnvScript: ${{ matrix.platform.buildEnvScript }} - timeout-minutes: 10 + timeout-minutes: 25 - name: Run cargo ${{ matrix.mode.cargoCommand }} uses: actions-rs/cargo@v1 @@ -111,7 +111,7 @@ jobs: with: platformCacheKey: ${{ matrix.platform.cacheKey }} buildEnvScript: ${{ matrix.platform.packagingEnvScript }} - timeout-minutes: 10 + timeout-minutes: 25 - name: Run cargo build (release) uses: actions-rs/cargo@v1 diff --git a/Cargo.lock b/Cargo.lock index 849a5ee..804c7c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -322,6 +322,31 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "cairo-rs" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d859b656775a6b1dd078d3e5924884e6ea88aa649a7fdde03d5b2ec56ffcc10b" +dependencies = [ + "bitflags 2.4.0", + "cairo-sys-rs", + "glib", + "libc", + "once_cell", + "thiserror", +] + +[[package]] +name = "cairo-sys-rs" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd4d115132e01c0165e3bf5f56aedee8980b0b96ede4eb000b693c05a8adb8ff" +dependencies = [ + "glib-sys", + "libc", + "system-deps", +] + [[package]] name = "calloop" version = "0.10.6" @@ -361,6 +386,16 @@ dependencies = [ "nom", ] +[[package]] +name = "cfg-expr" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b40ccee03b5175c18cde8f37e7d2a33bcef6f8ec8f7cc0d81090d1bb380949c9" +dependencies = [ + "smallvec", + "target-lexicon", +] + [[package]] name = "cfg-if" version = "1.0.0" @@ -836,6 +871,16 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "field-offset" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f" +dependencies = [ + "memoffset 0.9.0", + "rustc_version", +] + [[package]] name = "find-winsdk" version = "0.2.0" @@ -975,6 +1020,64 @@ dependencies = [ "slab", ] +[[package]] +name = "gdk-pixbuf" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbc9c2ed73a81d556b65d08879ba4ee58808a6b1927ce915262185d6d547c6f3" +dependencies = [ + "gdk-pixbuf-sys", + "gio", + "glib", + "libc", + "once_cell", +] + +[[package]] +name = "gdk-pixbuf-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9839ea644ed9c97a34d129ad56d38a25e6756f99f3a88e15cd39c20629caf7" +dependencies = [ + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + +[[package]] +name = "gdk4" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6982d9815ed6ac95b0467b189e81f29dea26d08a732926ec113e65744ed3f96c" +dependencies = [ + "cairo-rs", + "gdk-pixbuf", + "gdk4-sys", + "gio", + "glib", + "libc", + "pango", +] + +[[package]] +name = "gdk4-sys" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbab43f332a3cf1df9974da690b5bb0e26720ed09a228178ce52175372dcfef0" +dependencies = [ + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "pango-sys", + "pkg-config", + "system-deps", +] + [[package]] name = "gethostname" version = "0.2.3" @@ -1002,12 +1105,91 @@ version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +[[package]] +name = "gio" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7884cba6b1c5db1607d970cadf44b14a43913d42bc68766eea6a5e2fe0891524" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "gio-sys", + "glib", + "libc", + "once_cell", + "pin-project-lite", + "smallvec", + "thiserror", +] + +[[package]] +name = "gio-sys" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37566df850baf5e4cb0dfb78af2e4b9898d817ed9263d1090a2df958c64737d2" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", + "winapi", +] + [[package]] name = "glam" version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42218cb640844e3872cc3c153dc975229e080a6c4733b34709ef445610550226" +[[package]] +name = "glib" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "331156127e8166dd815cf8d2db3a5beb492610c716c03ee6db4f2d07092af0a7" +dependencies = [ + "bitflags 2.4.0", + "futures-channel", + "futures-core", + "futures-executor", + "futures-task", + "futures-util", + "gio-sys", + "glib-macros", + "glib-sys", + "gobject-sys", + "libc", + "memchr", + "once_cell", + "smallvec", + "thiserror", +] + +[[package]] +name = "glib-macros" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "179643c50bf28d20d2f6eacd2531a88f2f5d9747dd0b86b8af1e8bb5dd0de3c0" +dependencies = [ + "heck", + "proc-macro-crate", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.28", +] + +[[package]] +name = "glib-sys" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063ce2eb6a8d0ea93d2bf8ba1957e78dbab6be1c2220dd3daca57d5a9d869898" +dependencies = [ + "libc", + "system-deps", +] + [[package]] name = "glob" version = "0.3.1" @@ -1038,6 +1220,17 @@ dependencies = [ "wgpu", ] +[[package]] +name = "gobject-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0850127b514d1c4a4654ead6dedadb18198999985908e6ffe4436f53c785ce44" +dependencies = [ + "glib-sys", + "libc", + "system-deps", +] + [[package]] name = "gpu-alloc" version = "0.5.4" @@ -1090,6 +1283,114 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "graphene-rs" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2228cda1505613a7a956cca69076892cfbda84fc2b7a62b94a41a272c0c401" +dependencies = [ + "glib", + "graphene-sys", + "libc", +] + +[[package]] +name = "graphene-sys" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4144cee8fc8788f2a9b73dc5f1d4e1189d1f95305c4cb7bd9c1af1cfa31f59" +dependencies = [ + "glib-sys", + "libc", + "pkg-config", + "system-deps", +] + +[[package]] +name = "gsk4" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc25855255120f294d874acd6eaf4fbed7ce1cdc550e2d8415ea57fafbe816d5" +dependencies = [ + "cairo-rs", + "gdk4", + "glib", + "graphene-rs", + "gsk4-sys", + "libc", + "pango", +] + +[[package]] +name = "gsk4-sys" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1ecf3a63bf1223d68f80f72cc896c4d8c80482fbce1c9a12c66d3de7290ee46" +dependencies = [ + "cairo-sys-rs", + "gdk4-sys", + "glib-sys", + "gobject-sys", + "graphene-sys", + "libc", + "pango-sys", + "system-deps", +] + +[[package]] +name = "gtk4" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3b095b26f2a2df70be1805d3590eeb9d7a05ecb5be9649b82defc72dc56228c" +dependencies = [ + "cairo-rs", + "field-offset", + "futures-channel", + "gdk-pixbuf", + "gdk4", + "gio", + "glib", + "graphene-rs", + "gsk4", + "gtk4-macros", + "gtk4-sys", + "libc", + "pango", +] + +[[package]] +name = "gtk4-macros" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d57ec49cf9b657f69a05bca8027cff0a8dfd0c49e812be026fc7311f2163832f" +dependencies = [ + "anyhow", + "proc-macro-crate", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "gtk4-sys" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b0bdde87c50317b4f355bcbb4a9c2c414ece1b7c824fb4ad4ba8f3bdb2c6603" +dependencies = [ + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gdk4-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "graphene-sys", + "gsk4-sys", + "libc", + "pango-sys", + "system-deps", +] + [[package]] name = "guillotiere" version = "0.6.2" @@ -1573,6 +1874,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + [[package]] name = "metal" version = "0.24.0" @@ -1914,6 +2224,31 @@ dependencies = [ "syn 2.0.28", ] +[[package]] +name = "pango" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06a9e54b831d033206160096b825f2070cf5fda7e35167b1c01e9e774f9202d1" +dependencies = [ + "gio", + "glib", + "libc", + "once_cell", + "pango-sys", +] + +[[package]] +name = "pango-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "436737e391a843e5933d6d9aa102cb126d501e815b83601365a948a518555dc5" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + [[package]] name = "parking_lot" version = "0.11.2" @@ -2073,6 +2408,30 @@ dependencies = [ "toml_edit", ] +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.66" @@ -2181,6 +2540,16 @@ dependencies = [ "thiserror", ] +[[package]] +name = "rebootinto-gtk" +version = "0.1.0" +dependencies = [ + "anyhow", + "embed-resource 2.2.0", + "gtk4", + "rebootinto-core", +] + [[package]] name = "rebootinto-iced" version = "0.1.0" @@ -2612,6 +2981,25 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "system-deps" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30c2de8a4d8f4b823d634affc9cd2a74ec98c53a756f317e529a48046cbf71f3" +dependencies = [ + "cfg-expr", + "heck", + "pkg-config", + "toml 0.7.6", + "version-compare", +] + +[[package]] +name = "target-lexicon" +version = "0.12.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a" + [[package]] name = "termcolor" version = "1.2.0" @@ -2886,6 +3274,12 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +[[package]] +name = "version-compare" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29" + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index a31b3ab..a0dcdc3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,5 @@ members = [ "tui", "iui", "iced", + "gtk", ] diff --git a/README.md b/README.md index be12069..40954be 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ This project provides the following apps: - `rebootinto-tui` - a terminal user interface; - `rebootinto-iui` - a graphical user interface (based on `libiui`); - `rebootinto-iced` - a graphical user interface (based on `iced` crate). +- `rebootinto-gtk` - a graphical user interface (based on `gtk` crate). ## Installation diff --git a/debian/control b/debian/control index df0f146..384e5d2 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ Vcs-Browser: https://github.com/MOZGIII/rebootinto Package: rebootinto Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, rebootinto-cli, rebootinto-tui, rebootinto-iui +Depends: ${shlibs:Depends}, ${misc:Depends}, rebootinto-cli, rebootinto-tui, rebootinto-iui, rebootinto-gtk Description: Tools for rebooting into other OS. Package: rebootinto-cli @@ -32,3 +32,8 @@ Package: rebootinto-iced Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Description: The iced-based GUI tool for rebooting into other OS. + +Package: rebootinto-gtk +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: The GTK-based GUI tool for rebooting into other OS. diff --git a/debian/rebootinto-gtk.install b/debian/rebootinto-gtk.install new file mode 100644 index 0000000..31e038c --- /dev/null +++ b/debian/rebootinto-gtk.install @@ -0,0 +1 @@ +debian/tmp/usr/bin/rebootinto-gtk diff --git a/debian/rules b/debian/rules index 20fdbf3..f352b73 100755 --- a/debian/rules +++ b/debian/rules @@ -22,4 +22,5 @@ override_dh_auto_install: target/release/rebootinto-tui \ target/release/rebootinto-iui \ target/release/rebootinto-iced \ + target/release/rebootinto-gtk \ debian/tmp/usr/bin/ diff --git a/gtk/Cargo.toml b/gtk/Cargo.toml new file mode 100644 index 0000000..6abfdf8 --- /dev/null +++ b/gtk/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "rebootinto-gtk" +version = "0.1.0" +authors = ["MOZGIII "] +edition = "2021" +description = "The GTK-based GUI tool for rebooting into other OS." +license = "MIT" +repository = "https://github.com/MOZGIII/rebootinto" +keywords = ["rebootinto", "reboot", "efi", "uefi", "ui", "gui", "gtk"] +categories = ["gui"] + +[dependencies] +rebootinto-core = { path = "../core" } + +anyhow = "1" +gtk = { version = "0.7.2", package = "gtk4", features = ["v4_2"] } + +[build-dependencies] +embed-resource = "2.2" diff --git a/gtk/build.rs b/gtk/build.rs new file mode 100644 index 0000000..0af581b --- /dev/null +++ b/gtk/build.rs @@ -0,0 +1,6 @@ +//! Build script to include the manifest into the executable on Windows. + +fn main() { + println!("cargo:rerun-if-changed=manifest.rc"); + embed_resource::compile("manifest.rc", embed_resource::NONE); +} diff --git a/gtk/manifest.rc b/gtk/manifest.rc new file mode 100644 index 0000000..746a4bd --- /dev/null +++ b/gtk/manifest.rc @@ -0,0 +1,4 @@ +#pragma code_page(65001) +#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1 +#define RT_MANIFEST 24 +CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "rebootinto-gtk.exe.manifest" diff --git a/gtk/rebootinto-gtk.exe.manifest b/gtk/rebootinto-gtk.exe.manifest new file mode 100644 index 0000000..3f1577d --- /dev/null +++ b/gtk/rebootinto-gtk.exe.manifest @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gtk/src/main.rs b/gtk/src/main.rs new file mode 100644 index 0000000..e22eaf3 --- /dev/null +++ b/gtk/src/main.rs @@ -0,0 +1,97 @@ +//! A GTK-based GUI app for rebootinto. + +#![windows_subsystem = "windows"] + +use std::cell::RefCell; +use std::rc::Rc; + +use gtk::glib::{clone, gformat}; +use rebootinto_core as core; + +use gtk::{prelude::*, Button, Orientation, PolicyType, ScrolledWindow}; +use gtk::{Application, ApplicationWindow}; + +/// The Application ID. +const APP_ID: &str = "mozgiii.Rebootinto"; + +fn main() { + if let Err(err) = run() { + match std::env::var("PANIC_ON_ERROR") { + Ok(ref val) if val == "true" => panic!("Error: {err}"), + _ => {} + } + + eprintln!("Error: {err}"); + std::process::exit(1); + } +} + +/// Run the app and return the error. +fn run() -> Result<(), anyhow::Error> { + let mut backend = core::Backend::init()?; + let load_options = backend + .load_options()? + .collect::, core::LoadOptionError>>()?; + + let reboot_into = Rc::new(RefCell::new(None)); + + let app = Application::builder().application_id(APP_ID).build(); + app.connect_activate(clone!(@strong reboot_into => move |app| { + let buttons_box = gtk::Box::builder() + .orientation(Orientation::Vertical) + .homogeneous(true) + .margin_top(6) + .margin_bottom(6) + .margin_start(6) + .margin_end(6) + .build(); + + for load_option in &load_options { + let button = Button::builder() + .label(gformat!("{}", &load_option)) + .margin_top(6) + .margin_bottom(6) + .margin_start(6) + .margin_end(6) + .build(); + + button.connect_clicked(clone!(@strong app, @strong reboot_into, @strong load_option => move |_| { + *reboot_into.borrow_mut() = Some(load_option.clone()); + app.quit(); + })); + + buttons_box.append(&button); + } + + let scrolled_window = ScrolledWindow::builder() + .hscrollbar_policy(PolicyType::Never) + .propagate_natural_height(true) + .child(&buttons_box) + .build(); + + let window = ApplicationWindow::builder() + .application(app) + .title("Rebootinto") + .default_width(350) + .default_height(200) + .child(&scrolled_window) + .build(); + window.show(); + })); + + let exit_code = app.run(); + if exit_code.value() != 0 { + anyhow::bail!("error exit: {exit_code:?}") + } + + drop(app); + + if let Some(ref reboot_into) = *reboot_into.borrow() { + println!("Rebooting into: {}", &reboot_into); + backend.reboot_into(reboot_into.number)?; + } else { + println!("Reboot cancelled"); + } + + Ok(()) +} diff --git a/wix/main.wxs b/wix/main.wxs index ba8bd79..80b4945 100644 --- a/wix/main.wxs +++ b/wix/main.wxs @@ -28,6 +28,12 @@ + + + + + + @@ -63,6 +69,10 @@ + + + + @@ -80,6 +90,10 @@ + + + +