mirror of
https://github.com/13hannes11/toolbx-tuner.git
synced 2024-09-03 23:21:00 +02:00
remove all code and start with relm4 0.6
This commit is contained in:
23
.gitignore
vendored
23
.gitignore
vendored
@@ -1,16 +1,15 @@
|
|||||||
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
|
||||||
|
|
||||||
|
|||||||
868
Cargo.lock
generated
868
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
22
Cargo.toml
22
Cargo.toml
@@ -1,21 +1,15 @@
|
|||||||
[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.6.0", features = ["libadwaita", "gnome_44"] }
|
||||||
|
|
||||||
[package.metadata.appimage]
|
|
||||||
auto_link = true
|
|
||||||
auto_link_exclude_list = [
|
|
||||||
"libc.so*",
|
|
||||||
"libdl.so*",
|
|
||||||
"libpthread.so*",
|
|
||||||
]
|
|
||||||
|
|||||||
0
build-aux/dist-vendor.sh
Executable file → Normal file
0
build-aux/dist-vendor.sh
Executable file → Normal file
54
build-aux/org.kuchelmeister.ToolboxTuner.Devel.json
Normal file
54
build-aux/org.kuchelmeister.ToolboxTuner.Devel.json
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
{
|
||||||
|
"id": "org.kuchelmeister.ToolboxTuner.Devel",
|
||||||
|
"runtime": "org.gnome.Platform",
|
||||||
|
"runtime-version": "44",
|
||||||
|
"sdk": "org.gnome.Sdk",
|
||||||
|
"sdk-extensions": [
|
||||||
|
"org.freedesktop.Sdk.Extension.rust-stable",
|
||||||
|
"org.freedesktop.Sdk.Extension.llvm15"
|
||||||
|
],
|
||||||
|
"command": "toolbox-tuner",
|
||||||
|
"finish-args": [
|
||||||
|
"--share=ipc",
|
||||||
|
"--socket=fallback-x11",
|
||||||
|
"--socket=wayland",
|
||||||
|
"--device=dri",
|
||||||
|
"--env=RUST_LOG=toolbox_tuner=debug",
|
||||||
|
"--env=G_MESSAGES_DEBUG=none",
|
||||||
|
"--env=RUST_BACKTRACE=1"
|
||||||
|
],
|
||||||
|
"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_REGISTRIES_CRATES_IO_PROTOCOL": "sparse",
|
||||||
|
"CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER": "clang",
|
||||||
|
"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": "../"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -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,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,5 +1,5 @@
|
|||||||
<?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>
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
<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="1200" height="800">https://media.githubusercontent.com/media/13hannes11/toolbx-tuner/main/data/resources/screenshots/main_light.png</image>
|
||||||
@@ -19,9 +19,13 @@
|
|||||||
<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="1200" height="800">https://media.githubusercontent.com/media/13hannes11/toolbx-tuner/main/data/resources/screenshots/main_dark.png</image>
|
||||||
</screenshot>
|
</screenshot>
|
||||||
</screenshots>
|
</screenshots>
|
||||||
<content_rating type="oars-1.0" />
|
<branding>
|
||||||
|
<color type="primary" scheme_preference="light">#a3f6f1</color>
|
||||||
|
<color type="primary" scheme_preference="dark">#60ada6</color>
|
||||||
|
</branding>
|
||||||
|
<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"/>
|
||||||
</releases>
|
</releases>
|
||||||
<url type="homepage">https://github.com/13hannes11/toolbx-tuner</url>
|
<url type="homepage">https://github.com/13hannes11/toolbx-tuner</url>
|
||||||
<url type="bugtracker">https://github.com/13hannes11/toolbx-tuner/issues/</url>
|
<url type="bugtracker">https://github.com/13hannes11/toolbx-tuner/issues/</url>
|
||||||
@@ -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>
|
||||||
|
|||||||
@@ -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>
|
||||||
12
hooks/pre-commit.hook
Executable file → Normal file
12
hooks/pre-commit.hook
Executable file → Normal file
@@ -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
|
||||||
|
|||||||
10
meson.build
10
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,7 +35,7 @@ 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
|
||||||
@@ -57,7 +57,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,8 @@ option(
|
|||||||
type: 'combo',
|
type: 'combo',
|
||||||
choices: [
|
choices: [
|
||||||
'default',
|
'default',
|
||||||
'flathub',
|
|
||||||
'development'
|
'development'
|
||||||
],
|
],
|
||||||
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
|
||||||
|
|||||||
166
src/app.rs
Normal file
166
src/app.rs
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
use relm4::{
|
||||||
|
actions::{RelmAction, RelmActionGroup},
|
||||||
|
adw, gtk, main_application, Component, ComponentController, ComponentParts, ComponentSender,
|
||||||
|
Controller, SimpleComponent,
|
||||||
|
};
|
||||||
|
|
||||||
|
use gtk::prelude::{
|
||||||
|
ApplicationExt, ApplicationWindowExt, GtkWindowExt, OrientableExt, SettingsExt, WidgetExt,
|
||||||
|
};
|
||||||
|
use gtk::{gio, glib};
|
||||||
|
|
||||||
|
use crate::config::{APP_ID, PROFILE};
|
||||||
|
use crate::modals::about::AboutDialog;
|
||||||
|
|
||||||
|
pub(super) struct App {
|
||||||
|
about_dialog: Controller<AboutDialog>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub(super) enum AppMsg {
|
||||||
|
Quit,
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
|
#[relm4::component(pub)]
|
||||||
|
impl SimpleComponent for App {
|
||||||
|
type Init = ();
|
||||||
|
type Input = AppMsg;
|
||||||
|
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()) {
|
||||||
|
connect_close_request[sender] => move |_| {
|
||||||
|
sender.input(AppMsg::Quit);
|
||||||
|
gtk::Inhibit(true)
|
||||||
|
},
|
||||||
|
|
||||||
|
#[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::Label {
|
||||||
|
set_label: "Hello world!",
|
||||||
|
add_css_class: "title-header",
|
||||||
|
set_vexpand: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init(
|
||||||
|
_init: Self::Init,
|
||||||
|
root: &Self::Root,
|
||||||
|
sender: ComponentSender<Self>,
|
||||||
|
) -> ComponentParts<Self> {
|
||||||
|
let about_dialog = AboutDialog::builder()
|
||||||
|
.transient_for(root)
|
||||||
|
.launch(())
|
||||||
|
.detach();
|
||||||
|
|
||||||
|
let model = Self { about_dialog };
|
||||||
|
|
||||||
|
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();
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
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>) {
|
||||||
|
match message {
|
||||||
|
AppMsg::Quit => main_application().quit(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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");
|
||||||
|
|||||||
52
src/main.rs
52
src/main.rs
@@ -1,17 +1,47 @@
|
|||||||
use std::collections::VecDeque;
|
#[rustfmt::skip]
|
||||||
|
mod config;
|
||||||
|
mod app;
|
||||||
|
mod modals;
|
||||||
|
mod setup;
|
||||||
|
|
||||||
use relm4::gtk::{Application, ApplicationWindow};
|
use gtk::prelude::ApplicationExt;
|
||||||
use relm4::{factory::FactoryVecDeque, RelmApp};
|
use relm4::{
|
||||||
use ui::app::model::AppModel;
|
actions::{AccelsPlus, RelmAction, RelmActionGroup},
|
||||||
use util::toolbx::ToolbxContainer;
|
gtk, main_application, RelmApp,
|
||||||
|
};
|
||||||
|
|
||||||
mod ui;
|
use app::App;
|
||||||
mod util;
|
use setup::setup;
|
||||||
|
|
||||||
|
relm4::new_action_group!(AppActionGroup, "app");
|
||||||
|
relm4::new_stateless_action!(QuitAction, AppActionGroup, "quit");
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut model = AppModel {
|
// Enable logging
|
||||||
toolboxes: FactoryVecDeque::new(),
|
tracing_subscriber::fmt()
|
||||||
|
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::FULL)
|
||||||
|
.with_max_level(tracing::Level::INFO)
|
||||||
|
.init();
|
||||||
|
|
||||||
|
setup();
|
||||||
|
|
||||||
|
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();
|
||||||
|
})
|
||||||
};
|
};
|
||||||
let app = RelmApp::new(model);
|
actions.add_action(quit_action);
|
||||||
app.run();
|
actions.register_for_main_application();
|
||||||
|
|
||||||
|
app.set_accelerators_for_action::<QuitAction>(&["<Control>q"]);
|
||||||
|
|
||||||
|
let app = RelmApp::from_app(app);
|
||||||
|
|
||||||
|
app.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,
|
||||||
|
|||||||
50
src/modals/about.rs
Normal file
50
src/modals/about.rs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
1
src/modals/mod.rs
Normal file
1
src/modals/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod about;
|
||||||
39
src/setup.rs
Normal file
39
src/setup.rs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
use relm4::gtk;
|
||||||
|
|
||||||
|
use gettextrs::{gettext, LocaleCategory};
|
||||||
|
use gtk::{gio, glib};
|
||||||
|
|
||||||
|
use crate::config::{APP_ID, GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE};
|
||||||
|
|
||||||
|
pub fn setup() {
|
||||||
|
// Initialize GTK
|
||||||
|
gtk::init().unwrap();
|
||||||
|
|
||||||
|
setup_gettext();
|
||||||
|
|
||||||
|
glib::set_application_name(&gettext("Toolbox Tuner"));
|
||||||
|
|
||||||
|
let res = gio::Resource::load(RESOURCES_FILE).expect("Could not load gresource file");
|
||||||
|
gio::resources_register(&res);
|
||||||
|
|
||||||
|
setup_css(&res);
|
||||||
|
|
||||||
|
gtk::Window::set_default_icon_name(APP_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_gettext() {
|
||||||
|
// Prepare i18n
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_css(res: &gio::Resource) {
|
||||||
|
let data = res
|
||||||
|
.lookup_data(
|
||||||
|
"/org/kuchelmeister/ToolboxTuner/style.css",
|
||||||
|
gio::ResourceLookupFlags::NONE,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
relm4::set_global_css(&glib::GString::from_utf8_checked(data.to_vec()).unwrap());
|
||||||
|
}
|
||||||
@@ -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 +0,0 @@
|
|||||||
pub mod toolbx;
|
|
||||||
@@ -1,427 +0,0 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::{fmt::Display, iter::zip, process::Command, str::FromStr, string::ParseError, sync::Arc};
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub enum ToolbxError {
|
|
||||||
ParseStatusError(String),
|
|
||||||
JSONSerializationError(String),
|
|
||||||
CommandExecutionError(String),
|
|
||||||
CommandUnsuccessfulError(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::error::Error for ToolbxError {}
|
|
||||||
|
|
||||||
impl Display for ToolbxError {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
ToolbxError::ParseStatusError(parse_error) => write!(f, "{}", parse_error),
|
|
||||||
ToolbxError::CommandExecutionError(command_exec_error) => {
|
|
||||||
write!(f, "{}", command_exec_error)
|
|
||||||
}
|
|
||||||
ToolbxError::JSONSerializationError(msg) => {
|
|
||||||
write!(f, "{}", msg)
|
|
||||||
}
|
|
||||||
ToolbxError::CommandUnsuccessfulError(command_unsuc_error) => {
|
|
||||||
write!(f, "{}", command_unsuc_error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
|
||||||
pub enum ToolbxStatus {
|
|
||||||
Running,
|
|
||||||
Configured,
|
|
||||||
Created,
|
|
||||||
Exited,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ToolbxStatus {
|
|
||||||
fn default() -> Self {
|
|
||||||
ToolbxStatus::Configured
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromStr for ToolbxStatus {
|
|
||||||
type Err = ToolbxError;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<ToolbxStatus, ToolbxError> {
|
|
||||||
match s {
|
|
||||||
"running" => Ok(ToolbxStatus::Running),
|
|
||||||
"configured" => Ok(ToolbxStatus::Configured),
|
|
||||||
"created" => Ok(ToolbxStatus::Created),
|
|
||||||
"exited" => Ok(ToolbxStatus::Exited),
|
|
||||||
s => Err(ToolbxError::ParseStatusError(format!(
|
|
||||||
"'{}' is not a valid toolbx status.",
|
|
||||||
s
|
|
||||||
))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Default, Clone)]
|
|
||||||
pub struct ToolbxContainer {
|
|
||||||
pub id: String,
|
|
||||||
pub name: String,
|
|
||||||
pub created: String,
|
|
||||||
pub status: ToolbxStatus,
|
|
||||||
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 {
|
|
||||||
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> {
|
|
||||||
let output = run_cmd_toolbx_list_containers();
|
|
||||||
println!("{}", output);
|
|
||||||
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> {
|
|
||||||
let output = Command::new("flatpak-spawn")
|
|
||||||
.arg("--host")
|
|
||||||
.arg("podman")
|
|
||||||
.arg("container")
|
|
||||||
.arg("inspect")
|
|
||||||
.arg(self.name.clone())
|
|
||||||
.output()
|
|
||||||
.expect("Failed to execute command");
|
|
||||||
|
|
||||||
let output = String::from_utf8_lossy(&output.stdout).to_string();
|
|
||||||
let inspect_result = ToolbxContainer::parse_status(output.as_str())?;
|
|
||||||
self.status = ToolbxStatus::from_str(inspect_result.state.status.as_str())?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn stop(&mut self) -> Result<(), ToolbxError> {
|
|
||||||
let output = Command::new("flatpak-spawn")
|
|
||||||
.arg("--host") //Command::new("podman")
|
|
||||||
.arg("podman")
|
|
||||||
.arg("stop")
|
|
||||||
.arg(self.name.clone())
|
|
||||||
.output();
|
|
||||||
|
|
||||||
if output.is_err() {
|
|
||||||
return Err(ToolbxError::CommandExecutionError(
|
|
||||||
output.unwrap_err().to_string(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
let output = output.unwrap();
|
|
||||||
|
|
||||||
// Success: Output { status: ExitStatus(unix_wait_status(0)), stdout: "tbx_name\n", stderr: "" }
|
|
||||||
//Fail:
|
|
||||||
// Output {
|
|
||||||
// status: ExitStatus(unix_wait_status(32000)),
|
|
||||||
// stdout: "",
|
|
||||||
// stderr: "Error: no container with name or ID \"tbx_name\" found: no such container\n"
|
|
||||||
// }
|
|
||||||
|
|
||||||
if output.status.code() == Some(0) {
|
|
||||||
self.status = ToolbxStatus::Exited;
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(ToolbxError::CommandUnsuccessfulError(
|
|
||||||
String::from_utf8_lossy(&output.stderr).into_owned(),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn start(&mut self) -> Result<(), ToolbxError> {
|
|
||||||
let output = Command::new("flatpak-spawn")
|
|
||||||
.arg("--host") //Command::new("podman")
|
|
||||||
.arg("podman")
|
|
||||||
.arg("start")
|
|
||||||
.arg(self.name.clone())
|
|
||||||
.output();
|
|
||||||
|
|
||||||
if output.is_err() {
|
|
||||||
return Err(ToolbxError::CommandExecutionError(
|
|
||||||
output.unwrap_err().to_string(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
let output = output.unwrap();
|
|
||||||
|
|
||||||
// Success: status: Output { ExitStatus(unix_wait_status(0)), stdout: "tbx_name\n", stderr: "" }
|
|
||||||
// Fail: status:
|
|
||||||
// Output {
|
|
||||||
// status: ExitStatus(unix_wait_status(32000)),
|
|
||||||
// stdout: "",
|
|
||||||
// stderr: "Error: no container with name or ID \"tbx_name\" found: no such container\n"
|
|
||||||
// }
|
|
||||||
|
|
||||||
if output.status.code() == Some(0) {
|
|
||||||
self.status = ToolbxStatus::Running;
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(ToolbxError::CommandUnsuccessfulError(
|
|
||||||
String::from_utf8_lossy(&output.stderr).into_owned(),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_start_1non_existing_container() {
|
|
||||||
// TODO: create container that exists based on simple image
|
|
||||||
// run command
|
|
||||||
// delete container
|
|
||||||
//let tbx = ToolbxContainer{created: "".to_string(), id: "".to_string(), name: "latex".to_string(), image: "".to_string(), status: ToolbxStatus::Exited};
|
|
||||||
|
|
||||||
//tbx.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_inspect_parsing() {
|
|
||||||
let podman_inspect = concat!(
|
|
||||||
"[{",
|
|
||||||
"\"Id\": \"ae05203091ab4cdf047a9aeba6af8a7bed8105f7f59d09a35d2b64c837ecac0d\",",
|
|
||||||
"\"Created\": \"2021-12-10T20:51:43.140418098+01:00\",",
|
|
||||||
"\"State\": {",
|
|
||||||
"\"Status\": \"running\"",
|
|
||||||
"},",
|
|
||||||
"\"Image\": \"ab8bc106d4a710a7a27c538762864610467b3559f80b413d30e0a1bfcfe272a5\",",
|
|
||||||
"\"ImageName\": \"registry.fedoraproject.org/fedora-toolbox:35\",",
|
|
||||||
"\"Name\": \"rust\"",
|
|
||||||
"}]"
|
|
||||||
);
|
|
||||||
let inspect_info = ToolbxContainer::parse_status(podman_inspect).unwrap();
|
|
||||||
assert_eq!("running", inspect_info.state.status);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_start_non_existing_container() {
|
|
||||||
let name = "zy2lM6BdZoTnKHaVPkUJ".to_string();
|
|
||||||
let mut tbx = ToolbxContainer {
|
|
||||||
created: "".to_string(),
|
|
||||||
id: "".to_string(),
|
|
||||||
name: name.clone(),
|
|
||||||
image: "".to_string(),
|
|
||||||
status: ToolbxStatus::Exited,
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
Err(ToolbxError::CommandUnsuccessfulError(format!(
|
|
||||||
"Error: no container with name or ID \"{}\" found: no such container\n",
|
|
||||||
name
|
|
||||||
))),
|
|
||||||
tbx.start()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run_cmd_toolbx_list_containers() -> String {
|
|
||||||
let output = Command::new("flatpak-spawn")
|
|
||||||
.arg("--host")
|
|
||||||
.arg("toolbox")
|
|
||||||
.arg("list")
|
|
||||||
.arg("--containers")
|
|
||||||
.output()
|
|
||||||
.expect("Failed to execute command");
|
|
||||||
|
|
||||||
println!("{:?}", String::from_utf8_lossy(&output.stdout).to_string());
|
|
||||||
|
|
||||||
String::from_utf8_lossy(&output.stdout).to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
#[ignore]
|
|
||||||
fn test_cmd_list_containers() {
|
|
||||||
// This requires toolbx to be installed
|
|
||||||
let toolbox_cmd_container_header =
|
|
||||||
"CONTAINER ID CONTAINER NAME CREATED STATUS IMAGE NAME";
|
|
||||||
assert!(run_cmd_toolbx_list_containers().starts_with(toolbox_cmd_container_header));
|
|
||||||
}
|
|
||||||
|
|
||||||
fn tokenize_line_list_containers(line: &str) -> Vec<String> {
|
|
||||||
let mut tokens = Vec::<String>::new();
|
|
||||||
let mut current_token = Vec::<char>::new();
|
|
||||||
|
|
||||||
let mut whitespace_section = false;
|
|
||||||
|
|
||||||
let mut iter = line.chars().peekable();
|
|
||||||
while let Some(&c) = iter.peek() {
|
|
||||||
match (whitespace_section, c) {
|
|
||||||
(false, ' ') => {
|
|
||||||
iter.next();
|
|
||||||
if Some(' ') == iter.peek().map(|x| x.clone()) {
|
|
||||||
whitespace_section = true;
|
|
||||||
} else {
|
|
||||||
current_token.push(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(true, ' ') => {
|
|
||||||
iter.next();
|
|
||||||
}
|
|
||||||
(true, c) => {
|
|
||||||
whitespace_section = false;
|
|
||||||
tokens.push(current_token.into_iter().collect());
|
|
||||||
current_token = Vec::new();
|
|
||||||
current_token.push(c);
|
|
||||||
iter.next();
|
|
||||||
}
|
|
||||||
(false, c) => {
|
|
||||||
current_token.push(c);
|
|
||||||
iter.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tokens.push(current_token.into_iter().collect());
|
|
||||||
|
|
||||||
tokens
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_tokenize_line_list_containers() {
|
|
||||||
let toolbox_cmd_container_header = "ae05203091ab rust 4 months ago \
|
|
||||||
running registry.fedoraproject.org/fedora-toolbox:35";
|
|
||||||
|
|
||||||
let target = vec![
|
|
||||||
"ae05203091ab",
|
|
||||||
"rust",
|
|
||||||
"4 months ago",
|
|
||||||
"running",
|
|
||||||
"registry.fedoraproject.org/fedora-toolbox:35",
|
|
||||||
];
|
|
||||||
let result = tokenize_line_list_containers(toolbox_cmd_container_header);
|
|
||||||
assert_eq!(target, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_line_list_containers(line: &str) -> Result<ToolbxContainer, ToolbxError> {
|
|
||||||
let tokens = tokenize_line_list_containers(line);
|
|
||||||
if tokens.len() != 5 {
|
|
||||||
panic! {"Expected 5 tokens found {} in {:?}", tokens.len(), tokens};
|
|
||||||
}
|
|
||||||
Ok(ToolbxContainer {
|
|
||||||
id: tokens[0].clone(),
|
|
||||||
name: tokens[1].clone(),
|
|
||||||
created: tokens[2].clone(),
|
|
||||||
status: ToolbxStatus::from_str(&tokens[3])?,
|
|
||||||
image: tokens[4].clone(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_line_list_containers() {
|
|
||||||
let toolbox_cmd_container_header = "ae05203091ab rust 4 months ago \
|
|
||||||
running registry.fedoraproject.org/fedora-toolbox:35";
|
|
||||||
|
|
||||||
let target = ToolbxContainer {
|
|
||||||
id: "ae05203091ab".to_string(),
|
|
||||||
name: "rust".to_string(),
|
|
||||||
created: "4 months ago".to_string(),
|
|
||||||
status: ToolbxStatus::Running,
|
|
||||||
image: "registry.fedoraproject.org/fedora-toolbox:35".to_string(),
|
|
||||||
};
|
|
||||||
let result = parse_line_list_containers(toolbox_cmd_container_header);
|
|
||||||
assert_eq!(target, result.unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_cmd_list_containers(output: &str) -> Vec<ToolbxContainer> {
|
|
||||||
let lines = output.trim().split("\n").skip(1);
|
|
||||||
println!("{:?}", lines);
|
|
||||||
lines.map(parse_line_list_containers).flatten().collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_parse_cmd_list_containers() {
|
|
||||||
// This requires toolbx to be installed
|
|
||||||
let toolbox_cmd_container_header = concat!(
|
|
||||||
"CONTAINER ID CONTAINER NAME CREATED STATUS IMAGE NAME\n",
|
|
||||||
"cee1002b5f0b fedora-toolbox-35 2 months ago exited registry.fedoraproject.org/fedora-toolbox:35\n",
|
|
||||||
"9b611313bf65 latex 4 months ago configured registry.fedoraproject.org/fedora-toolbox:35\n",
|
|
||||||
"1235203091ab website 4 months ago created registry.fedoraproject.org/fedora-toolbox:35\n",
|
|
||||||
"ae05203091ab rust 4 months ago running registry.fedoraproject.org/fedora-toolbox:35\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
let desired_result = vec![
|
|
||||||
ToolbxContainer {
|
|
||||||
id: "cee1002b5f0b".to_string(),
|
|
||||||
name: "fedora-toolbox-35".to_string(),
|
|
||||||
created: "2 months ago".to_string(),
|
|
||||||
status: ToolbxStatus::Exited,
|
|
||||||
image: "registry.fedoraproject.org/fedora-toolbox:35".to_string(),
|
|
||||||
},
|
|
||||||
ToolbxContainer {
|
|
||||||
id: "9b611313bf65".to_string(),
|
|
||||||
name: "latex".to_string(),
|
|
||||||
created: "4 months ago".to_string(),
|
|
||||||
status: ToolbxStatus::Configured,
|
|
||||||
image: "registry.fedoraproject.org/fedora-toolbox:35".to_string(),
|
|
||||||
},
|
|
||||||
ToolbxContainer {
|
|
||||||
id: "1235203091ab".to_string(),
|
|
||||||
name: "website".to_string(),
|
|
||||||
created: "4 months ago".to_string(),
|
|
||||||
status: ToolbxStatus::Created,
|
|
||||||
image: "registry.fedoraproject.org/fedora-toolbox:35".to_string(),
|
|
||||||
},
|
|
||||||
ToolbxContainer {
|
|
||||||
id: "ae05203091ab".to_string(),
|
|
||||||
name: "rust".to_string(),
|
|
||||||
created: "4 months ago".to_string(),
|
|
||||||
status: ToolbxStatus::Running,
|
|
||||||
image: "registry.fedoraproject.org/fedora-toolbox:35".to_string(),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
for (result, desired) in zip(
|
|
||||||
parse_cmd_list_containers(toolbox_cmd_container_header).iter(),
|
|
||||||
desired_result.iter(),
|
|
||||||
) {
|
|
||||||
assert_eq!(result, desired)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user