mirror of
https://github.com/13hannes11/toolbx-tuner.git
synced 2024-09-03 23:21:00 +02:00
Merge pull request #41 from 13hannes11/feature/rewrite-relm4-0.8
Feature/rewrite relm4 0.8 - Rewrite the application and port to relm 0.8 - Add some more spinners to give the user additional feedback
This commit is contained in:
38
.github/workflows/build_and_publish.yml
vendored
38
.github/workflows/build_and_publish.yml
vendored
@@ -1,38 +0,0 @@
|
|||||||
name: Build (tag and pull_request) and publish (tag)
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- v*.*.*
|
|
||||||
pull_request:
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Build
|
|
||||||
run: docker-compose -f containers/docker-compose.yml up
|
|
||||||
- name: Show dir
|
|
||||||
run: ls
|
|
||||||
- name: Upload Artifact
|
|
||||||
uses: actions/upload-artifact@v2.3.1
|
|
||||||
with:
|
|
||||||
name: executables
|
|
||||||
path: |
|
|
||||||
**.AppImage
|
|
||||||
|
|
||||||
publish:
|
|
||||||
needs: [build]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
|
||||||
steps:
|
|
||||||
- uses: actions/download-artifact@v2
|
|
||||||
- uses: "marvinpinto/action-automatic-releases@v1.2.1"
|
|
||||||
with:
|
|
||||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
|
||||||
prerelease: false
|
|
||||||
files: |
|
|
||||||
**/*.AppImage
|
|
||||||
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@@ -8,7 +8,7 @@ name: CI
|
|||||||
jobs:
|
jobs:
|
||||||
rustfmt:
|
rustfmt:
|
||||||
name: Rustfmt
|
name: Rustfmt
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
@@ -26,9 +26,9 @@ jobs:
|
|||||||
|
|
||||||
flatpak:
|
flatpak:
|
||||||
name: Flatpak
|
name: Flatpak
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-22.04
|
||||||
container:
|
container:
|
||||||
image: bilelmoussaoui/flatpak-github-actions:gnome-42
|
image: bilelmoussaoui/flatpak-github-actions:gnome-45
|
||||||
options: --privileged
|
options: --privileged
|
||||||
steps:
|
steps:
|
||||||
- name: Install git-lfs
|
- name: Install git-lfs
|
||||||
@@ -39,7 +39,7 @@ jobs:
|
|||||||
- uses: bilelmoussaoui/flatpak-github-actions/flatpak-builder@v4
|
- uses: bilelmoussaoui/flatpak-github-actions/flatpak-builder@v4
|
||||||
with:
|
with:
|
||||||
bundle: toolbxtuner.flatpak
|
bundle: toolbxtuner.flatpak
|
||||||
manifest-path: build-aux/org.kuchelmeister.ToolbxTuner.Devel.json
|
manifest-path: build-aux/org.kuchelmeister.ToolboxTuner.Devel.json
|
||||||
run-tests: true
|
run-tests: true
|
||||||
cache-key: flatpak-builder-${{ github.sha }}
|
cache-key: flatpak-builder-${{ github.sha }}
|
||||||
- name: ls
|
- name: ls
|
||||||
|
|||||||
24
.gitignore
vendored
24
.gitignore
vendored
@@ -1,16 +1,16 @@
|
|||||||
target/
|
/target/
|
||||||
build/
|
/build/
|
||||||
_build/
|
/_build/
|
||||||
builddir/
|
/builddir/
|
||||||
build-aux/app
|
/build-aux/app
|
||||||
.flatpak-builder
|
/build-aux/.flatpak-builder/
|
||||||
src/config.rs
|
/src/config.rs
|
||||||
*.ui.in~
|
*.ui.in~
|
||||||
*.ui~
|
*.ui~
|
||||||
.json~
|
/.flatpak/
|
||||||
.flatpak/
|
/vendor
|
||||||
vendor
|
/.vscode
|
||||||
flatpak_app
|
.flatpak-builder/
|
||||||
libs
|
|
||||||
*.AppImage
|
*.AppImage
|
||||||
|
*.json~
|
||||||
|
|
||||||
|
|||||||
988
Cargo.lock
generated
988
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
25
Cargo.toml
25
Cargo.toml
@@ -1,21 +1,18 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "toolbxtuner"
|
name = "toolbox-tuner"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
authors = ["Hannes Kuchelmeister <hannes@kuchelmeister.org>"]
|
authors = ["Hannes Kuchelmeister <hannes@kuchelmeister.org>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
publish = false
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
[profile.release]
|
||||||
|
lto = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
relm4 = {version="0.4", features = ["libadwaita", "macros"]}
|
gettext-rs = { version = "0.7", features = ["gettext-system"] }
|
||||||
tokio = { version = "1", features = ["full"] }
|
tracing = "0.1"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
tracing-subscriber = "0.3"
|
||||||
serde_json = "1.0"
|
relm4 = { version = "0.8.1", features = ["libadwaita", "gnome_46", "macros"] }
|
||||||
|
relm4-icons = { version = "0.8.1" }
|
||||||
[package.metadata.appimage]
|
serde = { version = "1.0.199", features = ["derive"] }
|
||||||
auto_link = true
|
serde_json = "1.0.116"
|
||||||
auto_link_exclude_list = [
|
|
||||||
"libc.so*",
|
|
||||||
"libdl.so*",
|
|
||||||
"libpthread.so*",
|
|
||||||
]
|
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -1,24 +1,24 @@
|
|||||||
|
|
||||||
# Toolbx Tuner
|
# Toolbox Tuner
|
||||||
|
|
||||||
Toolbx Tuner is a tool to improve the experience with [toolbx](https://containertoolbx.org/).
|
Toolbox Tuner is a tool to improve the experience with [toolbox](https://containertoolbx.org/).
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
## Project Roadmap
|
## Project Roadmap
|
||||||
|
|
||||||
The project is currently only an mvp that only is able to list toolboxes and launch a terminal inside of them.
|
The project is currently only an mvp that only is able to list toolboxes and launch a terminal inside of them.
|
||||||
|
|
||||||
- [x] UI prototype
|
- [x] UI prototype
|
||||||
- [x] [Continuous development releases](https://github.com/13hannes11/toolbx-tuner/releases/tag/dev)
|
- [x] [Continuous development releases](https://github.com/13hannes11/toolbox-tuner/releases/tag/dev)
|
||||||
- [x] Flatpak support
|
- [x] Flatpak support
|
||||||
- [ ] Publish on Flathub
|
- [ ] Publish on Flathub
|
||||||
|
|
||||||
|
|
||||||
## Installing the application
|
## Installing the application
|
||||||
|
|
||||||
The application as of now is only available as a development build. You can download it [here](https://github.com/13hannes11/toolbx-tuner/releases/tag/dev) but be aware of unfinished features and possible instabilities.
|
The application as of now is only available as a development build. You can download it [here](https://github.com/13hannes11/toolbox-tuner/releases/tag/dev) but be aware of unfinished features and possible instabilities.
|
||||||
|
|
||||||
|
|
||||||
## Compiling Source
|
## Compiling Source
|
||||||
@@ -33,9 +33,7 @@ This project now uses *Gnome Builder* as main build tool and the Flatpak toolcha
|
|||||||
2. `flatpak install org.gnome.Sdk`
|
2. `flatpak install org.gnome.Sdk`
|
||||||
3. `flatpak install org.freedesktop.Sdk.Extension.rust-stable`
|
3. `flatpak install org.freedesktop.Sdk.Extension.rust-stable`
|
||||||
2. Compile with:
|
2. Compile with:
|
||||||
* Flatpak Builder by opening the project folder and pressing run or
|
* Flatpak Builder by opening the project folder and pressing run
|
||||||
* Run `build_install_local.sh`
|
|
||||||
|
|
||||||
|
|
||||||
### Traditional Compilation
|
### Traditional Compilation
|
||||||
|
|
||||||
|
|||||||
0
build-aux/dist-vendor.sh
Executable file → Normal file
0
build-aux/dist-vendor.sh
Executable file → Normal file
55
build-aux/org.kuchelmeister.ToolboxTuner.Devel.json
Normal file
55
build-aux/org.kuchelmeister.ToolboxTuner.Devel.json
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
{
|
||||||
|
"id" : "org.kuchelmeister.ToolboxTuner.Devel",
|
||||||
|
"runtime" : "org.gnome.Platform",
|
||||||
|
"runtime-version" : "46",
|
||||||
|
"sdk" : "org.gnome.Sdk",
|
||||||
|
"sdk-extensions" : [
|
||||||
|
"org.freedesktop.Sdk.Extension.rust-stable",
|
||||||
|
"org.freedesktop.Sdk.Extension.llvm15"
|
||||||
|
],
|
||||||
|
"command" : "toolbox-tuner",
|
||||||
|
"finish-args" : [
|
||||||
|
"--talk-name=org.freedesktop.Flatpak",
|
||||||
|
"--socket=fallback-x11",
|
||||||
|
"--socket=wayland",
|
||||||
|
"--device=dri",
|
||||||
|
"--env=RUST_LOG=toolbxtuner=debug",
|
||||||
|
"--env=G_MESSAGES_DEBUG=none",
|
||||||
|
"--env=RUST_BACKTRACE=1",
|
||||||
|
"--share=ipc"
|
||||||
|
],
|
||||||
|
"build-options" : {
|
||||||
|
"append-path" : "/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/llvm15/bin",
|
||||||
|
"prepend-ld-library-path" : "/usr/lib/sdk/llvm15/lib",
|
||||||
|
"build-args" : [
|
||||||
|
"--share=network"
|
||||||
|
],
|
||||||
|
"env" : {
|
||||||
|
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER" : "clang",
|
||||||
|
"CARGO_REGISTRIES_CRATES_IO_PROTOCOL" : "sparse",
|
||||||
|
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS" : "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold",
|
||||||
|
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER" : "clang",
|
||||||
|
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS" : "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold"
|
||||||
|
},
|
||||||
|
"test-args" : [
|
||||||
|
"--socket=x11",
|
||||||
|
"--share=network"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"modules" : [
|
||||||
|
{
|
||||||
|
"name" : "toolbox-tuner",
|
||||||
|
"buildsystem" : "meson",
|
||||||
|
"run-tests" : true,
|
||||||
|
"config-opts" : [
|
||||||
|
"-Dprofile=development"
|
||||||
|
],
|
||||||
|
"sources" : [
|
||||||
|
{
|
||||||
|
"type" : "dir",
|
||||||
|
"path" : "../"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
55
build-aux/org.kuchelmeister.ToolboxTuner.Screenshot.json
Normal file
55
build-aux/org.kuchelmeister.ToolboxTuner.Screenshot.json
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
{
|
||||||
|
"id" : "org.kuchelmeister.ToolboxTuner.Screenshot",
|
||||||
|
"runtime" : "org.gnome.Platform",
|
||||||
|
"runtime-version" : "46",
|
||||||
|
"sdk" : "org.gnome.Sdk",
|
||||||
|
"sdk-extensions" : [
|
||||||
|
"org.freedesktop.Sdk.Extension.rust-stable",
|
||||||
|
"org.freedesktop.Sdk.Extension.llvm15"
|
||||||
|
],
|
||||||
|
"command" : "toolbox-tuner",
|
||||||
|
"finish-args" : [
|
||||||
|
"--talk-name=org.freedesktop.Flatpak",
|
||||||
|
"--socket=fallback-x11",
|
||||||
|
"--socket=wayland",
|
||||||
|
"--device=dri",
|
||||||
|
"--env=RUST_LOG=toolbxtuner=debug",
|
||||||
|
"--env=G_MESSAGES_DEBUG=none",
|
||||||
|
"--env=RUST_BACKTRACE=1",
|
||||||
|
"--share=ipc"
|
||||||
|
],
|
||||||
|
"build-options" : {
|
||||||
|
"append-path" : "/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/llvm15/bin",
|
||||||
|
"prepend-ld-library-path" : "/usr/lib/sdk/llvm15/lib",
|
||||||
|
"build-args" : [
|
||||||
|
"--share=network"
|
||||||
|
],
|
||||||
|
"env" : {
|
||||||
|
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER" : "clang",
|
||||||
|
"CARGO_REGISTRIES_CRATES_IO_PROTOCOL" : "sparse",
|
||||||
|
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS" : "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold",
|
||||||
|
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER" : "clang",
|
||||||
|
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS" : "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold"
|
||||||
|
},
|
||||||
|
"test-args" : [
|
||||||
|
"--socket=x11",
|
||||||
|
"--share=network"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"modules" : [
|
||||||
|
{
|
||||||
|
"name" : "toolbox-tuner",
|
||||||
|
"buildsystem" : "meson",
|
||||||
|
"run-tests" : true,
|
||||||
|
"sources" : [
|
||||||
|
{
|
||||||
|
"type" : "dir",
|
||||||
|
"path" : "../"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"config-opts" : [
|
||||||
|
"-Dprofile=screenshot"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
{
|
|
||||||
"id": "org.kuchelmeister.ToolbxTuner.Devel",
|
|
||||||
"runtime": "org.gnome.Platform",
|
|
||||||
"runtime-version": "42",
|
|
||||||
"sdk": "org.gnome.Sdk",
|
|
||||||
"sdk-extensions": [
|
|
||||||
"org.freedesktop.Sdk.Extension.rust-stable"
|
|
||||||
],
|
|
||||||
"command": "toolbxtuner",
|
|
||||||
"finish-args": [
|
|
||||||
"--talk-name=org.freedesktop.Flatpak",
|
|
||||||
"--socket=fallback-x11",
|
|
||||||
"--socket=wayland",
|
|
||||||
"--device=dri",
|
|
||||||
"--env=RUST_LOG=toolbxtuner=debug",
|
|
||||||
"--env=G_MESSAGES_DEBUG=none",
|
|
||||||
"--env=RUST_BACKTRACE=1",
|
|
||||||
"--share=ipc"
|
|
||||||
],
|
|
||||||
"build-options": {
|
|
||||||
"append-path": "/usr/lib/sdk/rust-stable/bin",
|
|
||||||
"build-args": [
|
|
||||||
"--share=network"
|
|
||||||
],
|
|
||||||
"test-args": [
|
|
||||||
"--socket=x11",
|
|
||||||
"--share=network"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"modules": [
|
|
||||||
{
|
|
||||||
"name": "toolbxtuner",
|
|
||||||
"buildsystem": "meson",
|
|
||||||
"run-tests": true,
|
|
||||||
"config-opts": [
|
|
||||||
"-Dprofile=development"
|
|
||||||
],
|
|
||||||
"sources": [
|
|
||||||
{
|
|
||||||
"type": "dir",
|
|
||||||
"path": "../"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
flatpak run org.flatpak.Builder --user --install --force-clean flatpak_app build-aux/org.kuchelmeister.ToolbxTuner.Devel.json
|
|
||||||
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
FROM quay.io/podman/stable
|
|
||||||
|
|
||||||
ENV RUST_VERSION=1.61.0
|
|
||||||
ENV HOME=/home/root
|
|
||||||
|
|
||||||
RUN dnf install gtk4-devel gcc libadwaita-devel -y
|
|
||||||
RUN dnf install toolbox -y
|
|
||||||
|
|
||||||
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
|
|
||||||
RUN . $HOME/.cargo/env
|
|
||||||
ENV PATH=/home/root/.cargo/bin:$PATH
|
|
||||||
RUN rustup install ${RUST_VERSION}
|
|
||||||
|
|
||||||
WORKDIR /mnt
|
|
||||||
|
|
||||||
CMD cargo test
|
|
||||||
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
version: "3"
|
|
||||||
services:
|
|
||||||
toolbx-tuner-tests:
|
|
||||||
build: .
|
|
||||||
privileged: true
|
|
||||||
volumes:
|
|
||||||
- ..:/mnt:z
|
|
||||||
security_opt:
|
|
||||||
- label=disable
|
|
||||||
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
version: "3"
|
|
||||||
services:
|
|
||||||
gtk4-rs:
|
|
||||||
image: ghcr.io/13hannes11/gtk4-rs-docker:latest-appimage
|
|
||||||
volumes:
|
|
||||||
- ..:/mnt:z
|
|
||||||
command: sh -c "cargo appimage"
|
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ configure_file(
|
|||||||
install_dir: datadir / 'glib-2.0' / 'schemas'
|
install_dir: datadir / 'glib-2.0' / 'schemas'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Validate GSchema
|
# Validata GSchema
|
||||||
if glib_compile_schemas.found()
|
if glib_compile_schemas.found()
|
||||||
test(
|
test(
|
||||||
'validate-gschema', glib_compile_schemas,
|
'validate-gschema', glib_compile_schemas,
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
[Desktop Entry]
|
[Desktop Entry]
|
||||||
Name=Toolbx Tuner
|
Name=Toolbox Tuner
|
||||||
Comment=Manage and enhance your toolbxes (containertoolboxes)
|
Comment=Manage and enhance your toolboxes (containertoolboxes)
|
||||||
Exec=toolbxtuner
|
|
||||||
Terminal=false
|
|
||||||
Type=Application
|
Type=Application
|
||||||
|
Exec=toolbox-tuner
|
||||||
|
Terminal=false
|
||||||
Categories=Utility;
|
Categories=Utility;
|
||||||
# Translators: Search terms to find this application. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon!
|
# Translators: Search terms to find this application. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon!
|
||||||
Keywords=Gnome;GTK;Container;Toolbx;Podman;Toolbox;Fedora;Silvervblue;
|
Keywords=Gnome;GTK;Container;Podman;Toolbox;Fedora;Silvervblue;
|
||||||
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
|
# Translators: Do NOT translate or transliterate this text (this is an icon file name)!
|
||||||
Icon=@icon@
|
Icon=@icon@
|
||||||
StartupNotify=true
|
StartupNotify=true
|
||||||
17
data/org.kuchelmeister.ToolboxTuner.gschema.xml.in
Normal file
17
data/org.kuchelmeister.ToolboxTuner.gschema.xml.in
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<schemalist>
|
||||||
|
<schema path="/org/kuchelmeister/ToolboxTuner/" id="@app-id@" gettext-domain="@gettext-package@">
|
||||||
|
<key name="window-width" type="i">
|
||||||
|
<default>600</default>
|
||||||
|
<summary>Window width</summary>
|
||||||
|
</key>
|
||||||
|
<key name="window-height" type="i">
|
||||||
|
<default>400</default>
|
||||||
|
<summary>Window height</summary>
|
||||||
|
</key>
|
||||||
|
<key name="is-maximized" type="b">
|
||||||
|
<default>false</default>
|
||||||
|
<summary>Window maximized state</summary>
|
||||||
|
</key>
|
||||||
|
</schema>
|
||||||
|
</schemalist>
|
||||||
@@ -1,24 +1,28 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Hannes Kuchelmeister 2019 <hannes@kuchelmeister.org> -->
|
<!-- Hannes Kuchelmeister 2019-2024 <hannes@kuchelmeister.org> -->
|
||||||
<component type="desktop-application">
|
<component type="desktop-application">
|
||||||
<id>@app-id@</id>
|
<id>@app-id@</id>
|
||||||
<metadata_license>CC0</metadata_license>
|
<metadata_license>CC0</metadata_license>
|
||||||
<project_license>GPL-3.0-or-later</project_license>
|
<project_license>GPL-3.0-or-later</project_license>
|
||||||
<name>Toolbx Tuner</name>
|
<name>Toolbox Tuner</name>
|
||||||
<summary>Manage and enhance your toolbxes (containertoolboxes)</summary>
|
<summary>Manage and enhance toolboxes (containertoolbx.org)</summary>
|
||||||
<description>
|
<description>
|
||||||
<p>An application to manage and enhance your containertoolboxes.</p>
|
<p>An application to manage and enhance your containertoolboxes.</p>
|
||||||
</description>
|
</description>
|
||||||
<screenshots>
|
<screenshots>
|
||||||
<screenshot type="default">
|
<screenshot type="default">
|
||||||
<caption>Main application window showing multiple toolboxes</caption>
|
<caption>Main application window showing multiple toolboxes</caption>
|
||||||
<image type="source" width="1200" height="800">https://media.githubusercontent.com/media/13hannes11/toolbx-tuner/main/data/resources/screenshots/main_light.png</image>
|
<image type="source" width="900" height="600">https://media.githubusercontent.com/media/13hannes11/toolbox-tuner/main/data/resources/screenshots/main_light.png</image>
|
||||||
</screenshot>
|
</screenshot>
|
||||||
<screenshot>
|
<screenshot>
|
||||||
<caption>Main application window in dark mode</caption>
|
<caption>Main application window in dark mode</caption>
|
||||||
<image type="source" width="1200" height="800">https://media.githubusercontent.com/media/13hannes11/toolbx-tuner/main/data/resources/screenshots/main_dark.png</image>
|
<image type="source" width="900" height="600">https://github.com/13hannes11/toolbox-tuner/blob/main/data/resources/screenshots/main_dark.png</image>
|
||||||
</screenshot>
|
</screenshot>
|
||||||
</screenshots>
|
</screenshots>
|
||||||
|
<branding>
|
||||||
|
<color type="primary" scheme_preference="light">#a3f6f1</color>
|
||||||
|
<color type="primary" scheme_preference="dark">#2a9f94</color>
|
||||||
|
</branding>
|
||||||
<content_rating type="oars-1.0"/>
|
<content_rating type="oars-1.0"/>
|
||||||
<releases>
|
<releases>
|
||||||
<release version="0.0.0" type="development" date="2022-04-18"/>
|
<release version="0.0.0" type="development" date="2022-04-18"/>
|
||||||
@@ -30,3 +34,4 @@
|
|||||||
<translation type="gettext">@gettext-package@</translation>
|
<translation type="gettext">@gettext-package@</translation>
|
||||||
<launchable type="desktop-id">@app-id@.desktop</launchable>
|
<launchable type="desktop-id">@app-id@.desktop</launchable>
|
||||||
</component>
|
</component>
|
||||||
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<schemalist>
|
|
||||||
<schema path="/org/kuchelmeister/ToolbxTuner/" id="@app-id@" gettext-domain="@gettext-package@">
|
|
||||||
</schema>
|
|
||||||
</schemalist>
|
|
||||||
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<gresources>
|
<gresources>
|
||||||
<gresource prefix="/org/kuchelmeister/ToolbxTuner/">
|
<gresource prefix="/org/kuchelmeister/ToolboxTuner/">
|
||||||
<!-- see https://gtk-rs.org/gtk4-rs/git/docs/gtk4/struct.Application.html#automatic-resources -->
|
<!-- see https://gtk-rs.org/gtk4-rs/git/docs/gtk4/struct.Application.html#automatic-resources -->
|
||||||
|
<file compressed="true" preprocess="xml-stripblanks" alias="gtk/help-overlay.ui">ui/shortcuts.ui</file>
|
||||||
|
<file compressed="true">style.css</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
</gresources>
|
</gresources>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,4 @@
|
|||||||
|
.title-header{
|
||||||
|
font-size: 36px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
29
data/resources/ui/shortcuts.ui
Normal file
29
data/resources/ui/shortcuts.ui
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<interface>
|
||||||
|
<object class="GtkShortcutsWindow" id="help_overlay">
|
||||||
|
<property name="modal">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsSection">
|
||||||
|
<property name="section-name">shortcuts</property>
|
||||||
|
<property name="max-height">10</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsGroup">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">General</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Show Shortcuts</property>
|
||||||
|
<property name="action-name">win.show-help-overlay</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkShortcutsShortcut">
|
||||||
|
<property name="title" translatable="yes" context="shortcut window">Quit</property>
|
||||||
|
<property name="action-name">app.quit</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</interface>
|
||||||
@@ -2,16 +2,16 @@
|
|||||||
# Source: https://gitlab.gnome.org/GNOME/fractal/blob/master/hooks/pre-commit.hook
|
# Source: https://gitlab.gnome.org/GNOME/fractal/blob/master/hooks/pre-commit.hook
|
||||||
|
|
||||||
install_rustfmt() {
|
install_rustfmt() {
|
||||||
if ! which rustup &> /dev/null; then
|
if ! which rustup >/dev/null 2>&1; then
|
||||||
curl https://sh.rustup.rs -sSf | sh -s -- -y
|
curl https://sh.rustup.rs -sSf | sh -s -- -y
|
||||||
export PATH=$PATH:$HOME/.cargo/bin
|
export PATH=$PATH:$HOME/.cargo/bin
|
||||||
if ! which rustup &> /dev/null; then
|
if ! which rustup >/dev/null 2>&1; then
|
||||||
echo "Failed to install rustup. Performing the commit without style checking."
|
echo "Failed to install rustup. Performing the commit without style checking."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! rustup component list|grep rustfmt &> /dev/null; then
|
if ! rustup component list|grep rustfmt >/dev/null 2>&1; then
|
||||||
echo "Installing rustfmt…"
|
echo "Installing rustfmt…"
|
||||||
rustup component add rustfmt
|
rustup component add rustfmt
|
||||||
fi
|
fi
|
||||||
@@ -34,11 +34,11 @@ if ! which cargo >/dev/null 2>&1 || ! cargo fmt --help >/dev/null 2>&1; then
|
|||||||
echo ""
|
echo ""
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
echo -n "Install rustfmt via rustup? [y/n/Q]: "; read yn < /dev/tty
|
printf "%s" "Install rustfmt via rustup? [y/n/Q]: "; read yn < /dev/tty
|
||||||
case $yn in
|
case $yn in
|
||||||
[Yy]* ) install_rustfmt; break;;
|
[Yy]* ) install_rustfmt; break;;
|
||||||
[Nn]* ) echo "Performing commit."; exit 0;;
|
[Nn]* ) echo "Performing commit."; exit 0;;
|
||||||
[Qq]* | "" ) echo "Aborting commit."; exit -1 >/dev/null 2>&1;;
|
[Qq]* | "" ) echo "Aborting commit."; exit 1 >/dev/null 2>&1;;
|
||||||
* ) echo "Invalid input";;
|
* ) echo "Invalid input";;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@@ -51,7 +51,7 @@ if test $? != 0; then
|
|||||||
echo "--Checking style fail--"
|
echo "--Checking style fail--"
|
||||||
echo "Please fix the above issues, either manually or by running: cargo fmt --all"
|
echo "Please fix the above issues, either manually or by running: cargo fmt --all"
|
||||||
|
|
||||||
exit -1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "--Checking style pass--"
|
echo "--Checking style pass--"
|
||||||
fi
|
fi
|
||||||
|
|||||||
7
icons.toml
Normal file
7
icons.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Recommended: Specify your app ID *OR* your base resource path for more robust icon loading
|
||||||
|
app_id = "org.kuchelmeister.ToolboxTuner"
|
||||||
|
|
||||||
|
# List of icon names you found (shipped with this crate)
|
||||||
|
# Note: the file ending `-symbolic.svg` isn't part of the icon name.
|
||||||
|
icons = ["issue", "play", "pause", "terminal"]
|
||||||
|
|
||||||
14
meson.build
14
meson.build
@@ -1,15 +1,15 @@
|
|||||||
project(
|
project(
|
||||||
'toolbxtuner',
|
'toolbox-tuner',
|
||||||
'rust',
|
'rust',
|
||||||
version: '0.0.1',
|
version: '0.0.1',
|
||||||
meson_version: '>= 0.59',
|
meson_version: '>= 0.59',
|
||||||
license: 'GPL-3',
|
# license: 'MIT',
|
||||||
)
|
)
|
||||||
|
|
||||||
i18n = import('i18n')
|
i18n = import('i18n')
|
||||||
gnome = import('gnome')
|
gnome = import('gnome')
|
||||||
|
|
||||||
base_id = 'org.kuchelmeister.ToolbxTuner'
|
base_id = 'org.kuchelmeister.ToolboxTuner'
|
||||||
|
|
||||||
dependency('glib-2.0', version: '>= 2.66')
|
dependency('glib-2.0', version: '>= 2.66')
|
||||||
dependency('gio-2.0', version: '>= 2.66')
|
dependency('gio-2.0', version: '>= 2.66')
|
||||||
@@ -35,13 +35,17 @@ gettext_package = meson.project_name()
|
|||||||
|
|
||||||
if get_option('profile') == 'development'
|
if get_option('profile') == 'development'
|
||||||
profile = 'Devel'
|
profile = 'Devel'
|
||||||
vcs_tag = run_command('git', 'rev-parse', '--short', 'HEAD').stdout().strip()
|
vcs_tag = run_command('git', 'rev-parse', '--short', 'HEAD', check: false).stdout().strip()
|
||||||
if vcs_tag == ''
|
if vcs_tag == ''
|
||||||
version_suffix = '-devel'
|
version_suffix = '-devel'
|
||||||
else
|
else
|
||||||
version_suffix = '-@0@'.format(vcs_tag)
|
version_suffix = '-@0@'.format(vcs_tag)
|
||||||
endif
|
endif
|
||||||
application_id = '@0@.@1@'.format(base_id, profile)
|
application_id = '@0@.@1@'.format(base_id, profile)
|
||||||
|
elif get_option('profile') == 'screenshot'
|
||||||
|
profile = 'Screenshot'
|
||||||
|
version_suffix = ''
|
||||||
|
application_id = base_id
|
||||||
else
|
else
|
||||||
profile = ''
|
profile = ''
|
||||||
version_suffix = ''
|
version_suffix = ''
|
||||||
@@ -57,7 +61,7 @@ meson.add_dist_script(
|
|||||||
if get_option('profile') == 'development'
|
if get_option('profile') == 'development'
|
||||||
# Setup pre-commit hook for ensuring coding style is always consistent
|
# Setup pre-commit hook for ensuring coding style is always consistent
|
||||||
message('Setting up git pre-commit hook..')
|
message('Setting up git pre-commit hook..')
|
||||||
run_command('cp', '-f', 'hooks/pre-commit.hook', '.git/hooks/pre-commit')
|
run_command('cp', '-f', 'hooks/pre-commit.hook', '.git/hooks/pre-commit', check: false)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
subdir('data')
|
subdir('data')
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ option(
|
|||||||
type: 'combo',
|
type: 'combo',
|
||||||
choices: [
|
choices: [
|
||||||
'default',
|
'default',
|
||||||
'flathub',
|
'development',
|
||||||
'development'
|
'screenshot',
|
||||||
],
|
],
|
||||||
value: 'default',
|
value: 'default',
|
||||||
description: 'The build profile for Toolbx Tuner. One of "default" or "development".'
|
description: 'The build profile for Toolbox Tuner. One of "default" or "development".'
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
data/org.kuchelmeister.ToolbxTuner.desktop.in.in
|
data/org.kuchelmeister.ToolboxTuner.desktop.in.in
|
||||||
data/org.kuchelmeister.ToolbxTuner.gschema.xml.in
|
data/org.kuchelmeister.ToolboxTuner.gschema.xml.in
|
||||||
data/org.kuchelmeister.ToolbxTuner.metainfo.xml.in.in
|
data/org.kuchelmeister.ToolboxTuner.metainfo.xml.in.in
|
||||||
|
data/resources/ui/shortcuts.ui
|
||||||
|
data/resources/ui/window.ui
|
||||||
src/application.rs
|
src/application.rs
|
||||||
|
|||||||
296
src/app.rs
Normal file
296
src/app.rs
Normal file
@@ -0,0 +1,296 @@
|
|||||||
|
use crate::gtk::Align;
|
||||||
|
use crate::util::prerequisit::get_installed_terminals;
|
||||||
|
use crate::util::prerequisit::is_toolbox_installed;
|
||||||
|
|
||||||
|
use crate::util::toolbox::ToolbxContainer;
|
||||||
|
use relm4::adw::prelude::PreferencesGroupExt;
|
||||||
|
use relm4::factory::FactoryHashMap;
|
||||||
|
use relm4::gtk::PolicyType;
|
||||||
|
use relm4::RelmWidgetExt;
|
||||||
|
use relm4::{
|
||||||
|
actions::{RelmAction, RelmActionGroup},
|
||||||
|
adw, gtk, main_application, Component, ComponentController, ComponentParts, ComponentSender,
|
||||||
|
Controller,
|
||||||
|
};
|
||||||
|
use std::collections::HashSet;
|
||||||
|
use std::thread::sleep;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use crate::config::{APP_ID, PROFILE};
|
||||||
|
use crate::factories::container_list::Container;
|
||||||
|
use crate::factories::container_list::ContainerStatus;
|
||||||
|
use crate::modals::about::AboutDialog;
|
||||||
|
use crate::modals::unsupported::UnsupportedDialog;
|
||||||
|
use crate::modals::unsupported::UnsupportedDialogOutput;
|
||||||
|
use crate::util::toolbox::ToolbxStatus;
|
||||||
|
use gtk::prelude::{
|
||||||
|
ApplicationExt, ApplicationWindowExt, GtkWindowExt, OrientableExt, SettingsExt, WidgetExt,
|
||||||
|
};
|
||||||
|
use gtk::{gio, glib};
|
||||||
|
|
||||||
|
pub(super) struct App {
|
||||||
|
unsupported_dialog: Controller<UnsupportedDialog>,
|
||||||
|
about_dialog: Controller<AboutDialog>,
|
||||||
|
containers: FactoryHashMap<String, Container>,
|
||||||
|
spinning: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum AppMsg {
|
||||||
|
Quit,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub(super) enum AppCommandMsg {
|
||||||
|
PrerequisitsInstalled(bool),
|
||||||
|
UpdateToolboxes(Vec<ToolbxContainer>),
|
||||||
|
InitiateRefresh,
|
||||||
|
}
|
||||||
|
|
||||||
|
relm4::new_action_group!(pub(super) WindowActionGroup, "win");
|
||||||
|
//relm4::new_stateless_action!(PreferencesAction, WindowActionGroup, "preferences");
|
||||||
|
relm4::new_stateless_action!(pub(super) ShortcutsAction, WindowActionGroup, "show-help-overlay");
|
||||||
|
relm4::new_stateless_action!(AboutAction, WindowActionGroup, "about");
|
||||||
|
use crate::factories::container_list::ContainerInit;
|
||||||
|
|
||||||
|
#[relm4::component(pub)]
|
||||||
|
impl Component for App {
|
||||||
|
type Init = ();
|
||||||
|
type Input = AppMsg;
|
||||||
|
type CommandOutput = AppCommandMsg;
|
||||||
|
type Output = ();
|
||||||
|
type Widgets = AppWidgets;
|
||||||
|
|
||||||
|
menu! {
|
||||||
|
primary_menu: {
|
||||||
|
section! {
|
||||||
|
//"_Preferences" => PreferencesAction,
|
||||||
|
"_Keyboard" => ShortcutsAction,
|
||||||
|
"_About Toolbox Tuner" => AboutAction,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
view! {
|
||||||
|
main_window = adw::ApplicationWindow::new(&main_application()) {
|
||||||
|
set_visible: true,
|
||||||
|
|
||||||
|
connect_close_request[sender] => move |_| {
|
||||||
|
sender.input(AppMsg::Quit);
|
||||||
|
glib::Propagation::Stop
|
||||||
|
},
|
||||||
|
|
||||||
|
#[wrap(Some)]
|
||||||
|
set_help_overlay: shortcuts = >k::Builder::from_resource(
|
||||||
|
"/org/kuchelmeister/ToolboxTuner/gtk/help-overlay.ui"
|
||||||
|
)
|
||||||
|
.object::<gtk::ShortcutsWindow>("help_overlay")
|
||||||
|
.unwrap() -> gtk::ShortcutsWindow {
|
||||||
|
set_transient_for: Some(&main_window),
|
||||||
|
set_application: Some(&main_application()),
|
||||||
|
},
|
||||||
|
|
||||||
|
add_css_class?: if PROFILE == "Devel" {
|
||||||
|
Some("devel")
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
},
|
||||||
|
|
||||||
|
gtk::Box {
|
||||||
|
set_orientation: gtk::Orientation::Vertical,
|
||||||
|
|
||||||
|
adw::HeaderBar {
|
||||||
|
pack_end = >k::MenuButton {
|
||||||
|
set_icon_name: "open-menu-symbolic",
|
||||||
|
set_menu_model: Some(&primary_menu),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
gtk::ScrolledWindow {
|
||||||
|
set_hexpand: true,
|
||||||
|
set_vexpand: true,
|
||||||
|
set_hscrollbar_policy: PolicyType::Never,
|
||||||
|
|
||||||
|
adw::PreferencesGroup{
|
||||||
|
set_title: "Toolboxes",
|
||||||
|
set_margin_all: 30,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[wrap(Some)]
|
||||||
|
set_header_suffix: refresh_spinner = >k::Spinner {
|
||||||
|
#[watch]
|
||||||
|
set_spinning: model.spinning
|
||||||
|
},
|
||||||
|
|
||||||
|
#[local_ref]
|
||||||
|
container_box -> gtk::ListBox {
|
||||||
|
set_size_request: (200, -1),
|
||||||
|
set_selection_mode: gtk::SelectionMode::None,
|
||||||
|
set_valign: Align::Start,
|
||||||
|
set_css_classes: &["boxed-list"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init(
|
||||||
|
_init: Self::Init,
|
||||||
|
root: Self::Root,
|
||||||
|
sender: ComponentSender<Self>,
|
||||||
|
) -> ComponentParts<Self> {
|
||||||
|
let about_dialog = AboutDialog::builder()
|
||||||
|
.transient_for(&root)
|
||||||
|
.launch(())
|
||||||
|
.detach();
|
||||||
|
|
||||||
|
let unsupported_dialog = UnsupportedDialog::builder()
|
||||||
|
.transient_for(&root)
|
||||||
|
.launch(())
|
||||||
|
.forward(sender.input_sender(), |msg| match msg {
|
||||||
|
UnsupportedDialogOutput::CloseApplication => AppMsg::Quit,
|
||||||
|
});
|
||||||
|
|
||||||
|
let containers = FactoryHashMap::builder().launch_default().detach();
|
||||||
|
|
||||||
|
let model = Self {
|
||||||
|
about_dialog,
|
||||||
|
unsupported_dialog,
|
||||||
|
containers,
|
||||||
|
spinning: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
let container_box = model.containers.widget();
|
||||||
|
let widgets = view_output!();
|
||||||
|
|
||||||
|
let mut actions = RelmActionGroup::<WindowActionGroup>::new();
|
||||||
|
|
||||||
|
let shortcuts_action = {
|
||||||
|
let shortcuts = widgets.shortcuts.clone();
|
||||||
|
RelmAction::<ShortcutsAction>::new_stateless(move |_| {
|
||||||
|
shortcuts.present();
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
let about_action = {
|
||||||
|
let sender = model.about_dialog.sender().clone();
|
||||||
|
RelmAction::<AboutAction>::new_stateless(move |_| {
|
||||||
|
sender.send(()).unwrap();
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
sender.spawn_oneshot_command(|| {
|
||||||
|
let terminals = get_installed_terminals().unwrap_or_default();
|
||||||
|
let toolbox_installed = is_toolbox_installed().unwrap_or(false);
|
||||||
|
AppCommandMsg::PrerequisitsInstalled(terminals.len() > 0 && toolbox_installed)
|
||||||
|
});
|
||||||
|
|
||||||
|
actions.add_action(shortcuts_action);
|
||||||
|
actions.add_action(about_action);
|
||||||
|
actions.register_for_widget(&widgets.main_window);
|
||||||
|
|
||||||
|
widgets.load_window_size();
|
||||||
|
|
||||||
|
ComponentParts { model, widgets }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>, _root: &Self::Root) {
|
||||||
|
match message {
|
||||||
|
AppMsg::Quit => main_application().quit(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_cmd(
|
||||||
|
&mut self,
|
||||||
|
message: Self::CommandOutput,
|
||||||
|
sender: ComponentSender<Self>,
|
||||||
|
_: &Self::Root,
|
||||||
|
) {
|
||||||
|
match message {
|
||||||
|
AppCommandMsg::PrerequisitsInstalled(false) => {
|
||||||
|
self.unsupported_dialog.sender().clone().send(()).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
AppCommandMsg::PrerequisitsInstalled(true) | AppCommandMsg::InitiateRefresh => {
|
||||||
|
self.spinning = true;
|
||||||
|
sender.spawn_oneshot_command(|| {
|
||||||
|
AppCommandMsg::UpdateToolboxes(ToolbxContainer::get_toolboxes())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
AppCommandMsg::UpdateToolboxes(toolboxes) => {
|
||||||
|
let mut updated_containers = HashSet::<String>::new();
|
||||||
|
toolboxes.iter().for_each(|toolbox| {
|
||||||
|
self.containers.insert(
|
||||||
|
toolbox.id.clone(),
|
||||||
|
ContainerInit {
|
||||||
|
name: toolbox.name.clone(),
|
||||||
|
status: match toolbox.status {
|
||||||
|
ToolbxStatus::Running => ContainerStatus::Running,
|
||||||
|
_ => ContainerStatus::NotRunning,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
updated_containers.insert(toolbox.id.clone());
|
||||||
|
});
|
||||||
|
let obsolete_containers: Vec<String> = self
|
||||||
|
.containers
|
||||||
|
.iter()
|
||||||
|
.map(|(hash, _)| hash.clone())
|
||||||
|
.filter(|hash| !updated_containers.contains(hash))
|
||||||
|
.collect();
|
||||||
|
obsolete_containers.into_iter().for_each(|hash| {
|
||||||
|
self.containers.remove(&hash);
|
||||||
|
});
|
||||||
|
|
||||||
|
self.spinning = false;
|
||||||
|
|
||||||
|
sender.spawn_oneshot_command(|| {
|
||||||
|
sleep(Duration::from_millis(2000));
|
||||||
|
AppCommandMsg::InitiateRefresh
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shutdown(&mut self, widgets: &mut Self::Widgets, _output: relm4::Sender<Self::Output>) {
|
||||||
|
widgets.save_window_size().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AppWidgets {
|
||||||
|
fn save_window_size(&self) -> Result<(), glib::BoolError> {
|
||||||
|
let settings = gio::Settings::new(APP_ID);
|
||||||
|
let (width, height) = self.main_window.default_size();
|
||||||
|
|
||||||
|
if PROFILE != "Screenshot" {
|
||||||
|
settings.set_int("window-width", width)?;
|
||||||
|
settings.set_int("window-height", height)?;
|
||||||
|
|
||||||
|
settings.set_boolean("is-maximized", self.main_window.is_maximized())?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn load_window_size(&self) {
|
||||||
|
let settings = gio::Settings::new(APP_ID);
|
||||||
|
|
||||||
|
if PROFILE == "Screenshot" {
|
||||||
|
self.main_window.set_default_size(778, 478);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let width = settings.int("window-width");
|
||||||
|
let height = settings.int("window-height");
|
||||||
|
let is_maximized = settings.boolean("is-maximized");
|
||||||
|
|
||||||
|
self.main_window.set_default_size(width, height);
|
||||||
|
|
||||||
|
if is_maximized {
|
||||||
|
self.main_window.maximize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
pub const APP_ID: &str = @APP_ID@;
|
pub const APP_ID: &str = @APP_ID@;
|
||||||
pub const GETTEXT_PACKAGE: &str = @GETTEXT_PACKAGE@;
|
pub const GETTEXT_PACKAGE: &str = @GETTEXT_PACKAGE@;
|
||||||
pub const LOCALEDIR: &str = @LOCALEDIR@;
|
pub const LOCALEDIR: &str = @LOCALEDIR@;
|
||||||
|
#[allow(unused)]
|
||||||
pub const PKGDATADIR: &str = @PKGDATADIR@;
|
pub const PKGDATADIR: &str = @PKGDATADIR@;
|
||||||
pub const PROFILE: &str = @PROFILE@;
|
pub const PROFILE: &str = @PROFILE@;
|
||||||
pub const RESOURCES_FILE: &str = concat!(@PKGDATADIR@, "/resources.gresource");
|
pub const RESOURCES_FILE: &str = concat!(@PKGDATADIR@, "/resources.gresource");
|
||||||
|
|||||||
1
src/factories.rs
Normal file
1
src/factories.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod container_list;
|
||||||
199
src/factories/container_list.rs
Normal file
199
src/factories/container_list.rs
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
use crate::util::toolbox::open_toolbox_container_in_terminal;
|
||||||
|
use crate::util::toolbox::start_toolbox_container;
|
||||||
|
use crate::util::toolbox::stop_toolbox_container;
|
||||||
|
use gtk::prelude::ButtonExt;
|
||||||
|
use relm4::adw;
|
||||||
|
use relm4::adw::prelude::ActionRowExt;
|
||||||
|
use relm4::adw::prelude::PreferencesRowExt;
|
||||||
|
use relm4::factory::{FactoryComponent, FactorySender};
|
||||||
|
use relm4::gtk;
|
||||||
|
use relm4::gtk::prelude::WidgetExt;
|
||||||
|
use relm4_icons::icon_names;
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub enum ContainerStatus {
|
||||||
|
Running,
|
||||||
|
NotRunning,
|
||||||
|
Refreshing,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Hash, Eq)]
|
||||||
|
pub enum ContainerOperation {
|
||||||
|
LaunchingTerminal,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Container {
|
||||||
|
hash: String,
|
||||||
|
value: String,
|
||||||
|
status: ContainerStatus,
|
||||||
|
running_operations: HashSet<ContainerOperation>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum ContainerMsg {
|
||||||
|
Start,
|
||||||
|
Stop,
|
||||||
|
OpenTerminal,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum CommandMessage {
|
||||||
|
SetStarted,
|
||||||
|
SetStopped,
|
||||||
|
FinishLaunchTerminal,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ContainerInit {
|
||||||
|
pub name: String,
|
||||||
|
pub status: ContainerStatus,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[relm4::factory(pub)]
|
||||||
|
impl FactoryComponent for Container {
|
||||||
|
type Init = ContainerInit;
|
||||||
|
type Input = ContainerMsg;
|
||||||
|
type Output = ();
|
||||||
|
type CommandOutput = CommandMessage;
|
||||||
|
type Widgets = ContainerWidgets;
|
||||||
|
type ParentWidget = gtk::ListBox;
|
||||||
|
type Index = String;
|
||||||
|
|
||||||
|
view! {
|
||||||
|
root = adw::ActionRow {
|
||||||
|
#[watch]
|
||||||
|
set_title: &self.value,
|
||||||
|
#[watch]
|
||||||
|
set_subtitle: &self.hash,
|
||||||
|
|
||||||
|
add_prefix = >k::Box{
|
||||||
|
gtk::AspectFrame{
|
||||||
|
set_ratio: 1.0,
|
||||||
|
gtk::Box{
|
||||||
|
gtk::Button {
|
||||||
|
#[watch]
|
||||||
|
set_visible: self.status == ContainerStatus::Refreshing,
|
||||||
|
#[wrap(Some)]
|
||||||
|
set_child = >k::Spinner {
|
||||||
|
#[watch]
|
||||||
|
set_spinning: self.status == ContainerStatus::Refreshing,
|
||||||
|
},
|
||||||
|
set_margin_top: 10,
|
||||||
|
set_margin_bottom: 10,
|
||||||
|
set_css_classes: &["circular"],
|
||||||
|
},
|
||||||
|
gtk::Button {
|
||||||
|
#[watch]
|
||||||
|
set_visible: self.status == ContainerStatus::NotRunning,
|
||||||
|
set_icon_name: icon_names::PLAY,
|
||||||
|
set_margin_top: 10,
|
||||||
|
set_margin_bottom: 10,
|
||||||
|
set_css_classes: &["circular"],
|
||||||
|
connect_clicked => ContainerMsg::Start,
|
||||||
|
},
|
||||||
|
gtk::Button {
|
||||||
|
#[watch]
|
||||||
|
set_visible: self.status == ContainerStatus::Running,
|
||||||
|
set_icon_name: icon_names::PAUSE,
|
||||||
|
set_margin_top: 10,
|
||||||
|
set_margin_bottom: 10,
|
||||||
|
set_css_classes: &["circular"],
|
||||||
|
connect_clicked => ContainerMsg::Stop,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
add_prefix = >k::Box{
|
||||||
|
gtk::AspectFrame{
|
||||||
|
set_ratio: 1.0,
|
||||||
|
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
add_suffix = >k::Box{
|
||||||
|
gtk::AspectFrame{
|
||||||
|
#[watch]
|
||||||
|
set_visible: !self.running_operations.contains(&ContainerOperation::LaunchingTerminal),
|
||||||
|
set_ratio: 1.0,
|
||||||
|
gtk::Button {
|
||||||
|
set_icon_name: icon_names::TERMINAL,
|
||||||
|
set_margin_start: 10,
|
||||||
|
set_margin_top: 10,
|
||||||
|
set_margin_bottom: 10,
|
||||||
|
set_css_classes: &["flat"],
|
||||||
|
connect_clicked => ContainerMsg::OpenTerminal,
|
||||||
|
},
|
||||||
|
|
||||||
|
},
|
||||||
|
gtk::AspectFrame{
|
||||||
|
#[watch]
|
||||||
|
set_visible: self.running_operations.contains(&ContainerOperation::LaunchingTerminal),
|
||||||
|
set_ratio: 1.0,
|
||||||
|
gtk::Button {
|
||||||
|
set_margin_start: 10,
|
||||||
|
set_margin_top: 10,
|
||||||
|
set_margin_bottom: 10,
|
||||||
|
set_css_classes: &["flat"],
|
||||||
|
#[wrap(Some)]
|
||||||
|
set_child = >k::Spinner {
|
||||||
|
#[watch]
|
||||||
|
set_spinning: self.running_operations.contains(&ContainerOperation::LaunchingTerminal),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init_model(value: Self::Init, index: &Self::Index, _sender: FactorySender<Self>) -> Self {
|
||||||
|
Self {
|
||||||
|
hash: index.clone(),
|
||||||
|
value: value.name.clone(),
|
||||||
|
status: value.status,
|
||||||
|
running_operations: HashSet::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(&mut self, msg: Self::Input, sender: FactorySender<Self>) {
|
||||||
|
match msg {
|
||||||
|
ContainerMsg::Start => {
|
||||||
|
self.status = ContainerStatus::Refreshing;
|
||||||
|
let hash = (&self.hash).clone();
|
||||||
|
sender.spawn_oneshot_command(move || match start_toolbox_container(&hash) {
|
||||||
|
Ok(_) => CommandMessage::SetStarted,
|
||||||
|
Err(_) => CommandMessage::SetStopped,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ContainerMsg::Stop => {
|
||||||
|
self.status = ContainerStatus::Refreshing;
|
||||||
|
let hash = (&self.hash).clone();
|
||||||
|
sender.spawn_oneshot_command(move || match stop_toolbox_container(&hash) {
|
||||||
|
Ok(_) => CommandMessage::SetStopped,
|
||||||
|
Err(_) => CommandMessage::SetStarted,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ContainerMsg::OpenTerminal => {
|
||||||
|
self.running_operations
|
||||||
|
.insert(ContainerOperation::LaunchingTerminal);
|
||||||
|
let hash = (&self.hash).clone();
|
||||||
|
sender.spawn_oneshot_command(move || {
|
||||||
|
match open_toolbox_container_in_terminal(&hash) {
|
||||||
|
_ => CommandMessage::FinishLaunchTerminal,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_cmd(&mut self, message: Self::CommandOutput, _sender: FactorySender<Self>) {
|
||||||
|
match message {
|
||||||
|
CommandMessage::SetStarted => self.status = ContainerStatus::Running,
|
||||||
|
CommandMessage::SetStopped => self.status = ContainerStatus::NotRunning,
|
||||||
|
CommandMessage::FinishLaunchTerminal => {
|
||||||
|
self.running_operations
|
||||||
|
.remove(&ContainerOperation::LaunchingTerminal);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
77
src/main.rs
77
src/main.rs
@@ -1,17 +1,68 @@
|
|||||||
use std::collections::VecDeque;
|
mod app;
|
||||||
|
mod config;
|
||||||
use relm4::gtk::{Application, ApplicationWindow};
|
mod factories;
|
||||||
use relm4::{factory::FactoryVecDeque, RelmApp};
|
mod modals;
|
||||||
use ui::app::model::AppModel;
|
|
||||||
use util::toolbx::ToolbxContainer;
|
|
||||||
|
|
||||||
mod ui;
|
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
fn main() {
|
use crate::config::{APP_ID, GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE};
|
||||||
let mut model = AppModel {
|
use gettextrs::{gettext, LocaleCategory};
|
||||||
toolboxes: FactoryVecDeque::new(),
|
use gtk::prelude::ApplicationExt;
|
||||||
|
use gtk::{gio, glib};
|
||||||
|
use relm4::{
|
||||||
|
actions::{AccelsPlus, RelmAction, RelmActionGroup},
|
||||||
|
gtk, main_application, RelmApp,
|
||||||
};
|
};
|
||||||
let app = RelmApp::new(model);
|
|
||||||
app.run();
|
use app::App;
|
||||||
|
|
||||||
|
relm4::new_action_group!(AppActionGroup, "app");
|
||||||
|
relm4::new_stateless_action!(QuitAction, AppActionGroup, "quit");
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
gtk::init().unwrap();
|
||||||
|
// Enable logging
|
||||||
|
tracing_subscriber::fmt()
|
||||||
|
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::FULL)
|
||||||
|
.with_max_level(tracing::Level::INFO)
|
||||||
|
.init();
|
||||||
|
|
||||||
|
// setup gettext
|
||||||
|
gettextrs::setlocale(LocaleCategory::LcAll, "");
|
||||||
|
gettextrs::bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR).expect("Unable to bind the text domain");
|
||||||
|
gettextrs::textdomain(GETTEXT_PACKAGE).expect("Unable to switch to the text domain");
|
||||||
|
|
||||||
|
glib::set_application_name(&gettext("Toolbox Tuner"));
|
||||||
|
|
||||||
|
let res = gio::Resource::load(RESOURCES_FILE).expect("Could not load gresource file");
|
||||||
|
gio::resources_register(&res);
|
||||||
|
|
||||||
|
gtk::Window::set_default_icon_name(APP_ID);
|
||||||
|
|
||||||
|
let app = main_application();
|
||||||
|
app.set_resource_base_path(Some("/org/kuchelmeister/ToolboxTuner/"));
|
||||||
|
|
||||||
|
let mut actions = RelmActionGroup::<AppActionGroup>::new();
|
||||||
|
|
||||||
|
let quit_action = {
|
||||||
|
let app = app.clone();
|
||||||
|
RelmAction::<QuitAction>::new_stateless(move |_| {
|
||||||
|
app.quit();
|
||||||
|
})
|
||||||
|
};
|
||||||
|
actions.add_action(quit_action);
|
||||||
|
actions.register_for_main_application();
|
||||||
|
|
||||||
|
app.set_accelerators_for_action::<QuitAction>(&["<Control>q"]);
|
||||||
|
|
||||||
|
let app = RelmApp::from_app(app);
|
||||||
|
relm4_icons::initialize_icons();
|
||||||
|
|
||||||
|
let data = res
|
||||||
|
.lookup_data(
|
||||||
|
"/org/kuchelmeister/ToolboxTuner/style.css",
|
||||||
|
gio::ResourceLookupFlags::NONE,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
app.set_global_css(&glib::GString::from_utf8_checked(data.to_vec()).unwrap());
|
||||||
|
app.visible_on_activate(false).run::<App>(());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,20 +25,13 @@ if get_option('profile') == 'default'
|
|||||||
cargo_options += [ '--release' ]
|
cargo_options += [ '--release' ]
|
||||||
rust_target = 'release'
|
rust_target = 'release'
|
||||||
message('Building in release mode')
|
message('Building in release mode')
|
||||||
cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ]
|
else
|
||||||
endif
|
|
||||||
if get_option('profile') == 'flathub'
|
|
||||||
cargo_options += [ '--release', '--offline' ]
|
|
||||||
rust_target = 'release'
|
|
||||||
message('Building in flathub release mode')
|
|
||||||
cargo_env = [ 'CARGO_HOME=/run/build/toolbx-tuner/cargo' ]
|
|
||||||
endif
|
|
||||||
if get_option('profile') == 'development'
|
|
||||||
rust_target = 'debug'
|
rust_target = 'debug'
|
||||||
message('Building in debug mode')
|
message('Building in debug mode')
|
||||||
cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ]
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
cargo_env = [ 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home' ]
|
||||||
|
|
||||||
cargo_build = custom_target(
|
cargo_build = custom_target(
|
||||||
'cargo-build',
|
'cargo-build',
|
||||||
build_by_default: true,
|
build_by_default: true,
|
||||||
|
|||||||
2
src/modals.rs
Normal file
2
src/modals.rs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod about;
|
||||||
|
pub mod unsupported;
|
||||||
49
src/modals/about.rs
Normal file
49
src/modals/about.rs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
use gtk::prelude::GtkWindowExt;
|
||||||
|
use relm4::{adw, gtk, ComponentParts, ComponentSender, SimpleComponent};
|
||||||
|
|
||||||
|
use crate::config::{APP_ID, VERSION};
|
||||||
|
|
||||||
|
pub struct AboutDialog {}
|
||||||
|
|
||||||
|
impl SimpleComponent for AboutDialog {
|
||||||
|
type Init = ();
|
||||||
|
type Widgets = adw::AboutWindow;
|
||||||
|
type Input = ();
|
||||||
|
type Output = ();
|
||||||
|
type Root = adw::AboutWindow;
|
||||||
|
|
||||||
|
fn init_root() -> Self::Root {
|
||||||
|
adw::AboutWindow::builder()
|
||||||
|
.application_icon(APP_ID)
|
||||||
|
// Insert your license of choice here
|
||||||
|
.license_type(gtk::License::Lgpl30)
|
||||||
|
// Insert your website here
|
||||||
|
.website("https://github.com/13hannes11/toolbox-tuner")
|
||||||
|
// Insert your Issues page
|
||||||
|
.issue_url("https://github.com/13hannes11/toolbox-tuner/issues")
|
||||||
|
// Insert your application name here
|
||||||
|
.application_name("Toolbox Tuner")
|
||||||
|
.version(VERSION)
|
||||||
|
.translator_credits("translator-credits")
|
||||||
|
.copyright("© 2022-2024 Hannes Kuchelmeister")
|
||||||
|
.developers(vec!["Hannes Kuchelmeister"])
|
||||||
|
.designers(vec!["Hannes Kuchelmeister"])
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init(
|
||||||
|
_: Self::Init,
|
||||||
|
root: Self::Root,
|
||||||
|
_sender: ComponentSender<Self>,
|
||||||
|
) -> ComponentParts<Self> {
|
||||||
|
let model = Self {};
|
||||||
|
|
||||||
|
let widgets = root.clone();
|
||||||
|
widgets.set_hide_on_close(true);
|
||||||
|
ComponentParts { model, widgets }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_view(&self, dialog: &mut Self::Widgets, _sender: ComponentSender<Self>) {
|
||||||
|
dialog.present();
|
||||||
|
}
|
||||||
|
}
|
||||||
61
src/modals/unsupported.rs
Normal file
61
src/modals/unsupported.rs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
use adw::StatusPage;
|
||||||
|
use gtk::prelude::{ButtonExt, GtkWindowExt};
|
||||||
|
use relm4::view;
|
||||||
|
use relm4::{adw, gtk, ComponentParts, ComponentSender, SimpleComponent};
|
||||||
|
use relm4_icons::icon_names;
|
||||||
|
|
||||||
|
pub struct UnsupportedDialog {}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum UnsupportedDialogOutput {
|
||||||
|
CloseApplication,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SimpleComponent for UnsupportedDialog {
|
||||||
|
type Init = ();
|
||||||
|
type Widgets = adw::Window;
|
||||||
|
type Input = ();
|
||||||
|
type Output = UnsupportedDialogOutput;
|
||||||
|
type Root = adw::Window;
|
||||||
|
|
||||||
|
fn init_root() -> Self::Root {
|
||||||
|
adw::Window::builder().build()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init(
|
||||||
|
_: Self::Init,
|
||||||
|
root: Self::Root,
|
||||||
|
sender: ComponentSender<Self>,
|
||||||
|
) -> ComponentParts<Self> {
|
||||||
|
let model = Self {};
|
||||||
|
|
||||||
|
view! {
|
||||||
|
widgets = root.clone() {
|
||||||
|
set_hide_on_close: true,
|
||||||
|
set_modal: true,
|
||||||
|
set_resizable: false,
|
||||||
|
set_default_width: 400,
|
||||||
|
|
||||||
|
|
||||||
|
StatusPage::new() {
|
||||||
|
set_icon_name: Some(icon_names::ISSUE),
|
||||||
|
set_title: "Missing requirements",
|
||||||
|
set_description: Some("Make sure Toolbox and Gnome Terminal are installed."),
|
||||||
|
|
||||||
|
#[name = "btn_close"]
|
||||||
|
gtk::Button::with_label("Goodbye!") {
|
||||||
|
connect_clicked[sender] => move |_| {
|
||||||
|
sender.output(UnsupportedDialogOutput::CloseApplication).unwrap()
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ComponentParts { model, widgets }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_view(&self, dialog: &mut Self::Widgets, _sender: ComponentSender<Self>) {
|
||||||
|
dialog.present();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
pub mod messages;
|
|
||||||
pub mod model;
|
|
||||||
pub mod toolbox_list;
|
|
||||||
pub mod update;
|
|
||||||
pub mod widgets;
|
|
||||||
pub mod workers;
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
use relm4::factory::DynamicIndex;
|
|
||||||
|
|
||||||
use crate::util::toolbx::ToolbxContainer;
|
|
||||||
|
|
||||||
use super::model::ToolbxEntry;
|
|
||||||
|
|
||||||
pub enum AppMsg {
|
|
||||||
ToolbxListUpdate(Vec<ToolbxContainer>),
|
|
||||||
ToolbxContainerToggleStartStop(DynamicIndex),
|
|
||||||
OpenToolbxTerminal(DynamicIndex),
|
|
||||||
ToolbxContainerChanged(DynamicIndex, ToolbxEntry),
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
use relm4::{factory::FactoryVecDeque, Model};
|
|
||||||
|
|
||||||
use crate::{ui::components::AppComponents, util::toolbx::ToolbxContainer};
|
|
||||||
|
|
||||||
use super::{messages::AppMsg, widgets::AppWidgets};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct ToolbxEntry {
|
|
||||||
pub toolbx_container: ToolbxContainer,
|
|
||||||
pub changing_status: bool,
|
|
||||||
// TODO: settings
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToolbxEntry {
|
|
||||||
pub fn update_container(&mut self, container: ToolbxContainer) {
|
|
||||||
std::mem::replace::<ToolbxContainer>(&mut self.toolbx_container, container);
|
|
||||||
}
|
|
||||||
pub fn update_entry(&mut self, container: ToolbxEntry) {
|
|
||||||
std::mem::replace::<ToolbxContainer>(
|
|
||||||
&mut self.toolbx_container,
|
|
||||||
container.toolbx_container,
|
|
||||||
);
|
|
||||||
self.changing_status = container.changing_status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct AppModel {
|
|
||||||
pub toolboxes: FactoryVecDeque<ToolbxEntry>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Model for AppModel {
|
|
||||||
type Msg = AppMsg;
|
|
||||||
type Widgets = AppWidgets;
|
|
||||||
type Components = AppComponents;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AppModel {
|
|
||||||
pub fn update_toolbxes<I>(&mut self, toolbox_iter: I)
|
|
||||||
where
|
|
||||||
I: Iterator<Item = ToolbxContainer>,
|
|
||||||
{
|
|
||||||
// Update each toolbx entry if there were changes to it
|
|
||||||
// TODO: deal with the removal of toolboxes
|
|
||||||
for tbx_update in toolbox_iter {
|
|
||||||
println!("name: {}", tbx_update.name);
|
|
||||||
let mut exists = false;
|
|
||||||
for (index, tbx_entry) in self.toolboxes.iter().enumerate() {
|
|
||||||
if tbx_update.name == tbx_entry.toolbx_container.name {
|
|
||||||
self.toolboxes
|
|
||||||
.get_mut(index)
|
|
||||||
.map(|x| x.update_container(tbx_update.clone()));
|
|
||||||
exists = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !exists {
|
|
||||||
println!("{}", tbx_update.name);
|
|
||||||
self.toolboxes.push_back(ToolbxEntry {
|
|
||||||
toolbx_container: tbx_update,
|
|
||||||
changing_status: false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,165 +0,0 @@
|
|||||||
use relm4::{
|
|
||||||
adw::{
|
|
||||||
self,
|
|
||||||
prelude::{BoxExt, ButtonExt, WidgetExt},
|
|
||||||
traits::{ActionRowExt, PreferencesRowExt},
|
|
||||||
},
|
|
||||||
factory::{DynamicIndex, FactoryPrototype, FactoryVecDeque},
|
|
||||||
gtk, send, view, Sender,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
ui::ui_strings::{
|
|
||||||
APP_ICON, APP_TOOLTIP, SETTINGS_ICON, SETTINGS_TOOLTIP, SHUTDOWN_ICON, SHUTDOWN_TOOLTIP,
|
|
||||||
START_ICON, START_TOOLTIP, TERMINAL_ICON, TERMINAL_TOOLTIP, UPDATE_ICON, UPDATE_TOOLTIP,
|
|
||||||
},
|
|
||||||
util::toolbx::ToolbxStatus,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::{messages::AppMsg, model::ToolbxEntry};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct FactoryWidgets {
|
|
||||||
pub action_row: adw::ActionRow,
|
|
||||||
status_button: gtk::Button,
|
|
||||||
status_spinner: gtk::Spinner,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FactoryPrototype for ToolbxEntry {
|
|
||||||
type Factory = FactoryVecDeque<Self>;
|
|
||||||
type Widgets = FactoryWidgets;
|
|
||||||
type Root = adw::ActionRow;
|
|
||||||
type View = gtk::ListBox;
|
|
||||||
type Msg = AppMsg;
|
|
||||||
|
|
||||||
fn init_view(&self, key: &DynamicIndex, sender: Sender<Self::Msg>) -> Self::Widgets {
|
|
||||||
let index_terminal = key.clone();
|
|
||||||
let index_settings = key.clone();
|
|
||||||
|
|
||||||
view! {
|
|
||||||
suffix_box = >k::Box{
|
|
||||||
append = >k::AspectFrame{
|
|
||||||
set_ratio: 1.0,
|
|
||||||
set_child = Some(>k::Button::from_icon_name(TERMINAL_ICON)) {
|
|
||||||
set_margin_start: 10,
|
|
||||||
set_margin_top: 10,
|
|
||||||
set_margin_bottom: 10,
|
|
||||||
set_tooltip_text: Some(TERMINAL_TOOLTIP),
|
|
||||||
set_css_classes: &["flat"],
|
|
||||||
connect_clicked(sender) => move |btn| {
|
|
||||||
send!(sender, AppMsg::OpenToolbxTerminal(index_terminal.clone()));
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let mut status_button_tooltip = START_TOOLTIP;
|
|
||||||
let mut status_button_icon = START_ICON;
|
|
||||||
|
|
||||||
match self.toolbx_container.status {
|
|
||||||
ToolbxStatus::Running => {
|
|
||||||
status_button_tooltip = SHUTDOWN_TOOLTIP;
|
|
||||||
status_button_icon = SHUTDOWN_ICON;
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
status_button_tooltip = START_TOOLTIP;
|
|
||||||
status_button_icon = START_ICON;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let subtitle = format!(
|
|
||||||
"created {}\n{}",
|
|
||||||
self.toolbx_container.created, self.toolbx_container.image
|
|
||||||
);
|
|
||||||
|
|
||||||
let index = key.clone();
|
|
||||||
|
|
||||||
view! {
|
|
||||||
status_spinner = >k::Spinner {
|
|
||||||
set_margin_top: 10,
|
|
||||||
set_margin_bottom: 10,
|
|
||||||
set_tooltip_text: Some(status_button_tooltip),
|
|
||||||
set_css_classes: &["circular"],
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
//status_spinner.start();
|
|
||||||
|
|
||||||
view! {
|
|
||||||
status_button = >k::Button::from_icon_name(status_button_icon) {
|
|
||||||
set_margin_top: 10,
|
|
||||||
set_margin_bottom: 10,
|
|
||||||
set_tooltip_text: Some(status_button_tooltip),
|
|
||||||
set_css_classes: &["circular"],
|
|
||||||
connect_clicked(sender) => move |btn| {
|
|
||||||
// Disable button
|
|
||||||
btn.set_sensitive(false);
|
|
||||||
send!(sender, AppMsg::ToolbxContainerToggleStartStop(index.clone()));
|
|
||||||
},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
view! {
|
|
||||||
action_row = &adw::ActionRow {
|
|
||||||
set_title: &self.toolbx_container.name,
|
|
||||||
set_subtitle: subtitle.as_str(),
|
|
||||||
add_prefix = >k::Box {
|
|
||||||
append = >k::AspectFrame{
|
|
||||||
set_ratio: 1.0,
|
|
||||||
set_child: Some(&status_button),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
add_suffix: &suffix_box,
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
FactoryWidgets {
|
|
||||||
action_row,
|
|
||||||
status_button,
|
|
||||||
status_spinner,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(
|
|
||||||
&self,
|
|
||||||
key: &<Self::Factory as relm4::factory::Factory<Self, Self::View>>::Key,
|
|
||||||
widgets: &Self::Widgets,
|
|
||||||
) {
|
|
||||||
println!("updated {}", key.current_index());
|
|
||||||
|
|
||||||
// fixme: IDEALY this is would be done with message handling and only if the request actually is done
|
|
||||||
|
|
||||||
if self.changing_status {
|
|
||||||
widgets.status_button.set_sensitive(false);
|
|
||||||
widgets
|
|
||||||
.status_button
|
|
||||||
.set_child(Some(&widgets.status_spinner));
|
|
||||||
widgets.status_spinner.start();
|
|
||||||
} else {
|
|
||||||
match self.toolbx_container.status {
|
|
||||||
ToolbxStatus::Running => {
|
|
||||||
widgets.status_button.set_icon_name(SHUTDOWN_ICON);
|
|
||||||
widgets
|
|
||||||
.status_button
|
|
||||||
.set_tooltip_text(Some(SHUTDOWN_TOOLTIP));
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
widgets.status_button.set_icon_name(START_ICON);
|
|
||||||
widgets.status_button.set_tooltip_text(Some(START_TOOLTIP));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
widgets.status_button.set_sensitive(true);
|
|
||||||
widgets.status_spinner.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn root_widget(widgets: &Self::Widgets) -> &Self::Root {
|
|
||||||
&widgets.action_row
|
|
||||||
}
|
|
||||||
|
|
||||||
fn position(
|
|
||||||
&self,
|
|
||||||
key: &<Self::Factory as relm4::factory::Factory<Self, Self::View>>::Key,
|
|
||||||
) -> <Self::View as relm4::factory::FactoryView<Self::Root>>::Position {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
use std::process::Command;
|
|
||||||
|
|
||||||
use relm4::{AppUpdate, Sender};
|
|
||||||
|
|
||||||
use crate::{ui::components::AppComponents, util::toolbx::ToolbxStatus};
|
|
||||||
|
|
||||||
use super::{messages::AppMsg, model::AppModel, workers::AsyncHandlerMsg};
|
|
||||||
|
|
||||||
impl AppUpdate for AppModel {
|
|
||||||
fn update(&mut self, msg: AppMsg, components: &AppComponents, _sender: Sender<AppMsg>) -> bool {
|
|
||||||
match msg {
|
|
||||||
AppMsg::ToolbxContainerToggleStartStop(index) => {
|
|
||||||
if let Some(toolbx_container) = self.toolboxes.get_mut(index.current_index()) {
|
|
||||||
match toolbx_container.toolbx_container.status {
|
|
||||||
ToolbxStatus::Exited | ToolbxStatus::Configured | ToolbxStatus::Created => {
|
|
||||||
toolbx_container.changing_status = true;
|
|
||||||
components
|
|
||||||
.async_handler
|
|
||||||
.sender()
|
|
||||||
.blocking_send(AsyncHandlerMsg::StartToolbx(
|
|
||||||
index,
|
|
||||||
toolbx_container.clone(),
|
|
||||||
))
|
|
||||||
.expect("Receiver dropped");
|
|
||||||
}
|
|
||||||
ToolbxStatus::Running => {
|
|
||||||
toolbx_container.changing_status = true;
|
|
||||||
components
|
|
||||||
.async_handler
|
|
||||||
.sender()
|
|
||||||
.blocking_send(AsyncHandlerMsg::StopToolbx(
|
|
||||||
index,
|
|
||||||
toolbx_container.clone(),
|
|
||||||
))
|
|
||||||
.expect("Receiver dropped");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: tell button to reactivate somehow
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AppMsg::ToolbxContainerChanged(index, container) => {
|
|
||||||
if let Some(toolbx_container) = self.toolboxes.get_mut(index.current_index()) {
|
|
||||||
toolbx_container.update_entry(container);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AppMsg::ToolbxListUpdate(tbx_vec) => {
|
|
||||||
println!("Updating Toolbox List");
|
|
||||||
self.update_toolbxes(tbx_vec.into_iter());
|
|
||||||
}
|
|
||||||
|
|
||||||
AppMsg::OpenToolbxTerminal(index) => {
|
|
||||||
if let Some(toolbx_container) = self.toolboxes.get_mut(index.current_index()) {
|
|
||||||
// TODO: support many terminals and check which are installed
|
|
||||||
let output = Command::new("flatpak-spawn")
|
|
||||||
.arg("--host")
|
|
||||||
.arg("gnome-terminal") //Command::new("gnome-terminal")
|
|
||||||
.arg("--")
|
|
||||||
.arg("toolbox")
|
|
||||||
.arg("enter")
|
|
||||||
.arg(toolbx_container.toolbx_container.name.clone())
|
|
||||||
.output();
|
|
||||||
|
|
||||||
println!("{:?}", output);
|
|
||||||
|
|
||||||
// TODO: update status on worker and add refresh spinner in the meantime
|
|
||||||
toolbx_container.toolbx_container.update_status();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
use relm4::{
|
|
||||||
adw::{
|
|
||||||
self,
|
|
||||||
prelude::{BoxExt, GtkWindowExt, OrientableExt, WidgetExt},
|
|
||||||
traits::AdwApplicationWindowExt,
|
|
||||||
},
|
|
||||||
gtk::{self, Align, PolicyType, SelectionMode},
|
|
||||||
WidgetPlus, Widgets,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::model::AppModel;
|
|
||||||
|
|
||||||
#[relm4::widget(pub)]
|
|
||||||
impl Widgets<AppModel, ()> for AppWidgets {
|
|
||||||
view! {
|
|
||||||
main_window = adw::ApplicationWindow {
|
|
||||||
set_default_width: 800,
|
|
||||||
set_default_height: 600,
|
|
||||||
set_content : main_box = Some(>k::Box) {
|
|
||||||
set_orientation: gtk::Orientation::Vertical,
|
|
||||||
append = &adw::HeaderBar {
|
|
||||||
set_title_widget = Some(>k::Label) {
|
|
||||||
set_label: "Toolbox Tuner",
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
append = >k::ScrolledWindow {
|
|
||||||
set_hexpand: true,
|
|
||||||
set_vexpand: true,
|
|
||||||
set_hscrollbar_policy: PolicyType::Never,
|
|
||||||
set_child = Some(>k::ListBox) {
|
|
||||||
set_valign: Align::Start,
|
|
||||||
set_selection_mode: SelectionMode::None,
|
|
||||||
set_margin_all: 30,
|
|
||||||
set_css_classes: &["boxed-list"],
|
|
||||||
factory!(model.toolboxes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use relm4::factory::DynamicIndex;
|
|
||||||
use relm4::{send, MessageHandler, Sender};
|
|
||||||
use tokio::runtime::{Builder, Runtime};
|
|
||||||
use tokio::sync::mpsc::{channel, Sender as TokioSender};
|
|
||||||
|
|
||||||
use crate::util::toolbx::ToolbxContainer;
|
|
||||||
|
|
||||||
use super::{
|
|
||||||
messages::AppMsg,
|
|
||||||
model::{AppModel, ToolbxEntry},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Code adapted from https://relm4.org/book/stable/message_handler.html
|
|
||||||
pub struct AsyncHandler {
|
|
||||||
_rt: Runtime,
|
|
||||||
sender: TokioSender<AsyncHandlerMsg>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum AsyncHandlerMsg {
|
|
||||||
StopToolbx(DynamicIndex, ToolbxEntry),
|
|
||||||
StartToolbx(DynamicIndex, ToolbxEntry),
|
|
||||||
UpdateToolbxes,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MessageHandler<AppModel> for AsyncHandler {
|
|
||||||
type Msg = AsyncHandlerMsg;
|
|
||||||
type Sender = TokioSender<AsyncHandlerMsg>;
|
|
||||||
|
|
||||||
fn init(_parent_model: &AppModel, parent_sender: Sender<AppMsg>) -> Self {
|
|
||||||
let (sender, mut rx) = channel::<AsyncHandlerMsg>(10);
|
|
||||||
|
|
||||||
let rt = Builder::new_multi_thread()
|
|
||||||
.worker_threads(8)
|
|
||||||
.enable_time()
|
|
||||||
.build()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
rt.spawn(async move {
|
|
||||||
while let Some(msg) = rx.recv().await {
|
|
||||||
let parent_sender = parent_sender.clone();
|
|
||||||
tokio::spawn(async move {
|
|
||||||
match msg {
|
|
||||||
AsyncHandlerMsg::UpdateToolbxes => {
|
|
||||||
let toolboxes = ToolbxContainer::get_toolboxes();
|
|
||||||
send! {parent_sender, AppMsg::ToolbxListUpdate(toolboxes)};
|
|
||||||
}
|
|
||||||
AsyncHandlerMsg::StopToolbx(index, mut tbx) => {
|
|
||||||
tbx.toolbx_container.stop();
|
|
||||||
tbx.changing_status = false;
|
|
||||||
send! {parent_sender, AppMsg::ToolbxContainerChanged(index, tbx)};
|
|
||||||
}
|
|
||||||
AsyncHandlerMsg::StartToolbx(index, mut tbx) => {
|
|
||||||
tbx.toolbx_container.start();
|
|
||||||
tbx.changing_status = false;
|
|
||||||
send! {parent_sender, AppMsg::ToolbxContainerChanged(index, tbx)};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let _sender = sender.clone();
|
|
||||||
rt.spawn(async move {
|
|
||||||
loop {
|
|
||||||
_sender.send(AsyncHandlerMsg::UpdateToolbxes).await;
|
|
||||||
tokio::time::sleep(Duration::from_secs(10)).await;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
AsyncHandler { _rt: rt, sender }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn send(&self, msg: Self::Msg) {
|
|
||||||
self.sender.blocking_send(msg).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sender(&self) -> Self::Sender {
|
|
||||||
self.sender.clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
use relm4::RelmComponent;
|
|
||||||
use relm4::RelmMsgHandler;
|
|
||||||
use relm4::Sender;
|
|
||||||
|
|
||||||
use super::app::model::AppModel;
|
|
||||||
use super::app::workers::AsyncHandler;
|
|
||||||
|
|
||||||
#[derive(relm4::Components)]
|
|
||||||
pub struct AppComponents {
|
|
||||||
pub async_handler: RelmMsgHandler<AsyncHandler, AppModel>,
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
pub const START_ICON: &str = r#"media-playback-start-symbolic"#;
|
|
||||||
pub const START_TOOLTIP: &str = r#"Start toolbox"#;
|
|
||||||
|
|
||||||
pub const SHUTDOWN_ICON: &str = r#"system-shutdown-symbolic"#;
|
|
||||||
pub const SHUTDOWN_TOOLTIP: &str = r#"Stop toolbox"#;
|
|
||||||
|
|
||||||
pub const UPDATE_ICON: &str = r#"software-update-available-symbolic"#;
|
|
||||||
pub const UPDATE_TOOLTIP: &str = r#"Update all applications inside of the toolbox"#;
|
|
||||||
|
|
||||||
pub const APP_ICON: &str = r#"view-grid-symbolic"#;
|
|
||||||
pub const APP_TOOLTIP: &str = r#"Select applications to showup in the application menu"#;
|
|
||||||
|
|
||||||
pub const TERMINAL_ICON: &str = r#"utilities-terminal-symbolic"#;
|
|
||||||
pub const TERMINAL_TOOLTIP: &str = r#"Open terminal inside of toolbox"#;
|
|
||||||
|
|
||||||
pub const SETTINGS_ICON: &str = r#"applications-system-symbolic"#;
|
|
||||||
pub const SETTINGS_TOOLTIP: &str = r#"Open toolbox settings"#;
|
|
||||||
|
|
||||||
pub const FOLDER_PICKER_ICON: &str = r#"folder-open-symbolic"#;
|
|
||||||
pub const FOLDER_PICKER_TOOLTIP: &str = r#"Select folder dialogue"#;
|
|
||||||
@@ -1 +1,2 @@
|
|||||||
pub mod toolbx;
|
pub mod prerequisit;
|
||||||
|
pub mod toolbox;
|
||||||
|
|||||||
51
src/util/prerequisit.rs
Normal file
51
src/util/prerequisit.rs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
use crate::util::toolbox::ToolbxError;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
pub enum TerminalType {
|
||||||
|
GnomeTerminal,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_installed_terminals() -> Result<Vec<TerminalType>, ToolbxError> {
|
||||||
|
let output = Command::new("flatpak-spawn")
|
||||||
|
.arg("--host")
|
||||||
|
.arg("gnome-terminal")
|
||||||
|
.arg("--version")
|
||||||
|
.output();
|
||||||
|
|
||||||
|
if output.is_err() {
|
||||||
|
return Err(ToolbxError::CommandExecutionError(
|
||||||
|
output.unwrap_err().to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let output = output.unwrap();
|
||||||
|
|
||||||
|
if output.status.code() == Some(0) {
|
||||||
|
Ok(vec![TerminalType::GnomeTerminal])
|
||||||
|
} else {
|
||||||
|
Err(ToolbxError::CommandUnsuccessfulError(
|
||||||
|
String::from_utf8_lossy(&output.stderr).into_owned(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_toolbox_installed() -> Result<bool, ToolbxError> {
|
||||||
|
let output = Command::new("flatpak-spawn")
|
||||||
|
.arg("--host")
|
||||||
|
.arg("toolbox")
|
||||||
|
.arg("--version")
|
||||||
|
.output();
|
||||||
|
|
||||||
|
if output.is_err() {
|
||||||
|
return Err(ToolbxError::CommandExecutionError(
|
||||||
|
output.unwrap_err().to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let output = output.unwrap();
|
||||||
|
if output.status.code() == Some(0) {
|
||||||
|
Ok(true)
|
||||||
|
} else {
|
||||||
|
Err(ToolbxError::CommandUnsuccessfulError(
|
||||||
|
String::from_utf8_lossy(&output.stderr).into_owned(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use std::{fmt::Display, process::Command, str::FromStr};
|
||||||
use std::{fmt::Display, iter::zip, process::Command, str::FromStr, string::ParseError, sync::Arc};
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum ToolbxError {
|
pub enum ToolbxError {
|
||||||
ParseStatusError(String),
|
ParseStatusError(String),
|
||||||
JSONSerializationError(String),
|
|
||||||
CommandExecutionError(String),
|
CommandExecutionError(String),
|
||||||
CommandUnsuccessfulError(String),
|
CommandUnsuccessfulError(String),
|
||||||
}
|
}
|
||||||
@@ -18,9 +16,6 @@ impl Display for ToolbxError {
|
|||||||
ToolbxError::CommandExecutionError(command_exec_error) => {
|
ToolbxError::CommandExecutionError(command_exec_error) => {
|
||||||
write!(f, "{}", command_exec_error)
|
write!(f, "{}", command_exec_error)
|
||||||
}
|
}
|
||||||
ToolbxError::JSONSerializationError(msg) => {
|
|
||||||
write!(f, "{}", msg)
|
|
||||||
}
|
|
||||||
ToolbxError::CommandUnsuccessfulError(command_unsuc_error) => {
|
ToolbxError::CommandUnsuccessfulError(command_unsuc_error) => {
|
||||||
write!(f, "{}", command_unsuc_error)
|
write!(f, "{}", command_unsuc_error)
|
||||||
}
|
}
|
||||||
@@ -68,92 +63,45 @@ pub struct ToolbxContainer {
|
|||||||
pub image: String,
|
pub image: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type PodmanInspectArray = Vec<PodmanInspectInfo>;
|
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct PodmanInspectInfo {
|
|
||||||
#[serde(rename = "Id")]
|
|
||||||
pub id: String,
|
|
||||||
#[serde(rename = "Created")]
|
|
||||||
pub created: String,
|
|
||||||
#[serde(rename = "State")]
|
|
||||||
pub state: PodManInspectState,
|
|
||||||
#[serde(rename = "Image")]
|
|
||||||
pub image: String,
|
|
||||||
#[serde(rename = "ImageName")]
|
|
||||||
pub image_name: String,
|
|
||||||
#[serde(rename = "Name")]
|
|
||||||
pub name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct PodManInspectState {
|
|
||||||
#[serde(rename = "Status")]
|
|
||||||
pub status: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum ToolboxCreateParameter {
|
|
||||||
None,
|
|
||||||
Distro(String),
|
|
||||||
Image(String),
|
|
||||||
Release(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToolbxContainer {
|
impl ToolbxContainer {
|
||||||
pub fn new(name: String) -> ToolbxContainer {
|
|
||||||
ToolbxContainer {
|
|
||||||
name: name,
|
|
||||||
..Default::default()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create(name: String, parameter: ToolboxCreateParameter) {
|
|
||||||
todo!("Implement actual functionality to create toolbox via commandline")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_toolboxes() -> Vec<ToolbxContainer> {
|
pub fn get_toolboxes() -> Vec<ToolbxContainer> {
|
||||||
let output = run_cmd_toolbx_list_containers();
|
let output = run_cmd_toolbx_list_containers();
|
||||||
println!("{}", output);
|
println!("{}", output);
|
||||||
parse_cmd_list_containers(output.as_str())
|
parse_cmd_list_containers(output.as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_status(output: &str) -> Result<PodmanInspectInfo, ToolbxError> {
|
|
||||||
let result: Result<PodmanInspectArray, _> = serde_json::from_str(output);
|
|
||||||
match result {
|
|
||||||
Ok(inspect_vec) => match inspect_vec.first() {
|
|
||||||
Some(info) => Ok(info.clone()),
|
|
||||||
None => Err(ToolbxError::JSONSerializationError(
|
|
||||||
"Inspect command returned empty vector.".to_string(),
|
|
||||||
)),
|
|
||||||
},
|
|
||||||
Err(e) => Err(ToolbxError::JSONSerializationError(e.to_string())),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_status(&mut self) -> Result<(), ToolbxError> {
|
pub fn open_toolbox_container_in_terminal(hash: &str) -> Result<(), ToolbxError> {
|
||||||
let output = Command::new("flatpak-spawn")
|
let output = Command::new("flatpak-spawn")
|
||||||
.arg("--host")
|
.arg("--host")
|
||||||
.arg("podman")
|
.arg("gnome-terminal")
|
||||||
.arg("container")
|
.arg("--")
|
||||||
.arg("inspect")
|
.arg("toolbox")
|
||||||
.arg(self.name.clone())
|
.arg("enter")
|
||||||
.output()
|
.arg(hash)
|
||||||
.expect("Failed to execute command");
|
.output();
|
||||||
|
|
||||||
let output = String::from_utf8_lossy(&output.stdout).to_string();
|
if output.is_err() {
|
||||||
let inspect_result = ToolbxContainer::parse_status(output.as_str())?;
|
return Err(ToolbxError::CommandExecutionError(
|
||||||
self.status = ToolbxStatus::from_str(inspect_result.state.status.as_str())?;
|
output.unwrap_err().to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
let output = output.unwrap();
|
||||||
|
if output.status.code() == Some(0) {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(ToolbxError::CommandUnsuccessfulError(
|
||||||
|
String::from_utf8_lossy(&output.stderr).into_owned(),
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop(&mut self) -> Result<(), ToolbxError> {
|
pub fn stop_toolbox_container(hash: &str) -> Result<(), ToolbxError> {
|
||||||
let output = Command::new("flatpak-spawn")
|
let output = Command::new("flatpak-spawn")
|
||||||
.arg("--host") //Command::new("podman")
|
.arg("--host") //Command::new("podman")
|
||||||
.arg("podman")
|
.arg("podman")
|
||||||
.arg("stop")
|
.arg("stop")
|
||||||
.arg(self.name.clone())
|
.arg(hash)
|
||||||
.output();
|
.output();
|
||||||
|
|
||||||
if output.is_err() {
|
if output.is_err() {
|
||||||
@@ -172,7 +120,6 @@ impl ToolbxContainer {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
if output.status.code() == Some(0) {
|
if output.status.code() == Some(0) {
|
||||||
self.status = ToolbxStatus::Exited;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(ToolbxError::CommandUnsuccessfulError(
|
Err(ToolbxError::CommandUnsuccessfulError(
|
||||||
@@ -181,15 +128,16 @@ impl ToolbxContainer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(&mut self) -> Result<(), ToolbxError> {
|
pub fn start_toolbox_container(hash: &str) -> Result<(), ToolbxError> {
|
||||||
let output = Command::new("flatpak-spawn")
|
let output = Command::new("flatpak-spawn")
|
||||||
.arg("--host") //Command::new("podman")
|
.arg("--host") //Command::new("podman")
|
||||||
.arg("podman")
|
.arg("podman")
|
||||||
.arg("start")
|
.arg("start")
|
||||||
.arg(self.name.clone())
|
.arg(hash)
|
||||||
.output();
|
.output();
|
||||||
|
|
||||||
if output.is_err() {
|
if output.is_err() {
|
||||||
|
dbg!(&output);
|
||||||
return Err(ToolbxError::CommandExecutionError(
|
return Err(ToolbxError::CommandExecutionError(
|
||||||
output.unwrap_err().to_string(),
|
output.unwrap_err().to_string(),
|
||||||
));
|
));
|
||||||
@@ -205,15 +153,14 @@ impl ToolbxContainer {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
if output.status.code() == Some(0) {
|
if output.status.code() == Some(0) {
|
||||||
self.status = ToolbxStatus::Running;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
|
dbg!(&output);
|
||||||
Err(ToolbxError::CommandUnsuccessfulError(
|
Err(ToolbxError::CommandUnsuccessfulError(
|
||||||
String::from_utf8_lossy(&output.stderr).into_owned(),
|
String::from_utf8_lossy(&output.stderr).into_owned(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_start_1non_existing_container() {
|
fn test_start_1non_existing_container() {
|
||||||
Reference in New Issue
Block a user