Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67094b6e8f |
No files matched your search
@@ -0,0 +1,36 @@
|
||||
# Compile and bundle the gui into Android APKs
|
||||
# The resulting APKs are uploaded to gitea as artifacts, attached to the workflow run.
|
||||
|
||||
name: APK Builder
|
||||
run-name: Build Android APK
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build-apk:
|
||||
runs-on: amd64
|
||||
container:
|
||||
image: docker.nubo.sh/inkopslista-builder:2026-01-11
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [aarch64, x86_64]
|
||||
steps:
|
||||
# git clone
|
||||
- name: Check out repository code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# set the name of the output .apk based on commit and architecture
|
||||
- run: echo "SHA_SHORT=$(echo ${{ gitea.sha }} | head -c 8)" >> $GITEA_ENV
|
||||
- run: echo "OUT_NAME=inkopslista.${{ env.SHA_SHORT }}.${{ matrix.arch }}.apk" >> $GITEA_ENV
|
||||
|
||||
# build the apk
|
||||
- run: cargo apk build --lib --release -p inkopslista --target ${{ matrix.arch }}-linux-android
|
||||
- run: mv "$CARGO_TARGET_DIR/release/apk/inkopslista.apk" "$OUT_NAME"
|
||||
|
||||
# upload the apk to gitea
|
||||
- uses: https://gitea.com/actions/gitea-upload-artifact@v4
|
||||
with:
|
||||
name : "${{ env.OUT_NAME }}"
|
||||
path: "${{ env.OUT_NAME }}"
|
||||
if-no-files-found: error
|
||||
overwrite: true
|
||||
retention-days: 360 # delete it after one year
|
||||
Generated
+2010
-1154
File diff suppressed because it is too large.
Load diff
@@ -5,12 +5,3 @@ members = [
|
||||
"srv",
|
||||
"gui",
|
||||
]
|
||||
|
||||
# Enable max optimizations for dependencies, but not for our code:
|
||||
# Very helpful when developing in Slint.
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 3
|
||||
|
||||
# Enable only a small amount of optimization in debug mode
|
||||
[profile.dev]
|
||||
opt-level = 1
|
||||
+2
-1
@@ -63,7 +63,8 @@ RUN wasm-pack build --release --target web
|
||||
FROM scratch
|
||||
|
||||
ENV RUST_LOG="info"
|
||||
ENV BIND="0.0.0.0:8000"
|
||||
ENV ROCKET_ADDRESS="0.0.0.0"
|
||||
ENV ROCKET_PORT="8000"
|
||||
|
||||
VOLUME ["/data"]
|
||||
ENV DB_PATH="/data/db.sqlite"
|
||||
|
||||
+3
-2
@@ -39,7 +39,7 @@ serde_json = "1.0.148"
|
||||
anyhow = "1.0.100"
|
||||
|
||||
[dependencies.slint]
|
||||
version = "1.18.0"
|
||||
version = "1.17.1"
|
||||
default-features = false
|
||||
features = [
|
||||
"live-preview",
|
||||
@@ -49,6 +49,7 @@ features = [
|
||||
"backend-android-activity-06",
|
||||
]
|
||||
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
tokio = { version = "1.48.0", default-features = false, features = ["fs", "rt-multi-thread"] }
|
||||
xdg = "3.0.0"
|
||||
@@ -62,4 +63,4 @@ wasm-bindgen-futures = "0.4.56"
|
||||
web-sys = "0.3.83"
|
||||
|
||||
[build-dependencies]
|
||||
slint-build = "1.18.0"
|
||||
slint-build = "1.17.1"
|
||||
+1
-3
@@ -71,7 +71,7 @@ async fn put_category(
|
||||
) -> Result<(), anyhow::Error> {
|
||||
let client = reqwest::Client::new();
|
||||
let url: Url = format!(
|
||||
"{address}/api/favorites/{itemname}/category",
|
||||
"{address}/api/favourites/{itemname}/category",
|
||||
address = conf.lock().unwrap().address
|
||||
)
|
||||
.parse()?;
|
||||
@@ -93,7 +93,6 @@ fn update_slint_list(new_list: Vec<Item>, list: &VecModel<ui::SItem>) {
|
||||
name: item.name.to_shared_string(),
|
||||
checked: item.data.checked,
|
||||
amount: item.data.amount as i32,
|
||||
just_added: false,
|
||||
})
|
||||
.for_each(|item| list.push(item));
|
||||
}
|
||||
@@ -197,7 +196,6 @@ pub fn run() -> Result<(), anyhow::Error> {
|
||||
checked: false,
|
||||
name: item.clone(),
|
||||
amount: 1,
|
||||
just_added: true,
|
||||
});
|
||||
let conf = conf.clone();
|
||||
io.spawn(async move || {
|
||||
|
||||
+36
-61
@@ -9,13 +9,12 @@ import {
|
||||
GridBox,
|
||||
HorizontalBox,
|
||||
ComboBox,
|
||||
Palette,
|
||||
Spinner,
|
||||
SpinBox,
|
||||
Palette, Spinner, SpinBox,
|
||||
} from "std-widgets.slint";
|
||||
import { SettingsView } from "settings.slint";
|
||||
import { ConnectionStatus, State, SItem, SButtonItem } from "state.slint";
|
||||
export { ConnectionStatus, State, SItem }
|
||||
|
||||
component GoodListItem inherits Rectangle {
|
||||
in-out property <SItem> item;
|
||||
background: Palette.alternate-background;
|
||||
@@ -113,23 +112,6 @@ component PlusMinus inherits HorizontalLayout {
|
||||
|
||||
component GoodListItemAdd inherits Rectangle {
|
||||
in-out property <SItem> item;
|
||||
// Animate when this item appears.
|
||||
transform-scale: item.just-added ? 90% : 100%;
|
||||
opacity: item.just-added ? 0 : 100%;
|
||||
init => {
|
||||
self.transform-scale = 100%;
|
||||
self.opacity = 100%;
|
||||
item.just-added = false;
|
||||
}
|
||||
animate transform-scale {
|
||||
duration: 500ms;
|
||||
easing: ease-out-bounce;
|
||||
}
|
||||
animate opacity {
|
||||
duration: 300ms;
|
||||
easing: ease-out;
|
||||
}
|
||||
|
||||
background: Palette.alternate-background;
|
||||
border-radius: 8pt;
|
||||
border-width: 10pt;
|
||||
@@ -186,7 +168,7 @@ component GoodsListAdd {
|
||||
|
||||
for item in items: VerticalLayout {
|
||||
GoodListItemAdd {
|
||||
item <=> item;
|
||||
item: item;
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
@@ -203,21 +185,19 @@ component GoodButtons inherits ScrollView {
|
||||
|
||||
property <int> count-x: floor(root.width / (button-min-width + button-spacing));
|
||||
property <int> count-y: ceil(State.favorites.length / count-x);
|
||||
property <length> button-width: ((root.width + button-spacing) / count-x) - button-spacing;
|
||||
property <length> button-width: ((self.width + button-spacing ) / count-x) - button-spacing;
|
||||
|
||||
content-height: (count-y * (button-height + button-spacing));
|
||||
viewport-height: (count-y * (button-height + button-spacing));
|
||||
mouse-drag-pan-enabled: true;
|
||||
vertical-scrollbar-policy: always-off;
|
||||
|
||||
FlexboxLayout {
|
||||
spacing: button-spacing;
|
||||
for item in State.favorites: Button {
|
||||
width: root.button-width;
|
||||
height: root.button-height;
|
||||
text: item.name;
|
||||
clicked => {
|
||||
State.add-to-list(item.name);
|
||||
}
|
||||
for item[idx] in State.favorites: Button {
|
||||
x: floor(mod(idx, count-x)) * (root.button-width + root.button-spacing);
|
||||
y: floor(idx / count-x) * (root.button-height + root.button-spacing);
|
||||
width: root.button-width;
|
||||
height: root.button-height;
|
||||
text: item.name;
|
||||
clicked => {
|
||||
State.add-to-list(item.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -245,7 +225,7 @@ component ConnStatusIndicator inherits Rectangle {
|
||||
}
|
||||
|
||||
component RefreshButton inherits HorizontalLayout {
|
||||
spacing: 8px;
|
||||
spacing: 8px;
|
||||
alignment: center;
|
||||
Button {
|
||||
text: "Refresh";
|
||||
@@ -254,7 +234,6 @@ component RefreshButton inherits HorizontalLayout {
|
||||
State.refresh-list();
|
||||
}
|
||||
}
|
||||
|
||||
ConnStatusIndicator { }
|
||||
}
|
||||
|
||||
@@ -264,7 +243,7 @@ component AddView inherits VerticalLayout {
|
||||
padding: 8px;
|
||||
spacing: 8px;
|
||||
|
||||
RefreshButton { }
|
||||
RefreshButton {}
|
||||
|
||||
goods := GoodsListAdd {
|
||||
items <=> list;
|
||||
@@ -302,25 +281,24 @@ component AddView inherits VerticalLayout {
|
||||
GoodButtons { }
|
||||
}
|
||||
|
||||
component ShopView inherits ScrollView {
|
||||
component ShopView inherits VerticalLayout {
|
||||
in property <[SItem]> list;
|
||||
mouse-drag-pan-enabled: true;
|
||||
VerticalLayout {
|
||||
RefreshButton { }
|
||||
|
||||
padding: 8px;
|
||||
spacing: 8px;
|
||||
goods := GoodsList {
|
||||
items <=> list;
|
||||
}
|
||||
padding: 8px;
|
||||
spacing: 8px;
|
||||
|
||||
HorizontalLayout {
|
||||
padding: 12px;
|
||||
Button {
|
||||
text: "I am done hehe";
|
||||
clicked => {
|
||||
State.delete-checked();
|
||||
}
|
||||
RefreshButton { }
|
||||
|
||||
goods := GoodsList {
|
||||
items <=> list;
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
padding: 12px;
|
||||
Button {
|
||||
text: "I am done hehe";
|
||||
clicked => {
|
||||
State.delete-checked();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -344,26 +322,23 @@ component CatItem inherits HorizontalBox {
|
||||
}
|
||||
|
||||
|
||||
component CatView inherits ScrollView {
|
||||
component CatView inherits VerticalLayout {
|
||||
in-out property <[SButtonItem]> cats;
|
||||
mouse-drag-pan-enabled: true;
|
||||
VerticalLayout {
|
||||
for item in cats: CatItem {
|
||||
item: item;
|
||||
}
|
||||
|
||||
for item in cats: CatItem {
|
||||
item: item;
|
||||
}
|
||||
}
|
||||
|
||||
export component App inherits Window {
|
||||
in property <int> prefered-start-tab: 0;
|
||||
|
||||
title: "Inköpslista";
|
||||
icon: @image-url("../images/icon.svg");
|
||||
|
||||
preferred-height: 700px;
|
||||
preferred-width: 480px;
|
||||
|
||||
tabs := TabWidget {
|
||||
current-index: prefered-start-tab;
|
||||
TabWidget {
|
||||
Tab {
|
||||
title: "Add";
|
||||
AddView {
|
||||
|
||||
@@ -2,10 +2,6 @@ export struct SItem {
|
||||
name: string,
|
||||
checked: bool,
|
||||
amount: int,
|
||||
|
||||
/// Whether the item was just added by the user.
|
||||
/// Determines whether the add-animation plays.
|
||||
just_added: bool,
|
||||
}
|
||||
|
||||
export struct SButtonItem{
|
||||
|
||||
+1
-3
@@ -4,11 +4,9 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
rocket = { version = "0.5.1", features = ["json"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = "1.0.145"
|
||||
inkopslista-lib = { path = "../lib" }
|
||||
sqlite = "0.37.0"
|
||||
clap = { version = "4.6.6", features = ["derive", "env"] }
|
||||
axum = { version = "0.8.9", features = ["http1"] }
|
||||
tower-http = { version = "0.7.0", features = ["fs", "trace", "compression-gzip"] }
|
||||
tokio = { version = "1.53.1", features = ["full"] }
|
||||
+56
-49
@@ -1,25 +1,32 @@
|
||||
use axum::extract::{Path, State};
|
||||
use axum::response::Html;
|
||||
use axum::routing::method_routing::{get, put};
|
||||
use axum::{Json, Router};
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
use clap::Parser;
|
||||
use inkopslista_lib::{ButtonItem, Item, ItemData};
|
||||
use rocket::{
|
||||
State,
|
||||
fs::{FileServer, NamedFile},
|
||||
serde::json::Json,
|
||||
shield::Shield,
|
||||
};
|
||||
use sqlite::ConnectionThreadSafe;
|
||||
use std::net::SocketAddr;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use tower_http::services::ServeDir;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
/// The directory where the web files for the gui is stored.
|
||||
fn www_path() -> &'static std::path::Path {
|
||||
std::path::Path::new("./www")
|
||||
fn www_path() -> &'static Path {
|
||||
Path::new("./www")
|
||||
}
|
||||
|
||||
async fn index() -> Html<&'static str> {
|
||||
Html(include_str!("../../gui/index.html"))
|
||||
/// Serve `index.html` from [`www_path`].
|
||||
#[get("/")]
|
||||
async fn index() -> NamedFile {
|
||||
NamedFile::open(www_path().join("index.html"))
|
||||
.await
|
||||
.expect("index.html")
|
||||
}
|
||||
|
||||
async fn get_list(State(db): State<Arc<ConnectionThreadSafe>>) -> Json<Vec<Item>> {
|
||||
#[get("/api/list")]
|
||||
fn get_list(db: &State<ConnectionThreadSafe>) -> Json<Vec<Item>> {
|
||||
// TODO errorhandling
|
||||
let query = "SELECT * FROM list;";
|
||||
let list = db
|
||||
@@ -40,7 +47,8 @@ async fn get_list(State(db): State<Arc<ConnectionThreadSafe>>) -> Json<Vec<Item>
|
||||
Json(list)
|
||||
}
|
||||
|
||||
async fn get_favorites(State(db): State<Arc<ConnectionThreadSafe>>) -> Json<Vec<ButtonItem>> {
|
||||
#[get("/api/favorites")]
|
||||
fn get_favorites(db: &State<ConnectionThreadSafe>) -> Json<Vec<ButtonItem>> {
|
||||
let opt = Opt::parse();
|
||||
|
||||
let query = format!("WITH favorites as (SELECT itemname, COUNT(date_added) day_count
|
||||
@@ -67,30 +75,24 @@ async fn get_favorites(State(db): State<Arc<ConnectionThreadSafe>>) -> Json<Vec<
|
||||
Json(list)
|
||||
}
|
||||
|
||||
async fn put_category(
|
||||
State(db): State<Arc<ConnectionThreadSafe>>,
|
||||
Path(item): Path<String>,
|
||||
category: String,
|
||||
) {
|
||||
#[put("/api/favourites/<itemname>/category", data = "<category>")]
|
||||
fn put_category(db: &State<ConnectionThreadSafe>, itemname: &str, category: &str) {
|
||||
let query = "INSERT INTO categories VALUES (?, ?) ON CONFLICT DO UPDATE SET category = ?";
|
||||
let mut statement = db.prepare(query).unwrap();
|
||||
statement.bind((1, item.as_str())).unwrap();
|
||||
statement.bind((2, category.as_str())).unwrap();
|
||||
statement.bind((3, category.as_str())).unwrap();
|
||||
statement.bind((1, itemname)).unwrap();
|
||||
statement.bind((2, category)).unwrap();
|
||||
statement.bind((3, category)).unwrap();
|
||||
while let Ok(sqlite::State::Row) = statement.next() {}
|
||||
}
|
||||
|
||||
async fn put_list(
|
||||
State(db): State<Arc<ConnectionThreadSafe>>,
|
||||
Path(item): Path<String>,
|
||||
Json(data): Json<ItemData>,
|
||||
) {
|
||||
#[put("/api/list/<item>", data = "<data>")]
|
||||
fn put_list(item: &str, data: Json<ItemData>, db: &State<ConnectionThreadSafe>) {
|
||||
// TODO: errorhandling
|
||||
// TODO: transaction
|
||||
let query =
|
||||
"INSERT INTO list VALUES(?, ?, ?) ON CONFLICT DO UPDATE SET checked = ?, amount = ?;";
|
||||
let mut statement = db.prepare(query).unwrap();
|
||||
statement.bind((1, item.as_str())).unwrap();
|
||||
let data = data.into_inner();
|
||||
statement.bind((1, item)).unwrap();
|
||||
statement.bind((2, data.checked as i64)).unwrap();
|
||||
statement.bind((3, data.amount)).unwrap();
|
||||
statement.bind((4, data.checked as i64)).unwrap();
|
||||
@@ -98,45 +100,50 @@ async fn put_list(
|
||||
while let Ok(sqlite::State::Row) = statement.next() {}
|
||||
let query = "INSERT INTO adds VALUES(?, strftime('%s','now')) ON CONFLICT DO NOTHING";
|
||||
let mut statement = db.prepare(query).unwrap();
|
||||
statement.bind((1, item.as_str())).unwrap();
|
||||
statement.bind((1, item)).unwrap();
|
||||
while let Ok(sqlite::State::Row) = statement.next() {}
|
||||
}
|
||||
|
||||
async fn delete_item(State(db): State<Arc<ConnectionThreadSafe>>, Path(item): Path<String>) {
|
||||
#[delete("/api/list/<item>")]
|
||||
fn delete_item(item: &str, db: &State<ConnectionThreadSafe>) {
|
||||
// TODO: Eror handling
|
||||
let query = "DELETE FROM list WHERE itemname = ?";
|
||||
let mut statement = db.prepare(query).unwrap();
|
||||
statement.bind((1, item.as_str())).unwrap();
|
||||
statement.bind((1, item)).unwrap();
|
||||
while let Ok(sqlite::State::Row) = statement.next() {}
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Opt {
|
||||
#[clap(long, env = "BIND", default_value = "127.0.0.1:8000")]
|
||||
bind: SocketAddr,
|
||||
#[clap(long, env = "DB_PATH")]
|
||||
db_path: PathBuf,
|
||||
#[clap(long, env = "NUM_DAYS", default_value = "5")]
|
||||
num_days: u32,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
#[launch]
|
||||
fn rocket() -> _ {
|
||||
let opt = Opt::parse();
|
||||
let db = sqlite::Connection::open_thread_safe(opt.db_path).unwrap();
|
||||
db.execute(include_str!("db/init.sql"))
|
||||
.expect("unable to initialize database");
|
||||
let db = Arc::new(db);
|
||||
|
||||
let app = Router::new()
|
||||
.route("/", get(index))
|
||||
.route("/api/list", get(get_list))
|
||||
.route("/api/list/{item}", put(put_list).delete(delete_item))
|
||||
.route("/api/favorites", get(get_favorites))
|
||||
.route("/api/favorites/{item}/category", put(put_category))
|
||||
.fallback_service(ServeDir::new(www_path()))
|
||||
.with_state(db);
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(opt.bind).await.unwrap();
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
rocket::build()
|
||||
.attach(
|
||||
Shield::default()
|
||||
// Allow content to be served through iframes
|
||||
.disable::<rocket::shield::Frame>(),
|
||||
)
|
||||
.manage(db)
|
||||
.mount(
|
||||
"/",
|
||||
routes![
|
||||
index,
|
||||
get_list,
|
||||
put_list,
|
||||
delete_item,
|
||||
get_favorites,
|
||||
put_category
|
||||
],
|
||||
)
|
||||
.mount("/", FileServer::from(www_path()))
|
||||
}
|
||||
Reference in new issue
Block a user