Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bde94573f4 | ||
|
|
7967b90b99 | ||
|
|
d54c5c5b19 | ||
|
|
4ecabd56d2 | ||
|
|
68f9187776 | ||
|
|
6ff30ee6b1 | ||
|
|
7ec153aa5c | ||
|
|
f61c65b440 | ||
|
|
808c692026 | ||
|
|
025c2a5ca8 | ||
|
|
247d7d63ee | ||
|
|
ee6609dad0 | ||
|
|
32f1ad00ba | ||
|
|
3007696783 | ||
|
|
4fcd59890b | ||
|
|
eecbb33f18 | ||
|
|
41587d7f0f | ||
|
|
72fc32b970 | ||
|
|
c6e7977396 | ||
|
|
7a5c147d64 | ||
|
|
eceaa0380b | ||
|
|
9493b9e01d | ||
|
|
74d19b7cf8 | ||
|
|
d092192325 | ||
|
|
b9d1e1bd35 | ||
|
|
1818096275 | ||
|
|
78fe91d184 | ||
|
|
eed4c75706 | ||
|
|
d4c0f367f9 | ||
|
|
fdeea88672 | ||
|
|
cfa0b5c904 | ||
|
|
3e38257654 | ||
|
|
2bcccf0b12 |
No files matched your search
@@ -8,9 +8,3 @@ libfontconfig1-dev
|
||||
libpango1.0-dev
|
||||
xvfb
|
||||
xauth
|
||||
libgtk-3-dev
|
||||
python3-pil
|
||||
tesseract-ocr
|
||||
imagemagick
|
||||
gnumeric
|
||||
zenity
|
||||
@@ -34,7 +34,7 @@ jobs:
|
||||
- name: Install CLI test dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y openssl xclip xvfb xauth tesseract-ocr imagemagick
|
||||
sudo apt-get install -y openssl xclip xvfb xauth
|
||||
- name: Install Emscripten
|
||||
run: |
|
||||
set -euo pipefail
|
||||
@@ -52,19 +52,11 @@ jobs:
|
||||
env:
|
||||
WERK_WEB_BROWSER: google-chrome
|
||||
run: make web-smoke
|
||||
- name: Upload browser failure diagnostics
|
||||
if: failure()
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: werk-browser-diagnostics-ci
|
||||
path: build/web-test/*.png
|
||||
if-no-files-found: ignore
|
||||
- name: Verify generated site
|
||||
run: |
|
||||
test -s build/site/index.html
|
||||
test -s build/site/index.wasm
|
||||
test -s build/site/sw.js
|
||||
test -s build/site/assets.json
|
||||
test -s build/site/app/index.html
|
||||
test -s build/site/app/index.wasm
|
||||
- name: Check fastlane metadata
|
||||
run: |
|
||||
set -eu
|
||||
@@ -118,8 +110,7 @@ jobs:
|
||||
path: |
|
||||
build/werk
|
||||
build/apps
|
||||
build/pfp.webp
|
||||
build/tools
|
||||
build/pfp.png
|
||||
if-no-files-found: error
|
||||
|
||||
build-android:
|
||||
@@ -151,12 +142,15 @@ jobs:
|
||||
path: |
|
||||
droid/app/.cxx
|
||||
droid/app/build/intermediates/cxx
|
||||
key: android-native-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('src/*.zi', 'apps/*/*.zi', 'droid/app/src/main/cpp/CMakeLists.txt', 'droid/app/build.gradle', 'ziran.lock') }}
|
||||
key: android-native-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('src/*.zi', 'shared/*.zi', 'apps/*/*.zi', 'droid/app/src/main/cpp/CMakeLists.txt', 'droid/app/build.gradle', 'ziran.lock') }}
|
||||
restore-keys: |
|
||||
android-native-${{ runner.os }}-${{ runner.arch }}-
|
||||
- name: Install Android SDK components
|
||||
timeout-minutes: 15
|
||||
run: bash scripts/install_android_sdk.sh
|
||||
run: |
|
||||
set -euo pipefail
|
||||
SDKMANAGER="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
|
||||
yes | "$SDKMANAGER" --licenses >/dev/null || true
|
||||
"$SDKMANAGER" "platforms;android-36" "build-tools;34.0.0" "ndk;28.2.13676358" "cmake;3.22.1"
|
||||
- name: Build debug APK
|
||||
run: |
|
||||
set -euo pipefail
|
||||
@@ -164,22 +158,10 @@ jobs:
|
||||
make android-debug
|
||||
|
||||
android-input-test:
|
||||
name: ${{ matrix.name }}
|
||||
name: Android NativeActivity input
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 60
|
||||
needs: guard-package-urls
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- name: Android NativeActivity input
|
||||
api: 30
|
||||
image: default
|
||||
test: android-profile-test
|
||||
- name: Workbook Android documents
|
||||
api: 35
|
||||
image: google_apis
|
||||
test: workbook-android-test
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
@@ -188,33 +170,24 @@ jobs:
|
||||
java-version: '21'
|
||||
- uses: gradle/actions/setup-gradle@v3
|
||||
- name: Install Android SDK components
|
||||
timeout-minutes: 15
|
||||
run: bash scripts/install_android_sdk.sh 'platforms;android-${{ matrix.api }}'
|
||||
- name: Install screenshot OCR
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y tesseract-ocr python3-pil
|
||||
# Without /dev/kvm access the emulator runs unaccelerated and is too
|
||||
# slow to answer input before Android reports it not responding.
|
||||
- name: Enable KVM for the emulator
|
||||
run: |
|
||||
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
|
||||
sudo udevadm control --reload-rules
|
||||
sudo udevadm trigger --name-match=kvm
|
||||
set -euo pipefail
|
||||
SDKMANAGER="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
|
||||
yes | "$SDKMANAGER" --licenses >/dev/null || true
|
||||
"$SDKMANAGER" "platforms;android-36" "build-tools;34.0.0" "ndk;28.2.13676358" "cmake;3.22.1"
|
||||
- name: Run Android input tests
|
||||
uses: reactivecircus/android-emulator-runner@v2
|
||||
with:
|
||||
api-level: ${{ matrix.api }}
|
||||
api-level: 30
|
||||
arch: x86_64
|
||||
target: ${{ matrix.image }}
|
||||
target: default
|
||||
emulator-boot-timeout: 900
|
||||
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -no-metrics
|
||||
script: make android-emulator ${{ matrix.test }}
|
||||
script: make android-emulator android-input-test
|
||||
- uses: actions/upload-artifact@v4
|
||||
if: failure()
|
||||
with:
|
||||
name: android-input-test-reports-${{ matrix.api }}
|
||||
name: android-input-test-reports
|
||||
path: |
|
||||
build/android-input/
|
||||
build/workbook-android-test/
|
||||
if-no-files-found: ignore
|
||||
@@ -1,56 +0,0 @@
|
||||
name: Google Play testing bundle
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
bundle:
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 60
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '21'
|
||||
- uses: gradle/actions/setup-gradle@v4
|
||||
- name: Install build tools
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y build-essential cmake pkg-config libssl-dev
|
||||
bash scripts/install_android_sdk.sh
|
||||
- name: Prepare preserved release key
|
||||
env:
|
||||
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
|
||||
run: |
|
||||
test -n "$KEYSTORE_BASE64"
|
||||
umask 077
|
||||
mkdir -p "$HOME/.android"
|
||||
printf '%s' "$KEYSTORE_BASE64" | base64 -d > "$HOME/.android/pass-release.keystore"
|
||||
- name: Build signed testing candidate
|
||||
env:
|
||||
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}
|
||||
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
|
||||
run: |
|
||||
test -n "$KEYSTORE_PASSWORD"
|
||||
test -n "$KEY_ALIAS"
|
||||
make android-bundle
|
||||
- name: Validate the candidate
|
||||
run: |
|
||||
curl --fail --show-error --location --retry 3 \
|
||||
https://github.com/google/bundletool/releases/download/1.18.3/bundletool-all-1.18.3.jar \
|
||||
--output "$RUNNER_TEMP/bundletool.jar"
|
||||
python3 scripts/android-bundle-check.py "build/werk-$(cat VERSION).aab" \
|
||||
--bundletool "$RUNNER_TEMP/bundletool.jar" --version "$(cat VERSION)"
|
||||
- name: Remove temporary release key
|
||||
if: always()
|
||||
run: rm -f "$HOME/.android/pass-release.keystore"
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: werkzeug-play-testing
|
||||
path: build/*.aab
|
||||
if-no-files-found: error
|
||||
retention-days: 14
|
||||
@@ -73,7 +73,7 @@ jobs:
|
||||
run: |
|
||||
name="werk-linux-${{ matrix.arch }}"
|
||||
mkdir -p "build/release/$name"
|
||||
cp -R build/werk build/apps build/pfp.webp build/tools LICENSE README.md assets/app/icon.png "build/release/$name/"
|
||||
cp -R build/werk build/apps build/pfp.png LICENSE README.md assets/app/icon.png "build/release/$name/"
|
||||
tar -C build/release -czf "build/release/$name.tar.gz" "$name"
|
||||
make package-deb
|
||||
- name: Package AppImage
|
||||
@@ -124,12 +124,15 @@ jobs:
|
||||
path: |
|
||||
droid/app/.cxx
|
||||
droid/app/build/intermediates/cxx
|
||||
key: android-native-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('droid/app/src/main/cpp/CMakeLists.txt', 'droid/app/build.gradle', 'src/*.zi', 'apps/*/*.zi', 'ziran.lock') }}
|
||||
key: android-native-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('droid/app/src/main/cpp/CMakeLists.txt', 'droid/app/build.gradle', 'src/*.zi', 'shared/*.zi', 'apps/*/*.zi', 'ziran.lock') }}
|
||||
restore-keys: |
|
||||
android-native-${{ runner.os }}-${{ runner.arch }}-
|
||||
- name: Install Android SDK components
|
||||
timeout-minutes: 15
|
||||
run: bash scripts/install_android_sdk.sh
|
||||
run: |
|
||||
set -euo pipefail
|
||||
SDKMANAGER="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
|
||||
yes | "$SDKMANAGER" --licenses >/dev/null || true
|
||||
"$SDKMANAGER" "platforms;android-36" "build-tools;34.0.0" "ndk;28.2.13676358" "cmake;3.22.1"
|
||||
- name: Prepare Android signing key
|
||||
env:
|
||||
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
|
||||
@@ -149,6 +152,7 @@ jobs:
|
||||
chmod +x droid/gradlew
|
||||
export KRYON_DIR="$(./scripts/ziran.sh pkg path Kryon --locked)"
|
||||
export ZIRAN_ROOT="$(./scripts/ziran.sh pkg path ziran --locked)"
|
||||
export RAYLIB_DIR="$(./scripts/ziran.sh pkg path raylib --locked)/src"
|
||||
export LIBOQS_DIR="$(./scripts/ziran.sh pkg path liboqs --locked)"
|
||||
export MONOCYPHER_DIR="$(./scripts/ziran.sh pkg path monocypher --locked)"
|
||||
./droid/gradlew -p droid assembleRelease \
|
||||
@@ -172,12 +176,6 @@ jobs:
|
||||
test -s "build/release/werk-$VERSION.apk"
|
||||
test -s "build/release/werk-$VERSION-arm64-v8a.apk"
|
||||
test -s "build/release/werk-$VERSION-armeabi-v7a.apk"
|
||||
# Only a Google Play edition may hold a Google library, in its build
|
||||
# files as in its APK.
|
||||
- name: Keep Google libraries out of the APKs and their build files
|
||||
uses: kryonlabs/kryon/.github/actions/google-free@7217475dfa7f462939e47e3f0bc918aef248b179
|
||||
with:
|
||||
packages: build/release/werk-android*.apk
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: android
|
||||
@@ -204,10 +202,11 @@ jobs:
|
||||
cd build/site
|
||||
zip -qr ../werk-web.zip .
|
||||
|
||||
# The site root is the app: its page loads content-hashed script and
|
||||
# The whole app folder: its page loads content-hashed script and
|
||||
# Wasm names, and the service worker caches the files in assets.json.
|
||||
mkdir -p ../werk-html5
|
||||
cp -R . ../werk-html5/
|
||||
cp -R app/. ../werk-html5/
|
||||
cp -R icons/. ../werk-html5/icons/
|
||||
sed -i \
|
||||
-e 's#href="/manifest.webmanifest"#href="manifest.webmanifest"#g' \
|
||||
-e 's#href="/icons/#href="icons/#g' \
|
||||
|
||||
@@ -46,12 +46,8 @@ jobs:
|
||||
set -euo pipefail
|
||||
make site
|
||||
test -s build/site/index.html
|
||||
test -s build/site/index.wasm
|
||||
test -s build/site/sw.js
|
||||
- name: Install screenshot OCR
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y tesseract-ocr imagemagick
|
||||
test -s build/site/app/index.html
|
||||
test -s build/site/app/index.wasm
|
||||
- name: Verify browser input, storage, cache upgrades, and offline launch
|
||||
env:
|
||||
WERK_WEB_BROWSER: google-chrome
|
||||
|
||||
@@ -5,6 +5,3 @@
|
||||
__pycache__/
|
||||
*.pyc
|
||||
.wrangler/
|
||||
/backup/
|
||||
/work/
|
||||
/apps/*/build/
|
||||
@@ -5,13 +5,12 @@ first.
|
||||
|
||||
## Tools are separate apps
|
||||
|
||||
- Each tool builds into its own bundle, `build/apps/<tool>.zx`: Pass,
|
||||
Calculator and Clock from `apps/<tool>/`, Auth and Workbook from their own
|
||||
Ziran packages. The host (`src/apps.zi`) checks every call a bundle asks
|
||||
for and keeps each tool's files, assets and secret separate.
|
||||
- Tools never import another tool's modules. Code two tools need comes from
|
||||
a Ziran package, as SHA-256 and PBKDF2 come from `crypto`; no git
|
||||
submodules.
|
||||
- Each tool lives in `apps/<tool>/` and builds into its own bundle,
|
||||
`build/apps/<tool>.zib`. A tool reaches the host only through
|
||||
`shared/werk_app.zi`; the host (`src/apps.zi`) checks every call a
|
||||
bundle asks for and keeps each tool's files, assets and secret separate.
|
||||
- Tools never import another tool's modules. Code two tools need goes in
|
||||
`shared/`, as SHA-256 and PBKDF2 do.
|
||||
- Keep the host interface small and generic (files, clock, clipboard,
|
||||
key derivation, device secret, input). A new host call needs a new host
|
||||
build before any bundle can use it.
|
||||
@@ -24,10 +23,9 @@ first.
|
||||
- Never commit, print or log a real master password, Auth secret, otpauth
|
||||
link, export file or current code. Tests use fixture values only, such as
|
||||
the RFC 6238 keys.
|
||||
- Keep Pass's on-disk formats and `src/migrate.zi`. The owner's latest choice
|
||||
on 2026-10-23 is an update of the existing Android/F-Droid app: keep
|
||||
`xyz.waozi.pass` and its signing certificate, with the display name Werkzeug.
|
||||
Preserve existing Pass data and any separate `xyz.waozi.werk` installation.
|
||||
- Keep Pass's on-disk formats and the Android package `xyz.waozi.pass`:
|
||||
existing installations update in place and keep their saved master
|
||||
password. `src/migrate.zi` moves Pass's old files once; keep it.
|
||||
- Every file Werkzeug writes is private (0600 in 0700 folders).
|
||||
|
||||
## Platforms and tests
|
||||
|
||||
@@ -1,79 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
- Add Simple Calendar with Month, Week and Agenda views, recurring events, search and private local storage.
|
||||
- Include Task Manager from its separate `kryonlabs/taskmgr` package with live process monitoring, filtering, sorting, task termination, command launch and performance graphs.
|
||||
- Show a brief confirmation when Auth copies a code to the clipboard.
|
||||
- Show your account username in the top-right profile button.
|
||||
- Give Gallery matching artwork on Werkzeug Home and an icon in the Linux window switcher.
|
||||
- Use Mesh account sync and client imports while keeping existing account keys and Werkzeug data compatible.
|
||||
|
||||
- Embedded in Harmony's Sessions window, Werkzeug draws every colour from Harmony's theme and follows its changes; started on its own it keeps its own appearance.
|
||||
- Tap the whole Auth card to copy the current code as plain digits, while keeping Edit and the next-code preview.
|
||||
- Browse local photo folders and albums with Gallery on desktop and Android.
|
||||
- Remove the backgrounds from the five colorful tool icons.
|
||||
- Read the account picture back from the node without replacing a local choice still waiting to sync.
|
||||
- Auth shows grouped codes and the next code on clean cards, with a purple countdown line that turns orange halfway through.
|
||||
- Password fields in Profile start empty and show one mask character for each character you type.
|
||||
- Continue with an account already signed in to another Waozi app on Android, after approving the transfer there.
|
||||
- Signing out skips the backup warning once this account's key is backed up.
|
||||
- Open the newer account backups other waozi apps save.
|
||||
- Send the profile picture you choose to your node, so friends see it in every app.
|
||||
- Offer Entity's abstract profile pictures, like every other app, and keep the one you choose.
|
||||
- Continue as no longer crashes the other app when it was closed.
|
||||
- A fresh look: colorful artwork for each tool on Home, rounded tiles and softly tinted buttons that follow your accent color.
|
||||
|
||||
## [0.4.7] - 2026-10-28
|
||||
|
||||
- Use Workbook on Android and the web as well as Linux, with formulas, sheet tabs, automatic saving and document import/export.
|
||||
- Navigate Workbook cells with touch controls, and keep Android's keyboard focused while editing a cell.
|
||||
|
||||
## [0.4.6] - 2026-10-27
|
||||
|
||||
- Set an account alias with capitals, an @ or spaces; a taken alias now says so.
|
||||
|
||||
## [0.4.5] - 2026-10-26
|
||||
|
||||
- Fix Android opening to “Apps are unavailable”; Pass, Auth, Calculator and Clock load normally.
|
||||
|
||||
## [0.4.4] - 2026-10-23
|
||||
|
||||
- Werkzeug updates the existing Pass Android app using its original application ID and signing certificate, keeping its saved data.
|
||||
- The app continues to appear as Werkzeug, with Pass, Auth, Calculator and Clock together.
|
||||
|
||||
## [0.4.3] - 2026-10-23
|
||||
|
||||
- Werkzeug uses its own Android application ID, `xyz.waozi.werk`.
|
||||
- Werkzeug installs alongside legacy Pass, preserving the older app and its data.
|
||||
|
||||
## [0.4.2] - 2026-10-23
|
||||
|
||||
- Linux packages include the libraries needed for sync and importing QR-code pictures.
|
||||
- Packaging a new AppImage preserves previous downloads.
|
||||
|
||||
## [0.4.1] - 2026-10-23
|
||||
|
||||
- Open Pass, Auth, Calculator, Clock and Workbook directly from the Linux application menu, each with its own icon.
|
||||
- Desktop installs add shortcuts for Werkzeug and every tool to your configured desktop folder.
|
||||
- Tool windows show their own names and icons in the desktop switcher.
|
||||
|
||||
## [0.4.0] - 2026-10-19
|
||||
|
||||
- A new purple W logo across the app, Android and the website.
|
||||
- Calculator gets a Scientific mode.
|
||||
- Auth imports Google Authenticator, Aegis and Ente Auth exports, and on the desktop a picture of their QR code.
|
||||
- Rename an Auth account, note the websites it signs in to, or remove it.
|
||||
- Choose your own Daochi node, and pause sync without losing your account.
|
||||
- On the desktop, Profile manages your account: create it, import or back up its key, and link devices by QR code.
|
||||
- Sign in with a Daochi account key you already have, such as Inbe's.
|
||||
- `werk sync` and `werk auth` work without a window on Linux.
|
||||
- Reach every tool from the web app's mini version.
|
||||
- Fix the web version freezing when Clock opens.
|
||||
- Show π, √ and other symbols on phones older than Android 10.
|
||||
- Fix Profile breaking after choosing a file on desktops whose language writes decimals with a comma.
|
||||
- The `pass` command unlocks vaults whose text is wrapped with spaces or tabs on systems with OpenSSL 3.0.
|
||||
|
||||
## [0.3.1] - 2026-10-13
|
||||
|
||||
- Fix the web version on itch.io, which opened to a blank page.
|
||||
|
||||
@@ -1,51 +1,32 @@
|
||||
.DEFAULT_GOAL := all
|
||||
ZIRAN ?= ./scripts/ziran.sh
|
||||
# Gradle invokes make again for portable bundles. Inherited environment
|
||||
# variables otherwise export these shell-derived paths while resolving them.
|
||||
unexport ZIRAN_ROOT KRYON_DIR MINGCUTE_DIR LIBOQS_DIR MONOCYPHER_DIR QRCODE_DIR WORKBOOK_DIR TASKMGR_DIR ENTITY_DIR APPS_DIR AUTH_DIR CRYPTO_DIR
|
||||
# Local overrides refer to the real root repositories. Published builds
|
||||
# require the exact versions recorded in the committed lock.
|
||||
LOCK_FLAGS := $(if $(wildcard ziran.local.toml),,--locked)
|
||||
# Package resolution may build its compiler. Do not pass this make's target
|
||||
# overrides or jobserver descriptors to that independent package build.
|
||||
PACKAGE_ZIRAN = env -u MAKEFLAGS -u MFLAGS -u MAKEOVERRIDES $(ZIRAN)
|
||||
ZIRAN_ROOT = $(shell $(PACKAGE_ZIRAN) pkg path ziran $(LOCK_FLAGS))
|
||||
KRYON_DIR = $(shell $(PACKAGE_ZIRAN) pkg path kryon $(LOCK_FLAGS))
|
||||
MINGCUTE_DIR = $(shell $(PACKAGE_ZIRAN) pkg path mingcute $(LOCK_FLAGS))
|
||||
ZIRAN_ROOT = $(shell $(ZIRAN) pkg path ziran $(LOCK_FLAGS))
|
||||
KRYON_DIR = $(shell $(ZIRAN) pkg path kryon $(LOCK_FLAGS))
|
||||
RAYLIB_DIR = $(shell $(ZIRAN) pkg path raylib $(LOCK_FLAGS))/src
|
||||
MINGCUTE_DIR = $(shell $(ZIRAN) pkg path mingcute $(LOCK_FLAGS))
|
||||
# Account sync: ML-DSA-44 account keys from liboqs, and Ed25519, X25519,
|
||||
# BLAKE2b and XChaCha20-Poly1305 from Monocypher.
|
||||
LIBOQS_DIR = $(shell $(PACKAGE_ZIRAN) pkg path liboqs $(LOCK_FLAGS))
|
||||
MONOCYPHER_DIR = $(shell $(PACKAGE_ZIRAN) pkg path monocypher $(LOCK_FLAGS))
|
||||
QRCODE_DIR = $(shell $(PACKAGE_ZIRAN) pkg path qrcode $(LOCK_FLAGS))
|
||||
WORKBOOK_DIR = $(shell $(PACKAGE_ZIRAN) pkg path workbook $(LOCK_FLAGS))
|
||||
TASKMGR_DIR = $(shell $(PACKAGE_ZIRAN) pkg path taskmgr $(LOCK_FLAGS))
|
||||
ENTITY_DIR = $(shell $(PACKAGE_ZIRAN) pkg path entity $(LOCK_FLAGS))
|
||||
APPS_DIR = $(shell $(PACKAGE_ZIRAN) pkg path apps $(LOCK_FLAGS))
|
||||
# Auth is its own package; SHA-256 and PBKDF2 come from the crypto package.
|
||||
AUTH_DIR = $(shell $(PACKAGE_ZIRAN) pkg path auth $(LOCK_FLAGS))
|
||||
CRYPTO_DIR = $(shell $(PACKAGE_ZIRAN) pkg path crypto $(LOCK_FLAGS))
|
||||
# Qualified entries retain each package's import aliases while using the
|
||||
# consumer's locked compiler, UI library and runtime.
|
||||
PACKAGE_ID = $(shell python3 -c 'import json; print(json.load(open("ziran.lock"))["root"]["dependencies"]["$(1)"])')
|
||||
LIBOQS_DIR = $(shell $(ZIRAN) pkg path liboqs $(LOCK_FLAGS))
|
||||
MONOCYPHER_DIR = $(shell $(ZIRAN) pkg path monocypher $(LOCK_FLAGS))
|
||||
LIBOQS_FLAGS := -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_SHARED_LIBS=OFF -DOQS_BUILD_ONLY_LIB=ON \
|
||||
-DOQS_USE_OPENSSL=OFF -DOQS_DIST_BUILD=OFF -DOQS_OPT_TARGET=generic '-DOQS_MINIMAL_BUILD=SIG_ml_dsa_44;KEM_ml_kem_768'
|
||||
-DOQS_USE_OPENSSL=OFF -DOQS_DIST_BUILD=OFF -DOQS_OPT_TARGET=generic -DOQS_MINIMAL_BUILD=SIG_ml_dsa_44
|
||||
MONOCYPHER_SOURCES = $(MONOCYPHER_DIR)/src/monocypher.c $(MONOCYPHER_DIR)/src/optional/monocypher-ed25519.c
|
||||
CC ?= cc
|
||||
BIN_DIR ?= $(HOME)/bin
|
||||
DATA_DIR ?= $(if $(XDG_DATA_HOME),$(XDG_DATA_HOME),$(HOME)/.local/share)
|
||||
DESKTOP_DIR ?= $(shell xdg-user-dir DESKTOP 2>/dev/null)
|
||||
# The tool bundles and Werkzeug's other files.
|
||||
LIB_DIR ?= $(HOME)/.local/lib/werk
|
||||
WEB_CC ?= $(if $(wildcard $(HOME)/emsdk/upstream/emscripten/emcc),$(HOME)/emsdk/upstream/emscripten/emcc,emcc)
|
||||
SOURCES := $(wildcard src/*.zi apps/*/*.zi)
|
||||
LIBRARY_SOURCES = $(wildcard $(KRYON_DIR)/src/ui/*.zi $(KRYON_DIR)/src/ui/*/module.zi $(KRYON_DIR)/src/backend/*.zi $(KRYON_DIR)/src/backend/*/module.zi $(ZIRAN_ROOT)/std/*.zi)
|
||||
ZIRAN_RUNTIME_SOURCES = $(wildcard $(ZIRAN_ROOT)/cmd/zir/*.[ch] $(ZIRAN_ROOT)/include/*.h)
|
||||
ENTITY_SOURCES = $(wildcard $(ENTITY_DIR)/src/*.zi $(ENTITY_DIR)/assets/entity/*)
|
||||
SOURCES := $(wildcard src/*.zi shared/*.zi apps/*/*.zi)
|
||||
LIBRARY_SOURCES = $(wildcard $(KRYON_DIR)/src/ui/*.zi $(KRYON_DIR)/src/ui/*/module.zi $(KRYON_DIR)/src/kss/*.zi $(KRYON_DIR)/src/backend/*.zi $(KRYON_DIR)/src/backend/*/module.zi $(ZIRAN_ROOT)/std/*.zi)
|
||||
CFLAGS := -std=c99 -O2 -Wno-unused-variable -I$(ZIRAN_ROOT)/include
|
||||
PROJECT := --project $(LOCK_FLAGS)
|
||||
ANDROID_ABIS ?= armeabi-v7a,arm64-v8a
|
||||
|
||||
.PHONY: all apps portable-apps cli gui native run test source-check core-test ziran-core-test cli-test pass-state-test app-logic-test lesspass-compat-test entity-account-test gui-smoke gui-test web web-canvas site web-smoke android-debug android-emulator android-release android-smoke android-input-test e2e check-package-urls install install-cli install-gui uninstall-cli uninstall-gui package-deb package-appimage
|
||||
.PHONY: all apps cli gui native run test source-check core-test ziran-core-test cli-test pass-state-test app-logic-test lesspass-compat-test gui-smoke gui-test web web-canvas site web-smoke android-debug android-emulator android-release android-smoke android-input-test e2e check-package-urls install install-cli install-gui uninstall-cli uninstall-gui package-deb package-appimage plan9-c
|
||||
all: cli gui
|
||||
native: all
|
||||
|
||||
@@ -59,65 +40,26 @@ build/pass: build/generated/cli/.complete
|
||||
cli: build/pass
|
||||
cp build/pass pass
|
||||
|
||||
# Each app is its own bundle, shared by the desktop, web and Android hosts.
|
||||
APPS := pass calculator clock calendar gallery
|
||||
PORTABLE_BUNDLES := $(APPS:%=build/apps/%.zx) build/apps/auth.zx build/apps/entity.zx build/apps/apps.zx build/apps/workbook.zx build/apps/taskmgr.zx
|
||||
APP_BUNDLES := $(PORTABLE_BUNDLES)
|
||||
CRYPTO_SOURCES = $(wildcard $(CRYPTO_DIR)/src/*.zi)
|
||||
APPS_UI_SOURCES = $(wildcard $(APPS_DIR)/src/*.zi $(APPS_DIR)/ui/*.zi $(APPS_DIR)/ui/locales/*.json)
|
||||
# Each app is its own bundle; Werkzeug runs them in one window.
|
||||
APPS := pass auth calculator clock
|
||||
APP_BUNDLES := $(APPS:%=build/apps/%.zib)
|
||||
SHARED_SOURCES := $(wildcard shared/*.zi)
|
||||
APP_MODULE_PATHS = --module-path shared --module-path $(KRYON_DIR)/src/ui --module-path $(MINGCUTE_DIR)/src --module-path $(ZIRAN_ROOT)/std
|
||||
apps: $(APP_BUNDLES)
|
||||
portable-apps: $(PORTABLE_BUNDLES)
|
||||
# Compile the shared screen with the host's compiler and UI library. The
|
||||
# reviewed payload must match both the build pin and the native host pin.
|
||||
build/apps/apps.zx: $(APPS_UI_SOURCES) $(LIBRARY_SOURCES) $(ZIRAN_RUNTIME_SOURCES) ziran.lock apps-controller.sha256 Makefile scripts/ziran.sh
|
||||
mkdir -p $(@D)
|
||||
python3 '$(APPS_DIR)/scripts/build-ui.py' --project $(CURDIR) --output $(abspath $(@D)) \
|
||||
--compiler $(if $(findstring /,$(ZIRAN)),$(abspath $(ZIRAN)),$(ZIRAN))
|
||||
test "$$(cat $(@D)/apps.sha256)" = "$$(cat apps-controller.sha256)"
|
||||
.SECONDEXPANSION:
|
||||
build/apps/%.zx: $$(wildcard apps/$$*/*.zi apps/$$*/assets/*) $(CRYPTO_SOURCES) $(LIBRARY_SOURCES) $(ZIRAN_RUNTIME_SOURCES) ziran.lock Makefile scripts/ziran.sh
|
||||
build/apps/%.zib: $$(wildcard apps/$$*/*.zi apps/$$*/assets/*) $(SHARED_SOURCES) ziran.lock
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) bundle $(PROJECT) --root . --define KRYON_HOSTED_UI --define WERK_APP \
|
||||
$(ZIRAN) bundle --root . --module-path apps/$* $(APP_MODULE_PATHS) --define KRYON_HOSTED_UI --define WERK_APP \
|
||||
$(if $(wildcard apps/$*/assets),--asset-dir assets=apps/$*/assets) --entry $*:Main -o $@ apps/$*/$*.zi
|
||||
|
||||
build/apps/auth.zx: $(wildcard $(AUTH_DIR)/src/*.zi) $(CRYPTO_SOURCES) $(LIBRARY_SOURCES) $(ZIRAN_RUNTIME_SOURCES) ziran.lock Makefile scripts/ziran.sh
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) bundle $(PROJECT) --root $(AUTH_DIR)/src --define KRYON_HOSTED_UI --define WERK_APP \
|
||||
--entry $(call PACKAGE_ID,auth)_auth:Main -o $@ $(AUTH_DIR)/src/auth.zi
|
||||
|
||||
build/apps/workbook.zx: $(wildcard $(WORKBOOK_DIR)/src/*.zi) $(LIBRARY_SOURCES) $(ZIRAN_RUNTIME_SOURCES) ziran.lock Makefile
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) bundle $(PROJECT) --root $(WORKBOOK_DIR)/src \
|
||||
--define KRYON_HOSTED_UI --entry $(call PACKAGE_ID,workbook)_app:Main -o $@ $(WORKBOOK_DIR)/src/app.zi
|
||||
|
||||
build/apps/taskmgr.zx: $(wildcard $(TASKMGR_DIR)/src/*.zi) $(LIBRARY_SOURCES) $(ZIRAN_RUNTIME_SOURCES) ziran.lock Makefile
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) bundle $(PROJECT) --root $(TASKMGR_DIR)/src \
|
||||
--define KRYON_HOSTED_UI --entry $(call PACKAGE_ID,taskmgr)_hosted:Main -o $@ $(TASKMGR_DIR)/src/hosted.zi
|
||||
|
||||
# These portable apps use their public package exports. Their UI sources may
|
||||
# advance independently; all bundles are emitted by this host's compiler.
|
||||
build/apps/gallery.zx: $(wildcard apps/gallery/*.zi) apps/gallery/ziran.toml apps/gallery/ziran.lock ziran.lock Makefile
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) bundle $(PROJECT) --root . --define KRYON_HOSTED_UI --entry gallery:Main -o $@ apps/gallery/gallery.zi
|
||||
|
||||
build/apps/entity.zx: $(ENTITY_SOURCES) ziran.lock Makefile
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) bundle $(PROJECT) --root $(ENTITY_DIR)/src --define KRYON_HOSTED_UI \
|
||||
--asset-dir assets=$(ENTITY_DIR)/assets --entry $(call PACKAGE_ID,entity)_entity:Main -o $@ $(ENTITY_DIR)/src/entity.zi
|
||||
|
||||
# The portable bundle runtime the host links, built from the locked Ziran.
|
||||
.PHONY: runtime-cache-force
|
||||
runtime-cache-force:
|
||||
build/ziran/.toolchain: runtime-cache-force scripts/runtime_cache.py
|
||||
python3 scripts/runtime_cache.py "$(ZIRAN_ROOT)" "$(abspath build/ziran)"
|
||||
build/ziran/libziran.a: ziran.lock $(ZIRAN_RUNTIME_SOURCES) build/ziran/.toolchain
|
||||
env -u DISPLAY -u WAYLAND_DISPLAY -u MAKEFLAGS -u MFLAGS -u MAKEOVERRIDES $(MAKE) -C $(ZIRAN_ROOT) BUILD_DIR=$(abspath build/ziran) $(abspath $@)
|
||||
build/ziran/libziran.a: ziran.lock
|
||||
env -u DISPLAY -u WAYLAND_DISPLAY $(MAKE) -C $(ZIRAN_ROOT) BUILD_DIR=$(abspath build/ziran) $(abspath $@)
|
||||
|
||||
build/generated/desktop/.complete: $(wildcard src/*.zi) $(wildcard $(WORKBOOK_DIR)/src/*.zi) $(wildcard $(TASKMGR_DIR)/src/*.zi) $(CRYPTO_SOURCES) $(LIBRARY_SOURCES) $(ENTITY_SOURCES) ziran.toml ziran.lock
|
||||
build/generated/desktop/.complete: $(wildcard src/*.zi) $(SHARED_SOURCES) $(LIBRARY_SOURCES) ziran.toml ziran.lock
|
||||
rm -rf $(@D)
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) build $(PROJECT) --define PLATFORM_DESKTOP --target=c --entry desktop:main -o $(@D) src/desktop.zi
|
||||
$(ZIRAN) build $(PROJECT) --target=c --entry desktop:main -o $(@D) src/desktop.zi
|
||||
touch $@
|
||||
build/liboqs/lib/liboqs.a: ziran.lock
|
||||
cmake -S $(LIBOQS_DIR) -B build/liboqs $(LIBOQS_FLAGS) > /dev/null
|
||||
@@ -125,16 +67,10 @@ build/liboqs/lib/liboqs.a: ziran.lock
|
||||
build/werk: build/generated/desktop/.complete build/ziran/libziran.a build/liboqs/lib/liboqs.a Makefile
|
||||
$(CC) $(CFLAGS) -Ibuild/generated/desktop -I$(MONOCYPHER_DIR)/src -I$(MONOCYPHER_DIR)/src/optional \
|
||||
build/generated/desktop/*.c $(MONOCYPHER_SOURCES) build/ziran/libziran.a build/liboqs/lib/liboqs.a \
|
||||
$(shell pkg-config --libs sdl2 cairo freetype2 fontconfig pangocairo gtk+-3.0) -lX11 -l:libcurl.so.4 -lm -lpthread -o $@.new
|
||||
mv -f $@.new $@
|
||||
build/pfp.webp: $(KRYON_DIR)/icons/pfp.webp
|
||||
$(shell pkg-config --libs sdl2 cairo freetype2 fontconfig pangocairo) -l:libcurl.so.4 -lm -lpthread -o $@
|
||||
build/pfp.png: $(KRYON_DIR)/icons/pfp.png
|
||||
cp $< $@
|
||||
# Launcher artwork for the bundled tools, beside the host like pfp.webp.
|
||||
TOOL_ICONS := $(wildcard assets/tools/*.webp)
|
||||
build/tools/%.webp: assets/tools/%.webp
|
||||
mkdir -p $(@D)
|
||||
cp $< $@
|
||||
gui: build/werk build/pfp.webp $(TOOL_ICONS:assets/%=build/%) apps
|
||||
gui: build/werk build/pfp.png apps
|
||||
run: gui
|
||||
./build/werk
|
||||
|
||||
@@ -151,57 +87,33 @@ cli-test: cli
|
||||
sh scripts/cli_test.sh ./pass
|
||||
lesspass-compat-test: cli
|
||||
python3 scripts/lesspass_compat_test.py --cli ./pass
|
||||
entity-account-test: build/liboqs/lib/liboqs.a
|
||||
ZIRAN_BIN=$(ZIRAN) python3 scripts/entity_account_test.py
|
||||
.PHONY: android-sdk-install-test
|
||||
android-sdk-install-test:
|
||||
python3 scripts/install_android_sdk_test.py
|
||||
test: source-check core-test pass-state-test app-logic-test cli-test lesspass-compat-test entity-account-test android-sdk-install-test android-apk-check-test android-startup-test runtime-cache-test gallery-test
|
||||
|
||||
.PHONY: android-startup-test
|
||||
android-startup-test:
|
||||
python3 scripts/android_startup_test.py
|
||||
.PHONY: android-apk-check-test
|
||||
android-apk-check-test:
|
||||
python3 scripts/android_apk_check_test.py
|
||||
.PHONY: runtime-cache-test
|
||||
runtime-cache-test:
|
||||
python3 scripts/runtime_cache_test.py
|
||||
test: source-check core-test pass-state-test app-logic-test cli-test lesspass-compat-test
|
||||
gui-smoke: gui
|
||||
sh scripts/gui_smoke.sh
|
||||
gui-test: gui
|
||||
python3 scripts/private-display.py python3 scripts/apps_gui_test.py
|
||||
python3 scripts/private-display.py python3 scripts/calendar_taskmgr_gui_test.py
|
||||
sh scripts/werk_gui_test.sh
|
||||
python3 scripts/private-display.py python3 scripts/workbook_gui_test.py
|
||||
WERK_TEST_ZIRAN="$(ZIRAN)" python3 scripts/private-display.py python3 scripts/launcher_gui_test.py
|
||||
sh scripts/migration_test.sh
|
||||
python3 -I scripts/auth_command_test.py
|
||||
python3 scripts/private-display.py python3 scripts/auth_gui_test.py
|
||||
|
||||
# The bundle runtime for the browser, built from the locked Ziran.
|
||||
WEB_AR ?= $(dir $(WEB_CC))emar
|
||||
build/web-runtime/.toolchain: runtime-cache-force scripts/runtime_cache.py
|
||||
python3 scripts/runtime_cache.py "$(ZIRAN_ROOT)" "$(abspath build/web-runtime)"
|
||||
build/web-runtime/libziran.a: Makefile ziran.lock build/web-runtime/.toolchain
|
||||
env -u DISPLAY -u WAYLAND_DISPLAY -u MAKEFLAGS -u MFLAGS -u MAKEOVERRIDES $(MAKE) -C $(ZIRAN_ROOT) BOOTSTRAP=0 BUILD_DIR=$(abspath build/web-runtime) \
|
||||
GEN_ZI2C=$(ZIRAN_ROOT)/build/bin/zi2c BOOTSTRAP_BIN=$(ZIRAN_ROOT)/build/bootstrap/bin/zi2c \
|
||||
build/web-runtime/libziran.a: ziran.lock
|
||||
env -u DISPLAY -u WAYLAND_DISPLAY $(MAKE) -C $(ZIRAN_ROOT) BOOTSTRAP=1 BUILD_DIR=$(abspath build/web-runtime) \
|
||||
CC=$(WEB_CC) AR=$(WEB_AR) OBJCOPY=true CFLAGS=-O2 $(abspath $@)
|
||||
build/generated/browser/.complete: $(wildcard src/*.zi) $(wildcard $(WORKBOOK_DIR)/src/*.zi) $(wildcard $(TASKMGR_DIR)/src/*.zi) $(CRYPTO_SOURCES) $(LIBRARY_SOURCES) ziran.toml ziran.lock
|
||||
build/generated/browser/.complete: $(wildcard src/*.zi) $(SHARED_SOURCES) $(LIBRARY_SOURCES) ziran.toml ziran.lock
|
||||
rm -rf $(@D)
|
||||
mkdir -p $(@D)
|
||||
$(ZIRAN) build $(PROJECT) --define PLATFORM_WEB --target-os web --target-cpu wasm32 --target=c -o $(@D) src/browser.zi
|
||||
$(ZIRAN) build $(PROJECT) --define PLATFORM_WEB --target=c -o $(@D) src/browser.zi
|
||||
touch $@
|
||||
build/web-app/index.js: build/generated/browser/.complete build/web-runtime/libziran.a $(PORTABLE_BUNDLES) build/pfp.webp $(TOOL_ICONS) assets/app/icon.png assets/fonts/NotoSans-Regular.ttf
|
||||
build/web-app/index.js: build/generated/browser/.complete build/web-runtime/libziran.a $(APP_BUNDLES) build/pfp.png assets/app/icon.png assets/fonts/NotoSans-Regular.ttf
|
||||
mkdir -p $(@D)
|
||||
$(WEB_CC) -O2 -Wno-parentheses-equality -I$(ZIRAN_ROOT)/include -iquote build/generated/browser build/generated/browser/*.c \
|
||||
build/web-runtime/libziran.a \
|
||||
--js-library $(ZIRAN_ROOT)/web/ziran_web.js -sEXPORTED_RUNTIME_METHODS=FS,IDBFS -lidbfs.js \
|
||||
-sASYNCIFY -sALLOW_MEMORY_GROWTH=1 -sSTACK_SIZE=16777216 -sASYNCIFY_STACK_SIZE=1048576 -sENVIRONMENT=web \
|
||||
--embed-file assets/fonts/NotoSans-Regular.ttf@/kryon-font.ttf \
|
||||
$(foreach bundle,$(PORTABLE_BUNDLES),--embed-file $(bundle)@/apps/$(notdir $(bundle))) --embed-file build/pfp.webp@/pfp.webp --embed-file assets/tools@/tools --embed-file assets/app/icon.png@/icon.png -o $@
|
||||
build/web-app/index.html: build/web-app/index.js web/site/index.html
|
||||
cp web/site/index.html $@
|
||||
--embed-file build/apps@/apps --embed-file build/pfp.png@/pfp.png --embed-file assets/app/icon.png@/icon.png -o $@
|
||||
build/web-app/index.html: build/web-app/index.js web/site/app/index.html
|
||||
cp web/site/app/index.html $@
|
||||
build/generated/worker/.complete: src/service_worker.zi ziran.toml ziran.lock
|
||||
rm -rf $(@D)
|
||||
mkdir -p $(@D)
|
||||
@@ -218,44 +130,29 @@ web-smoke: site
|
||||
bash scripts/web_smoke.sh
|
||||
|
||||
# CMake emits JNI and foreign ABI types separately for each Android ABI.
|
||||
android-debug: portable-apps
|
||||
cd droid && env WERK_ZIRAN_COMMAND="$(ZIRAN)" KRYON_DIR="$(KRYON_DIR)" ZIRAN_ROOT="$(ZIRAN_ROOT)" LIBOQS_DIR="$(LIBOQS_DIR)" MONOCYPHER_DIR="$(MONOCYPHER_DIR)" ./gradlew assembleDebug -Pabi=$(ANDROID_ABIS) -PsplitApks=true $(GRADLE_ARGS)
|
||||
android-debug: apps
|
||||
cd droid && env WERK_ZIRAN_COMMAND="$(ZIRAN)" KRYON_DIR="$(KRYON_DIR)" ZIRAN_ROOT="$(ZIRAN_ROOT)" RAYLIB_DIR="$(RAYLIB_DIR)" LIBOQS_DIR="$(LIBOQS_DIR)" MONOCYPHER_DIR="$(MONOCYPHER_DIR)" ./gradlew assembleDebug -Pabi=$(ANDROID_ABIS) -PsplitApks=true $(GRADLE_ARGS)
|
||||
mkdir -p build
|
||||
cp droid/app/build/outputs/apk/debug/app-universal-debug.apk build/werk-android-debug.apk
|
||||
python3 scripts/android_apk_check.py build/werk-android-debug.apk
|
||||
cp droid/app/build/outputs/apk/debug/app-arm64-v8a-debug.apk build/werk-android-arm64-v8a-debug.apk
|
||||
cp droid/app/build/outputs/apk/debug/app-armeabi-v7a-debug.apk build/werk-android-armeabi-v7a-debug.apk
|
||||
android-emulator: portable-apps
|
||||
cd droid && env WERK_ZIRAN_COMMAND="$(ZIRAN)" KRYON_DIR="$(KRYON_DIR)" ZIRAN_ROOT="$(ZIRAN_ROOT)" LIBOQS_DIR="$(LIBOQS_DIR)" MONOCYPHER_DIR="$(MONOCYPHER_DIR)" ./gradlew assembleDebug -Pabi=x86_64 $(GRADLE_ARGS)
|
||||
android-emulator: apps
|
||||
cd droid && env WERK_ZIRAN_COMMAND="$(ZIRAN)" KRYON_DIR="$(KRYON_DIR)" ZIRAN_ROOT="$(ZIRAN_ROOT)" RAYLIB_DIR="$(RAYLIB_DIR)" LIBOQS_DIR="$(LIBOQS_DIR)" MONOCYPHER_DIR="$(MONOCYPHER_DIR)" ./gradlew assembleDebug -Pabi=x86_64 $(GRADLE_ARGS)
|
||||
mkdir -p build
|
||||
cp droid/app/build/outputs/apk/debug/app-debug.apk build/werk-android-emulator.apk
|
||||
python3 scripts/android_apk_check.py build/werk-android-emulator.apk
|
||||
android-release: portable-apps
|
||||
cd droid && env WERK_ZIRAN_COMMAND="$(ZIRAN)" KRYON_DIR="$(KRYON_DIR)" ZIRAN_ROOT="$(ZIRAN_ROOT)" LIBOQS_DIR="$(LIBOQS_DIR)" MONOCYPHER_DIR="$(MONOCYPHER_DIR)" ./gradlew assembleRelease -Pabi=$(ANDROID_ABIS) -PsplitApks=true $(GRADLE_ARGS)
|
||||
.PHONY: android-bundle
|
||||
android-bundle: portable-apps
|
||||
cd droid && env WERK_ZIRAN_COMMAND="$(ZIRAN)" KRYON_DIR="$(KRYON_DIR)" ZIRAN_ROOT="$(ZIRAN_ROOT)" LIBOQS_DIR="$(LIBOQS_DIR)" MONOCYPHER_DIR="$(MONOCYPHER_DIR)" ./gradlew bundleRelease -Pabi=$(ANDROID_ABIS) $(GRADLE_ARGS)
|
||||
cp droid/app/build/outputs/bundle/release/app-release.aab build/werk-$(shell cat VERSION).aab
|
||||
.PHONY: android-fdroid
|
||||
# F-Droid compares this source build with the signed upstream release.
|
||||
android-fdroid:
|
||||
$(MAKE) android-release GRADLE_ARGS="$(GRADLE_ARGS) -PfDroidBuild=true"
|
||||
mkdir -p build/fdroid
|
||||
cp droid/app/build/outputs/apk/release/app-universal-release-unsigned.apk build/fdroid/werk.apk
|
||||
python3 scripts/android_apk_check.py build/fdroid/werk.apk
|
||||
android-release: apps
|
||||
cd droid && env WERK_ZIRAN_COMMAND="$(ZIRAN)" KRYON_DIR="$(KRYON_DIR)" ZIRAN_ROOT="$(ZIRAN_ROOT)" RAYLIB_DIR="$(RAYLIB_DIR)" LIBOQS_DIR="$(LIBOQS_DIR)" MONOCYPHER_DIR="$(MONOCYPHER_DIR)" ./gradlew assembleRelease -Pabi=$(ANDROID_ABIS) -PsplitApks=true $(GRADLE_ARGS)
|
||||
android-smoke:
|
||||
bash scripts/android_smoke.sh
|
||||
android-input-test:
|
||||
$(MAKE) android-profile-test
|
||||
$(MAKE) workbook-android-test
|
||||
$(MAKE) gallery-android-test
|
||||
.PHONY: android-profile-test workbook-android-test gallery-android-test
|
||||
android-profile-test:
|
||||
python3 scripts/android_input_test.py
|
||||
workbook-android-test:
|
||||
python3 scripts/workbook_android_test.py
|
||||
gallery-android-test:
|
||||
python3 scripts/android_gallery_test.py
|
||||
|
||||
# The pass command for Plan 9; transfer the checkout with build/plan9 and run mk.
|
||||
plan9-c:
|
||||
mkdir -p build/plan9
|
||||
$(ZIRAN) build $(PROJECT) --define PLAN9_BUILD --target=plan9-c --entry cli:main -o build/plan9/cli apps/pass/cli.zi
|
||||
|
||||
check-package-urls:
|
||||
bash scripts/check_package_urls.sh
|
||||
@@ -266,36 +163,18 @@ install-cli: cli
|
||||
mkdir -p $(BIN_DIR)
|
||||
install -m 0755 pass $(BIN_DIR)/pass
|
||||
install-gui: gui
|
||||
mkdir -p "$(BIN_DIR)" "$(DATA_DIR)/applications" "$(DATA_DIR)/icons/hicolor/512x512/apps" "$(DATA_DIR)/mime/packages"
|
||||
install -d -m 0700 "$(LIB_DIR)" "$(LIB_DIR)/apps"
|
||||
install -m 0755 build/werk "$(BIN_DIR)/werk.new"
|
||||
mv -f "$(BIN_DIR)/werk.new" "$(BIN_DIR)/werk"
|
||||
install -m 0600 $(APP_BUNDLES) "$(LIB_DIR)/apps/"
|
||||
install -m 0644 build/pfp.webp "$(LIB_DIR)/pfp.webp"
|
||||
install -d -m 0755 "$(LIB_DIR)/tools"
|
||||
install -m 0644 $(TOOL_ICONS) "$(LIB_DIR)/tools/"
|
||||
python3 scripts/install-launchers.py --data-dir "$(DATA_DIR)" --bin-dir "$(BIN_DIR)" $(if $(filter-out $(HOME),$(DESKTOP_DIR)),--desktop-dir "$(DESKTOP_DIR)")
|
||||
install -m 0644 packaging/linux/werk-bundle.xml "$(DATA_DIR)/mime/packages/werk-bundle.xml"
|
||||
@if command -v update-mime-database >/dev/null; then update-mime-database "$(DATA_DIR)/mime"; fi
|
||||
@if command -v update-desktop-database >/dev/null; then update-desktop-database "$(DATA_DIR)/applications"; fi
|
||||
mkdir -p $(BIN_DIR) $(LIB_DIR)/apps $(DATA_DIR)/applications $(DATA_DIR)/icons/hicolor/512x512/apps
|
||||
install -m 0755 build/werk $(BIN_DIR)/werk
|
||||
install -m 0644 $(APP_BUNDLES) $(LIB_DIR)/apps/
|
||||
install -m 0644 build/pfp.png $(LIB_DIR)/pfp.png
|
||||
cp packaging/linux/xyz.waozi.werk.desktop $(DATA_DIR)/applications/xyz.waozi.werk.desktop
|
||||
cp assets/app/icon.png $(DATA_DIR)/icons/hicolor/512x512/apps/werk.png
|
||||
uninstall-cli:
|
||||
rm -f $(BIN_DIR)/pass
|
||||
uninstall-gui:
|
||||
python3 scripts/install-launchers.py --data-dir "$(DATA_DIR)" $(if $(filter-out $(HOME),$(DESKTOP_DIR)),--desktop-dir "$(DESKTOP_DIR)") --uninstall
|
||||
rm -f $(BIN_DIR)/werk
|
||||
rm -f $(BIN_DIR)/werk $(DATA_DIR)/applications/xyz.waozi.werk.desktop $(DATA_DIR)/icons/hicolor/512x512/apps/werk.png
|
||||
rm -rf $(LIB_DIR)
|
||||
package-deb: gui
|
||||
./scripts/package-deb.sh
|
||||
package-appimage: gui
|
||||
./scripts/package-appimage.sh
|
||||
|
||||
.PHONY: gallery-test gallery-gui-test
|
||||
gallery-test:
|
||||
rm -rf build/gallery-test-generated
|
||||
mkdir -p build/gallery-test-generated
|
||||
$(ZIRAN) build $(PROJECT) --root . --target=c --entry gallery_test:Check -o build/gallery-test-generated tests/gallery_test.zi
|
||||
printf '%s\n' '#include "tests/gallery_test.h"' 'int main(void) { return Check(); }' > build/gallery-test-generated/main.c
|
||||
$(CC) -std=c11 -O2 -I$(ZIRAN_ROOT)/include -Ibuild/gallery-test-generated $$(find build/gallery-test-generated -name '*.c' -print) -o build/gallery-test
|
||||
python3 scripts/gallery_gui_test.py --behavioral-only
|
||||
gallery-gui-test: gui gallery-test
|
||||
python3 scripts/private-display.py dbus-run-session -- python3 scripts/gallery_gui_test.py
|
||||
@@ -1,48 +1,162 @@
|
||||
<p align="center">
|
||||
<img src="fastlane/metadata/android/en-US/images/featureGraphic.png" alt="Werkzeug" width="100%">
|
||||
<a href="https://f-droid.org/packages/xyz.waozi.pass/">
|
||||
<img src="assets/app/badge-f-droid.png" alt="Get it on F-Droid" height="56">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
# Werkzeug
|
||||
|
||||
Small, private tools for everyday life. Generate passwords, manage sign-in
|
||||
codes, calculate and keep time in one free, open-source app.
|
||||
Small private tools in one app. The home screen opens each one:
|
||||
|
||||
[Try it online](https://werk.waozi.xyz/)
|
||||
· [Download the latest release](https://github.com/waozixyz/werk/releases/latest)
|
||||
· [What's new](CHANGELOG.md)
|
||||
- **Pass**: a stateless password generator. The same site, login, master
|
||||
password and settings always give the same password, so there is no
|
||||
password database to keep. It is an independent implementation of the
|
||||
LessPass algorithm; compatibility does not imply endorsement by or
|
||||
affiliation with the LessPass project.
|
||||
- **Auth**: two-factor sign-in codes (TOTP, RFC 6238, with SHA-1, SHA-256 or
|
||||
SHA-512 and 6 to 8 digits). Add accounts by pasting `otpauth://` links, one
|
||||
or many such as an authenticator's plain-text export, or by entering the
|
||||
secret key. Tap a code to copy it; it is cleared from the clipboard after
|
||||
30 seconds.
|
||||
- **Calculator**: arithmetic with brackets, powers and percent, by keypad or
|
||||
keyboard.
|
||||
- **Clock**: the local time and date, and a stopwatch that keeps running
|
||||
while the app is closed.
|
||||
|
||||
## Your everyday tools
|
||||
The profile holds your name, a picture and the appearance every tool shares:
|
||||
system, light or dark, an accent color and Material or Classic widgets.
|
||||
|
||||
- **Pass:** generate the same password from your site, login, master password and settings. Save profiles without keeping a password database.
|
||||
- **Auth:** keep two-factor sign-in codes together. Tap anywhere on a card to copy its current code, or use Edit to change the account.
|
||||
- **Calculator:** everyday arithmetic and scientific functions, with a keypad or keyboard.
|
||||
- **Clock:** see the local time and use a stopwatch that keeps running while the app is closed.
|
||||
- **Workbook:** edit spreadsheets on Linux, Android and the web, with formulas, sheet tabs and portable workbook files.
|
||||
- **Gallery:** browse local photo folders and albums on Linux and Android. Open a photo, move between pictures and zoom; your photos stay local.
|
||||
Werkzeug was previously Pass. On its first start it moves Pass's saved
|
||||
profiles, settings and theme into the new layout; the Android app keeps
|
||||
Pass's package, so it updates in place and keeps a saved master password.
|
||||
|
||||
<p align="center">
|
||||
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/02-pass.png" alt="Pass password generation" width="30%">
|
||||
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/03-auth.png" alt="Auth sign-in codes" width="30%">
|
||||
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/04-calculator.png" alt="Scientific calculator" width="30%">
|
||||
</p>
|
||||
## Privacy
|
||||
|
||||
## Make it yours
|
||||
Everything is computed on the device. Werkzeug makes no network requests
|
||||
unless you turn on sync. Each tool keeps its own files, readable only by your
|
||||
user:
|
||||
|
||||
Choose light or dark appearance, an accent color and your profile picture.
|
||||
On Linux, open each tool directly from its own application-menu or Desktop
|
||||
shortcut, with its own icon.
|
||||
| Platform | Data |
|
||||
|---|---|
|
||||
| Linux | `$XDG_DATA_HOME/werk` (or `~/.local/share/werk`) |
|
||||
| Android | the app's private storage |
|
||||
| Browser | IndexedDB on this site |
|
||||
|
||||
## Your data and choices
|
||||
Auth's accounts are synced records: `otpauth` links in the private
|
||||
`records/auth.txt`, protected by the file permissions of your account or the
|
||||
Android app sandbox.
|
||||
|
||||
Password generation and local tools work on your device. Account sync and
|
||||
node connections are optional. Each tool keeps its own private files.
|
||||
## Sync
|
||||
|
||||
Werkzeug was formerly Pass. Android keeps the original `xyz.waozi.pass`
|
||||
package and signing certificate so existing Pass installations can update
|
||||
to Werkzeug while keeping their saved data.
|
||||
Profile → Sync keeps Auth's accounts on all your devices through a
|
||||
[Daochi](https://github.com/kryonlabs/daochi) account, `api.waozi.xyz` by
|
||||
default. Sync is off until you create or connect an account.
|
||||
|
||||
[F-Droid update submission (draft)](https://gitlab.com/fdroid/fdroiddata/-/merge_requests/53909)
|
||||
· [Report a problem](https://github.com/waozixyz/werk/issues)
|
||||
· [Build, command-line tools and data details](docs/development.md)
|
||||
- Each record is sealed on the device with XChaCha20-Poly1305 under a random
|
||||
vault key that never leaves your devices unencrypted. The seal covers the
|
||||
account, the record and the time of the change, so the server can neither
|
||||
read nor alter a record or a removal.
|
||||
- The account key (ML-DSA-44) signs in and signs each sync together with
|
||||
the device's own Ed25519 key.
|
||||
- To connect another device, open Profile → Sync → Connect a device and enter
|
||||
the 12-character code on the other device. The devices swap X25519 keys
|
||||
through the server's link mailbox, and the account and vault keys travel
|
||||
sealed with a key derived from that exchange and the code, so the server
|
||||
cannot open or replace them. The code works for 10 minutes.
|
||||
- The server can still withhold changes or serve an older copy to a device
|
||||
that has not seen a newer one. A lost device keeps the keys it had: stop
|
||||
syncing there if you can, and replace two-factor secrets you care about.
|
||||
|
||||
BSD 3-Clause. See [LICENSE](LICENSE).
|
||||
`scripts/sync_e2e_test.sh` runs two devices against a local Daochi node.
|
||||
|
||||
## Tools are separate apps
|
||||
|
||||
Each tool lives in `apps/<tool>/` and is built into its own portable bundle,
|
||||
`build/apps/<tool>.zib`. All four are preinstalled. A tool reaches the host
|
||||
only through the calls in `shared/werk_app.zi` (its private files,
|
||||
clipboard, clock, key derivation and device-protected secret), and the host
|
||||
checks every call a bundle asks for before it runs. Tools never import each
|
||||
other.
|
||||
|
||||
## Build and test
|
||||
|
||||
Dependencies and the compiler are pinned in `ziran.lock`. Desktop builds need
|
||||
SDL2, Cairo, FreeType, Fontconfig and Pango development packages; browser
|
||||
builds need Emscripten; Android builds need JDK 21 and the SDK/NDK versions in
|
||||
`droid/app/build.gradle`. Desktop tests use Xvfb, xdotool, xclip and
|
||||
ImageMagick on private displays.
|
||||
|
||||
```sh
|
||||
make gui # build/werk and the app bundles in build/apps
|
||||
make test # Pass core and CLI, Pass state, Auth codes, Calculator
|
||||
make gui-smoke # light and dark home screens on a private Xvfb display
|
||||
make gui-test # every tool, clipboard and profile on a private display
|
||||
make site # build/site: browser app and offline worker
|
||||
make web-smoke # private headless Chromium
|
||||
make android-debug # ARM32, ARM64 and universal APKs
|
||||
make android-emulator # the x86_64 APK for a private emulator
|
||||
```
|
||||
|
||||
For development with the real project repositories, create an ignored
|
||||
`ziran.local.toml`:
|
||||
|
||||
```toml
|
||||
[overrides]
|
||||
kryon = "../../kryonlabs/kryon"
|
||||
ziran = "../../ziranlang/ziran"
|
||||
```
|
||||
|
||||
## The `pass` command
|
||||
|
||||
```text
|
||||
pass [OPTIONS] SITE LOGIN [MASTER_PASSWORD]
|
||||
pass [OPTIONS] PROFILE SITE
|
||||
```
|
||||
|
||||
`make cli` builds it and `make install-cli` installs it. The default password
|
||||
has 16 characters and includes lowercase letters, uppercase letters, digits
|
||||
and symbols. Length must be between 5 and 35, matching LessPass clients. The
|
||||
default counter is 1.
|
||||
|
||||
Passing a master password as an argument can expose it to process inspection
|
||||
and shell history. Omitting it is safer: `pass` first checks
|
||||
`LESSPASS_MASTER_PASSWORD`, then reads one line from standard input. Use
|
||||
`--prompt` to bypass the environment and read from standard input:
|
||||
|
||||
```sh
|
||||
pass --prompt example.com alice
|
||||
pass --length 24 --counter 2 example.com alice
|
||||
pass --no-symbols --exclude '0O1Il' example.com alice
|
||||
```
|
||||
|
||||
The Linux CLI also reads saved identities from
|
||||
`$XDG_CONFIG_HOME/pass/profiles.json` (or `~/.config/pass/profiles.json`).
|
||||
`pass w example.com` and `pass --profile w example.com` use the saved login
|
||||
and generation options. Existing OpenSSL-encrypted vaults are unlocked with
|
||||
a hidden `Vault passphrase:` prompt. A configured vault takes precedence over
|
||||
`LESSPASS_MASTER_PASSWORD`; `--prompt` bypasses it. Explicit flags override
|
||||
profile defaults. Profiles and vaults are read without changing them.
|
||||
|
||||
`--copy` or a profile's `copy` setting copies through `xclip` on X11;
|
||||
`--clear-after 90s` releases that clipboard selection after the given time
|
||||
without erasing a later copy from another application. Use `--no-copy` to
|
||||
print the generated password instead. Run `pass --help` for all flags.
|
||||
|
||||
## Source layout
|
||||
|
||||
```text
|
||||
apps/pass/ Pass: LessPass core, settings and profiles, screens, CLI
|
||||
apps/auth/ Auth: TOTP, otpauth links, accounts and screens
|
||||
apps/calculator/ Calculator
|
||||
apps/clock/ Clock and stopwatch
|
||||
shared/ the app interface, protocol and SHA-256/PBKDF2
|
||||
src/werk.zi home screen, profile screen and the bar above a tool
|
||||
src/apps.zi loads, checks and runs the app bundles
|
||||
src/platform.zi files, clock, clipboard and secrets per platform
|
||||
src/desktop.zi, src/android_main.zi, src/browser.zi platform main loops
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2026 Waozi. Distributed under the BSD 3-Clause License. See
|
||||
[`LICENSE`](LICENSE).
|
||||
@@ -1 +0,0 @@
|
||||
7a9599b7e728333c237b2bf23cdf9fb985f4a3c82f9cc0ba4dd16434ac876c12
|
||||
@@ -0,0 +1,534 @@
|
||||
// Auth: two-factor sign-in codes. Each account is a synced record holding
|
||||
// its otpauth link, so it follows the owner's Werkzeug account to their
|
||||
// other devices; secrets are never shown again after adding.
|
||||
#import "session"
|
||||
#import "geometry"
|
||||
#import "text_props"
|
||||
#import "text_widget"
|
||||
#import "text_input_props"
|
||||
#import "text_field_widget"
|
||||
#import "button_props"
|
||||
#import "button_widget"
|
||||
#import "control_props"
|
||||
#import "box_props"
|
||||
#import "box_widget"
|
||||
#import "scroll_props"
|
||||
#import "scroll_widget"
|
||||
#import "tree"
|
||||
#import "text_buffer"
|
||||
#import "number_text"
|
||||
#import "werk_app"
|
||||
#import "app_protocol"
|
||||
#import "totp"
|
||||
#import "sha256"
|
||||
Icon :: #import "mingcute_regular_shield";
|
||||
Remove :: #import "mingcute_regular_delete_2";
|
||||
|
||||
ACCOUNT_LIMIT :: 128
|
||||
LIST_LIMIT :: 65536
|
||||
// Copied codes clear from the clipboard after this many seconds.
|
||||
CODE_CLEAR_SECONDS :: 30
|
||||
|
||||
VIEW_LIST :: 0
|
||||
VIEW_ADD :: 1
|
||||
|
||||
FIELD_LINKS :: 1
|
||||
FIELD_ISSUER :: 2
|
||||
FIELD_NAME :: 3
|
||||
FIELD_SECRET :: 4
|
||||
|
||||
FieldState :: struct {
|
||||
cursor: s32
|
||||
anchor: s32
|
||||
scroll_x: s32
|
||||
}
|
||||
|
||||
CachedCode :: struct {
|
||||
step: s64
|
||||
code: [12]u8
|
||||
}
|
||||
|
||||
accounts: [ACCOUNT_LIMIT]Account;
|
||||
codes: [ACCOUNT_LIMIT]CachedCode;
|
||||
// Each account's record id, and whether its record is written.
|
||||
record_ids: [ACCOUNT_LIMIT][33]u8;
|
||||
recorded: [ACCOUNT_LIMIT]bool;
|
||||
records_version: s32 = -1;
|
||||
ids: [8192]u8;
|
||||
account_count: s32;
|
||||
loaded: bool;
|
||||
view: s32;
|
||||
focused: s32;
|
||||
fields: [5]FieldState;
|
||||
links: [16384]u8;
|
||||
issuer: [64]u8;
|
||||
name: [128]u8;
|
||||
secret: [256]u8;
|
||||
status: [128]u8;
|
||||
// The account whose Remove was tapped once; a second tap removes it.
|
||||
remove_pending: s32 = -1;
|
||||
list_scroll: s32;
|
||||
store: [LIST_LIMIT]u8;
|
||||
session: Session;
|
||||
|
||||
SetStatus :: (text: string) {
|
||||
unused CopyLimited(text, status[:])
|
||||
}
|
||||
|
||||
Clear :: (bytes: []u8) {
|
||||
index: s64 = 0
|
||||
while index < bytes.count {
|
||||
bytes[index] = cast(u8)0
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
|
||||
HexDigit :: (value: u8) -> u8 {
|
||||
return ifx value < cast(u8)10 then cast(u8)48 + value else cast(u8)87 + value
|
||||
}
|
||||
|
||||
// An account's record id comes from its link, so the same account added on
|
||||
// two devices is one record.
|
||||
SetRecordId :: (index: s32, link: string) {
|
||||
digest := Sha256(link)
|
||||
for at: 0..15 {
|
||||
record_ids[index][at * 2] = HexDigit(digest[at] >> cast(u8)4)
|
||||
record_ids[index][at * 2 + 1] = HexDigit(digest[at] & cast(u8)15)
|
||||
}
|
||||
record_ids[index][32] = cast(u8)0
|
||||
for at: 0..31 {
|
||||
digest[at] = cast(u8)0
|
||||
}
|
||||
}
|
||||
|
||||
// Writes the records of accounts added since the last save.
|
||||
SaveAccounts :: () -> bool {
|
||||
saved := true
|
||||
index: s32 = 0
|
||||
while index < account_count {
|
||||
if !recorded[index] {
|
||||
line: [1024]u8
|
||||
{
|
||||
link := LinkText(*accounts[index], line[:])
|
||||
if link != "" {
|
||||
SetRecordId(index, link)
|
||||
recorded[index] = RecordWrite(TextUntilNul(record_ids[index][:]), link)
|
||||
}
|
||||
}
|
||||
Clear(line[:])
|
||||
saved = saved && recorded[index]
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
return saved
|
||||
}
|
||||
|
||||
LoadAccounts :: () {
|
||||
records_version = RecordsVersion()
|
||||
// Accounts saved before records existed move into records once.
|
||||
count := ReadStore("accounts.txt", store[:])
|
||||
if count > 0 {
|
||||
account_count = 0
|
||||
unused AddLinks(TextView(store[0:count]), false)
|
||||
if SaveAccounts() {
|
||||
unused WriteStore("accounts.txt", "")
|
||||
}
|
||||
}
|
||||
Clear(store[:])
|
||||
while account_count > 0 {
|
||||
account_count -= 1
|
||||
accounts[account_count] = Account.{}
|
||||
}
|
||||
listed := RecordList(ids[:])
|
||||
start: s32 = 0
|
||||
at: s32 = 0
|
||||
while listed > 0 && at <= listed && account_count < ACCOUNT_LIMIT {
|
||||
if at == listed || ids[at] == cast(u8)10 {
|
||||
if at > start {
|
||||
id := TextView(ids[start:at])
|
||||
length := RecordRead(id, store[:])
|
||||
account: Account
|
||||
if length > 0 && ParseLink(TextView(store[0:length]), *account) {
|
||||
accounts[account_count] = account
|
||||
codes[account_count] = CachedCode.{.step = -1}
|
||||
unused CopyLimited(id, record_ids[account_count][:])
|
||||
recorded[account_count] = true
|
||||
account_count += 1
|
||||
}
|
||||
account = Account.{}
|
||||
Clear(store[0:ifx length > 0 then length else 0])
|
||||
}
|
||||
start = at + 1
|
||||
}
|
||||
at += 1
|
||||
}
|
||||
}
|
||||
|
||||
SameAccount :: (left: *Account, right: *Account) -> bool {
|
||||
return TextUntilNul(left.issuer[:]) == TextUntilNul(right.issuer[:]) &&
|
||||
TextUntilNul(left.name[:]) == TextUntilNul(right.name[:]) &&
|
||||
TextUntilNul(left.secret[:]) == TextUntilNul(right.secret[:])
|
||||
}
|
||||
|
||||
// Adds every otpauth link in text, separated by spaces or line breaks.
|
||||
// Returns how many were new.
|
||||
AddLinks :: (text: string, report: bool) -> s32 {
|
||||
added: s32 = 0
|
||||
refused: s32 = 0
|
||||
start: s64 = 0
|
||||
while start < text.count {
|
||||
while start < text.count && text[start] <= cast(u8)32 {
|
||||
start += 1
|
||||
}
|
||||
end := start
|
||||
while end < text.count && text[end] > cast(u8)32 {
|
||||
end += 1
|
||||
}
|
||||
if end > start {
|
||||
account: Account
|
||||
if ParseLink(text[start:end], *account) && account_count < ACCOUNT_LIMIT {
|
||||
known := false
|
||||
index: s32 = 0
|
||||
while index < account_count {
|
||||
if SameAccount(*accounts[index], *account) {
|
||||
known = true
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
if !known {
|
||||
accounts[account_count] = account
|
||||
codes[account_count] = CachedCode.{.step = -1}
|
||||
recorded[account_count] = false
|
||||
account_count += 1
|
||||
added += 1
|
||||
}
|
||||
} else {
|
||||
refused += 1
|
||||
}
|
||||
account = Account.{}
|
||||
}
|
||||
start = end
|
||||
}
|
||||
if report {
|
||||
number: [24]u8
|
||||
message: [128]u8
|
||||
used := AppendText(message[:], 0, "Added ")
|
||||
used = AppendText(message[:], used, FormatInteger(cast(s64)added, number[:]))
|
||||
used = AppendText(message[:], used, ifx added == 1 then " account" else " accounts")
|
||||
if refused > 0 {
|
||||
used = AppendText(message[:], used, ", skipped ")
|
||||
used = AppendText(message[:], used, FormatInteger(cast(s64)refused, number[:]))
|
||||
}
|
||||
SetStatus(TextView(message[0:used]))
|
||||
}
|
||||
return added
|
||||
}
|
||||
|
||||
AddManual :: () -> bool {
|
||||
account := Account.{.kind = HASH_SHA1, .digits = 6, .period = 30}
|
||||
if name[0] == cast(u8)0 && issuer[0] == cast(u8)0 {
|
||||
SetStatus("Enter a name for the account")
|
||||
return false
|
||||
}
|
||||
if !SetSecret(*account, TextUntilNul(secret[:])) {
|
||||
SetStatus("The secret key is not valid Base32")
|
||||
account = Account.{}
|
||||
return false
|
||||
}
|
||||
account.issuer = issuer
|
||||
account.name = name
|
||||
if account_count >= ACCOUNT_LIMIT {
|
||||
SetStatus("Auth holds at most 128 accounts")
|
||||
account = Account.{}
|
||||
return false
|
||||
}
|
||||
accounts[account_count] = account
|
||||
codes[account_count] = CachedCode.{.step = -1}
|
||||
recorded[account_count] = false
|
||||
account_count += 1
|
||||
account = Account.{}
|
||||
return true
|
||||
}
|
||||
|
||||
RemoveAccount :: (index: s32) -> bool {
|
||||
if recorded[index] && !RecordRemove(TextUntilNul(record_ids[index][:])) {
|
||||
return false
|
||||
}
|
||||
position := index
|
||||
while position + 1 < account_count {
|
||||
accounts[position] = accounts[position + 1]
|
||||
codes[position] = codes[position + 1]
|
||||
record_ids[position] = record_ids[position + 1]
|
||||
recorded[position] = recorded[position + 1]
|
||||
position += 1
|
||||
}
|
||||
account_count -= 1
|
||||
accounts[account_count] = Account.{}
|
||||
codes[account_count] = CachedCode.{}
|
||||
recorded[account_count] = false
|
||||
return true
|
||||
}
|
||||
|
||||
Unix :: () -> s64 {
|
||||
return cast(s64)AppNow()
|
||||
}
|
||||
|
||||
// The current code, computed once per time step.
|
||||
Code :: (index: s32) -> string {
|
||||
account := *accounts[index]
|
||||
step := Unix() / cast(s64)account.period
|
||||
if codes[index].step != step {
|
||||
codes[index].step = step
|
||||
unused CodeNow(account.kind, account.key[:], account.key_count, account.digits, account.period,
|
||||
Unix(), codes[index].code[:])
|
||||
}
|
||||
return TextUntilNul(codes[index].code[:])
|
||||
}
|
||||
|
||||
Label :: (key: u64, text: string, bounds: Rectangle, font: s32) {
|
||||
Text(session, TextProps.{.key = key, .bounds = bounds, .text = text, .font = font,
|
||||
.wrap = TextWrap.TextWrapEllipsis})
|
||||
}
|
||||
|
||||
Action :: (id: s32, label: string, bounds: Rectangle, accent: bool) -> bool {
|
||||
props := ButtonProps.{.key = cast(u64)id, .id = id, .bounds = bounds, .label = label,
|
||||
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}
|
||||
if accent {
|
||||
props.tone = ButtonTone.ButtonToneAccent
|
||||
props.emphasis = ButtonEmphasis.ButtonEmphasisFilled
|
||||
}
|
||||
return Button(session, props) != 0
|
||||
}
|
||||
|
||||
ApplyEdit :: (buffer: []u8, edit: TextFieldEdit) {
|
||||
if !edit.changed {
|
||||
return
|
||||
}
|
||||
length: s64 = 0
|
||||
while length < buffer.count && buffer[length] != cast(u8)0 {
|
||||
length += 1
|
||||
}
|
||||
if edit.start < 0 || edit.end < edit.start || cast(s64)edit.end > length {
|
||||
return
|
||||
}
|
||||
used := length - cast(s64)(edit.end - edit.start) + edit.replacement.count
|
||||
if used >= buffer.count {
|
||||
return
|
||||
}
|
||||
tail := length - cast(s64)edit.end
|
||||
if edit.replacement.count > cast(s64)(edit.end - edit.start) {
|
||||
// Move the tail right, from its end.
|
||||
index := tail - 1
|
||||
while index >= 0 {
|
||||
buffer[cast(s64)edit.start + edit.replacement.count + index] = buffer[cast(s64)edit.end + index]
|
||||
index -= 1
|
||||
}
|
||||
} else {
|
||||
index: s64 = 0
|
||||
while index < tail {
|
||||
buffer[cast(s64)edit.start + edit.replacement.count + index] = buffer[cast(s64)edit.end + index]
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
index: s64 = 0
|
||||
while index < edit.replacement.count {
|
||||
buffer[cast(s64)edit.start + index] = edit.replacement[index]
|
||||
index += 1
|
||||
}
|
||||
index = used
|
||||
while index < buffer.count {
|
||||
buffer[index] = cast(u8)0
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
|
||||
Field :: (id: s32, label: string, placeholder: string, buffer: []u8, bounds: Rectangle, secure: bool) {
|
||||
state := *fields[id]
|
||||
edit: TextFieldEdit
|
||||
{
|
||||
props := TextFieldProps.{.key = cast(u64)(500 + id), .focus_id = 500 + id, .bounds = bounds,
|
||||
.label = label, .placeholder = placeholder, .value = TextUntilNul(buffer),
|
||||
.cursor = state.cursor, .anchor = state.anchor, .scroll_x = state.scroll_x,
|
||||
.focused = focused == id, .max_bytes = cast(s32)buffer.count - 1,
|
||||
.max_codepoints = cast(s32)buffer.count - 1, .secure = secure}
|
||||
// A secret shows as dots once typed; an empty field shows its hint.
|
||||
if secure && buffer[0] != cast(u8)0 {
|
||||
props.display_value = "••••••••"
|
||||
}
|
||||
if focused == id {
|
||||
props.input = AppFieldInput()
|
||||
}
|
||||
result := TextField(session, props)
|
||||
state.cursor = result.cursor
|
||||
state.anchor = result.anchor
|
||||
state.scroll_x = result.scroll_x
|
||||
if result.focused {
|
||||
focused = id
|
||||
} else if focused == id {
|
||||
focused = 0
|
||||
}
|
||||
edit = result.edit
|
||||
}
|
||||
ApplyEdit(buffer, edit)
|
||||
}
|
||||
|
||||
// One account: its name, current code (tap to copy), the seconds left and
|
||||
// Remove. True when Remove was confirmed.
|
||||
DrawRow :: (index: s32, x: float32, y: float32, inner: float32, row: float32) -> bool {
|
||||
account := *accounts[index]
|
||||
Box(session, BoxProps.{.key = cast(u64)(1000 + index), .bounds = Rectangle.{x, y, inner, row - 8.0},
|
||||
.radius = 10.0})
|
||||
title := TextUntilNul(account.issuer[:])
|
||||
subtitle := TextUntilNul(account.name[:])
|
||||
if title == "" {
|
||||
title = subtitle
|
||||
subtitle = ""
|
||||
}
|
||||
text_width := inner - 210.0
|
||||
Label(cast(u64)(2000 + index), title, Rectangle.{x + 12.0, y + 12.0, text_width, 22.0}, 16)
|
||||
Label(cast(u64)(3000 + index), subtitle, Rectangle.{x + 12.0, y + 38.0, text_width, 18.0}, 12)
|
||||
code := Code(index)
|
||||
if Action(4000 + index, code, Rectangle.{x + inner - 196.0, y + 12.0, 140.0, 44.0}, false) {
|
||||
if ClipboardCopy(code, CODE_CLEAR_SECONDS) {
|
||||
SetStatus("Code copied; it clears in 30 seconds")
|
||||
} else {
|
||||
SetStatus("The clipboard is unavailable")
|
||||
}
|
||||
}
|
||||
remaining := cast(s64)account.period - Unix() % cast(s64)account.period
|
||||
number: [24]u8
|
||||
Label(cast(u64)(5000 + index), FormatInteger(remaining, number[:]),
|
||||
Rectangle.{x + inner - 52.0, y + 24.0, 16.0, 18.0}, 12)
|
||||
remove := ButtonProps.{.key = cast(u64)(6000 + index), .id = 6000 + index,
|
||||
.label = ifx remove_pending == index then "Tap again to remove" else "Remove",
|
||||
.bounds = Rectangle.{x + inner - 40.0, y + 16.0, 36.0, 36.0},
|
||||
.icon_shape = Remove.Shape, .icon_only = true,
|
||||
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}
|
||||
if remove_pending == index {
|
||||
remove.tone = ButtonTone.ButtonToneDanger
|
||||
remove.emphasis = ButtonEmphasis.ButtonEmphasisFilled
|
||||
}
|
||||
if Button(session, remove) == 0 {
|
||||
return false
|
||||
}
|
||||
if remove_pending == index {
|
||||
return true
|
||||
}
|
||||
remove_pending = index
|
||||
SetStatus("Tap the red button again to remove this account")
|
||||
return false
|
||||
}
|
||||
|
||||
ListView :: (area: Rectangle, left: float32, width: float32) {
|
||||
if Action(10, "Add account", Rectangle.{left, area.y + 12.0, width, 40.0}, true) {
|
||||
view = VIEW_ADD
|
||||
focused = 0
|
||||
SetStatus("")
|
||||
return
|
||||
}
|
||||
top := area.y + 64.0
|
||||
height := area.height - 100.0
|
||||
if account_count == 0 {
|
||||
Label(cast(u64)11, "No accounts yet. Add one with its otpauth link or secret key.",
|
||||
Rectangle.{left, top, width, 24.0}, 14)
|
||||
}
|
||||
row: float32 = 76.0
|
||||
scroll := Scroll(session, ScrollProps.{.key = cast(u64)12, .bounds = Rectangle.{left, top, width, height},
|
||||
.content_height = cast(s32)(cast(float32)account_count * row), .scroll_offset = list_scroll,
|
||||
.scale = 1.0})
|
||||
list_scroll = scroll.scroll_offset
|
||||
if scroll.opened {
|
||||
x := scroll.content.x
|
||||
inner := scroll.content.width - 10.0
|
||||
index: s32 = 0
|
||||
while index < account_count {
|
||||
y := scroll.content.y + cast(float32)index * row
|
||||
if DrawRow(index, x, y, inner, row) {
|
||||
remove_pending = -1
|
||||
SetStatus(ifx RemoveAccount(index) then "Account removed" else "Could not remove the account")
|
||||
break
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
End(session)
|
||||
}
|
||||
}
|
||||
|
||||
AddView :: (area: Rectangle, left: float32, width: float32) {
|
||||
y := area.y + 12.0
|
||||
Label(cast(u64)20, "Paste otpauth:// links, one or many", Rectangle.{left, y, width, 20.0}, 14)
|
||||
Field(FIELD_LINKS, "Links", "otpauth://totp/…", links[:], Rectangle.{left, y + 24.0, width, 40.0}, true)
|
||||
y += 76.0
|
||||
if Action(21, "Import links", Rectangle.{left, y, width, 40.0}, true) {
|
||||
added := AddLinks(TextUntilNul(links[:]), true)
|
||||
if added > 0 && !SaveAccounts() {
|
||||
SetStatus("Could not save the accounts")
|
||||
}
|
||||
Clear(links[:])
|
||||
fields[FIELD_LINKS] = FieldState.{}
|
||||
if added > 0 {
|
||||
view = VIEW_LIST
|
||||
}
|
||||
}
|
||||
y += 64.0
|
||||
Label(cast(u64)22, "Or enter the secret key", Rectangle.{left, y, width, 20.0}, 14)
|
||||
y += 24.0
|
||||
Field(FIELD_ISSUER, "Service", "Service, such as GitHub", issuer[:], Rectangle.{left, y, width, 40.0}, false)
|
||||
y += 48.0
|
||||
Field(FIELD_NAME, "Account", "Account name or email", name[:], Rectangle.{left, y, width, 40.0}, false)
|
||||
y += 48.0
|
||||
Field(FIELD_SECRET, "Secret key", "Secret key", secret[:], Rectangle.{left, y, width, 40.0}, true)
|
||||
y += 56.0
|
||||
half := (width - 8.0) / 2.0
|
||||
if Action(23, "Add", Rectangle.{left, y, half, 40.0}, true) {
|
||||
if AddManual() {
|
||||
if SaveAccounts() {
|
||||
SetStatus("Account added")
|
||||
} else {
|
||||
SetStatus("Could not save the accounts")
|
||||
}
|
||||
Clear(issuer[:])
|
||||
Clear(name[:])
|
||||
Clear(secret[:])
|
||||
view = VIEW_LIST
|
||||
}
|
||||
}
|
||||
if Action(24, "Cancel", Rectangle.{left + half + 8.0, y, half, 40.0}, false) {
|
||||
Clear(links[:])
|
||||
Clear(secret[:])
|
||||
view = VIEW_LIST
|
||||
SetStatus("")
|
||||
}
|
||||
}
|
||||
|
||||
Draw :: () {
|
||||
session = AppSession()
|
||||
area := AppBounds()
|
||||
width := area.width - 32.0
|
||||
if width > 520.0 {
|
||||
width = 520.0
|
||||
}
|
||||
left := area.x + (area.width - width) * 0.5
|
||||
if view == VIEW_ADD {
|
||||
AddView(area, left, width)
|
||||
} else {
|
||||
ListView(area, left, width)
|
||||
}
|
||||
Label(cast(u64)30, TextUntilNul(status[:]), Rectangle.{left, area.y + area.height - 28.0, width, 20.0}, 12)
|
||||
AppKeyboard(focused != 0)
|
||||
}
|
||||
|
||||
#program_export "AuthMain"
|
||||
Main :: () -> s32 {
|
||||
if AppMode() == APP_IDENTIFY {
|
||||
AppDescribe("Auth", Icon.Shape)
|
||||
return APP_PROTOCOL
|
||||
}
|
||||
// Records from another device replace the list.
|
||||
if !loaded || RecordsVersion() != records_version {
|
||||
LoadAccounts()
|
||||
loaded = true
|
||||
}
|
||||
Draw()
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,676 @@
|
||||
// Time-based one-time passwords (RFC 6238) with HMAC-SHA-1, SHA-256 or
|
||||
// SHA-512, and the otpauth:// links authenticator apps export.
|
||||
#import "text_buffer"
|
||||
#import "sha256"
|
||||
|
||||
HASH_SHA1 :: 1
|
||||
HASH_SHA256 :: 2
|
||||
HASH_SHA512 :: 3
|
||||
// Longest key, message and decoded secret this module handles.
|
||||
KEY_LIMIT :: 128
|
||||
HASH_INPUT_LIMIT :: 256
|
||||
|
||||
Digest :: struct {
|
||||
bytes: [64]u8
|
||||
count: s32
|
||||
}
|
||||
|
||||
// The 80 SHA-512 round constants, each as its high and low 32 bits.
|
||||
sha512_round_halves: [160]u32 = .[
|
||||
0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd, 0xb5c0fbcf, 0xec4d3b2f,
|
||||
0xe9b5dba5, 0x8189dbbc, 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
|
||||
0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118, 0xd807aa98, 0xa3030242,
|
||||
0x12835b01, 0x45706fbe, 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
|
||||
0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1, 0x9bdc06a7, 0x25c71235,
|
||||
0xc19bf174, 0xcf692694, 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
|
||||
0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65, 0x2de92c6f, 0x592b0275,
|
||||
0x4a7484aa, 0x6ea6e483, 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
|
||||
0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210, 0xb00327c8, 0x98fb213f,
|
||||
0xbf597fc7, 0xbeef0ee4, 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
|
||||
0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70, 0x27b70a85, 0x46d22ffc,
|
||||
0x2e1b2138, 0x5c26c926, 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
|
||||
0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8, 0x81c2c92e, 0x47edaee6,
|
||||
0x92722c85, 0x1482353b, 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
|
||||
0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30, 0xd192e819, 0xd6ef5218,
|
||||
0xd6990624, 0x5565a910, 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
|
||||
0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53, 0x2748774c, 0xdf8eeb99,
|
||||
0x34b0bcb5, 0xe19b48a8, 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
|
||||
0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3, 0x748f82ee, 0x5defb2fc,
|
||||
0x78a5636f, 0x43172f60, 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
|
||||
0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9, 0xbef9a3f7, 0xb2c67915,
|
||||
0xc67178f2, 0xe372532b, 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
|
||||
0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178, 0x06f067aa, 0x72176fba,
|
||||
0x0a637dc5, 0xa2c898a6, 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
|
||||
0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493, 0x3c9ebe0a, 0x15c9bebc,
|
||||
0x431d67c4, 0x9c100d4c, 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
|
||||
0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
|
||||
];
|
||||
|
||||
RotateLeft32 :: (value: u32, amount: u32) -> u32 {
|
||||
return (value << amount) | (value >> (cast(u32)32 - amount))
|
||||
}
|
||||
|
||||
RotateRight64 :: (value: u64, amount: u64) -> u64 {
|
||||
return (value >> amount) | (value << (cast(u64)64 - amount))
|
||||
}
|
||||
|
||||
// Pads a message the SHA way into blocks: 0x80, zeros, then the bit length
|
||||
// in the last eight bytes. Returns the padded length.
|
||||
Pad :: (input: []u8, count: s32, block: s32, output: []u8) -> s32 {
|
||||
index: s32 = 0
|
||||
while index < count {
|
||||
output[index] = input[index]
|
||||
index += 1
|
||||
}
|
||||
output[count] = cast(u8)0x80
|
||||
length_bytes: s32 = ifx block == 128 then 16 else 8
|
||||
total := ((count + 1 + length_bytes + block - 1) / block) * block
|
||||
index = count + 1
|
||||
while index < total {
|
||||
output[index] = cast(u8)0
|
||||
index += 1
|
||||
}
|
||||
bits := cast(u64)count * cast(u64)8
|
||||
for shift: 0..7 {
|
||||
output[total - 1 - cast(s32)shift] = cast(u8)(bits >> (cast(u64)shift * cast(u64)8))
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
Sha1 :: (input: []u8, count: s32) -> Digest {
|
||||
padded: [HASH_INPUT_LIMIT + 128]u8
|
||||
total := Pad(input, count, 64, padded[:])
|
||||
state: [5]u32 = .[0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]
|
||||
offset: s32 = 0
|
||||
while offset < total {
|
||||
words: [80]u32
|
||||
for index: 0..15 {
|
||||
at := offset + cast(s32)index * 4
|
||||
words[index] = (cast(u32)padded[at] << cast(u32)24) | (cast(u32)padded[at + 1] << cast(u32)16) |
|
||||
(cast(u32)padded[at + 2] << cast(u32)8) | cast(u32)padded[at + 3]
|
||||
}
|
||||
for index: 16..79 {
|
||||
mixed: u32 = words[index - 3] ^ words[index - 8]
|
||||
mixed = mixed ^ words[index - 14]
|
||||
mixed = mixed ^ words[index - 16]
|
||||
words[index] = RotateLeft32(mixed, cast(u32)1)
|
||||
}
|
||||
a := state[0]
|
||||
b := state[1]
|
||||
c := state[2]
|
||||
d := state[3]
|
||||
e := state[4]
|
||||
for index: 0..79 {
|
||||
mix: u32
|
||||
constant: u32
|
||||
if index < 20 {
|
||||
mix = (b & c) | (~b & d)
|
||||
constant = 0x5a827999
|
||||
} else if index < 40 {
|
||||
mix = b ^ c ^ d
|
||||
constant = 0x6ed9eba1
|
||||
} else if index < 60 {
|
||||
mix = (b & c) | (b & d) | (c & d)
|
||||
constant = 0x8f1bbcdc
|
||||
} else {
|
||||
mix = b ^ c ^ d
|
||||
constant = 0xca62c1d6
|
||||
}
|
||||
next := RotateLeft32(a, cast(u32)5) + mix + e + constant + words[index]
|
||||
e = d
|
||||
d = c
|
||||
c = RotateLeft32(b, cast(u32)30)
|
||||
b = a
|
||||
a = next
|
||||
}
|
||||
state[0] += a
|
||||
state[1] += b
|
||||
state[2] += c
|
||||
state[3] += d
|
||||
state[4] += e
|
||||
offset += 64
|
||||
}
|
||||
digest: Digest
|
||||
digest.count = 20
|
||||
for index: 0..4 {
|
||||
for part: 0..3 {
|
||||
digest.bytes[index * 4 + part] = cast(u8)(state[index] >> (cast(u32)(3 - part) * cast(u32)8))
|
||||
}
|
||||
}
|
||||
return digest
|
||||
}
|
||||
|
||||
Sha512 :: (input: []u8, count: s32) -> Digest {
|
||||
padded: [HASH_INPUT_LIMIT + 256]u8
|
||||
total := Pad(input, count, 128, padded[:])
|
||||
initial: [16]u32 = .[0x6a09e667, 0xf3bcc908, 0xbb67ae85, 0x84caa73b, 0x3c6ef372, 0xfe94f82b,
|
||||
0xa54ff53a, 0x5f1d36f1, 0x510e527f, 0xade682d1, 0x9b05688c, 0x2b3e6c1f, 0x1f83d9ab, 0xfb41bd6b,
|
||||
0x5be0cd19, 0x137e2179]
|
||||
state: [8]u64
|
||||
for index: 0..7 {
|
||||
state[index] = (cast(u64)initial[index * 2] << cast(u64)32) | cast(u64)initial[index * 2 + 1]
|
||||
}
|
||||
offset: s32 = 0
|
||||
while offset < total {
|
||||
words: [80]u64
|
||||
for index: 0..15 {
|
||||
value: u64 = 0
|
||||
for part: 0..7 {
|
||||
value = (value << cast(u64)8) | cast(u64)padded[offset + cast(s32)index * 8 + cast(s32)part]
|
||||
}
|
||||
words[index] = value
|
||||
}
|
||||
for index: 16..79 {
|
||||
low: u64 = RotateRight64(words[index - 15], cast(u64)1)
|
||||
low = low ^ RotateRight64(words[index - 15], cast(u64)8)
|
||||
low = low ^ (words[index - 15] >> cast(u64)7)
|
||||
high: u64 = RotateRight64(words[index - 2], cast(u64)19)
|
||||
high = high ^ RotateRight64(words[index - 2], cast(u64)61)
|
||||
high = high ^ (words[index - 2] >> cast(u64)6)
|
||||
words[index] = words[index - 16] + low + words[index - 7] + high
|
||||
}
|
||||
a := state[0]
|
||||
b := state[1]
|
||||
c := state[2]
|
||||
d := state[3]
|
||||
e := state[4]
|
||||
f := state[5]
|
||||
g := state[6]
|
||||
h := state[7]
|
||||
for index: 0..79 {
|
||||
major: u64 = RotateRight64(e, cast(u64)14)
|
||||
major = major ^ RotateRight64(e, cast(u64)18)
|
||||
major = major ^ RotateRight64(e, cast(u64)41)
|
||||
choose := (e & f) ^ (~e & g)
|
||||
constant := (cast(u64)sha512_round_halves[index * 2] << cast(u64)32) | cast(u64)sha512_round_halves[index * 2 + 1]
|
||||
first := h + major + choose + constant + words[index]
|
||||
minor: u64 = RotateRight64(a, cast(u64)28)
|
||||
minor = minor ^ RotateRight64(a, cast(u64)34)
|
||||
minor = minor ^ RotateRight64(a, cast(u64)39)
|
||||
mixture := (a & b) ^ (a & c) ^ (b & c)
|
||||
h = g
|
||||
g = f
|
||||
f = e
|
||||
e = d + first
|
||||
d = c
|
||||
c = b
|
||||
b = a
|
||||
a = first + minor + mixture
|
||||
}
|
||||
state[0] += a
|
||||
state[1] += b
|
||||
state[2] += c
|
||||
state[3] += d
|
||||
state[4] += e
|
||||
state[5] += f
|
||||
state[6] += g
|
||||
state[7] += h
|
||||
offset += 128
|
||||
}
|
||||
digest: Digest
|
||||
digest.count = 64
|
||||
for index: 0..7 {
|
||||
for part: 0..7 {
|
||||
digest.bytes[index * 8 + part] = cast(u8)(state[index] >> (cast(u64)(7 - part) * cast(u64)8))
|
||||
}
|
||||
}
|
||||
return digest
|
||||
}
|
||||
|
||||
Hash :: (kind: s32, input: []u8, count: s32) -> Digest {
|
||||
if kind == HASH_SHA256 {
|
||||
hashed := Sha256(TextView(input[0:count]))
|
||||
digest: Digest
|
||||
digest.count = 32
|
||||
for index: 0..31 {
|
||||
digest.bytes[index] = hashed[index]
|
||||
}
|
||||
return digest
|
||||
}
|
||||
if kind == HASH_SHA512 {
|
||||
return Sha512(input, count)
|
||||
}
|
||||
return Sha1(input, count)
|
||||
}
|
||||
|
||||
// HMAC (RFC 2104). Keys up to KEY_LIMIT bytes and messages up to 64 bytes.
|
||||
Hmac :: (kind: s32, key: []u8, key_count: s32, message: []u8, message_count: s32) -> Digest {
|
||||
block: s32 = ifx kind == HASH_SHA512 then 128 else 64
|
||||
block_key: [128]u8
|
||||
if key_count > block {
|
||||
hashed := Hash(kind, key, key_count)
|
||||
for index: 0..63 {
|
||||
block_key[index] = hashed.bytes[index]
|
||||
}
|
||||
} else {
|
||||
index: s32 = 0
|
||||
while index < key_count {
|
||||
block_key[index] = key[index]
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
inner_input: [HASH_INPUT_LIMIT]u8
|
||||
index: s32 = 0
|
||||
while index < block {
|
||||
inner_input[index] = block_key[index] ^ cast(u8)0x36
|
||||
index += 1
|
||||
}
|
||||
index = 0
|
||||
while index < message_count {
|
||||
inner_input[block + index] = message[index]
|
||||
index += 1
|
||||
}
|
||||
inner := Hash(kind, inner_input[:], block + message_count)
|
||||
outer_input: [HASH_INPUT_LIMIT]u8
|
||||
index = 0
|
||||
while index < block {
|
||||
outer_input[index] = block_key[index] ^ cast(u8)0x5c
|
||||
index += 1
|
||||
}
|
||||
index = 0
|
||||
while index < inner.count {
|
||||
outer_input[block + index] = inner.bytes[index]
|
||||
index += 1
|
||||
}
|
||||
result := Hash(kind, outer_input[:], block + inner.count)
|
||||
for wipe: 0..127 {
|
||||
block_key[wipe] = cast(u8)0
|
||||
}
|
||||
for wipe: 0..HASH_INPUT_LIMIT - 1 {
|
||||
inner_input[wipe] = cast(u8)0
|
||||
outer_input[wipe] = cast(u8)0
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// The code for a counter (HOTP, RFC 4226), zero-padded to digits.
|
||||
CodeAt :: (kind: s32, key: []u8, key_count: s32, digits: s32, counter: u64, output: []u8) -> string {
|
||||
message: [8]u8
|
||||
for index: 0..7 {
|
||||
message[index] = cast(u8)(counter >> (cast(u64)(7 - index) * cast(u64)8))
|
||||
}
|
||||
mac := Hmac(kind, key, key_count, message[:], 8)
|
||||
offset := cast(s32)(mac.bytes[mac.count - 1] & cast(u8)0x0f)
|
||||
binary := ((cast(u32)mac.bytes[offset] & cast(u32)0x7f) << cast(u32)24) |
|
||||
(cast(u32)mac.bytes[offset + 1] << cast(u32)16) |
|
||||
(cast(u32)mac.bytes[offset + 2] << cast(u32)8) | cast(u32)mac.bytes[offset + 3]
|
||||
modulus: u32 = 1
|
||||
for step: 1..digits {
|
||||
modulus *= cast(u32)10
|
||||
}
|
||||
value := binary % modulus
|
||||
position := digits - 1
|
||||
while position >= 0 {
|
||||
output[position] = cast(u8)(48 + cast(s32)(value % cast(u32)10))
|
||||
value /= cast(u32)10
|
||||
position -= 1
|
||||
}
|
||||
output[digits] = cast(u8)0
|
||||
return TextView(output[0:digits])
|
||||
}
|
||||
|
||||
// The code for a Unix time (TOTP, RFC 6238).
|
||||
CodeNow :: (kind: s32, key: []u8, key_count: s32, digits: s32, period: s32, unix: s64, output: []u8) -> string {
|
||||
step := unix / cast(s64)period
|
||||
if step < 0 {
|
||||
step = 0
|
||||
}
|
||||
return CodeAt(kind, key, key_count, digits, cast(u64)step, output)
|
||||
}
|
||||
|
||||
// Decodes Base32 (RFC 4648) ignoring case, spaces, hyphens and padding.
|
||||
// Returns the byte count, or -1 for any other character or a key too long.
|
||||
Base32Decode :: (text: string, output: []u8) -> s32 {
|
||||
buffer: u32 = 0
|
||||
bits: s32 = 0
|
||||
count: s32 = 0
|
||||
index: s64 = 0
|
||||
while index < text.count {
|
||||
byte := text[index]
|
||||
index += 1
|
||||
if byte == cast(u8)32 || byte == cast(u8)45 || byte == cast(u8)61 {
|
||||
continue
|
||||
}
|
||||
value: s32 = -1
|
||||
if byte >= cast(u8)65 && byte <= cast(u8)90 {
|
||||
value = cast(s32)(byte - cast(u8)65)
|
||||
} else if byte >= cast(u8)97 && byte <= cast(u8)122 {
|
||||
value = cast(s32)(byte - cast(u8)97)
|
||||
} else if byte >= cast(u8)50 && byte <= cast(u8)55 {
|
||||
value = cast(s32)(byte - cast(u8)50) + 26
|
||||
}
|
||||
if value < 0 {
|
||||
return -1
|
||||
}
|
||||
buffer = (buffer << cast(u32)5) | cast(u32)value
|
||||
bits += 5
|
||||
if bits >= 8 {
|
||||
bits -= 8
|
||||
if count >= cast(s32)output.count {
|
||||
return -1
|
||||
}
|
||||
output[count] = cast(u8)(buffer >> cast(u32)bits)
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
Account :: struct {
|
||||
issuer: [64]u8
|
||||
name: [128]u8
|
||||
// The secret as Base32, kept to save it again.
|
||||
secret: [256]u8
|
||||
key: [KEY_LIMIT]u8
|
||||
key_count: s32
|
||||
kind: s32
|
||||
digits: s32
|
||||
period: s32
|
||||
}
|
||||
|
||||
Lower :: (byte: u8) -> u8 {
|
||||
if byte >= cast(u8)65 && byte <= cast(u8)90 {
|
||||
return byte + cast(u8)32
|
||||
}
|
||||
return byte
|
||||
}
|
||||
|
||||
StartsWithIgnoringCase :: (text: string, prefix: string) -> bool {
|
||||
if text.count < prefix.count {
|
||||
return false
|
||||
}
|
||||
index: s64 = 0
|
||||
while index < prefix.count {
|
||||
if Lower(text[index]) != Lower(prefix[index]) {
|
||||
return false
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
HexValue :: (byte: u8) -> s32 {
|
||||
if byte >= cast(u8)48 && byte <= cast(u8)57 {
|
||||
return cast(s32)(byte - cast(u8)48)
|
||||
}
|
||||
lower := Lower(byte)
|
||||
if lower >= cast(u8)97 && lower <= cast(u8)102 {
|
||||
return cast(s32)(lower - cast(u8)97) + 10
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// Percent-decodes into output ("+" is a space in a query). False when it
|
||||
// does not fit.
|
||||
Unescape :: (text: string, output: []u8) -> bool {
|
||||
used: s64 = 0
|
||||
index: s64 = 0
|
||||
while index < text.count {
|
||||
byte := text[index]
|
||||
if byte == cast(u8)37 && index + 2 < text.count && HexValue(text[index + 1]) >= 0 && HexValue(text[index + 2]) >= 0 {
|
||||
byte = cast(u8)(HexValue(text[index + 1]) * 16 + HexValue(text[index + 2]))
|
||||
index += 2
|
||||
} else if byte == cast(u8)43 {
|
||||
byte = cast(u8)32
|
||||
}
|
||||
if used >= output.count - 1 || byte < cast(u8)32 {
|
||||
return false
|
||||
}
|
||||
output[used] = byte
|
||||
used += 1
|
||||
index += 1
|
||||
}
|
||||
output[used] = cast(u8)0
|
||||
return true
|
||||
}
|
||||
|
||||
ParseNumber :: (text: string) -> s32 {
|
||||
if text.count == 0 || text.count > 6 {
|
||||
return -1
|
||||
}
|
||||
value: s32 = 0
|
||||
index: s64 = 0
|
||||
while index < text.count {
|
||||
if text[index] < cast(u8)48 || text[index] > cast(u8)57 {
|
||||
return -1
|
||||
}
|
||||
value = value * 10 + cast(s32)(text[index] - cast(u8)48)
|
||||
index += 1
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
ParseAlgorithm :: (text: string) -> s32 {
|
||||
upper: [8]u8
|
||||
if text.count > 7 {
|
||||
return 0
|
||||
}
|
||||
index: s64 = 0
|
||||
while index < text.count {
|
||||
byte := text[index]
|
||||
upper[index] = ifx byte >= cast(u8)97 && byte <= cast(u8)122 then byte - cast(u8)32 else byte
|
||||
index += 1
|
||||
}
|
||||
name := TextView(upper[0:text.count])
|
||||
if name == "SHA1" {
|
||||
return HASH_SHA1
|
||||
}
|
||||
if name == "SHA256" {
|
||||
return HASH_SHA256
|
||||
}
|
||||
if name == "SHA512" {
|
||||
return HASH_SHA512
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Checks a Base32 secret and fills the account's key from it.
|
||||
SetSecret :: (account: *Account, secret: string) -> bool {
|
||||
clean: [256]u8
|
||||
used: s64 = 0
|
||||
index: s64 = 0
|
||||
while index < secret.count {
|
||||
byte := secret[index]
|
||||
index += 1
|
||||
if byte == cast(u8)32 || byte == cast(u8)45 || byte == cast(u8)61 {
|
||||
continue
|
||||
}
|
||||
if used >= 255 {
|
||||
return false
|
||||
}
|
||||
clean[used] = ifx byte >= cast(u8)97 && byte <= cast(u8)122 then byte - cast(u8)32 else byte
|
||||
used += 1
|
||||
}
|
||||
count := Base32Decode(TextView(clean[0:used]), account.key[:])
|
||||
// Shorter keys than 80 bits are refused as RFC 4226 asks; most services
|
||||
// use 160.
|
||||
if count < 10 {
|
||||
return false
|
||||
}
|
||||
account.key_count = count
|
||||
index = 0
|
||||
while index < used {
|
||||
account.secret[index] = clean[index]
|
||||
index += 1
|
||||
}
|
||||
account.secret[used] = cast(u8)0
|
||||
return true
|
||||
}
|
||||
|
||||
CopyLimited :: (text: string, output: []u8) -> bool {
|
||||
if text.count >= output.count {
|
||||
return false
|
||||
}
|
||||
index: s64 = 0
|
||||
while index < text.count {
|
||||
if text[index] < cast(u8)32 {
|
||||
return false
|
||||
}
|
||||
output[index] = text[index]
|
||||
index += 1
|
||||
}
|
||||
output[text.count] = cast(u8)0
|
||||
return true
|
||||
}
|
||||
|
||||
// Reads an otpauth://totp/ link. HOTP and other kinds are refused.
|
||||
ParseLink :: (link: string, account: *Account) -> bool {
|
||||
account.* = Account.{.kind = HASH_SHA1, .digits = 6, .period = 30}
|
||||
prefix := "otpauth://totp/"
|
||||
if !StartsWithIgnoringCase(link, prefix) {
|
||||
return false
|
||||
}
|
||||
rest := link[prefix.count:link.count]
|
||||
query_at: s64 = 0
|
||||
while query_at < rest.count && rest[query_at] != cast(u8)63 {
|
||||
query_at += 1
|
||||
}
|
||||
label: [256]u8
|
||||
if !Unescape(rest[0:query_at], label[:]) {
|
||||
return false
|
||||
}
|
||||
label_text := TextUntilNul(label[:])
|
||||
colon: s64 = 0
|
||||
while colon < label_text.count && label_text[colon] != cast(u8)58 {
|
||||
colon += 1
|
||||
}
|
||||
if colon < label_text.count {
|
||||
start := colon + 1
|
||||
while start < label_text.count && label_text[start] == cast(u8)32 {
|
||||
start += 1
|
||||
}
|
||||
if !CopyLimited(label_text[0:colon], account.issuer[:]) ||
|
||||
!CopyLimited(label_text[start:label_text.count], account.name[:]) {
|
||||
return false
|
||||
}
|
||||
} else if !CopyLimited(label_text, account.name[:]) {
|
||||
return false
|
||||
}
|
||||
has_secret := false
|
||||
position := query_at + 1
|
||||
while position < rest.count {
|
||||
end := position
|
||||
while end < rest.count && rest[end] != cast(u8)38 {
|
||||
end += 1
|
||||
}
|
||||
pair := rest[position:end]
|
||||
equals: s64 = 0
|
||||
while equals < pair.count && pair[equals] != cast(u8)61 {
|
||||
equals += 1
|
||||
}
|
||||
if equals < pair.count {
|
||||
key := pair[0:equals]
|
||||
value: [256]u8
|
||||
if !Unescape(pair[equals + 1:pair.count], value[:]) {
|
||||
return false
|
||||
}
|
||||
text := TextUntilNul(value[:])
|
||||
if key == "secret" {
|
||||
if !SetSecret(account, text) {
|
||||
return false
|
||||
}
|
||||
has_secret = true
|
||||
} else if key == "issuer" {
|
||||
if !CopyLimited(text, account.issuer[:]) {
|
||||
return false
|
||||
}
|
||||
} else if key == "algorithm" {
|
||||
account.kind = ParseAlgorithm(text)
|
||||
if account.kind == 0 {
|
||||
return false
|
||||
}
|
||||
} else if key == "digits" {
|
||||
account.digits = ParseNumber(text)
|
||||
if account.digits < 6 || account.digits > 8 {
|
||||
return false
|
||||
}
|
||||
} else if key == "period" {
|
||||
account.period = ParseNumber(text)
|
||||
if account.period < 1 || account.period > 300 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
position = end + 1
|
||||
}
|
||||
return has_secret && (account.issuer[0] != cast(u8)0 || account.name[0] != cast(u8)0)
|
||||
}
|
||||
|
||||
Unreserved :: (byte: u8) -> bool {
|
||||
return byte >= cast(u8)65 && byte <= cast(u8)90 || byte >= cast(u8)97 && byte <= cast(u8)122 ||
|
||||
byte >= cast(u8)48 && byte <= cast(u8)57 || byte == cast(u8)45 || byte == cast(u8)46 ||
|
||||
byte == cast(u8)95 || byte == cast(u8)126
|
||||
}
|
||||
|
||||
AppendText :: (output: []u8, used: s64, text: string) -> s64 {
|
||||
index: s64 = 0
|
||||
while index < text.count {
|
||||
if used < 0 || used >= output.count - 1 {
|
||||
return -1
|
||||
}
|
||||
output[used] = text[index]
|
||||
used += 1
|
||||
index += 1
|
||||
}
|
||||
output[used] = cast(u8)0
|
||||
return used
|
||||
}
|
||||
|
||||
AppendEscaped :: (output: []u8, used: s64, text: string) -> s64 {
|
||||
hex := "0123456789ABCDEF"
|
||||
index: s64 = 0
|
||||
while index < text.count && used >= 0 {
|
||||
byte := text[index]
|
||||
if Unreserved(byte) {
|
||||
used = AppendText(output, used, text[index:index + 1])
|
||||
} else if used + 3 < output.count {
|
||||
output[used] = cast(u8)37
|
||||
output[used + 1] = hex[cast(s64)(byte >> cast(u8)4)]
|
||||
output[used + 2] = hex[cast(s64)(byte & cast(u8)15)]
|
||||
used += 3
|
||||
output[used] = cast(u8)0
|
||||
} else {
|
||||
return -1
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
return used
|
||||
}
|
||||
|
||||
// The account as an otpauth link, the format Auth saves and imports.
|
||||
LinkText :: (account: *Account, output: []u8) -> string {
|
||||
used := AppendText(output, 0, "otpauth://totp/")
|
||||
issuer := TextUntilNul(account.issuer[:])
|
||||
if issuer != "" {
|
||||
used = AppendEscaped(output, used, issuer)
|
||||
used = AppendText(output, used, ":")
|
||||
}
|
||||
used = AppendEscaped(output, used, TextUntilNul(account.name[:]))
|
||||
used = AppendText(output, used, "?secret=")
|
||||
used = AppendText(output, used, TextUntilNul(account.secret[:]))
|
||||
if issuer != "" {
|
||||
used = AppendText(output, used, "&issuer=")
|
||||
used = AppendEscaped(output, used, issuer)
|
||||
}
|
||||
algorithms: [4]string = .["", "SHA1", "SHA256", "SHA512"]
|
||||
used = AppendText(output, used, "&algorithm=")
|
||||
used = AppendText(output, used, algorithms[account.kind])
|
||||
digits: [2]u8
|
||||
digits[0] = cast(u8)(48 + account.digits)
|
||||
used = AppendText(output, used, "&digits=")
|
||||
used = AppendText(output, used, TextView(digits[0:1]))
|
||||
period: [8]u8
|
||||
value := account.period
|
||||
length: s32 = 0
|
||||
while value > 0 || length == 0 {
|
||||
period[7 - length] = cast(u8)(48 + value % 10)
|
||||
value /= 10
|
||||
length += 1
|
||||
}
|
||||
used = AppendText(output, used, "&period=")
|
||||
used = AppendText(output, used, TextView(period[8 - length:8]))
|
||||
if used < 0 {
|
||||
return ""
|
||||
}
|
||||
return TextView(output[0:used])
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// RFC 6238 and RFC 4648 test vectors, with the RFCs' public fixture keys.
|
||||
#import "text_buffer"
|
||||
#import "totp"
|
||||
|
||||
KeyFrom :: (text: string, output: []u8) -> s32 {
|
||||
index: s64 = 0
|
||||
while index < text.count {
|
||||
output[index] = text[index]
|
||||
index += 1
|
||||
}
|
||||
return cast(s32)text.count
|
||||
}
|
||||
|
||||
Expect :: (kind: s32, key: string, unix: s64, expected: string) -> bool {
|
||||
bytes: [KEY_LIMIT]u8
|
||||
count := KeyFrom(key, bytes[:])
|
||||
code: [12]u8
|
||||
return CodeNow(kind, bytes[:], count, 8, 30, unix, code[:]) == expected
|
||||
}
|
||||
|
||||
#program_export
|
||||
Run :: () -> s32 {
|
||||
sha1 := "12345678901234567890"
|
||||
sha256 := "12345678901234567890123456789012"
|
||||
sha512 := "1234567890123456789012345678901234567890123456789012345678901234"
|
||||
times: [6]s64 = .[59, 1111111109, 1111111111, 1234567890, 2000000000, 20000000000]
|
||||
sha1_codes: [6]string = .["94287082", "07081804", "14050471", "89005924", "69279037", "65353130"]
|
||||
sha256_codes: [6]string = .["46119246", "68084774", "67062674", "91819424", "90698825", "77737706"]
|
||||
sha512_codes: [6]string = .["90693936", "25091201", "99943326", "93441116", "38618901", "47863826"]
|
||||
for index: 0..5 {
|
||||
if !Expect(HASH_SHA1, sha1, times[index], sha1_codes[index]) {
|
||||
return 10 + cast(s32)index
|
||||
}
|
||||
if !Expect(HASH_SHA256, sha256, times[index], sha256_codes[index]) {
|
||||
return 20 + cast(s32)index
|
||||
}
|
||||
if !Expect(HASH_SHA512, sha512, times[index], sha512_codes[index]) {
|
||||
return 30 + cast(s32)index
|
||||
}
|
||||
}
|
||||
decoded: [KEY_LIMIT]u8
|
||||
count := Base32Decode("gezd gnbv-gy3t qojq GEZDGNBVGY3TQOJQ====", decoded[:])
|
||||
if count != 20 || TextView(decoded[0:20]) != sha1 || Base32Decode("GEZ1", decoded[:]) != -1 {
|
||||
return 40
|
||||
}
|
||||
account: Account
|
||||
link := "otpauth://totp/Example%20Co:alice%40example.com?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&issuer=Example%20Co&algorithm=SHA256&digits=8&period=60"
|
||||
if !ParseLink(link, *account) || TextUntilNul(account.issuer[:]) != "Example Co" ||
|
||||
TextUntilNul(account.name[:]) != "[email protected]" || account.kind != HASH_SHA256 ||
|
||||
account.digits != 8 || account.period != 60 || account.key_count != 20 {
|
||||
return 41
|
||||
}
|
||||
saved: [1024]u8
|
||||
again: Account
|
||||
if !ParseLink(LinkText(*account, saved[:]), *again) || TextUntilNul(again.secret[:]) != TextUntilNul(account.secret[:]) ||
|
||||
TextUntilNul(again.issuer[:]) != "Example Co" || again.digits != 8 || again.period != 60 {
|
||||
return 42
|
||||
}
|
||||
if ParseLink("otpauth://hotp/Example:alice?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&counter=1", *again) ||
|
||||
ParseLink("otpauth://totp/Example:alice?secret=SHORT", *again) {
|
||||
return 43
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -1,12 +1,8 @@
|
||||
// Evaluates calculator expressions: + − × ÷ (also - * /), ^ for powers,
|
||||
// postfix %, ², ³, ! and ⁻¹, unary signs, brackets, the functions sin cos tan
|
||||
// and their inverses (sin⁻¹ or asin) and hyperbolic forms, ln, log, √, ∛,
|
||||
// abs and exp, the constants π, e and Ans, and E for a power of ten, as in
|
||||
// 6.02E23. A number, constant or function next to another multiplies, so
|
||||
// 2π and 3sin(30) work. Brackets left open at the end are closed there.
|
||||
// a postfix % for percent, unary signs and brackets. Brackets left open at
|
||||
// the end are closed there.
|
||||
#import "text_buffer"
|
||||
#import "number_text"
|
||||
#import "math"
|
||||
|
||||
Answer :: struct {
|
||||
valid: bool
|
||||
@@ -17,13 +13,6 @@ Answer :: struct {
|
||||
source: string;
|
||||
position: s32;
|
||||
failure: string;
|
||||
// Trigonometric angles are degrees when set, otherwise radians.
|
||||
degrees: bool;
|
||||
// The last result, for Ans.
|
||||
last_answer: float64;
|
||||
|
||||
PI_VALUE :: 3.141592653589793
|
||||
E_VALUE :: 2.718281828459045
|
||||
|
||||
EvaluateExpression :: (text: string) -> Answer {
|
||||
source = text
|
||||
@@ -34,18 +23,12 @@ EvaluateExpression :: (text: string) -> Answer {
|
||||
if failure == "" && position < cast(s32)source.count {
|
||||
failure = "Cannot read this expression"
|
||||
}
|
||||
if failure == "" && value != value {
|
||||
failure = "Not a real number"
|
||||
}
|
||||
if failure == "" && !Finite(value) {
|
||||
failure = "Result is too large"
|
||||
}
|
||||
if failure != "" {
|
||||
return Answer.{.error = failure}
|
||||
}
|
||||
if value == 0.0 {
|
||||
value = 0.0
|
||||
}
|
||||
return Answer.{.valid = true, .value = value}
|
||||
}
|
||||
|
||||
@@ -59,7 +42,7 @@ SkipSpaces :: () {
|
||||
}
|
||||
}
|
||||
|
||||
// Whether the next text is the given one, consuming it when it is.
|
||||
// Whether the next character is the given one, consuming it when it is.
|
||||
Take :: (symbol: string) -> bool {
|
||||
SkipSpaces()
|
||||
end := position + cast(s32)symbol.count
|
||||
@@ -70,13 +53,6 @@ Take :: (symbol: string) -> bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Whether the next text is the given one, without consuming it.
|
||||
Peek :: (symbol: string) -> bool {
|
||||
SkipSpaces()
|
||||
end := position + cast(s32)symbol.count
|
||||
return end <= cast(s32)source.count && source[position:end] == symbol
|
||||
}
|
||||
|
||||
ParseSum :: () -> float64 {
|
||||
value := ParseProduct()
|
||||
while failure == "" {
|
||||
@@ -103,8 +79,6 @@ ParseProduct :: () -> float64 {
|
||||
return 0.0
|
||||
}
|
||||
value /= divisor
|
||||
} else if StartsFactor() {
|
||||
value *= ParsePower()
|
||||
} else {
|
||||
return value
|
||||
}
|
||||
@@ -112,23 +86,6 @@ ParseProduct :: () -> float64 {
|
||||
return value
|
||||
}
|
||||
|
||||
// A factor follows without an operator, so the two multiply.
|
||||
StartsFactor :: () -> bool {
|
||||
SkipSpaces()
|
||||
if position >= cast(s32)source.count {
|
||||
return false
|
||||
}
|
||||
byte := source[position]
|
||||
if IsDigit(byte) || byte == cast(u8)46 || byte == cast(u8)40 {
|
||||
return true
|
||||
}
|
||||
// Letters start functions and constants; E alone is a number's exponent.
|
||||
if byte >= cast(u8)97 && byte <= cast(u8)122 || byte == cast(u8)65 {
|
||||
return true
|
||||
}
|
||||
return Peek("π") || Peek("√") || Peek("∛")
|
||||
}
|
||||
|
||||
ParseSigned :: () -> float64 {
|
||||
if Take("-") || Take("−") {
|
||||
return 0.0 - ParseSigned()
|
||||
@@ -140,7 +97,7 @@ ParseSigned :: () -> float64 {
|
||||
}
|
||||
|
||||
ParsePower :: () -> float64 {
|
||||
base := ParsePostfix()
|
||||
base := ParsePercent()
|
||||
if failure == "" && Take("^") {
|
||||
exponent := ParseSigned()
|
||||
return Power(base, exponent)
|
||||
@@ -148,26 +105,10 @@ ParsePower :: () -> float64 {
|
||||
return base
|
||||
}
|
||||
|
||||
ParsePostfix :: () -> float64 {
|
||||
ParsePercent :: () -> float64 {
|
||||
value := ParseAtom()
|
||||
while failure == "" {
|
||||
if Take("%") {
|
||||
value /= 100.0
|
||||
} else if Take("²") {
|
||||
value *= value
|
||||
} else if Take("³") {
|
||||
value = value * value * value
|
||||
} else if Take("⁻¹") {
|
||||
if value == 0.0 {
|
||||
failure = "Cannot divide by zero"
|
||||
return 0.0
|
||||
}
|
||||
value = 1.0 / value
|
||||
} else if Take("!") {
|
||||
value = Factorial(value)
|
||||
} else {
|
||||
return value
|
||||
}
|
||||
while failure == "" && Take("%") {
|
||||
value /= 100.0
|
||||
}
|
||||
return value
|
||||
}
|
||||
@@ -177,251 +118,17 @@ ParseAtom :: () -> float64 {
|
||||
return 0.0
|
||||
}
|
||||
if Take("(") {
|
||||
return Bracketed()
|
||||
}
|
||||
if Take("π") || Take("pi") {
|
||||
return PI_VALUE
|
||||
}
|
||||
if Take("Ans") {
|
||||
return last_answer
|
||||
}
|
||||
if Take("√") || Take("sqrt") {
|
||||
return Root(Argument(), 2)
|
||||
}
|
||||
if Take("∛") || Take("cbrt") {
|
||||
return Root(Argument(), 3)
|
||||
}
|
||||
// Longer names first: sinh⁻¹ before sinh before sin.
|
||||
names: [21]string = .["sinh⁻¹", "cosh⁻¹", "tanh⁻¹", "asinh", "acosh", "atanh",
|
||||
"sin⁻¹", "cos⁻¹", "tan⁻¹", "asin", "acos", "atan",
|
||||
"sinh", "cosh", "tanh", "sin", "cos", "tan", "ln", "log", "abs"]
|
||||
operations: [21]s32 = .[10, 11, 12, 10, 11, 12, 4, 5, 6, 4, 5, 6, 7, 8, 9, 1, 2, 3, 13, 14, 15]
|
||||
index: s32 = 0
|
||||
while index < 21 {
|
||||
if Take(names[index]) {
|
||||
return Apply(operations[index], Argument())
|
||||
value := ParseSum()
|
||||
// A bracket still open at the end closes there.
|
||||
SkipSpaces()
|
||||
if !Take(")") && position < cast(s32)source.count {
|
||||
failure = "Missing closing bracket"
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
if Take("exp") {
|
||||
return Exponential(Argument())
|
||||
}
|
||||
if Take("e") {
|
||||
return E_VALUE
|
||||
return value
|
||||
}
|
||||
return ParseNumber()
|
||||
}
|
||||
|
||||
Bracketed :: () -> float64 {
|
||||
value := ParseSum()
|
||||
// A bracket still open at the end closes there.
|
||||
SkipSpaces()
|
||||
if !Take(")") && position < cast(s32)source.count && failure == "" {
|
||||
failure = "Missing closing bracket"
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// A function's argument: a bracketed expression, or the signed value that
|
||||
// follows, as in √9 or sin 30.
|
||||
Argument :: () -> float64 {
|
||||
if Take("(") {
|
||||
return Bracketed()
|
||||
}
|
||||
return ParseSigned()
|
||||
}
|
||||
|
||||
Apply :: (operation: s32, value: float64) -> float64 {
|
||||
if failure != "" {
|
||||
return 0.0
|
||||
}
|
||||
if operation == 1 {
|
||||
return Sine(value)
|
||||
}
|
||||
if operation == 2 {
|
||||
return Cosine(value)
|
||||
}
|
||||
if operation == 3 {
|
||||
return Tangent(value)
|
||||
}
|
||||
if operation >= 4 && operation <= 6 {
|
||||
if operation != 6 && (value > 1.0 || value < -1.0) {
|
||||
failure = "Not a real number"
|
||||
return 0.0
|
||||
}
|
||||
angle := ifx operation == 4 then Asin(value) else ifx operation == 5 then Acos(value) else Atan(value)
|
||||
return ifx degrees then angle * 180.0 / PI_VALUE else angle
|
||||
}
|
||||
if operation == 7 {
|
||||
return Sinh(value)
|
||||
}
|
||||
if operation == 8 {
|
||||
return Cosh(value)
|
||||
}
|
||||
if operation == 9 {
|
||||
return Tanh(value)
|
||||
}
|
||||
if operation == 10 {
|
||||
return Asinh(value)
|
||||
}
|
||||
if operation == 11 {
|
||||
return Checked(Acosh(value))
|
||||
}
|
||||
if operation == 12 {
|
||||
if value >= 1.0 || value <= -1.0 {
|
||||
failure = ifx value == 1.0 || value == -1.0 then "Result is too large" else "Not a real number"
|
||||
return 0.0
|
||||
}
|
||||
return Atanh(value)
|
||||
}
|
||||
if operation == 13 || operation == 14 {
|
||||
if value <= 0.0 {
|
||||
failure = ifx value == 0.0 then "Result is too large" else "Not a real number"
|
||||
return 0.0
|
||||
}
|
||||
return ifx operation == 13 then Log(value) else Log10Exact(value)
|
||||
}
|
||||
return ifx value < 0.0 then 0.0 - value else value
|
||||
}
|
||||
|
||||
// A NaN from a function outside its domain is an error, not a value.
|
||||
Checked :: (value: float64) -> float64 {
|
||||
if value != value && failure == "" {
|
||||
failure = "Not a real number"
|
||||
return 0.0
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// log10 exactly for powers of ten, which people expect to be whole.
|
||||
Log10Exact :: (value: float64) -> float64 {
|
||||
result := Log10(value)
|
||||
nearest := cast(float64)RoundToInteger(result)
|
||||
if nearest - result < 1.0e-12 && result - nearest < 1.0e-12 && Power(10.0, nearest) == value {
|
||||
return nearest
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// An angle in degrees, reduced to [0, 360).
|
||||
Degrees360 :: (value: float64) -> float64 {
|
||||
turns := cast(float64)RoundToInteger(value / 360.0)
|
||||
reduced := value - turns * 360.0
|
||||
if reduced < 0.0 {
|
||||
reduced += 360.0
|
||||
}
|
||||
return reduced
|
||||
}
|
||||
|
||||
Radians :: (value: float64) -> float64 {
|
||||
return ifx degrees then value * PI_VALUE / 180.0 else value
|
||||
}
|
||||
|
||||
// In degrees, whole quarter turns give exact results: sin 180° is 0.
|
||||
Sine :: (value: float64) -> float64 {
|
||||
if degrees && value < 1.0e15 && value > -1.0e15 {
|
||||
reduced := Degrees360(value)
|
||||
if reduced == 0.0 || reduced == 180.0 {
|
||||
return 0.0
|
||||
}
|
||||
if reduced == 90.0 {
|
||||
return 1.0
|
||||
}
|
||||
if reduced == 270.0 {
|
||||
return -1.0
|
||||
}
|
||||
if reduced == 30.0 || reduced == 150.0 {
|
||||
return 0.5
|
||||
}
|
||||
if reduced == 210.0 || reduced == 330.0 {
|
||||
return -0.5
|
||||
}
|
||||
}
|
||||
return Sin(Radians(value))
|
||||
}
|
||||
|
||||
Cosine :: (value: float64) -> float64 {
|
||||
if degrees && value < 1.0e15 && value > -1.0e15 {
|
||||
reduced := Degrees360(value)
|
||||
if reduced == 90.0 || reduced == 270.0 {
|
||||
return 0.0
|
||||
}
|
||||
if reduced == 0.0 {
|
||||
return 1.0
|
||||
}
|
||||
if reduced == 180.0 {
|
||||
return -1.0
|
||||
}
|
||||
if reduced == 60.0 || reduced == 300.0 {
|
||||
return 0.5
|
||||
}
|
||||
if reduced == 120.0 || reduced == 240.0 {
|
||||
return -0.5
|
||||
}
|
||||
}
|
||||
return Cos(Radians(value))
|
||||
}
|
||||
|
||||
Tangent :: (value: float64) -> float64 {
|
||||
if degrees && value < 1.0e15 && value > -1.0e15 {
|
||||
reduced := Degrees360(value)
|
||||
if reduced == 90.0 || reduced == 270.0 {
|
||||
failure = "Undefined"
|
||||
return 0.0
|
||||
}
|
||||
if reduced == 0.0 || reduced == 180.0 {
|
||||
return 0.0
|
||||
}
|
||||
if reduced == 45.0 || reduced == 225.0 {
|
||||
return 1.0
|
||||
}
|
||||
if reduced == 135.0 || reduced == 315.0 {
|
||||
return -1.0
|
||||
}
|
||||
}
|
||||
return Tan(Radians(value))
|
||||
}
|
||||
|
||||
Root :: (value: float64, degree: s32) -> float64 {
|
||||
if failure != "" {
|
||||
return 0.0
|
||||
}
|
||||
if degree == 2 {
|
||||
if value < 0.0 {
|
||||
failure = "Not a real number"
|
||||
return 0.0
|
||||
}
|
||||
return Sqrt(value)
|
||||
}
|
||||
return Cbrt(value)
|
||||
}
|
||||
|
||||
Exponential :: (value: float64) -> float64 {
|
||||
if failure != "" {
|
||||
return 0.0
|
||||
}
|
||||
return Exp(value)
|
||||
}
|
||||
|
||||
Factorial :: (value: float64) -> float64 {
|
||||
whole := RoundToInteger(value)
|
||||
if value < 0.0 || cast(float64)whole != value {
|
||||
failure = "Factorial needs a whole number"
|
||||
return 0.0
|
||||
}
|
||||
if whole > 170 {
|
||||
failure = "Result is too large"
|
||||
return 0.0
|
||||
}
|
||||
result: float64 = 1.0
|
||||
factor: s64 = 2
|
||||
while factor <= whole {
|
||||
result *= cast(float64)factor
|
||||
factor += 1
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
ParseNumber :: () -> float64 {
|
||||
SkipSpaces()
|
||||
value: float64 = 0.0
|
||||
@@ -443,29 +150,6 @@ ParseNumber :: () -> float64 {
|
||||
}
|
||||
if digits == 0 {
|
||||
failure = ifx position >= cast(s32)source.count then "Incomplete expression" else "Cannot read this expression"
|
||||
return value
|
||||
}
|
||||
// E and a whole power of ten: 6.02E23, 1E−5.
|
||||
if position < cast(s32)source.count && source[position] == cast(u8)69 {
|
||||
position += 1
|
||||
negative := false
|
||||
if Take("-") || Take("−") {
|
||||
negative = true
|
||||
} else {
|
||||
unused Take("+")
|
||||
}
|
||||
power: s64 = 0
|
||||
power_digits: s32 = 0
|
||||
while position < cast(s32)source.count && IsDigit(source[position]) && power < 100000 {
|
||||
power = power * 10 + cast(s64)(source[position] - cast(u8)48)
|
||||
position += 1
|
||||
power_digits += 1
|
||||
}
|
||||
if power_digits == 0 {
|
||||
failure = ifx position >= cast(s32)source.count then "Incomplete expression" else "Cannot read this expression"
|
||||
return value
|
||||
}
|
||||
value *= Power(10.0, cast(float64)(ifx negative then 0 - power else power))
|
||||
}
|
||||
return value
|
||||
}
|
||||
@@ -474,22 +158,35 @@ IsDigit :: (byte: u8) -> bool {
|
||||
return byte >= cast(u8)48 && byte <= cast(u8)57
|
||||
}
|
||||
|
||||
// Whole exponents multiply exactly; others use the real power, which a
|
||||
// negative base does not have.
|
||||
// Whole exponents multiply exactly; others are refused rather than
|
||||
// approximated.
|
||||
Power :: (base: float64, exponent: float64) -> float64 {
|
||||
if failure != "" {
|
||||
whole := cast(s64)exponent
|
||||
if cast(float64)whole != exponent || whole > 4096 || whole < -4096 {
|
||||
failure = "Powers must be whole numbers"
|
||||
return 0.0
|
||||
}
|
||||
if base == 0.0 && exponent < 0.0 {
|
||||
failure = "Cannot divide by zero"
|
||||
return 0.0
|
||||
negative := whole < 0
|
||||
if negative {
|
||||
whole = 0 - whole
|
||||
}
|
||||
whole := cast(float64)RoundToInteger(exponent) == exponent && exponent < 1.0e15 && exponent > -1.0e15
|
||||
if base < 0.0 && !whole {
|
||||
failure = "Not a real number"
|
||||
return 0.0
|
||||
result: float64 = 1.0
|
||||
factor := base
|
||||
while whole > 0 {
|
||||
if whole % 2 == 1 {
|
||||
result *= factor
|
||||
}
|
||||
factor *= factor
|
||||
whole /= 2
|
||||
}
|
||||
return Pow(base, exponent)
|
||||
if negative {
|
||||
if result == 0.0 {
|
||||
failure = "Cannot divide by zero"
|
||||
return 0.0
|
||||
}
|
||||
return 1.0 / result
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Up to ten significant digits; very large and very small numbers use an
|
||||
|
||||
@@ -16,7 +16,6 @@ Refuses :: (expression: string) -> bool {
|
||||
|
||||
#program_export
|
||||
Run :: () -> s32 {
|
||||
degrees = false
|
||||
if !Shows("12+30×2", "72") || !Shows("12+30*2", "72") || !Shows("(1+2)×3", "9") {
|
||||
return 1
|
||||
}
|
||||
@@ -29,48 +28,8 @@ Run :: () -> s32 {
|
||||
if !Shows("0.1+0.2", "0.3") || !Shows("10^20", "1e20") || !Shows("2^-2", "0.25") {
|
||||
return 4
|
||||
}
|
||||
if !Refuses("1÷0") || !Refuses("3+") || !Refuses("4)") || !Refuses("(−8)^0.5") {
|
||||
if !Refuses("1÷0") || !Refuses("2^0.5") || !Refuses("3+") || !Refuses("4)") {
|
||||
return 5
|
||||
}
|
||||
// Powers, roots and logarithms.
|
||||
if !Shows("2^0.5", "1.414213562") || !Shows("√144", "12") || !Shows("√(2)", "1.414213562") ||
|
||||
!Shows("∛27", "3") || !Shows("∛(−8)", "-2") || !Shows("3²", "9") || !Shows("2³", "8") {
|
||||
return 6
|
||||
}
|
||||
if !Shows("ln(e)", "1") || !Shows("log(1000)", "3") || !Shows("e^(2)", "7.389056099") ||
|
||||
!Shows("10^(3)", "1000") || !Shows("exp(1)", "2.718281828") || !Refuses("ln(−1)") || !Refuses("√(−4)") {
|
||||
return 7
|
||||
}
|
||||
// Factorials, reciprocals, constants, Ans and E notation.
|
||||
if !Shows("5!", "120") || !Shows("0!", "1") || !Shows("4⁻¹", "0.25") || !Shows("2π", "6.283185307") ||
|
||||
!Shows("π", "3.141592654") || !Refuses("2.5!") || !Refuses("171!") || !Refuses("0⁻¹") {
|
||||
return 8
|
||||
}
|
||||
last_answer = 21.0
|
||||
if !Shows("Ans×2", "42") || !Shows("6.02E23", "6.02e23") || !Shows("1E−3", "0.001") || !Shows("2(3+4)", "14") ||
|
||||
!Shows("abs(−7)", "7") || !Shows("3sqrt(16)", "12") {
|
||||
return 9
|
||||
}
|
||||
// Radians.
|
||||
if !Shows("sin(π÷2)", "1") || !Shows("cos(0)", "1") || !Shows("tan(π÷4)", "1") ||
|
||||
!Shows("sin⁻¹(1)", "1.570796327") || !Shows("atan(1)×4", "3.141592654") {
|
||||
return 10
|
||||
}
|
||||
// Degrees, with exact quarter turns.
|
||||
degrees = true
|
||||
if !Shows("sin(30)", "0.5") || !Shows("sin(180)", "0") || !Shows("cos(90)", "0") || !Shows("cos(−60)", "0.5") ||
|
||||
!Shows("tan(45)", "1") || !Refuses("tan(90)") || !Shows("sin(390)", "0.5") || !Shows("sin 30 + 1", "1.5") {
|
||||
return 11
|
||||
}
|
||||
if !Shows("sin⁻¹(0.5)", "30") || !Shows("cos⁻¹(0)", "90") || !Shows("tan⁻¹(1)", "45") || !Refuses("asin(2)") {
|
||||
return 12
|
||||
}
|
||||
degrees = false
|
||||
// Hyperbolic functions and their inverses.
|
||||
if !Shows("sinh(1)", "1.175201194") || !Shows("cosh(0)", "1") || !Shows("tanh(1)", "0.761594156") ||
|
||||
!Shows("sinh⁻¹(1)", "0.881373587") || !Shows("cosh⁻¹(2)", "1.316957897") ||
|
||||
!Shows("tanh⁻¹(0.5)", "0.549306144") || !Refuses("acosh(0.5)") || !Refuses("atanh(1)") {
|
||||
return 13
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -1,22 +1,22 @@
|
||||
Box :: #import "kryon/box";
|
||||
Text :: #import "kryon/text";
|
||||
Button :: #import "kryon/button";
|
||||
// Calculator: a keypad and keyboard calculator. Basic covers ordinary
|
||||
// arithmetic with brackets; Scientific adds trigonometry in degrees or
|
||||
// radians, hyperbolic functions, powers, roots, logarithms, factorials and
|
||||
// constants. It keeps the expression in memory; the mode and angle unit are
|
||||
// saved.
|
||||
#import "kryon/session"
|
||||
#import "kryon/geometry"
|
||||
#import "kryon/text_align"
|
||||
#import "kryon/control_props"
|
||||
#import "std/text_buffer"
|
||||
#import "std/number_text"
|
||||
#import "kryon/app_context"
|
||||
#import "kryon/app_protocol"
|
||||
// Calculator: a keypad and keyboard calculator for ordinary arithmetic with
|
||||
// brackets. It keeps the expression and the last result in memory only.
|
||||
#import "session"
|
||||
#import "geometry"
|
||||
#import "text_props"
|
||||
#import "text_align"
|
||||
#import "text_widget"
|
||||
#import "button_props"
|
||||
#import "button_widget"
|
||||
#import "control_props"
|
||||
#import "box_props"
|
||||
#import "box_widget"
|
||||
#import "text_buffer"
|
||||
#import "number_text"
|
||||
#import "werk_app"
|
||||
#import "app_protocol"
|
||||
#import "arithmetic"
|
||||
Icon :: #import "mingcute/mingcute_regular_counter";
|
||||
DeleteBack :: #import "mingcute/mingcute_regular_delete_back";
|
||||
Icon :: #import "mingcute_regular_counter";
|
||||
DeleteBack :: #import "mingcute_regular_delete_back";
|
||||
|
||||
using ButtonTone;
|
||||
using ButtonEmphasis;
|
||||
@@ -26,13 +26,8 @@ EXPRESSION_LIMIT :: 256
|
||||
expression: [EXPRESSION_LIMIT]u8;
|
||||
expression_length: s32;
|
||||
result_text: [64]u8;
|
||||
// The expression shows the last result, which typing a number replaces.
|
||||
// The expression shows the last result, which typing a digit replaces.
|
||||
showing_result: bool;
|
||||
loaded: bool;
|
||||
scientific: bool;
|
||||
// One-shot shifts for the next scientific function key.
|
||||
second: bool;
|
||||
hyperbolic: bool;
|
||||
|
||||
ExpressionText :: () -> string {
|
||||
return TextView(expression[0:expression_length])
|
||||
@@ -44,26 +39,10 @@ Clear :: () {
|
||||
showing_result = false
|
||||
}
|
||||
|
||||
// Whether text begins a new value rather than continuing the last one: a
|
||||
// result is replaced by a number, constant or function, and continued by
|
||||
// an operator.
|
||||
StartsValue :: (text: string) -> bool {
|
||||
first := text[0]
|
||||
if first >= cast(u8)48 && first <= cast(u8)57 || first == cast(u8)46 || first == cast(u8)40 {
|
||||
return true
|
||||
}
|
||||
if first >= cast(u8)97 && first <= cast(u8)122 || first == cast(u8)65 {
|
||||
return true
|
||||
}
|
||||
count := cast(s32)text.count
|
||||
return count >= 2 && text[0:2] == "π" || count >= 3 && (text[0:3] == "√" || text[0:3] == "∛")
|
||||
}
|
||||
|
||||
Append :: (text: string) {
|
||||
if text.count == 0 {
|
||||
return
|
||||
}
|
||||
if showing_result && StartsValue(text) {
|
||||
starts_number := text[0] >= cast(u8)48 && text[0] <= cast(u8)57 || text[0] == cast(u8)46 ||
|
||||
text[0] == cast(u8)40
|
||||
if showing_result && starts_number {
|
||||
expression_length = 0
|
||||
}
|
||||
showing_result = false
|
||||
@@ -101,7 +80,6 @@ Evaluate :: () {
|
||||
CopyResult(answer.error)
|
||||
return
|
||||
}
|
||||
last_answer = answer.value
|
||||
formatted: [64]u8
|
||||
text := FormatNumber(answer.value, formatted[:])
|
||||
expression_length = 0
|
||||
@@ -119,38 +97,25 @@ CopyResult :: (text: string) {
|
||||
result_text[index] = cast(u8)0
|
||||
}
|
||||
|
||||
// calculator.txt holds "scientific degrees" as 0 or 1 each.
|
||||
LoadSettings :: () {
|
||||
buffer: [16]u8
|
||||
count := ReadStore("calculator.txt", buffer[:])
|
||||
if count >= 3 {
|
||||
scientific = buffer[0] == cast(u8)49
|
||||
degrees = buffer[2] == cast(u8)49
|
||||
} else {
|
||||
degrees = true
|
||||
}
|
||||
}
|
||||
|
||||
SaveSettings :: () {
|
||||
buffer: [3]u8
|
||||
buffer[0] = cast(u8)(ifx scientific then 49 else 48)
|
||||
buffer[1] = cast(u8)32
|
||||
buffer[2] = cast(u8)(ifx degrees then 49 else 48)
|
||||
unused WriteStore("calculator.txt", TextView(buffer[0:3]))
|
||||
}
|
||||
|
||||
// Typed characters and keys act like the keypad; letters spell functions
|
||||
// such as sin and sqrt.
|
||||
// Typed characters and keys act like the keypad.
|
||||
Keyboard :: () {
|
||||
key := AppKey()
|
||||
if key == 257 || key == 335 {
|
||||
Evaluate()
|
||||
}
|
||||
if key == 259 {
|
||||
Backspace()
|
||||
}
|
||||
if key == 256 {
|
||||
Clear()
|
||||
}
|
||||
typed := AppFieldInput().text
|
||||
index: s32 = 0
|
||||
while index < cast(s32)typed.count {
|
||||
byte := typed[index]
|
||||
if byte >= cast(u8)48 && byte <= cast(u8)57 || byte == cast(u8)46 || byte == cast(u8)40 ||
|
||||
byte == cast(u8)41 || byte == cast(u8)43 || byte == cast(u8)45 || byte == cast(u8)37 ||
|
||||
byte == cast(u8)94 || byte == cast(u8)33 || byte >= cast(u8)97 && byte <= cast(u8)122 ||
|
||||
byte >= cast(u8)65 && byte <= cast(u8)90 {
|
||||
byte == cast(u8)94 {
|
||||
Append(typed[index:index + 1])
|
||||
}
|
||||
if byte == cast(u8)42 {
|
||||
@@ -167,197 +132,44 @@ Keyboard :: () {
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
// Text queued before a command key belongs to the expression it acts on.
|
||||
if key == 257 || key == 335 {
|
||||
Evaluate()
|
||||
}
|
||||
if key == 259 {
|
||||
Backspace()
|
||||
}
|
||||
if key == 256 {
|
||||
Clear()
|
||||
}
|
||||
}
|
||||
|
||||
ACTION_INSERT :: 0
|
||||
ACTION_CLEAR :: 1
|
||||
ACTION_DELETE :: 2
|
||||
ACTION_EVALUATE :: 3
|
||||
ACTION_SECOND :: 4
|
||||
ACTION_HYPERBOLIC :: 5
|
||||
ACTION_NEGATE :: 6
|
||||
KEYS :: 20
|
||||
|
||||
Key :: struct {
|
||||
label: string
|
||||
input: string
|
||||
action: s32
|
||||
accent: bool
|
||||
// A function key whose 2nd or hyp shift is used up when pressed.
|
||||
shifted: bool
|
||||
}
|
||||
|
||||
BASIC_KEYS :: 20
|
||||
|
||||
BasicKey :: (index: s32) -> Key {
|
||||
labels: [BASIC_KEYS]string = .["C", "(", ")", "÷",
|
||||
KeyAt :: (index: s32) -> Key {
|
||||
labels: [KEYS]string = .["C", "(", ")", "÷",
|
||||
"7", "8", "9", "×",
|
||||
"4", "5", "6", "−",
|
||||
"1", "2", "3", "+",
|
||||
"", "0", ".", "="]
|
||||
inputs: [BASIC_KEYS]string = .["", "(", ")", "÷",
|
||||
"Delete", "0", ".", "="]
|
||||
inputs: [KEYS]string = .["", "(", ")", "÷",
|
||||
"7", "8", "9", "×",
|
||||
"4", "5", "6", "-",
|
||||
"1", "2", "3", "+",
|
||||
"", "0", ".", ""]
|
||||
key := Key.{.label = labels[index], .input = inputs[index]}
|
||||
return Key.{.label = labels[index], .input = inputs[index], .accent = index == 19}
|
||||
}
|
||||
|
||||
Press :: (index: s32) {
|
||||
if index == 0 {
|
||||
key.action = ACTION_CLEAR
|
||||
Clear()
|
||||
return
|
||||
}
|
||||
if index == 16 {
|
||||
key.action = ACTION_DELETE
|
||||
Backspace()
|
||||
return
|
||||
}
|
||||
if index == 19 {
|
||||
key.action = ACTION_EVALUATE
|
||||
key.accent = true
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
// Eight rows of five; = spans the last two columns.
|
||||
SCIENTIFIC_KEYS :: 39
|
||||
|
||||
ScientificKey :: (index: s32) -> Key {
|
||||
labels: [SCIENTIFIC_KEYS]string = .["2nd", "hyp", "sin", "cos", "tan",
|
||||
"x²", "xʸ", "√x", "ln", "log",
|
||||
"(", ")", "1/x", "n!", "π",
|
||||
"C", "", "%", "÷", "e",
|
||||
"7", "8", "9", "×", "EE",
|
||||
"4", "5", "6", "−", "Ans",
|
||||
"1", "2", "3", "+", "|x|",
|
||||
"±", "0", ".", "="]
|
||||
inputs: [SCIENTIFIC_KEYS]string = .["", "", "", "", "",
|
||||
"²", "^", "√(", "ln(", "log(",
|
||||
"(", ")", "⁻¹", "!", "π",
|
||||
"", "", "%", "÷", "e",
|
||||
"7", "8", "9", "×", "E",
|
||||
"4", "5", "6", "-", "Ans",
|
||||
"1", "2", "3", "+", "abs(",
|
||||
"", "0", ".", ""]
|
||||
key := Key.{.label = labels[index], .input = inputs[index]}
|
||||
if index == 0 {
|
||||
key.action = ACTION_SECOND
|
||||
key.accent = second
|
||||
}
|
||||
if index == 1 {
|
||||
key.action = ACTION_HYPERBOLIC
|
||||
key.accent = hyperbolic
|
||||
}
|
||||
if index >= 2 && index <= 4 {
|
||||
names: [3]string = .["sin", "cos", "tan"]
|
||||
hyperbolic_names: [3]string = .["sinh", "cosh", "tanh"]
|
||||
inverse_names: [3]string = .["sin⁻¹", "cos⁻¹", "tan⁻¹"]
|
||||
inverse_hyperbolic_names: [3]string = .["sinh⁻¹", "cosh⁻¹", "tanh⁻¹"]
|
||||
name := names[index - 2]
|
||||
if hyperbolic {
|
||||
name = ifx second then inverse_hyperbolic_names[index - 2] else hyperbolic_names[index - 2]
|
||||
} else if second {
|
||||
name = inverse_names[index - 2]
|
||||
}
|
||||
key.label = name
|
||||
key.shifted = true
|
||||
}
|
||||
if second {
|
||||
if index == 5 {
|
||||
key.label = "x³"
|
||||
key.input = "³"
|
||||
}
|
||||
if index == 6 {
|
||||
key.label = "ʸ√x"
|
||||
key.input = "^(1÷"
|
||||
}
|
||||
if index == 7 {
|
||||
key.label = "∛x"
|
||||
key.input = "∛("
|
||||
}
|
||||
if index == 8 {
|
||||
key.label = "eˣ"
|
||||
key.input = "e^("
|
||||
}
|
||||
if index == 9 {
|
||||
key.label = "10ˣ"
|
||||
key.input = "10^("
|
||||
}
|
||||
}
|
||||
if index >= 5 && index <= 9 {
|
||||
key.shifted = true
|
||||
}
|
||||
if index == 15 {
|
||||
key.action = ACTION_CLEAR
|
||||
}
|
||||
if index == 16 {
|
||||
key.action = ACTION_DELETE
|
||||
}
|
||||
if index == 35 {
|
||||
key.action = ACTION_NEGATE
|
||||
}
|
||||
if index == 38 {
|
||||
key.action = ACTION_EVALUATE
|
||||
key.accent = true
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
Press :: (key: Key) {
|
||||
if key.action == ACTION_CLEAR {
|
||||
Clear()
|
||||
} else if key.action == ACTION_DELETE {
|
||||
Backspace()
|
||||
} else if key.action == ACTION_EVALUATE {
|
||||
Evaluate()
|
||||
} else if key.action == ACTION_SECOND {
|
||||
second = !second
|
||||
} else if key.action == ACTION_HYPERBOLIC {
|
||||
hyperbolic = !hyperbolic
|
||||
} else if key.action == ACTION_NEGATE {
|
||||
Append("−")
|
||||
} else if key.input != "" {
|
||||
Append(key.input)
|
||||
} else {
|
||||
// A trigonometric key: its name and an opening bracket.
|
||||
text: [24]u8
|
||||
used: s32 = AppendTo(text[:], 0, key.label)
|
||||
used = AppendTo(text[:], used, "(")
|
||||
Append(TextView(text[0:used]))
|
||||
}
|
||||
if key.shifted {
|
||||
second = false
|
||||
hyperbolic = false
|
||||
}
|
||||
}
|
||||
|
||||
Tab :: (session: Session, id: s32, label: string, bounds: Rectangle, active: bool) -> bool {
|
||||
props := Button.Props.{.key = cast(u64)id, .id = id, .bounds = bounds, .label = label,
|
||||
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}
|
||||
if active {
|
||||
props.tone = ButtonTone.ButtonToneAccent
|
||||
props.emphasis = ButtonEmphasis.ButtonEmphasisFilled
|
||||
}
|
||||
return Button.Draw(session, props) != 0
|
||||
}
|
||||
|
||||
DrawKey :: (session: Session, index: s32, key: Key, bounds: Rectangle) {
|
||||
props := Button.Props.{.key = cast(u64)(100 + index), .id = 100 + index, .bounds = bounds,
|
||||
.label = key.label,
|
||||
.tone = cast(ButtonTone)(ifx key.accent then ButtonToneAccent else ButtonToneNeutral),
|
||||
.emphasis = cast(ButtonEmphasis)(ifx key.accent then ButtonEmphasisFilled else ButtonEmphasisSoft)}
|
||||
// Delete is an icon on a key as wide as the others.
|
||||
if key.action == ACTION_DELETE {
|
||||
props.icon_shape = DeleteBack.Shape
|
||||
props.label = ""
|
||||
}
|
||||
if Button.Draw(session, props) != 0 {
|
||||
Press(key)
|
||||
return
|
||||
}
|
||||
Append(KeyAt(index).input)
|
||||
}
|
||||
|
||||
Draw :: () {
|
||||
@@ -365,74 +177,52 @@ Draw :: () {
|
||||
area := AppBounds()
|
||||
gap: float32 = 8.0
|
||||
width := area.width - 32.0
|
||||
if width > 460.0 {
|
||||
width = 460.0
|
||||
if width > 420.0 {
|
||||
width = 420.0
|
||||
}
|
||||
left := area.x + (area.width - width) * 0.5
|
||||
top := area.y + 12.0
|
||||
half := (width - gap) / 2.0
|
||||
if Tab(session, 1, "Basic", Rectangle.{left, top, half, 36.0}, !scientific) && scientific {
|
||||
scientific = false
|
||||
SaveSettings()
|
||||
}
|
||||
if Tab(session, 2, "Scientific", Rectangle.{left + half + gap, top, half, 36.0}, scientific) && !scientific {
|
||||
scientific = true
|
||||
SaveSettings()
|
||||
}
|
||||
top += 36.0 + gap
|
||||
display_height: float32 = ifx scientific then 104.0 else 112.0
|
||||
display := Rectangle.{left, top, width, display_height}
|
||||
Box.Draw(session, Box.Props.{.key = cast(u64)3, .bounds = display, .radius = 12.0})
|
||||
top := area.y + 16.0
|
||||
display := Rectangle.{left, top, width, 112.0}
|
||||
Box(session, BoxProps.{.key = cast(u64)1, .bounds = display, .radius = 12.0})
|
||||
shown := ExpressionText()
|
||||
if shown == "" {
|
||||
shown = "0"
|
||||
}
|
||||
font: s32 = 32
|
||||
if shown.count > 18 {
|
||||
font = 24
|
||||
}
|
||||
if shown.count > 28 {
|
||||
font = 18
|
||||
}
|
||||
Text.Draw(session, Text.Props.{.key = cast(u64)4,
|
||||
.bounds = Rectangle.{left + 16.0, top + 14.0, width - 32.0, 48.0},
|
||||
.text = shown, .size = font, .align = TextAlign.TextAlignEnd, .wrap = Text.Wrap.TextWrapEllipsis})
|
||||
Text.Draw(session, Text.Props.{.key = cast(u64)5,
|
||||
.bounds = Rectangle.{left + 16.0, top + display_height - 36.0, width - 32.0, 24.0},
|
||||
.text = TextUntilNul(result_text[:]), .size = 16, .align = TextAlign.TextAlignEnd})
|
||||
if scientific {
|
||||
// The angle unit, switched by tapping it.
|
||||
unit := Button.Props.{.key = cast(u64)6, .id = 6, .bounds = Rectangle.{left + 10.0, top + display_height - 38.0, 64.0, 28.0},
|
||||
.label = ifx degrees then "DEG" else "RAD", .size = ControlSize.ControlSizeSmall,
|
||||
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}
|
||||
if Button.Draw(session, unit) != 0 {
|
||||
degrees = !degrees
|
||||
SaveSettings()
|
||||
}
|
||||
}
|
||||
pad_top := top + display_height + gap * 2.0
|
||||
columns: s32 = ifx scientific then 5 else 4
|
||||
rows: s32 = ifx scientific then 8 else 5
|
||||
key_width := (width - gap * cast(float32)(columns - 1)) / cast(float32)columns
|
||||
key_height := (area.y + area.height - 16.0 - pad_top - gap * cast(float32)(rows - 1)) / cast(float32)rows
|
||||
Text(session, TextProps.{.key = cast(u64)2,
|
||||
.bounds = Rectangle.{left + 16.0, top + 16.0, width - 32.0, 48.0},
|
||||
.text = shown, .font = 32, .align = TextAlign.TextAlignEnd, .wrap = TextWrap.TextWrapEllipsis})
|
||||
Text(session, TextProps.{.key = cast(u64)3,
|
||||
.bounds = Rectangle.{left + 16.0, top + 72.0, width - 32.0, 24.0},
|
||||
.text = TextUntilNul(result_text[:]), .font = 16, .align = TextAlign.TextAlignEnd})
|
||||
pad_top := top + 112.0 + gap * 2.0
|
||||
rows: float32 = 5.0
|
||||
key_width := (width - gap * 3.0) / 4.0
|
||||
key_height := (area.y + area.height - 16.0 - pad_top - gap * (rows - 1.0)) / rows
|
||||
if key_height > 72.0 {
|
||||
key_height = 72.0
|
||||
}
|
||||
if key_height < 34.0 {
|
||||
key_height = 34.0
|
||||
if key_height < 36.0 {
|
||||
key_height = 36.0
|
||||
}
|
||||
count: s32 = ifx scientific then SCIENTIFIC_KEYS else BASIC_KEYS
|
||||
index: s32 = 0
|
||||
while index < count {
|
||||
key := ifx scientific then ScientificKey(index) else BasicKey(index)
|
||||
column := cast(float32)(index % columns)
|
||||
row := cast(float32)(index / columns)
|
||||
while index < KEYS {
|
||||
key := KeyAt(index)
|
||||
column := cast(float32)(index % 4)
|
||||
row := cast(float32)(index / 4)
|
||||
bounds := Rectangle.{left + column * (key_width + gap), pad_top + row * (key_height + gap),
|
||||
key_width, key_height}
|
||||
if scientific && index == SCIENTIFIC_KEYS - 1 {
|
||||
bounds.width = key_width * 2.0 + gap
|
||||
props := ButtonProps.{.key = cast(u64)(100 + index), .id = 100 + index, .bounds = bounds,
|
||||
.label = key.label,
|
||||
.tone = cast(ButtonTone)(ifx key.accent then ButtonToneAccent else ButtonToneNeutral),
|
||||
.emphasis = cast(ButtonEmphasis)(ifx key.accent then ButtonEmphasisFilled else ButtonEmphasisSoft)}
|
||||
// Delete is an icon on a key as wide as the others.
|
||||
if index == 16 {
|
||||
props.icon_shape = DeleteBack.Shape
|
||||
props.label = ""
|
||||
}
|
||||
if Button(session, props) != 0 {
|
||||
Press(index)
|
||||
}
|
||||
DrawKey(session, index, key, bounds)
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
@@ -440,17 +230,9 @@ Draw :: () {
|
||||
#program_export "CalculatorMain"
|
||||
Main :: () -> s32 {
|
||||
if AppMode() == APP_IDENTIFY {
|
||||
AppIdentity("calculator")
|
||||
AppDescribe("Calculator", Icon.Shape)
|
||||
return APP_PROTOCOL
|
||||
}
|
||||
if AppMode() != APP_FRAME {
|
||||
return 0
|
||||
}
|
||||
if !loaded {
|
||||
LoadSettings()
|
||||
loaded = true
|
||||
}
|
||||
Keyboard()
|
||||
Draw()
|
||||
return 0
|
||||
|
||||
@@ -1,812 +0,0 @@
|
||||
// Simple Calendar: Month, Week, and Agenda views with local event creation,
|
||||
// editing, deletion, recurrence, search and private persistence.
|
||||
Box :: #import "kryon/box";
|
||||
Button :: #import "kryon/button";
|
||||
Checkbox :: #import "kryon/checkbox";
|
||||
Scroll :: #import "kryon/scroll";
|
||||
Text :: #import "kryon/text";
|
||||
TextField :: #import "kryon/text_field";
|
||||
#import "kryon/app_context"
|
||||
#import "kryon/app_protocol"
|
||||
#import "kryon/control_props"
|
||||
#import "kryon/drawing_props"
|
||||
#import "kryon/geometry"
|
||||
#import "kryon/session"
|
||||
#import "kryon/text_align"
|
||||
#import "kryon/tree"
|
||||
#import "std/number_text"
|
||||
#import "std/text_buffer"
|
||||
#import "calendar_model"
|
||||
Icon :: #import "mingcute/mingcute_regular_calendar";
|
||||
|
||||
FieldState :: struct {
|
||||
cursor: s32
|
||||
anchor: s32
|
||||
scroll_x: s32
|
||||
}
|
||||
|
||||
STORE_BUFFER_CAP :: 65536;
|
||||
|
||||
session: Session;
|
||||
store: CalendarStore;
|
||||
loaded: bool;
|
||||
dirty: bool;
|
||||
|
||||
view_mode: s32 = VIEW_MONTH;
|
||||
display_year: s64 = 2026;
|
||||
display_month: s32 = 1;
|
||||
selected_year: s64 = 2026;
|
||||
selected_month: s32 = 1;
|
||||
selected_day: s32 = 1;
|
||||
local_offset: s32;
|
||||
local_offset_at: float64 = -61.0;
|
||||
|
||||
day_scroll_y: s32;
|
||||
week_scroll_y: s32;
|
||||
agenda_scroll_y: s32;
|
||||
editor_scroll_y: s32;
|
||||
|
||||
// Search in Agenda view.
|
||||
search_buf: [96]u8;
|
||||
search_state: FieldState;
|
||||
|
||||
// Event editor state.
|
||||
editing: bool;
|
||||
edit_index: s32 = -1; // -1 when creating a new event
|
||||
edit_title: [EVENT_TITLE_CAP]u8;
|
||||
edit_date: [16]u8;
|
||||
edit_start: [16]u8;
|
||||
edit_end: [16]u8;
|
||||
edit_location: [EVENT_LOCATION_CAP]u8;
|
||||
edit_notes: [EVENT_NOTES_CAP]u8;
|
||||
edit_all_day: bool;
|
||||
edit_recurrence: s32;
|
||||
edit_color: s32;
|
||||
edit_error: [96]u8;
|
||||
edit_fields: [6]FieldState;
|
||||
focused_field: s32; // 0 none, 1..6 editor fields, 10 search
|
||||
|
||||
store_io_buf: [STORE_BUFFER_CAP]u8;
|
||||
|
||||
TodayCivil :: () -> CivilDate {
|
||||
now := AppNow()
|
||||
if now - local_offset_at > 60.0 {
|
||||
local_offset = AppLocalOffset()
|
||||
local_offset_at = now
|
||||
}
|
||||
secs := cast(s64)now
|
||||
if cast(float64)secs > now { secs -= 1 }
|
||||
local := secs + cast(s64)local_offset
|
||||
days := local / 86400
|
||||
if local < 0 && local % 86400 != 0 { days -= 1 }
|
||||
return CivilFromDays(days)
|
||||
}
|
||||
|
||||
JumpToday :: () {
|
||||
today := TodayCivil()
|
||||
display_year = today.year
|
||||
display_month = today.month
|
||||
selected_year = today.year
|
||||
selected_month = today.month
|
||||
selected_day = today.day
|
||||
day_scroll_y = 0
|
||||
}
|
||||
|
||||
LoadCalendar :: () {
|
||||
StoreInit(*store)
|
||||
count := ReadStore("calendar.json", store_io_buf[:])
|
||||
if count > 0 {
|
||||
unused DeserializeStore(TextView(store_io_buf[:count]), *store)
|
||||
}
|
||||
view_mode = store.default_view
|
||||
JumpToday()
|
||||
loaded = true
|
||||
dirty = false
|
||||
}
|
||||
|
||||
SaveCalendar :: () {
|
||||
store.default_view = view_mode
|
||||
used := SerializeStore(*store, store_io_buf[:])
|
||||
if used > 0 {
|
||||
unused WriteStore("calendar.json", TextView(store_io_buf[:used]))
|
||||
dirty = false
|
||||
}
|
||||
}
|
||||
|
||||
SwatchColor :: (index: s32) -> Color {
|
||||
if index == 1 { return Color.{46, 158, 102, 255} } // Green
|
||||
if index == 2 { return Color.{219, 143, 36, 255} } // Amber
|
||||
if index == 3 { return Color.{209, 71, 77, 255} } // Red
|
||||
if index == 4 { return Color.{138, 92, 199, 255} } // Purple
|
||||
if index == 5 { return Color.{36, 153, 168, 255} } // Teal
|
||||
return Color.{56, 128, 219, 255} // Blue
|
||||
}
|
||||
|
||||
SwatchName :: (index: s32) -> string {
|
||||
names: [COLOR_COUNT]string = .["Blue", "Green", "Amber", "Red", "Purple", "Teal"]
|
||||
if index < 0 || index >= COLOR_COUNT { return names[0] }
|
||||
return names[index]
|
||||
}
|
||||
|
||||
OpenNewEvent :: (year: s64, month: s32, day: s32) {
|
||||
editing = true
|
||||
edit_index = -1
|
||||
edit_title[0] = cast(u8)0
|
||||
edit_location[0] = cast(u8)0
|
||||
edit_notes[0] = cast(u8)0
|
||||
edit_error[0] = cast(u8)0
|
||||
unused FormatDateISO(year, month, day, edit_date[:])
|
||||
CopyField(edit_start[:], "09:00")
|
||||
CopyField(edit_end[:], "10:00")
|
||||
edit_all_day = false
|
||||
edit_recurrence = REPEAT_NONE
|
||||
edit_color = 0
|
||||
for i: 0..5 { edit_fields[i] = FieldState.{} }
|
||||
editor_scroll_y = 0
|
||||
focused_field = 1
|
||||
}
|
||||
|
||||
OpenEditEvent :: (index: s32) {
|
||||
if index < 0 || index >= MAX_EVENTS || !store.events[index].active { return }
|
||||
ev := *store.events[index]
|
||||
editing = true
|
||||
edit_index = index
|
||||
CopyField(edit_title[:], TextUntilNul(ev.title[:]))
|
||||
CopyField(edit_location[:], TextUntilNul(ev.location[:]))
|
||||
CopyField(edit_notes[:], TextUntilNul(ev.notes[:]))
|
||||
unused FormatDateISO(ev.year, ev.month, ev.day, edit_date[:])
|
||||
unused FormatTimeHHMM(ev.start_minute, edit_start[:])
|
||||
unused FormatTimeHHMM(ev.end_minute, edit_end[:])
|
||||
edit_all_day = ev.all_day
|
||||
edit_recurrence = ev.recurrence
|
||||
edit_color = ev.color
|
||||
edit_error[0] = cast(u8)0
|
||||
for i: 0..5 { edit_fields[i] = FieldState.{} }
|
||||
editor_scroll_y = 0
|
||||
focused_field = 1
|
||||
}
|
||||
|
||||
CommitEditor :: () {
|
||||
title := TextUntilNul(edit_title[:])
|
||||
if title.count == 0 {
|
||||
CopyField(edit_error[:], "Please enter an event title.")
|
||||
return
|
||||
}
|
||||
parsed := ParseDateISO(TextUntilNul(edit_date[:]))
|
||||
if !parsed.ok {
|
||||
CopyField(edit_error[:], "Date must be YYYY-MM-DD.")
|
||||
return
|
||||
}
|
||||
start_min: s32 = 540
|
||||
end_min: s32 = 600
|
||||
if !edit_all_day {
|
||||
st := ParseTimeHHMM(TextUntilNul(edit_start[:]))
|
||||
et := ParseTimeHHMM(TextUntilNul(edit_end[:]))
|
||||
if !st.ok || !et.ok {
|
||||
CopyField(edit_error[:], "Times must be HH:MM (24-hour).")
|
||||
return
|
||||
}
|
||||
if et.minute < st.minute {
|
||||
CopyField(edit_error[:], "End time must be after start time.")
|
||||
return
|
||||
}
|
||||
start_min = st.minute
|
||||
end_min = et.minute
|
||||
}
|
||||
ev: CalendarEvent
|
||||
ev.year = parsed.year
|
||||
ev.month = parsed.month
|
||||
ev.day = parsed.day
|
||||
ev.all_day = edit_all_day
|
||||
ev.start_minute = start_min
|
||||
ev.end_minute = end_min
|
||||
ev.recurrence = edit_recurrence
|
||||
ev.color = edit_color
|
||||
CopyField(ev.title[:], title)
|
||||
CopyField(ev.location[:], TextUntilNul(edit_location[:]))
|
||||
CopyField(ev.notes[:], TextUntilNul(edit_notes[:]))
|
||||
|
||||
if edit_index >= 0 {
|
||||
unused UpdateEvent(*store, edit_index, ev)
|
||||
} else {
|
||||
if AddEvent(*store, ev) < 0 {
|
||||
CopyField(edit_error[:], "Calendar event limit reached.")
|
||||
return
|
||||
}
|
||||
}
|
||||
selected_year = parsed.year
|
||||
selected_month = parsed.month
|
||||
selected_day = parsed.day
|
||||
display_year = parsed.year
|
||||
display_month = parsed.month
|
||||
editing = false
|
||||
focused_field = 0
|
||||
dirty = true
|
||||
SaveCalendar()
|
||||
}
|
||||
|
||||
ApplyEdit :: (buffer: []u8, edit: TextField.Edit) -> bool {
|
||||
if !edit.changed { return false }
|
||||
length := cast(s32)TextUntilNul(buffer).count
|
||||
if edit.start < 0 || edit.end < edit.start || edit.end > length { return false }
|
||||
used := length - (edit.end - edit.start) + cast(s32)edit.replacement.count
|
||||
if used >= cast(s32)buffer.count || used >= 512 { return false }
|
||||
next: [512]u8
|
||||
pos: s32 = 0
|
||||
for i: 0..edit.start - 1 { next[pos] = buffer[i]; pos += 1 }
|
||||
for i: 0..cast(s32)edit.replacement.count - 1 { next[pos] = edit.replacement[i]; pos += 1 }
|
||||
for i: edit.end..length - 1 { next[pos] = buffer[i]; pos += 1 }
|
||||
for i: 0..cast(s32)buffer.count - 1 {
|
||||
buffer[i] = ifx i < used then next[i] else cast(u8)0
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
DrawField :: (id: s32, label: string, buffer: []u8, state: *FieldState, bounds: Rectangle) -> bool {
|
||||
snapshot: [512]u8
|
||||
CopyField(snapshot[:], TextUntilNul(buffer))
|
||||
props: TextField.Props
|
||||
props.key = cast(u64)(900 + id)
|
||||
props.focus_id = 900 + id
|
||||
props.bounds = bounds
|
||||
props.label = label
|
||||
props.value = TextUntilNul(snapshot[:])
|
||||
props.cursor = state.cursor
|
||||
props.anchor = state.anchor
|
||||
props.scroll_x = state.scroll_x
|
||||
props.focused = focused_field == id
|
||||
props.max_bytes = cast(s32)buffer.count - 1
|
||||
props.max_codepoints = props.max_bytes
|
||||
if props.focused { props.input = AppFieldInput() }
|
||||
result := TextField.Draw(session, props)
|
||||
state.cursor = result.cursor
|
||||
state.anchor = result.anchor
|
||||
state.scroll_x = result.scroll_x
|
||||
changed := ApplyEdit(buffer, result.edit)
|
||||
if result.focused { focused_field = id }
|
||||
if result.escaped && focused_field == id { focused_field = 0 }
|
||||
return changed
|
||||
}
|
||||
|
||||
Action :: (id: s32, label: string, bounds: Rectangle, accent: bool) -> bool {
|
||||
props: Button.Props
|
||||
props.key = cast(u64)id
|
||||
props.id = id
|
||||
props.bounds = bounds
|
||||
props.label = label
|
||||
props.size = ControlSize.ControlSizeSmall
|
||||
props.tone = ifx accent then ButtonTone.ButtonToneAccent else ButtonTone.ButtonToneNeutral
|
||||
props.emphasis = ifx accent then ButtonEmphasis.ButtonEmphasisFilled else ButtonEmphasis.ButtonEmphasisSoft
|
||||
return Button.Draw(session, props) != 0
|
||||
}
|
||||
|
||||
DangerAction :: (id: s32, label: string, bounds: Rectangle) -> bool {
|
||||
props: Button.Props
|
||||
props.key = cast(u64)id
|
||||
props.id = id
|
||||
props.bounds = bounds
|
||||
props.label = label
|
||||
props.size = ControlSize.ControlSizeSmall
|
||||
props.tone = ButtonTone.ButtonToneDanger
|
||||
props.emphasis = ButtonEmphasis.ButtonEmphasisFilled
|
||||
return Button.Draw(session, props) != 0
|
||||
}
|
||||
|
||||
DrawText :: (key: u64, value: string, bounds: Rectangle, size: s32, align: TextAlign) {
|
||||
Text.Draw(session, Text.Props.{.key = key, .bounds = bounds, .text = value, .size = size,
|
||||
.align = align, .wrap = Text.Wrap.TextWrapEllipsis})
|
||||
}
|
||||
|
||||
FormatEventTimeRange :: (ev: *CalendarEvent, out: []u8) -> string {
|
||||
if ev.all_day { return "All day" }
|
||||
s_buf: [12]u8
|
||||
e_buf: [12]u8
|
||||
used := AppendText(out, 0, FormatTimeHHMM(ev.start_minute, s_buf[:]))
|
||||
used = AppendText(out, used, " - ")
|
||||
used = AppendText(out, used, FormatTimeHHMM(ev.end_minute, e_buf[:]))
|
||||
return TextView(out[:used])
|
||||
}
|
||||
|
||||
DrawEventRow :: (row_id: s32, ev_index: s32, bounds: Rectangle, show_date: bool, y: s64, m: s32, d: s32) -> bool {
|
||||
ev := *store.events[ev_index]
|
||||
dark := AppDark()
|
||||
card_bg := ifx dark then Color.{38, 41, 48, 255} else Color.{242, 245, 250, 255}
|
||||
border := ifx dark then Color.{66, 71, 87, 255} else Color.{214, 219, 232, 255}
|
||||
base_key := cast(u64)(5000 + row_id * 10)
|
||||
Box.Draw(session, Box.Props.{.key = base_key, .bounds = bounds, .fill = card_bg, .border = border, .radius = 8.0})
|
||||
// Color accent bar on the left.
|
||||
Box.Draw(session, Box.Props.{.key = base_key + 1,
|
||||
.bounds = Rectangle.{bounds.x + 2.0, bounds.y + 6.0, 5.0, bounds.height - 12.0},
|
||||
.fill = SwatchColor(ev.color), .radius = 2.5})
|
||||
|
||||
time_buf: [32]u8
|
||||
meta_buf: [160]u8
|
||||
used: s32 = 0
|
||||
if show_date {
|
||||
iso: [16]u8
|
||||
used = AppendText(meta_buf[:], used, FormatDateISO(y, m, d, iso[:]))
|
||||
used = AppendText(meta_buf[:], used, " ")
|
||||
}
|
||||
used = AppendText(meta_buf[:], used, FormatEventTimeRange(ev, time_buf[:]))
|
||||
if ev.recurrence != REPEAT_NONE {
|
||||
used = AppendText(meta_buf[:], used, " [")
|
||||
used = AppendText(meta_buf[:], used, RecurrenceLabel(ev.recurrence))
|
||||
used = AppendText(meta_buf[:], used, "]")
|
||||
}
|
||||
loc := TextUntilNul(ev.location[:])
|
||||
if loc.count > 0 {
|
||||
used = AppendText(meta_buf[:], used, " @ ")
|
||||
used = AppendText(meta_buf[:], used, loc)
|
||||
}
|
||||
|
||||
text_w := bounds.width - 78.0
|
||||
DrawText(base_key + 2, TextUntilNul(ev.title[:]),
|
||||
Rectangle.{bounds.x + 14.0, bounds.y + 6.0, text_w, 20.0}, 14, TextAlign.TextAlignStart)
|
||||
DrawText(base_key + 3, TextView(meta_buf[:used]),
|
||||
Rectangle.{bounds.x + 14.0, bounds.y + 27.0, text_w, 18.0}, 12, TextAlign.TextAlignStart)
|
||||
return Action(6000 + row_id, "Edit",
|
||||
Rectangle.{bounds.x + bounds.width - 58.0, bounds.y + 10.0, 50.0, 30.0}, false)
|
||||
}
|
||||
|
||||
DrawMonthView :: (area: Rectangle) {
|
||||
today := TodayCivil()
|
||||
|
||||
// Month navigation header.
|
||||
nav_y := area.y
|
||||
if Action(100, "<", Rectangle.{area.x, nav_y, 34.0, 32.0}, false) {
|
||||
step := StepMonth(display_year, display_month, -1)
|
||||
display_year = step.year
|
||||
display_month = step.month
|
||||
}
|
||||
if Action(101, ">", Rectangle.{area.x + 38.0, nav_y, 34.0, 32.0}, false) {
|
||||
step := StepMonth(display_year, display_month, 1)
|
||||
display_year = step.year
|
||||
display_month = step.month
|
||||
}
|
||||
title_buf: [48]u8
|
||||
tu := AppendText(title_buf[:], 0, MonthName(display_month))
|
||||
tu = AppendText(title_buf[:], tu, " ")
|
||||
tu = AppendNumber(title_buf[:], tu, display_year)
|
||||
DrawText(102, TextView(title_buf[:tu]),
|
||||
Rectangle.{area.x + 78.0, nav_y + 5.0, area.width - 216.0, 24.0}, 16, TextAlign.TextAlignCenter)
|
||||
|
||||
if Action(103, "Today", Rectangle.{area.x + area.width - 134.0, nav_y, 58.0, 32.0}, false) {
|
||||
JumpToday()
|
||||
}
|
||||
if Action(104, ifx store.week_starts_monday then "Mon" else "Sun",
|
||||
Rectangle.{area.x + area.width - 72.0, nav_y, 36.0, 32.0}, false) {
|
||||
store.week_starts_monday = !store.week_starts_monday
|
||||
dirty = true
|
||||
SaveCalendar()
|
||||
}
|
||||
if Action(105, "+", Rectangle.{area.x + area.width - 32.0, nav_y, 32.0, 32.0}, true) {
|
||||
OpenNewEvent(selected_year, selected_month, selected_day)
|
||||
}
|
||||
|
||||
// Weekday headers.
|
||||
wd_y := nav_y + 38.0
|
||||
col_w := area.width / 7.0
|
||||
for col: 0..6 {
|
||||
wd_idx := ifx store.week_starts_monday then (cast(s32)col + 1) % 7 else cast(s32)col
|
||||
DrawText(cast(u64)(110 + col), WeekdayShortName(wd_idx),
|
||||
Rectangle.{area.x + cast(float32)col * col_w, wd_y, col_w, 18.0}, 12, TextAlign.TextAlignCenter)
|
||||
}
|
||||
|
||||
// 6x7 Month grid.
|
||||
grid: [42]GridCell
|
||||
BuildMonthGrid(display_year, display_month, store.week_starts_monday, grid[:])
|
||||
grid_y := wd_y + 22.0
|
||||
cell_h: float32 = 38.0
|
||||
if area.height < 480.0 { cell_h = 32.0 }
|
||||
|
||||
dark := AppDark()
|
||||
today_border := Color.{56, 140, 235, 255}
|
||||
dot_color := Color.{61, 173, 115, 255}
|
||||
muted_fill := ifx dark then Color.{28, 31, 36, 255} else Color.{245, 247, 250, 255}
|
||||
|
||||
for idx: 0..41 {
|
||||
row := idx / 7
|
||||
col := idx % 7
|
||||
cell := grid[idx]
|
||||
cx := area.x + cast(float32)col * col_w + 1.5
|
||||
cy := grid_y + cast(float32)row * cell_h + 1.5
|
||||
cw := col_w - 3.0
|
||||
ch := cell_h - 3.0
|
||||
is_sel := cell.year == selected_year && cell.month == selected_month && cell.day == selected_day
|
||||
is_today := cell.year == today.year && cell.month == today.month && cell.day == today.day
|
||||
ev_count := DateEventCount(*store, cell.year, cell.month, cell.day)
|
||||
|
||||
if !cell.in_month && !is_sel {
|
||||
Box.Draw(session, Box.Props.{.key = cast(u64)(200 + idx), .bounds = Rectangle.{cx, cy, cw, ch},
|
||||
.fill = muted_fill, .radius = 6.0})
|
||||
}
|
||||
label_buf: [16]u8
|
||||
lu := AppendNumber(label_buf[:], 0, cast(s64)cell.day)
|
||||
if ev_count > 0 {
|
||||
lu = AppendText(label_buf[:], lu, "*")
|
||||
}
|
||||
props: Button.Props
|
||||
props.key = cast(u64)(300 + idx)
|
||||
props.id = 300 + cast(s32)idx
|
||||
props.bounds = Rectangle.{cx, cy, cw, ch}
|
||||
props.label = TextView(label_buf[:lu])
|
||||
props.size = ControlSize.ControlSizeSmall
|
||||
props.tone = ifx is_sel then ButtonTone.ButtonToneAccent else ButtonTone.ButtonToneNeutral
|
||||
props.emphasis = ifx is_sel then ButtonEmphasis.ButtonEmphasisFilled else (ifx cell.in_month then ButtonEmphasis.ButtonEmphasisSoft else ButtonEmphasis.ButtonEmphasisGhost)
|
||||
if Button.Draw(session, props) != 0 {
|
||||
selected_year = cell.year
|
||||
selected_month = cell.month
|
||||
selected_day = cell.day
|
||||
display_year = cell.year
|
||||
display_month = cell.month
|
||||
day_scroll_y = 0
|
||||
}
|
||||
if is_today && !is_sel {
|
||||
Box.Draw(session, Box.Props.{.key = cast(u64)(400 + idx), .bounds = Rectangle.{cx, cy, cw, ch},
|
||||
.border = today_border, .radius = 6.0})
|
||||
}
|
||||
if ev_count > 0 {
|
||||
Box.Draw(session, Box.Props.{.key = cast(u64)(450 + idx),
|
||||
.bounds = Rectangle.{cx + cw * 0.5 - 3.0, cy + ch - 5.0, 6.0, 3.0},
|
||||
.fill = ifx is_sel then Color.{255, 255, 255, 230} else dot_color, .radius = 1.5})
|
||||
}
|
||||
}
|
||||
|
||||
// Selected day agenda panel below grid.
|
||||
panel_y := grid_y + cell_h * 6.0 + 10.0
|
||||
date_buf: [64]u8
|
||||
DrawText(500, FormatDateLong(selected_year, selected_month, selected_day, date_buf[:]),
|
||||
Rectangle.{area.x, panel_y + 4.0, area.width - 102.0, 22.0}, 15, TextAlign.TextAlignStart)
|
||||
if Action(501, "+ Event", Rectangle.{area.x + area.width - 94.0, panel_y, 94.0, 30.0}, true) {
|
||||
OpenNewEvent(selected_year, selected_month, selected_day)
|
||||
}
|
||||
|
||||
list_y := panel_y + 36.0
|
||||
list_h := area.y + area.height - list_y
|
||||
if list_h < 56.0 { list_h = 56.0 }
|
||||
day_events: [64]s32
|
||||
found := EventsOnDate(*store, selected_year, selected_month, selected_day, day_events[:])
|
||||
if found == 0 {
|
||||
DrawText(502, "No events scheduled for this day.",
|
||||
Rectangle.{area.x + 4.0, list_y + 10.0, area.width - 8.0, 22.0}, 13, TextAlign.TextAlignStart)
|
||||
return
|
||||
}
|
||||
row_h: float32 = 54.0
|
||||
content_h := cast(s32)(cast(float32)found * row_h) + 8
|
||||
if content_h < cast(s32)list_h { content_h = cast(s32)list_h }
|
||||
list_bounds := Rectangle.{area.x, list_y, area.width, list_h}
|
||||
scroll := Scroll.Draw(session, Scroll.Props.{.key = 505, .bounds = list_bounds,
|
||||
.scroll_offset = day_scroll_y, .content_height = content_h, .scale = 1.0})
|
||||
day_scroll_y = scroll.scroll_offset
|
||||
if scroll.opened {
|
||||
for i: 0..found - 1 {
|
||||
y := scroll.content.y + cast(float32)i * row_h
|
||||
if DrawEventRow(cast(s32)i, day_events[i],
|
||||
Rectangle.{scroll.content.x, y, scroll.content.width - 10.0, row_h - 4.0},
|
||||
false, selected_year, selected_month, selected_day) {
|
||||
OpenEditEvent(day_events[i])
|
||||
}
|
||||
}
|
||||
End(session)
|
||||
}
|
||||
}
|
||||
|
||||
DrawWeekView :: (area: Rectangle) {
|
||||
sel_days := DaysFromCivil(selected_year, selected_month, selected_day)
|
||||
start_days := WeekStartDays(sel_days, store.week_starts_monday)
|
||||
start_c := CivilFromDays(start_days)
|
||||
end_c := CivilFromDays(start_days + 6)
|
||||
today := TodayCivil()
|
||||
|
||||
// Week navigation header.
|
||||
nav_y := area.y
|
||||
if Action(150, "<", Rectangle.{area.x, nav_y, 34.0, 32.0}, false) {
|
||||
c := CivilFromDays(sel_days - 7)
|
||||
selected_year = c.year; selected_month = c.month; selected_day = c.day
|
||||
display_year = c.year; display_month = c.month
|
||||
}
|
||||
if Action(151, ">", Rectangle.{area.x + 38.0, nav_y, 34.0, 32.0}, false) {
|
||||
c := CivilFromDays(sel_days + 7)
|
||||
selected_year = c.year; selected_month = c.month; selected_day = c.day
|
||||
display_year = c.year; display_month = c.month
|
||||
}
|
||||
range_buf: [64]u8
|
||||
ru := AppendNumber(range_buf[:], 0, cast(s64)start_c.day)
|
||||
ru = AppendText(range_buf[:], ru, " ")
|
||||
ru = AppendText(range_buf[:], ru, MonthShortName(start_c.month))
|
||||
ru = AppendText(range_buf[:], ru, " - ")
|
||||
ru = AppendNumber(range_buf[:], ru, cast(s64)end_c.day)
|
||||
ru = AppendText(range_buf[:], ru, " ")
|
||||
ru = AppendText(range_buf[:], ru, MonthShortName(end_c.month))
|
||||
ru = AppendText(range_buf[:], ru, " ")
|
||||
ru = AppendNumber(range_buf[:], ru, end_c.year)
|
||||
DrawText(152, TextView(range_buf[:ru]),
|
||||
Rectangle.{area.x + 76.0, nav_y + 5.0, area.width - 176.0, 24.0}, 15, TextAlign.TextAlignCenter)
|
||||
if Action(153, "Today", Rectangle.{area.x + area.width - 96.0, nav_y, 58.0, 32.0}, false) { JumpToday() }
|
||||
if Action(154, "+", Rectangle.{area.x + area.width - 34.0, nav_y, 34.0, 32.0}, true) {
|
||||
OpenNewEvent(selected_year, selected_month, selected_day)
|
||||
}
|
||||
|
||||
// Scrollable 7-day breakdown.
|
||||
list_y := nav_y + 40.0
|
||||
list_h := area.y + area.height - list_y
|
||||
if list_h < 60.0 { list_h = 60.0 }
|
||||
list_bounds := Rectangle.{area.x, list_y, area.width, list_h}
|
||||
|
||||
// Measure total content height.
|
||||
day_counts: [7]s32
|
||||
total_h: float32 = 8.0
|
||||
for d: 0..6 {
|
||||
c := CivilFromDays(start_days + cast(s64)d)
|
||||
day_counts[d] = DateEventCount(*store, c.year, c.month, c.day)
|
||||
total_h += 34.0 + (ifx day_counts[d] > 0 then cast(float32)day_counts[d] * 54.0 else 26.0) + 6.0
|
||||
}
|
||||
content_h := cast(s32)total_h
|
||||
if content_h < cast(s32)list_h { content_h = cast(s32)list_h }
|
||||
|
||||
scroll := Scroll.Draw(session, Scroll.Props.{.key = 160, .bounds = list_bounds,
|
||||
.scroll_offset = week_scroll_y, .content_height = content_h, .scale = 1.0})
|
||||
week_scroll_y = scroll.scroll_offset
|
||||
if scroll.opened {
|
||||
cur_y := scroll.content.y
|
||||
cw := scroll.content.width - 10.0
|
||||
row_counter: s32 = 100
|
||||
day_events: [32]s32
|
||||
for d: 0..6 {
|
||||
c := CivilFromDays(start_days + cast(s64)d)
|
||||
is_today := c.year == today.year && c.month == today.month && c.day == today.day
|
||||
is_sel := c.year == selected_year && c.month == selected_month && c.day == selected_day
|
||||
hdr_buf: [64]u8
|
||||
hu := AppendText(hdr_buf[:], 0, WeekdayShortName(c.weekday))
|
||||
hu = AppendText(hdr_buf[:], hu, ", ")
|
||||
hu = AppendNumber(hdr_buf[:], hu, cast(s64)c.day)
|
||||
hu = AppendText(hdr_buf[:], hu, " ")
|
||||
hu = AppendText(hdr_buf[:], hu, MonthShortName(c.month))
|
||||
if is_today { hu = AppendText(hdr_buf[:], hu, " (Today)") }
|
||||
|
||||
if Action(700 + cast(s32)d, TextView(hdr_buf[:hu]),
|
||||
Rectangle.{scroll.content.x, cur_y, cw - 66.0, 28.0}, is_sel) {
|
||||
selected_year = c.year; selected_month = c.month; selected_day = c.day
|
||||
display_year = c.year; display_month = c.month
|
||||
}
|
||||
if Action(710 + cast(s32)d, "+ Add",
|
||||
Rectangle.{scroll.content.x + cw - 60.0, cur_y, 60.0, 28.0}, false) {
|
||||
OpenNewEvent(c.year, c.month, c.day)
|
||||
}
|
||||
cur_y += 34.0
|
||||
found := EventsOnDate(*store, c.year, c.month, c.day, day_events[:])
|
||||
if found == 0 {
|
||||
DrawText(cast(u64)(720 + d), "No events",
|
||||
Rectangle.{scroll.content.x + 10.0, cur_y, cw - 20.0, 20.0}, 12, TextAlign.TextAlignStart)
|
||||
cur_y += 26.0
|
||||
} else {
|
||||
for k: 0..found - 1 {
|
||||
if DrawEventRow(row_counter, day_events[k],
|
||||
Rectangle.{scroll.content.x, cur_y, cw, 50.0},
|
||||
false, c.year, c.month, c.day) {
|
||||
OpenEditEvent(day_events[k])
|
||||
}
|
||||
row_counter += 1
|
||||
cur_y += 54.0
|
||||
}
|
||||
}
|
||||
cur_y += 6.0
|
||||
}
|
||||
End(session)
|
||||
}
|
||||
}
|
||||
|
||||
DrawAgendaView :: (area: Rectangle) {
|
||||
top_y := area.y
|
||||
if DrawField(10, "Search events...", search_buf[:], *search_state,
|
||||
Rectangle.{area.x, top_y, area.width - 76.0, 36.0}) {
|
||||
agenda_scroll_y = 0
|
||||
}
|
||||
if Action(170, "+ New", Rectangle.{area.x + area.width - 70.0, top_y, 70.0, 36.0}, true) {
|
||||
OpenNewEvent(selected_year, selected_month, selected_day)
|
||||
}
|
||||
|
||||
today := TodayCivil()
|
||||
items: [128]AgendaItem
|
||||
query := TextUntilNul(search_buf[:])
|
||||
count := CollectAgenda(*store, DaysFromCivil(today.year, today.month, today.day), 60, query, items[:])
|
||||
|
||||
list_y := top_y + 44.0
|
||||
list_h := area.y + area.height - list_y
|
||||
if list_h < 60.0 { list_h = 60.0 }
|
||||
if count == 0 {
|
||||
DrawText(171, ifx query.count > 0 then "No matching events found." else "No upcoming events in the next 60 days.",
|
||||
Rectangle.{area.x + 4.0, list_y + 10.0, area.width - 8.0, 24.0}, 14, TextAlign.TextAlignStart)
|
||||
return
|
||||
}
|
||||
row_h: float32 = 54.0
|
||||
content_h := cast(s32)(cast(float32)count * row_h) + 8
|
||||
if content_h < cast(s32)list_h { content_h = cast(s32)list_h }
|
||||
list_bounds := Rectangle.{area.x, list_y, area.width, list_h}
|
||||
scroll := Scroll.Draw(session, Scroll.Props.{.key = 175, .bounds = list_bounds,
|
||||
.scroll_offset = agenda_scroll_y, .content_height = content_h, .scale = 1.0})
|
||||
agenda_scroll_y = scroll.scroll_offset
|
||||
if scroll.opened {
|
||||
for i: 0..count - 1 {
|
||||
y := scroll.content.y + cast(float32)i * row_h
|
||||
it := items[i]
|
||||
if DrawEventRow(400 + cast(s32)i, it.event_index,
|
||||
Rectangle.{scroll.content.x, y, scroll.content.width - 10.0, row_h - 4.0},
|
||||
true, it.year, it.month, it.day) {
|
||||
OpenEditEvent(it.event_index)
|
||||
}
|
||||
}
|
||||
End(session)
|
||||
}
|
||||
}
|
||||
|
||||
StepEditorDate :: (delta: s64) {
|
||||
p := ParseDateISO(TextUntilNul(edit_date[:]))
|
||||
if !p.ok { return }
|
||||
c := CivilFromDays(DaysFromCivil(p.year, p.month, p.day) + delta)
|
||||
unused FormatDateISO(c.year, c.month, c.day, edit_date[:])
|
||||
}
|
||||
|
||||
DrawEditor :: (area: Rectangle) {
|
||||
DrawText(800, ifx edit_index >= 0 then "Edit Event" else "New Event",
|
||||
Rectangle.{area.x, area.y, area.width, 26.0}, 18, TextAlign.TextAlignStart)
|
||||
|
||||
body_y := area.y + 32.0
|
||||
body_h := area.height - 84.0
|
||||
if body_h < 120.0 { body_h = 120.0 }
|
||||
list_bounds := Rectangle.{area.x, body_y, area.width, body_h}
|
||||
content_h: s32 = 430
|
||||
if content_h < cast(s32)body_h { content_h = cast(s32)body_h }
|
||||
|
||||
scroll := Scroll.Draw(session, Scroll.Props.{.key = 805, .bounds = list_bounds,
|
||||
.scroll_offset = editor_scroll_y, .content_height = content_h, .scale = 1.0})
|
||||
editor_scroll_y = scroll.scroll_offset
|
||||
if scroll.opened {
|
||||
y := scroll.content.y
|
||||
x := scroll.content.x
|
||||
w := scroll.content.width - 10.0
|
||||
|
||||
unused DrawField(1, "Title", edit_title[:], *edit_fields[0], Rectangle.{x, y, w, 38.0})
|
||||
y += 46.0
|
||||
|
||||
// Date field with -1d / +1d quick step buttons.
|
||||
unused DrawField(2, "Date (YYYY-MM-DD)", edit_date[:], *edit_fields[1], Rectangle.{x, y, w - 92.0, 38.0})
|
||||
if Action(810, "-1d", Rectangle.{x + w - 88.0, y, 42.0, 38.0}, false) { StepEditorDate(-1) }
|
||||
if Action(811, "+1d", Rectangle.{x + w - 42.0, y, 42.0, 38.0}, false) { StepEditorDate(1) }
|
||||
y += 46.0
|
||||
|
||||
// All-day checkbox.
|
||||
cb_props := Checkbox.Props.{.key = 812, .id = 812, .label = "All-day event",
|
||||
.bounds = Rectangle.{x, y, w, 30.0}, .checked = edit_all_day}
|
||||
edit_all_day = Checkbox.Draw(session, cb_props).checked
|
||||
y += 36.0
|
||||
|
||||
if !edit_all_day {
|
||||
half := (w - 8.0) * 0.5
|
||||
unused DrawField(3, "Start (HH:MM)", edit_start[:], *edit_fields[2], Rectangle.{x, y, half, 38.0})
|
||||
unused DrawField(4, "End (HH:MM)", edit_end[:], *edit_fields[3], Rectangle.{x + half + 8.0, y, half, 38.0})
|
||||
y += 46.0
|
||||
}
|
||||
|
||||
// Recurrence selector.
|
||||
DrawText(813, "Repeat", Rectangle.{x, y, w, 18.0}, 13, TextAlign.TextAlignStart)
|
||||
y += 22.0
|
||||
rep_w := (w - 16.0) / 5.0
|
||||
for r: 0..4 {
|
||||
if Action(820 + cast(s32)r, RecurrenceLabel(cast(s32)r),
|
||||
Rectangle.{x + cast(float32)r * (rep_w + 4.0), y, rep_w, 30.0},
|
||||
edit_recurrence == cast(s32)r) {
|
||||
edit_recurrence = cast(s32)r
|
||||
}
|
||||
}
|
||||
y += 38.0
|
||||
|
||||
// Color swatches.
|
||||
DrawText(814, "Color", Rectangle.{x, y, w, 18.0}, 13, TextAlign.TextAlignStart)
|
||||
y += 22.0
|
||||
sw_w := (w - 20.0) / cast(float32)COLOR_COUNT
|
||||
for c: 0..COLOR_COUNT - 1 {
|
||||
sx := x + cast(float32)c * (sw_w + 4.0)
|
||||
if Action(830 + cast(s32)c, SwatchName(cast(s32)c),
|
||||
Rectangle.{sx, y, sw_w, 28.0}, edit_color == cast(s32)c) {
|
||||
edit_color = cast(s32)c
|
||||
}
|
||||
Box.Draw(session, Box.Props.{.key = cast(u64)(840 + c),
|
||||
.bounds = Rectangle.{sx + 4.0, y + 29.0, sw_w - 8.0, 4.0},
|
||||
.fill = SwatchColor(cast(s32)c), .radius = 2.0})
|
||||
}
|
||||
y += 42.0
|
||||
|
||||
unused DrawField(5, "Location (optional)", edit_location[:], *edit_fields[4], Rectangle.{x, y, w, 38.0})
|
||||
y += 46.0
|
||||
unused DrawField(6, "Notes (optional)", edit_notes[:], *edit_fields[5], Rectangle.{x, y, w, 38.0})
|
||||
y += 46.0
|
||||
|
||||
err := TextUntilNul(edit_error[:])
|
||||
if err.count > 0 {
|
||||
DrawText(850, err, Rectangle.{x, y, w, 22.0}, 13, TextAlign.TextAlignStart)
|
||||
}
|
||||
End(session)
|
||||
}
|
||||
|
||||
// Bottom buttons: Save, Cancel, Delete.
|
||||
btn_y := area.y + area.height - 42.0
|
||||
if Action(860, "Save", Rectangle.{area.x, btn_y, 96.0, 38.0}, true) {
|
||||
CommitEditor()
|
||||
}
|
||||
if Action(861, "Cancel", Rectangle.{area.x + 104.0, btn_y, 96.0, 38.0}, false) {
|
||||
editing = false
|
||||
focused_field = 0
|
||||
}
|
||||
if edit_index >= 0 {
|
||||
if DangerAction(862, "Delete", Rectangle.{area.x + area.width - 96.0, btn_y, 96.0, 38.0}) {
|
||||
unused DeleteEvent(*store, edit_index)
|
||||
editing = false
|
||||
focused_field = 0
|
||||
dirty = true
|
||||
SaveCalendar()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Draw :: () {
|
||||
session = AppSession()
|
||||
bounds := AppBounds()
|
||||
pad: float32 = 12.0
|
||||
area := Rectangle.{bounds.x + pad, bounds.y + 8.0, bounds.width - pad * 2.0, bounds.height - 16.0}
|
||||
|
||||
if editing {
|
||||
DrawEditor(area)
|
||||
AppKeyboard(focused_field != 0)
|
||||
return
|
||||
}
|
||||
|
||||
// Top view switcher: Month | Week | Agenda.
|
||||
tab_w := (area.width - 12.0) / 3.0
|
||||
if Action(10, "Month", Rectangle.{area.x, area.y, tab_w, 34.0}, view_mode == VIEW_MONTH) {
|
||||
view_mode = VIEW_MONTH
|
||||
focused_field = 0
|
||||
dirty = true
|
||||
}
|
||||
if Action(11, "Week", Rectangle.{area.x + tab_w + 6.0, area.y, tab_w, 34.0}, view_mode == VIEW_WEEK) {
|
||||
view_mode = VIEW_WEEK
|
||||
focused_field = 0
|
||||
dirty = true
|
||||
}
|
||||
if Action(12, "Agenda", Rectangle.{area.x + (tab_w + 6.0) * 2.0, area.y, tab_w, 34.0}, view_mode == VIEW_AGENDA) {
|
||||
view_mode = VIEW_AGENDA
|
||||
dirty = true
|
||||
}
|
||||
|
||||
body := Rectangle.{area.x, area.y + 42.0, area.width, area.height - 42.0}
|
||||
if view_mode == VIEW_MONTH {
|
||||
DrawMonthView(body)
|
||||
} else if view_mode == VIEW_WEEK {
|
||||
DrawWeekView(body)
|
||||
} else {
|
||||
DrawAgendaView(body)
|
||||
}
|
||||
AppKeyboard(focused_field != 0)
|
||||
}
|
||||
|
||||
#program_export "CalendarMain"
|
||||
Main :: () -> s32 {
|
||||
mode := AppMode()
|
||||
if mode == APP_IDENTIFY {
|
||||
AppIdentity("calendar")
|
||||
AppDescribe("Calendar", Icon.Shape)
|
||||
return APP_PROTOCOL
|
||||
}
|
||||
if mode == APP_SAVE {
|
||||
if loaded && dirty { SaveCalendar() }
|
||||
return 0
|
||||
}
|
||||
if mode != APP_FRAME {
|
||||
return 0
|
||||
}
|
||||
if !loaded {
|
||||
LoadCalendar()
|
||||
}
|
||||
Draw()
|
||||
return 0
|
||||
}
|
||||
@@ -1,630 +0,0 @@
|
||||
// Simple Calendar model: proleptic Gregorian date math, month/week grids,
|
||||
// recurring events, search, agenda queries and JSON persistence.
|
||||
#import "std/json_scan"
|
||||
#import "std/number_text"
|
||||
#import "std/text_buffer"
|
||||
#import "std/vec"
|
||||
|
||||
MAX_EVENTS :: 256;
|
||||
EVENT_TITLE_CAP :: 128;
|
||||
EVENT_LOCATION_CAP :: 128;
|
||||
EVENT_NOTES_CAP :: 256;
|
||||
|
||||
REPEAT_NONE :: 0;
|
||||
REPEAT_DAILY :: 1;
|
||||
REPEAT_WEEKLY :: 2;
|
||||
REPEAT_MONTHLY :: 3;
|
||||
REPEAT_YEARLY :: 4;
|
||||
|
||||
VIEW_MONTH :: 0;
|
||||
VIEW_WEEK :: 1;
|
||||
VIEW_AGENDA :: 2;
|
||||
|
||||
COLOR_COUNT :: 6;
|
||||
|
||||
CivilDate :: struct {
|
||||
year: s64
|
||||
month: s32
|
||||
day: s32
|
||||
weekday: s32 // 0 = Sunday .. 6 = Saturday
|
||||
}
|
||||
|
||||
CalendarEvent :: struct {
|
||||
id: s32
|
||||
active: bool
|
||||
year: s64
|
||||
month: s32
|
||||
day: s32
|
||||
all_day: bool
|
||||
start_minute: s32 // 0..1439
|
||||
end_minute: s32 // 0..1440
|
||||
recurrence: s32
|
||||
color: s32
|
||||
title: [EVENT_TITLE_CAP]u8
|
||||
location: [EVENT_LOCATION_CAP]u8
|
||||
notes: [EVENT_NOTES_CAP]u8
|
||||
}
|
||||
|
||||
GridCell :: struct {
|
||||
year: s64
|
||||
month: s32
|
||||
day: s32
|
||||
in_month: bool
|
||||
days: s64
|
||||
}
|
||||
|
||||
CalendarStore :: struct {
|
||||
events: [MAX_EVENTS]CalendarEvent
|
||||
next_id: s32
|
||||
week_starts_monday: bool
|
||||
default_view: s32
|
||||
}
|
||||
|
||||
AgendaItem :: struct {
|
||||
event_index: s32
|
||||
days: s64
|
||||
year: s64
|
||||
month: s32
|
||||
day: s32
|
||||
}
|
||||
|
||||
MonthYear :: struct {
|
||||
year: s64
|
||||
month: s32
|
||||
}
|
||||
|
||||
ParsedDate :: struct {
|
||||
year: s64
|
||||
month: s32
|
||||
day: s32
|
||||
ok: bool
|
||||
}
|
||||
|
||||
ParsedTime :: struct {
|
||||
minute: s32
|
||||
ok: bool
|
||||
}
|
||||
|
||||
IsLeapYear :: (year: s64) -> bool {
|
||||
if year % 400 == 0 { return true }
|
||||
if year % 100 == 0 { return false }
|
||||
return year % 4 == 0
|
||||
}
|
||||
|
||||
DaysInMonth :: (year: s64, month: s32) -> s32 {
|
||||
if month == 2 { return ifx IsLeapYear(year) then 29 else 28 }
|
||||
if month == 4 || month == 6 || month == 9 || month == 11 { return 30 }
|
||||
return 31
|
||||
}
|
||||
|
||||
// Howard Hinnant's civil/days algorithms (proleptic Gregorian, 1970-01-01 = 0).
|
||||
DaysFromCivil :: (year: s64, month: s32, day: s32) -> s64 {
|
||||
y := year - (ifx month <= 2 then 1 else 0)
|
||||
era := ifx y >= 0 then y / 400 else (y - 399) / 400
|
||||
yoe := y - era * 400
|
||||
m := cast(s64)month
|
||||
doy := (153 * (ifx m > 2 then m - 3 else m + 9) + 2) / 5 + cast(s64)day - 1
|
||||
doe := yoe * 365 + yoe / 4 - yoe / 100 + doy
|
||||
return era * 146097 + doe - 719468
|
||||
}
|
||||
|
||||
CivilFromDays :: (days: s64) -> CivilDate {
|
||||
shifted := days + 719468
|
||||
era := ifx shifted >= 0 then shifted / 146097 else (shifted - 146096) / 146097
|
||||
doe := shifted - era * 146097
|
||||
yoe := (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365
|
||||
doy := doe - (365 * yoe + yoe / 4 - yoe / 100)
|
||||
mp := (5 * doy + 2) / 153
|
||||
result: CivilDate
|
||||
result.day = cast(s32)(doy - (153 * mp + 2) / 5 + 1)
|
||||
result.month = cast(s32)(ifx mp < 10 then mp + 3 else mp - 9)
|
||||
result.year = yoe + era * 400 + (ifx result.month <= 2 then 1 else 0)
|
||||
wd := (days + 4) % 7
|
||||
if wd < 0 { wd += 7 }
|
||||
result.weekday = cast(s32)wd
|
||||
return result
|
||||
}
|
||||
|
||||
WeekdayOf :: (year: s64, month: s32, day: s32) -> s32 {
|
||||
return CivilFromDays(DaysFromCivil(year, month, day)).weekday
|
||||
}
|
||||
|
||||
ValidDate :: (year: s64, month: s32, day: s32) -> bool {
|
||||
if year < 1 || year > 9999 { return false }
|
||||
if month < 1 || month > 12 { return false }
|
||||
if day < 1 || day > DaysInMonth(year, month) { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
StepMonth :: (year: s64, month: s32, delta: s32) -> MonthYear {
|
||||
total := year * 12 + cast(s64)(month - 1) + cast(s64)delta
|
||||
ny := total / 12
|
||||
nm := total % 12
|
||||
if nm < 0 {
|
||||
nm += 12
|
||||
ny -= 1
|
||||
}
|
||||
return MonthYear.{.year = ny, .month = cast(s32)(nm + 1)}
|
||||
}
|
||||
|
||||
MonthName :: (month: s32) -> string {
|
||||
names: [12]string = .["January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December"]
|
||||
if month < 1 || month > 12 { return names[0] }
|
||||
return names[month - 1]
|
||||
}
|
||||
|
||||
MonthShortName :: (month: s32) -> string {
|
||||
names: [12]string = .["Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
||||
if month < 1 || month > 12 { return names[0] }
|
||||
return names[month - 1]
|
||||
}
|
||||
|
||||
WeekdayName :: (weekday: s32) -> string {
|
||||
names: [7]string = .["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
|
||||
if weekday < 0 || weekday > 6 { return names[0] }
|
||||
return names[weekday]
|
||||
}
|
||||
|
||||
WeekdayShortName :: (weekday: s32) -> string {
|
||||
names: [7]string = .["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
|
||||
if weekday < 0 || weekday > 6 { return names[0] }
|
||||
return names[weekday]
|
||||
}
|
||||
|
||||
RecurrenceLabel :: (recurrence: s32) -> string {
|
||||
if recurrence == REPEAT_DAILY { return "Daily" }
|
||||
if recurrence == REPEAT_WEEKLY { return "Weekly" }
|
||||
if recurrence == REPEAT_MONTHLY { return "Monthly" }
|
||||
if recurrence == REPEAT_YEARLY { return "Yearly" }
|
||||
return "Once"
|
||||
}
|
||||
|
||||
BuildMonthGrid :: (year: s64, month: s32, week_starts_monday: bool, out: []GridCell) {
|
||||
first_days := DaysFromCivil(year, month, 1)
|
||||
first_wd := CivilFromDays(first_days).weekday
|
||||
offset: s32 = ifx week_starts_monday then (first_wd + 6) % 7 else first_wd
|
||||
start_days := first_days - cast(s64)offset
|
||||
for index: 0..41 {
|
||||
if index >= out.count { break }
|
||||
d := start_days + cast(s64)index
|
||||
c := CivilFromDays(d)
|
||||
out[index] = GridCell.{.year = c.year, .month = c.month, .day = c.day,
|
||||
.in_month = c.year == year && c.month == month, .days = d}
|
||||
}
|
||||
}
|
||||
|
||||
WeekStartDays :: (days: s64, week_starts_monday: bool) -> s64 {
|
||||
wd := CivilFromDays(days).weekday
|
||||
offset: s32 = ifx week_starts_monday then (wd + 6) % 7 else wd
|
||||
return days - cast(s64)offset
|
||||
}
|
||||
|
||||
StoreInit :: (store: *CalendarStore) {
|
||||
store.* = CalendarStore.{}
|
||||
store.next_id = 1
|
||||
store.week_starts_monday = false
|
||||
store.default_view = VIEW_MONTH
|
||||
}
|
||||
|
||||
CopyField :: (dst: []u8, src: string) {
|
||||
limit := src.count
|
||||
if limit >= dst.count { limit = dst.count - 1 }
|
||||
for i: 0..limit - 1 { dst[i] = src[i] }
|
||||
dst[limit] = cast(u8)0
|
||||
}
|
||||
|
||||
AppendText :: (out: []u8, used: s32, text: string) -> s32 {
|
||||
pos := used
|
||||
for i: 0..text.count - 1 {
|
||||
if pos >= cast(s32)out.count - 1 { break }
|
||||
out[pos] = text[i]
|
||||
pos += 1
|
||||
}
|
||||
out[pos] = cast(u8)0
|
||||
return pos
|
||||
}
|
||||
|
||||
AppendTwoDigits :: (out: []u8, used: s32, value: s64) -> s32 {
|
||||
v := ifx value < 0 then 0 else value
|
||||
digits: [2]u8
|
||||
digits[0] = cast(u8)(48 + cast(s32)((v / 10) % 10))
|
||||
digits[1] = cast(u8)(48 + cast(s32)(v % 10))
|
||||
return AppendText(out, used, TextView(digits[:]))
|
||||
}
|
||||
|
||||
AppendFourDigits :: (out: []u8, used: s32, value: s64) -> s32 {
|
||||
v := ifx value < 0 then 0 else value
|
||||
digits: [4]u8
|
||||
digits[0] = cast(u8)(48 + cast(s32)((v / 1000) % 10))
|
||||
digits[1] = cast(u8)(48 + cast(s32)((v / 100) % 10))
|
||||
digits[2] = cast(u8)(48 + cast(s32)((v / 10) % 10))
|
||||
digits[3] = cast(u8)(48 + cast(s32)(v % 10))
|
||||
return AppendText(out, used, TextView(digits[:]))
|
||||
}
|
||||
|
||||
AppendNumber :: (out: []u8, used: s32, value: s64) -> s32 {
|
||||
buf: [32]u8
|
||||
return AppendText(out, used, FormatInteger(value, buf[:]))
|
||||
}
|
||||
|
||||
FormatDateISO :: (year: s64, month: s32, day: s32, out: []u8) -> string {
|
||||
used := AppendFourDigits(out, 0, year)
|
||||
used = AppendText(out, used, "-")
|
||||
used = AppendTwoDigits(out, used, cast(s64)month)
|
||||
used = AppendText(out, used, "-")
|
||||
used = AppendTwoDigits(out, used, cast(s64)day)
|
||||
return TextView(out[:used])
|
||||
}
|
||||
|
||||
ParseDateISO :: (text: string) -> ParsedDate {
|
||||
bad := ParsedDate.{}
|
||||
if text.count != 10 { return bad }
|
||||
if text[4] != cast(u8)45 || text[7] != cast(u8)45 { return bad }
|
||||
for i: 0..9 {
|
||||
if i == 4 || i == 7 { continue }
|
||||
if text[i] < cast(u8)48 || text[i] > cast(u8)57 { return bad }
|
||||
}
|
||||
year := cast(s64)(text[0] - 48) * 1000 + cast(s64)(text[1] - 48) * 100 +
|
||||
cast(s64)(text[2] - 48) * 10 + cast(s64)(text[3] - 48)
|
||||
month := cast(s32)(text[5] - 48) * 10 + cast(s32)(text[6] - 48)
|
||||
day := cast(s32)(text[8] - 48) * 10 + cast(s32)(text[9] - 48)
|
||||
if !ValidDate(year, month, day) { return bad }
|
||||
return ParsedDate.{.year = year, .month = month, .day = day, .ok = true}
|
||||
}
|
||||
|
||||
FormatTimeHHMM :: (minute_of_day: s32, out: []u8) -> string {
|
||||
m := minute_of_day
|
||||
if m < 0 { m = 0 }
|
||||
if m > 1439 { m = 1439 }
|
||||
used := AppendTwoDigits(out, 0, cast(s64)(m / 60))
|
||||
used = AppendText(out, used, ":")
|
||||
used = AppendTwoDigits(out, used, cast(s64)(m % 60))
|
||||
return TextView(out[:used])
|
||||
}
|
||||
|
||||
ParseTimeHHMM :: (text: string) -> ParsedTime {
|
||||
bad := ParsedTime.{}
|
||||
if text.count < 4 || text.count > 5 { return bad }
|
||||
colon: s64 = -1
|
||||
for i: 0..text.count - 1 {
|
||||
if text[i] == cast(u8)58 { colon = i; break }
|
||||
}
|
||||
if colon < 1 || colon > 2 || text.count - colon - 1 != 2 { return bad }
|
||||
hour: s32 = 0
|
||||
for i: 0..colon - 1 {
|
||||
if text[i] < cast(u8)48 || text[i] > cast(u8)57 { return bad }
|
||||
hour = hour * 10 + cast(s32)(text[i] - 48)
|
||||
}
|
||||
minute: s32 = 0
|
||||
for i: colon + 1..text.count - 1 {
|
||||
if text[i] < cast(u8)48 || text[i] > cast(u8)57 { return bad }
|
||||
minute = minute * 10 + cast(s32)(text[i] - 48)
|
||||
}
|
||||
if hour < 0 || hour > 23 || minute < 0 || minute > 59 { return bad }
|
||||
return ParsedTime.{.minute = hour * 60 + minute, .ok = true}
|
||||
}
|
||||
|
||||
FormatDateLong :: (year: s64, month: s32, day: s32, out: []u8) -> string {
|
||||
wd := WeekdayOf(year, month, day)
|
||||
used := AppendText(out, 0, WeekdayName(wd))
|
||||
used = AppendText(out, used, ", ")
|
||||
used = AppendNumber(out, used, cast(s64)day)
|
||||
used = AppendText(out, used, " ")
|
||||
used = AppendText(out, used, MonthName(month))
|
||||
used = AppendText(out, used, " ")
|
||||
used = AppendNumber(out, used, year)
|
||||
return TextView(out[:used])
|
||||
}
|
||||
|
||||
EventOccursOn :: (event: *CalendarEvent, year: s64, month: s32, day: s32) -> bool {
|
||||
if !event.active { return false }
|
||||
target_days := DaysFromCivil(year, month, day)
|
||||
start_days := DaysFromCivil(event.year, event.month, event.day)
|
||||
if target_days < start_days { return false }
|
||||
if event.recurrence == REPEAT_NONE {
|
||||
return target_days == start_days
|
||||
}
|
||||
if event.recurrence == REPEAT_DAILY {
|
||||
return true
|
||||
}
|
||||
if event.recurrence == REPEAT_WEEKLY {
|
||||
return (target_days - start_days) % 7 == 0
|
||||
}
|
||||
if event.recurrence == REPEAT_MONTHLY {
|
||||
max_day := DaysInMonth(year, month)
|
||||
expected_day := ifx event.day > max_day then max_day else event.day
|
||||
return day == expected_day
|
||||
}
|
||||
if event.recurrence == REPEAT_YEARLY {
|
||||
if month != event.month { return false }
|
||||
max_day := DaysInMonth(year, month)
|
||||
expected_day := ifx event.day > max_day then max_day else event.day
|
||||
return day == expected_day
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
EventBefore :: (a: *CalendarEvent, b: *CalendarEvent) -> bool {
|
||||
if a.all_day != b.all_day { return a.all_day }
|
||||
if !a.all_day && a.start_minute != b.start_minute { return a.start_minute < b.start_minute }
|
||||
return a.id < b.id
|
||||
}
|
||||
|
||||
EventsOnDate :: (store: *CalendarStore, year: s64, month: s32, day: s32, out: []s32) -> s32 {
|
||||
count: s32 = 0
|
||||
for i: 0..MAX_EVENTS - 1 {
|
||||
if EventOccursOn(*store.events[i], year, month, day) {
|
||||
if count >= cast(s32)out.count { break }
|
||||
out[count] = cast(s32)i
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
// Insertion sort by all_day first, then start_minute, then id.
|
||||
for i: 1..count - 1 {
|
||||
key := out[i]
|
||||
j := i - 1
|
||||
while j >= 0 && EventBefore(*store.events[key], *store.events[out[j]]) {
|
||||
out[j + 1] = out[j]
|
||||
j -= 1
|
||||
}
|
||||
out[j + 1] = key
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
DateEventCount :: (store: *CalendarStore, year: s64, month: s32, day: s32) -> s32 {
|
||||
count: s32 = 0
|
||||
for i: 0..MAX_EVENTS - 1 {
|
||||
if EventOccursOn(*store.events[i], year, month, day) { count += 1 }
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
AddEvent :: (store: *CalendarStore, item: CalendarEvent) -> s32 {
|
||||
for i: 0..MAX_EVENTS - 1 {
|
||||
if !store.events[i].active {
|
||||
ev := item
|
||||
ev.active = true
|
||||
if ev.id <= 0 {
|
||||
ev.id = store.next_id
|
||||
store.next_id += 1
|
||||
} else if ev.id >= store.next_id {
|
||||
store.next_id = ev.id + 1
|
||||
}
|
||||
if ev.color < 0 || ev.color >= COLOR_COUNT { ev.color = 0 }
|
||||
if ev.recurrence < REPEAT_NONE || ev.recurrence > REPEAT_YEARLY { ev.recurrence = REPEAT_NONE }
|
||||
store.events[i] = ev
|
||||
return cast(s32)i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
UpdateEvent :: (store: *CalendarStore, index: s32, item: CalendarEvent) -> bool {
|
||||
if index < 0 || index >= MAX_EVENTS || !store.events[index].active { return false }
|
||||
ev := item
|
||||
ev.id = store.events[index].id
|
||||
ev.active = true
|
||||
if ev.color < 0 || ev.color >= COLOR_COUNT { ev.color = 0 }
|
||||
if ev.recurrence < REPEAT_NONE || ev.recurrence > REPEAT_YEARLY { ev.recurrence = REPEAT_NONE }
|
||||
store.events[index] = ev
|
||||
return true
|
||||
}
|
||||
|
||||
DeleteEvent :: (store: *CalendarStore, index: s32) -> bool {
|
||||
if index < 0 || index >= MAX_EVENTS || !store.events[index].active { return false }
|
||||
store.events[index] = CalendarEvent.{}
|
||||
return true
|
||||
}
|
||||
|
||||
FindEventById :: (store: *CalendarStore, id: s32) -> s32 {
|
||||
for i: 0..MAX_EVENTS - 1 {
|
||||
if store.events[i].active && store.events[i].id == id { return cast(s32)i }
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
AsciiLower :: (b: u8) -> u8 {
|
||||
if b >= cast(u8)65 && b <= cast(u8)90 { return b + cast(u8)32 }
|
||||
return b
|
||||
}
|
||||
|
||||
ContainsFold :: (haystack: string, needle: string) -> bool {
|
||||
if needle.count == 0 { return true }
|
||||
if needle.count > haystack.count { return false }
|
||||
limit := haystack.count - needle.count
|
||||
for start: 0..limit {
|
||||
ok := true
|
||||
for k: 0..needle.count - 1 {
|
||||
if AsciiLower(haystack[start + k]) != AsciiLower(needle[k]) {
|
||||
ok = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if ok { return true }
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
EventMatchesQuery :: (event: *CalendarEvent, query: string) -> bool {
|
||||
if query.count == 0 { return true }
|
||||
if ContainsFold(TextUntilNul(event.title[:]), query) { return true }
|
||||
if ContainsFold(TextUntilNul(event.location[:]), query) { return true }
|
||||
if ContainsFold(TextUntilNul(event.notes[:]), query) { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
CollectAgenda :: (store: *CalendarStore, from_days: s64, horizon_days: s32, query: string, out: []AgendaItem) -> s32 {
|
||||
count: s32 = 0
|
||||
if query.count > 0 {
|
||||
// When searching, list all matching events sorted by their start date.
|
||||
for i: 0..MAX_EVENTS - 1 {
|
||||
if !store.events[i].active { continue }
|
||||
if !EventMatchesQuery(*store.events[i], query) { continue }
|
||||
if count >= cast(s32)out.count { break }
|
||||
ev := *store.events[i]
|
||||
out[count] = AgendaItem.{.event_index = cast(s32)i,
|
||||
.days = DaysFromCivil(ev.year, ev.month, ev.day),
|
||||
.year = ev.year, .month = ev.month, .day = ev.day}
|
||||
count += 1
|
||||
}
|
||||
for i: 1..count - 1 {
|
||||
key := out[i]
|
||||
j := i - 1
|
||||
while j >= 0 && (key.days < out[j].days ||
|
||||
(key.days == out[j].days && EventBefore(*store.events[key.event_index], *store.events[out[j].event_index]))) {
|
||||
out[j + 1] = out[j]
|
||||
j -= 1
|
||||
}
|
||||
out[j + 1] = key
|
||||
}
|
||||
return count
|
||||
}
|
||||
day_indices: [64]s32
|
||||
for offset: 0..horizon_days - 1 {
|
||||
if count >= cast(s32)out.count { break }
|
||||
d := from_days + cast(s64)offset
|
||||
c := CivilFromDays(d)
|
||||
found := EventsOnDate(store, c.year, c.month, c.day, day_indices[:])
|
||||
for k: 0..found - 1 {
|
||||
if count >= cast(s32)out.count { break }
|
||||
out[count] = AgendaItem.{.event_index = day_indices[k], .days = d,
|
||||
.year = c.year, .month = c.month, .day = c.day}
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
WriteQuoted :: (bytes: *Vec(u8), text: string) {
|
||||
BuilderPrint(bytes, "\"")
|
||||
hex := "0123456789abcdef"
|
||||
for byte: text {
|
||||
if byte == cast(u8)34 || byte == cast(u8)92 {
|
||||
BuilderPrint(bytes, "\\")
|
||||
unused VecPush(bytes.*, byte)
|
||||
} else if byte == cast(u8)10 {
|
||||
BuilderPrint(bytes, "\\n")
|
||||
} else if byte == cast(u8)13 {
|
||||
BuilderPrint(bytes, "\\r")
|
||||
} else if byte == cast(u8)9 {
|
||||
BuilderPrint(bytes, "\\t")
|
||||
} else if byte < cast(u8)32 {
|
||||
BuilderPrint(bytes, "\\u00")
|
||||
unused VecPush(bytes.*, hex[cast(s32)byte / 16])
|
||||
unused VecPush(bytes.*, hex[cast(s32)byte % 16])
|
||||
} else {
|
||||
unused VecPush(bytes.*, byte)
|
||||
}
|
||||
}
|
||||
BuilderPrint(bytes, "\"")
|
||||
}
|
||||
|
||||
SerializeStore :: (store: *CalendarStore, out: []u8) -> s32 {
|
||||
bytes: Vec(u8)
|
||||
BuilderPrint(*bytes, "{\"v\":1,\"next_id\":%,\"week_starts_monday\":%,\"default_view\":%,\"events\":[",
|
||||
store.next_id, ifx store.week_starts_monday then "true" else "false", store.default_view)
|
||||
first := true
|
||||
for i: 0..MAX_EVENTS - 1 {
|
||||
ev := *store.events[i]
|
||||
if !ev.active { continue }
|
||||
if !first { BuilderPrint(*bytes, ",") }
|
||||
first = false
|
||||
BuilderPrint(*bytes, "{\"id\":%,\"y\":%,\"m\":%,\"d\":%,\"all_day\":%,\"start\":%,\"end\":%,\"repeat\":%,\"color\":%,\"title\":",
|
||||
ev.id, ev.year, ev.month, ev.day,
|
||||
ifx ev.all_day then "true" else "false",
|
||||
ev.start_minute, ev.end_minute, ev.recurrence, ev.color)
|
||||
WriteQuoted(*bytes, TextUntilNul(ev.title[:]))
|
||||
BuilderPrint(*bytes, ",\"location\":")
|
||||
WriteQuoted(*bytes, TextUntilNul(ev.location[:]))
|
||||
BuilderPrint(*bytes, ",\"notes\":")
|
||||
WriteQuoted(*bytes, TextUntilNul(ev.notes[:]))
|
||||
BuilderPrint(*bytes, "}")
|
||||
}
|
||||
BuilderPrint(*bytes, "]}\n")
|
||||
count := cast(s32)bytes.count
|
||||
if count >= cast(s32)out.count {
|
||||
VecFree(bytes)
|
||||
return -1
|
||||
}
|
||||
{
|
||||
slice := VecSlice(bytes, 0, bytes.count)
|
||||
for i: 0..count - 1 { out[i] = slice[i] }
|
||||
}
|
||||
out[count] = cast(u8)0
|
||||
VecFree(bytes)
|
||||
return count
|
||||
}
|
||||
|
||||
ReadJsonInt :: (text: string, obj: s32, field: string, fallback: s64) -> s64 {
|
||||
at := FieldAt(text, obj, field)
|
||||
if at < 0 { return fallback }
|
||||
num := ReadNumber(text, at)
|
||||
return ifx num.valid then cast(s64)num.value else fallback
|
||||
}
|
||||
|
||||
ReadJsonBool :: (text: string, obj: s32, field: string, fallback: bool) -> bool {
|
||||
at := FieldAt(text, obj, field)
|
||||
if at < 0 { return fallback }
|
||||
if MatchLiteral(text, at, "true") { return true }
|
||||
if MatchLiteral(text, at, "false") { return false }
|
||||
return fallback
|
||||
}
|
||||
|
||||
ReadJsonString :: (text: string, obj: s32, field: string, out: []u8) {
|
||||
out[0] = cast(u8)0
|
||||
at := FieldAt(text, obj, field)
|
||||
if at < 0 { return }
|
||||
used := ReadStringText(text, at, out)
|
||||
if used < 0 {
|
||||
out[0] = cast(u8)0
|
||||
} else if used < cast(s32)out.count {
|
||||
out[used] = cast(u8)0
|
||||
} else {
|
||||
out[out.count - 1] = cast(u8)0
|
||||
}
|
||||
}
|
||||
|
||||
DeserializeStore :: (text: string, store: *CalendarStore) -> bool {
|
||||
StoreInit(store)
|
||||
if text.count == 0 { return false }
|
||||
root := Space(text, 0)
|
||||
if root >= cast(s32)text.count || text[root] != cast(u8)123 { return false }
|
||||
store.next_id = cast(s32)ReadJsonInt(text, root, "next_id", 1)
|
||||
if store.next_id < 1 { store.next_id = 1 }
|
||||
store.week_starts_monday = ReadJsonBool(text, root, "week_starts_monday", false)
|
||||
store.default_view = cast(s32)ReadJsonInt(text, root, "default_view", VIEW_MONTH)
|
||||
if store.default_view < VIEW_MONTH || store.default_view > VIEW_AGENDA {
|
||||
store.default_view = VIEW_MONTH
|
||||
}
|
||||
arr := FieldAt(text, root, "events")
|
||||
if arr < 0 { return true }
|
||||
count := ArrayCount(text, arr)
|
||||
at := Space(text, arr + 1)
|
||||
for i: 0..count - 1 {
|
||||
if at >= cast(s32)text.count { break }
|
||||
if text[at] == cast(u8)123 {
|
||||
ev: CalendarEvent
|
||||
ev.id = cast(s32)ReadJsonInt(text, at, "id", 0)
|
||||
ev.year = ReadJsonInt(text, at, "y", 2026)
|
||||
ev.month = cast(s32)ReadJsonInt(text, at, "m", 1)
|
||||
ev.day = cast(s32)ReadJsonInt(text, at, "d", 1)
|
||||
ev.all_day = ReadJsonBool(text, at, "all_day", false)
|
||||
ev.start_minute = cast(s32)ReadJsonInt(text, at, "start", 540)
|
||||
ev.end_minute = cast(s32)ReadJsonInt(text, at, "end", 600)
|
||||
ev.recurrence = cast(s32)ReadJsonInt(text, at, "repeat", REPEAT_NONE)
|
||||
ev.color = cast(s32)ReadJsonInt(text, at, "color", 0)
|
||||
ReadJsonString(text, at, "title", ev.title[:])
|
||||
ReadJsonString(text, at, "location", ev.location[:])
|
||||
ReadJsonString(text, at, "notes", ev.notes[:])
|
||||
if ValidDate(ev.year, ev.month, ev.day) && ev.title[0] != cast(u8)0 {
|
||||
unused AddEvent(store, ev)
|
||||
}
|
||||
}
|
||||
at = Space(text, ValueEnd(text, at, 0))
|
||||
if at < cast(s32)text.count && text[at] == cast(u8)44 { at = Space(text, at + 1) }
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
// Unit tests for Simple Calendar date math, grid generation, recurrence,
|
||||
// search, agenda ordering and JSON persistence.
|
||||
#import "std/text_buffer"
|
||||
#import "calendar_model"
|
||||
|
||||
#program_export
|
||||
Run :: () -> s32 {
|
||||
// Leap years and month lengths.
|
||||
if !IsLeapYear(2024) || !IsLeapYear(2000) { return 1 }
|
||||
if IsLeapYear(1900) || IsLeapYear(2026) { return 2 }
|
||||
if DaysInMonth(2024, 2) != 29 || DaysInMonth(2026, 2) != 28 { return 3 }
|
||||
if DaysInMonth(2026, 11) != 30 || DaysInMonth(2026, 12) != 31 { return 4 }
|
||||
|
||||
// Civil <-> Days roundtrip and weekdays (1970-01-01 = Thursday = 4; 2026-11-21 = Saturday = 6).
|
||||
if DaysFromCivil(1970, 1, 1) != 0 { return 5 }
|
||||
epoch := CivilFromDays(0)
|
||||
if epoch.year != 1970 || epoch.month != 1 || epoch.day != 1 || epoch.weekday != 4 { return 6 }
|
||||
d2026 := DaysFromCivil(2026, 11, 21)
|
||||
c2026 := CivilFromDays(d2026)
|
||||
if c2026.year != 2026 || c2026.month != 11 || c2026.day != 21 || c2026.weekday != 6 { return 7 }
|
||||
|
||||
// StepMonth across year boundaries.
|
||||
s1 := StepMonth(2026, 1, -1)
|
||||
if s1.year != 2025 || s1.month != 12 { return 8 }
|
||||
s2 := StepMonth(2026, 12, 1)
|
||||
if s2.year != 2027 || s2.month != 1 { return 9 }
|
||||
|
||||
// Month grid (November 2026 starts on Sunday = 0).
|
||||
grid_sun: [42]GridCell
|
||||
BuildMonthGrid(2026, 11, false, grid_sun[:])
|
||||
if grid_sun[0].year != 2026 || grid_sun[0].month != 11 || grid_sun[0].day != 1 || !grid_sun[0].in_month { return 10 }
|
||||
if grid_sun[29].day != 30 || !grid_sun[29].in_month { return 11 }
|
||||
if grid_sun[30].month != 12 || grid_sun[30].day != 1 || grid_sun[30].in_month { return 12 }
|
||||
|
||||
grid_mon: [42]GridCell
|
||||
BuildMonthGrid(2026, 11, true, grid_mon[:])
|
||||
if grid_mon[0].month != 10 || grid_mon[0].day != 26 || grid_mon[0].in_month { return 13 }
|
||||
if grid_mon[6].month != 11 || grid_mon[6].day != 1 || !grid_mon[6].in_month { return 14 }
|
||||
|
||||
// Date and time parsing/formatting.
|
||||
pd := ParseDateISO("2026-11-21")
|
||||
if !pd.ok || pd.year != 2026 || pd.month != 11 || pd.day != 21 { return 15 }
|
||||
bad_date := ParseDateISO("2026-02-29")
|
||||
if bad_date.ok { return 16 }
|
||||
pt := ParseTimeHHMM("09:45")
|
||||
if !pt.ok || pt.minute != 585 { return 17 }
|
||||
bad_time := ParseTimeHHMM("25:00")
|
||||
if bad_time.ok { return 18 }
|
||||
|
||||
// Store CRUD, recurrence, sorting, search.
|
||||
store: CalendarStore
|
||||
StoreInit(*store)
|
||||
store.week_starts_monday = true
|
||||
|
||||
e1: CalendarEvent
|
||||
e1.year = 2026; e1.month = 11; e1.day = 21
|
||||
e1.all_day = false; e1.start_minute = 600; e1.end_minute = 660
|
||||
e1.recurrence = REPEAT_WEEKLY; e1.color = 1
|
||||
CopyField(e1.title[:], "Team Sync")
|
||||
CopyField(e1.location[:], "Room \"A\"")
|
||||
CopyField(e1.notes[:], "Line1\nLine2")
|
||||
idx1 := AddEvent(*store, e1)
|
||||
if idx1 < 0 { return 19 }
|
||||
|
||||
e2: CalendarEvent
|
||||
e2.year = 2026; e2.month = 11; e2.day = 21
|
||||
e2.all_day = true; e2.recurrence = REPEAT_NONE; e2.color = 2
|
||||
CopyField(e2.title[:], "Release Day")
|
||||
idx2 := AddEvent(*store, e2)
|
||||
if idx2 < 0 { return 20 }
|
||||
|
||||
e3: CalendarEvent
|
||||
e3.year = 2026; e3.month = 1; e3.day = 31
|
||||
e3.all_day = false; e3.start_minute = 480; e3.end_minute = 510
|
||||
e3.recurrence = REPEAT_MONTHLY; e3.color = 3
|
||||
CopyField(e3.title[:], "Month End")
|
||||
if AddEvent(*store, e3) < 0 { return 21 }
|
||||
|
||||
// Sorting on 2026-11-21: all-day event first, then timed event.
|
||||
hits: [16]s32
|
||||
found := EventsOnDate(*store, 2026, 11, 21, hits[:])
|
||||
if found != 2 || hits[0] != idx2 || hits[1] != idx1 { return 22 }
|
||||
|
||||
// Weekly recurrence on 2026-11-28, and not before start date (2026-11-14).
|
||||
if DateEventCount(*store, 2026, 11, 28) != 1 { return 23 }
|
||||
if DateEventCount(*store, 2026, 11, 14) != 0 { return 24 }
|
||||
|
||||
// Monthly clamping on Feb 28 2026 for a Jan 31 monthly event.
|
||||
if DateEventCount(*store, 2026, 2, 28) != 1 { return 25 }
|
||||
|
||||
// JSON persistence round-trip.
|
||||
json_buf: [8192]u8
|
||||
used := SerializeStore(*store, json_buf[:])
|
||||
if used <= 0 { return 26 }
|
||||
reloaded: CalendarStore
|
||||
if !DeserializeStore(TextView(json_buf[:used]), *reloaded) { return 27 }
|
||||
if !reloaded.week_starts_monday { return 28 }
|
||||
if DateEventCount(*reloaded, 2026, 11, 21) != 2 { return 29 }
|
||||
r_idx := FindEventById(*reloaded, store.events[idx1].id)
|
||||
if r_idx < 0 { return 30 }
|
||||
if TextUntilNul(reloaded.events[r_idx].title[:]) != "Team Sync" { return 31 }
|
||||
if TextUntilNul(reloaded.events[r_idx].location[:]) != "Room \"A\"" { return 32 }
|
||||
|
||||
// Search via CollectAgenda.
|
||||
agenda: [16]AgendaItem
|
||||
qcount := CollectAgenda(*reloaded, d2026, 30, "sync", agenda[:])
|
||||
if qcount != 1 || agenda[0].event_index != r_idx { return 33 }
|
||||
|
||||
// Delete event.
|
||||
if !DeleteEvent(*reloaded, r_idx) { return 34 }
|
||||
if DateEventCount(*reloaded, 2026, 11, 21) != 1 { return 35 }
|
||||
|
||||
return 0
|
||||
}
|
||||
@@ -1,16 +1,18 @@
|
||||
Text :: #import "kryon/text";
|
||||
Button :: #import "kryon/button";
|
||||
// Clock: the local time and date, and a stopwatch that keeps running while
|
||||
// the app is closed.
|
||||
#import "kryon/session"
|
||||
#import "kryon/geometry"
|
||||
#import "kryon/text_align"
|
||||
#import "kryon/control_props"
|
||||
#import "std/text_buffer"
|
||||
#import "std/number_text"
|
||||
#import "kryon/app_context"
|
||||
#import "kryon/app_protocol"
|
||||
Icon :: #import "mingcute/mingcute_regular_time";
|
||||
#import "session"
|
||||
#import "geometry"
|
||||
#import "text_props"
|
||||
#import "text_align"
|
||||
#import "text_widget"
|
||||
#import "button_props"
|
||||
#import "button_widget"
|
||||
#import "control_props"
|
||||
#import "text_buffer"
|
||||
#import "number_text"
|
||||
#import "werk_app"
|
||||
#import "app_protocol"
|
||||
Icon :: #import "mingcute_regular_time";
|
||||
|
||||
VIEW_CLOCK :: 0
|
||||
VIEW_STOPWATCH :: 1
|
||||
@@ -30,8 +32,6 @@ running: bool;
|
||||
started_at: float64;
|
||||
elapsed: float64;
|
||||
session: Session;
|
||||
local_offset: s32;
|
||||
local_offset_read_at: float64 = -61.0;
|
||||
|
||||
// The civil date of a day count since 1970-01-01 (proleptic Gregorian).
|
||||
CivilFromDays :: (days: s64) -> Civil {
|
||||
@@ -78,15 +78,11 @@ AppendNumber :: (output: []u8, used: s32, value: s64) -> s32 {
|
||||
|
||||
LocalSeconds :: () -> s64 {
|
||||
now := AppNow()
|
||||
if now - local_offset_read_at > 60.0 {
|
||||
local_offset = AppLocalOffset()
|
||||
local_offset_read_at = now
|
||||
}
|
||||
seconds := cast(s64)now
|
||||
if cast(float64)seconds > now {
|
||||
seconds -= 1
|
||||
}
|
||||
return seconds + cast(s64)local_offset
|
||||
return seconds + cast(s64)AppLocalOffset()
|
||||
}
|
||||
|
||||
TimeText :: (output: []u8) -> string {
|
||||
@@ -203,18 +199,18 @@ SaveStopwatch :: () {
|
||||
}
|
||||
|
||||
Big :: (key: u64, text: string, area: Rectangle, y: float32, font: s32) {
|
||||
Text.Draw(session, Text.Props.{.key = key, .bounds = Rectangle.{area.x + 16.0, y, area.width - 32.0, cast(float32)(font + 16)},
|
||||
.text = text, .size = font, .align = TextAlign.TextAlignCenter})
|
||||
Text(session, TextProps.{.key = key, .bounds = Rectangle.{area.x + 16.0, y, area.width - 32.0, cast(float32)(font + 16)},
|
||||
.text = text, .font = font, .align = TextAlign.TextAlignCenter})
|
||||
}
|
||||
|
||||
Action :: (id: s32, label: string, bounds: Rectangle, accent: bool) -> bool {
|
||||
props := Button.Props.{.key = cast(u64)id, .id = id, .bounds = bounds, .label = label,
|
||||
props := ButtonProps.{.key = cast(u64)id, .id = id, .bounds = bounds, .label = label,
|
||||
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}
|
||||
if accent {
|
||||
props.tone = ButtonTone.ButtonToneAccent
|
||||
props.emphasis = ButtonEmphasis.ButtonEmphasisFilled
|
||||
}
|
||||
return Button.Draw(session, props) != 0
|
||||
return Button(session, props) != 0
|
||||
}
|
||||
|
||||
Draw :: () {
|
||||
@@ -263,13 +259,9 @@ Draw :: () {
|
||||
#program_export "ClockMain"
|
||||
Main :: () -> s32 {
|
||||
if AppMode() == APP_IDENTIFY {
|
||||
AppIdentity("clock")
|
||||
AppDescribe("Clock", Icon.Shape)
|
||||
return APP_PROTOCOL
|
||||
}
|
||||
if AppMode() != APP_FRAME {
|
||||
return 0
|
||||
}
|
||||
if !loaded {
|
||||
LoadStopwatch()
|
||||
loaded = true
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
// Gallery is a separate portable tool. Only Werk knows platform file grants.
|
||||
#import "kryon/session"
|
||||
#import "kryon/geometry"
|
||||
#import "kryon/tree"
|
||||
Text :: #import "kryon/text";
|
||||
Button :: #import "kryon/button";
|
||||
#import "kryon/control_props"
|
||||
#import "std/number_text"
|
||||
#import "std/c_string"
|
||||
#import "std/text_buffer"
|
||||
#import "kryon/app_context"
|
||||
#import "kryon/app_protocol"
|
||||
Model :: #import "gallery_model";
|
||||
Icon :: #import "mingcute/mingcute_regular_photo_album";
|
||||
Image :: #import "kryon/image";
|
||||
Showing :: #import "kryon/image_showing";
|
||||
Scroll :: #import "kryon/scroll";
|
||||
|
||||
listing: Model.Listing;
|
||||
viewer: Model.Viewer = Model.Viewer.{.selected = -1, .zoom = 1};
|
||||
loaded: bool;
|
||||
status: [32]u8;
|
||||
location: [1024]u8;
|
||||
can_up: bool;
|
||||
grid_offset: s32;
|
||||
zoom_x: s32;
|
||||
zoom_y: s32;
|
||||
session: Session;
|
||||
// The host's navigation is in the same retained tree as the active tool.
|
||||
// Keep Gallery controls separate from its Home/avatar keys.
|
||||
KEY_BASE :: 2000000
|
||||
|
||||
Call :: (request: string) -> string { return AppService("gallery.local.v1", request) }
|
||||
Indexed :: (verb: string, index: s32) -> string {
|
||||
number: [24]u8; buffer: [64]u8
|
||||
text := FormatInteger(cast(s64)index, number[:])
|
||||
for at: 0..verb.count - 1 { buffer[at] = verb[at] }
|
||||
for at: 0..text.count - 1 { buffer[verb.count + at] = text[at] }
|
||||
buffer[verb.count + text.count] = cast(u8)0
|
||||
return Call(TextUntilNul(buffer[:]))
|
||||
}
|
||||
Reload :: () {
|
||||
listing.count = Model.Index(Call("count"))
|
||||
if listing.count < 0 { listing.count = 0 }
|
||||
if listing.count > Model.LIMIT { listing.count = Model.LIMIT }
|
||||
for index: 0..listing.count - 1 {
|
||||
unused CopyCString(Indexed("name:", cast(s32)index), listing.entries[index].name[:])
|
||||
listing.entries[index].folder = Indexed("kind:", cast(s32)index) == "folder"
|
||||
listing.entries[index].path[0] = cast(u8)0
|
||||
}
|
||||
unused CopyCString(Call("location"), location[:]); can_up = Call("can-up") == "yes"
|
||||
unused CopyCString(Call("status"), status[:])
|
||||
viewer = Model.Viewer.{.selected = -1, .zoom = 1}; grid_offset = 0; zoom_x = 0; zoom_y = 0
|
||||
}
|
||||
Action :: (id: s32, label: string, bounds: Rectangle, disabled: bool) -> bool {
|
||||
return Button.Draw(session, Button.Props.{.key = cast(u64)(KEY_BASE + id), .id = KEY_BASE + id, .bounds = bounds,
|
||||
.label = label, .disabled = disabled, .tone = ButtonTone.ButtonToneNeutral,
|
||||
.emphasis = ButtonEmphasis.ButtonEmphasisSoft, .fit_content = true}) != 0
|
||||
}
|
||||
Label :: (key: u64, text: string, bounds: Rectangle) {
|
||||
Text.Draw(session, Text.Props.{.key = cast(u64)KEY_BASE + key, .bounds = bounds, .text = text, .size = 16})
|
||||
}
|
||||
Picture :: (index: s32, bounds: Rectangle, preview: bool = false) -> bool {
|
||||
entry := *listing.entries[index]
|
||||
unused CopyCString(Indexed(ifx preview then "thumb:" else "asset:", index), entry.path[:])
|
||||
props := Image.Props.{.key = cast(u64)(KEY_BASE + 5000 + index), .bounds = bounds,
|
||||
.asset_path = TextUntilNul(entry.path[:]), .alt_text = TextUntilNul(entry.name[:]),
|
||||
.fit = Image.ImageFit.ImageFitContain, .smooth = true}
|
||||
if props.asset_path == "" {
|
||||
Label(cast(u64)(7000 + index), "Image unavailable", bounds)
|
||||
return false
|
||||
}
|
||||
state := Showing.ImageShowingOf(session, props)
|
||||
if state == Image.ImageShowing.ImageShowingUnavailable {
|
||||
Label(cast(u64)(7000 + index), "Image unavailable", bounds)
|
||||
return false
|
||||
}
|
||||
if state == Image.ImageShowing.ImageShowingNone { Label(cast(u64)(7000 + index), "Loading image...", bounds) }
|
||||
Image.Draw(session, props)
|
||||
return true
|
||||
}
|
||||
|
||||
DrawViewer :: (area: Rectangle) {
|
||||
width := (area.width - 32.0) / 3.0
|
||||
if Action(30, "Albums", Rectangle.{area.x, area.y, width, 42.0}, false) { viewer.selected = -1; return }
|
||||
previous := viewer; Model.Move(*previous, *listing, -1)
|
||||
next := viewer; Model.Move(*next, *listing, 1)
|
||||
if Action(31, "Previous", Rectangle.{area.x + width + 8.0, area.y, width, 42.0}, previous.selected == viewer.selected) { viewer = previous; zoom_x = 0; zoom_y = 0 }
|
||||
if Action(32, "Next", Rectangle.{area.x + (width + 8.0) * 2.0, area.y, width, 42.0}, next.selected == viewer.selected) { viewer = next; zoom_x = 0; zoom_y = 0 }
|
||||
if AppKey() == 263 { Model.Move(*viewer, *listing, -1); zoom_x = 0; zoom_y = 0 }
|
||||
if AppKey() == 262 { Model.Move(*viewer, *listing, 1); zoom_x = 0; zoom_y = 0 }
|
||||
if AppKey() == 256 { viewer.selected = -1; return }
|
||||
Label(40, TextUntilNul(listing.entries[viewer.selected].name[:]), Rectangle.{area.x, area.y + 50.0, area.width, 28.0})
|
||||
viewport := Rectangle.{area.x, area.y + 84.0, area.width - 8.0, area.height - 194.0}
|
||||
if viewport.height < 40.0 { viewport.height = 40.0 }
|
||||
scale := cast(float32)viewer.zoom
|
||||
horizontal := Scroll.Draw(session, Scroll.Props.{.key = KEY_BASE + 50, .bounds = viewport, .horizontal = true,
|
||||
.content_width = cast(s32)(viewport.width * scale), .scroll_offset = zoom_x, .manual_scroll = true})
|
||||
zoom_x = horizontal.scroll_offset
|
||||
vertical := Scroll.Draw(session, Scroll.Props.{.key = KEY_BASE + 51, .bounds = viewport,
|
||||
.content_height = cast(s32)(viewport.height * scale), .scroll_offset = zoom_y, .manual_scroll = true})
|
||||
zoom_y = vertical.scroll_offset
|
||||
available := Picture(viewer.selected, Rectangle.{horizontal.content.x, vertical.content.y, viewport.width * scale, viewport.height * scale})
|
||||
if vertical.opened { unused End(session) }
|
||||
if horizontal.opened { unused End(session) }
|
||||
if !available {
|
||||
problem: [256]u8
|
||||
unused CopyCString(Indexed("asset-error:", viewer.selected), problem[:])
|
||||
if problem[0] == cast(u8)0 { unused CopyCString(Model.ImageError(Model.IMAGE_FORMAT_ERROR), problem[:]) }
|
||||
Label(54, TextUntilNul(problem[:]), Rectangle.{viewport.x + 8.0, viewport.y + 36.0, viewport.width - 16.0, 80.0})
|
||||
if Action(55, "Retry image", Rectangle.{viewport.x + 8.0, viewport.y + 122.0, 140.0, 40.0}, false) { unused Indexed("retry:", viewer.selected) }
|
||||
}
|
||||
pan_width := (area.width - 24.0) / 4.0
|
||||
pan_y := area.y + area.height - 94.0
|
||||
step_x := cast(s32)(viewport.width / 4.0)
|
||||
step_y := cast(s32)(viewport.height / 4.0)
|
||||
max_x := cast(s32)(viewport.width * cast(float32)(viewer.zoom - 1))
|
||||
max_y := cast(s32)(viewport.height * cast(float32)(viewer.zoom - 1))
|
||||
if Action(60, "Pan left", Rectangle.{area.x, pan_y, pan_width, 38.0}, !available || zoom_x <= 0) { zoom_x -= step_x }
|
||||
if Action(61, "Pan right", Rectangle.{area.x + pan_width + 8.0, pan_y, pan_width, 38.0}, !available || zoom_x >= max_x) { zoom_x += step_x }
|
||||
if Action(62, "Pan up", Rectangle.{area.x + (pan_width + 8.0) * 2.0, pan_y, pan_width, 38.0}, !available || zoom_y <= 0) { zoom_y -= step_y }
|
||||
if Action(63, "Pan down", Rectangle.{area.x + (pan_width + 8.0) * 3.0, pan_y, pan_width, 38.0}, !available || zoom_y >= max_y) { zoom_y += step_y }
|
||||
if zoom_x < 0 { zoom_x = 0 }; if zoom_x > max_x { zoom_x = max_x }
|
||||
if zoom_y < 0 { zoom_y = 0 }; if zoom_y > max_y { zoom_y = max_y }
|
||||
y := area.y + area.height - 48.0
|
||||
if Action(33, "Zoom out", Rectangle.{area.x, y, width, 42.0}, !available || viewer.zoom == 1) { Model.Zoom(*viewer, -1); zoom_x = cast(s32)(viewport.width * cast(float32)(viewer.zoom - 1) * 0.5); zoom_y = cast(s32)(viewport.height * cast(float32)(viewer.zoom - 1) * 0.5) }
|
||||
if Action(34, "Fit", Rectangle.{area.x + width + 8.0, y, width, 42.0}, false) { viewer.zoom = 1; zoom_x = 0; zoom_y = 0 }
|
||||
if Action(35, "Zoom in", Rectangle.{area.x + (width + 8.0) * 2.0, y, width, 42.0}, !available || viewer.zoom == 4) { Model.Zoom(*viewer, 1); zoom_x = cast(s32)(viewport.width * cast(float32)(viewer.zoom - 1) * 0.5); zoom_y = cast(s32)(viewport.height * cast(float32)(viewer.zoom - 1) * 0.5) }
|
||||
}
|
||||
|
||||
DrawGrid :: (area: Rectangle) {
|
||||
pending := TextUntilNul(status[:]) == "pending"
|
||||
if Action(10, "Choose folder", Rectangle.{area.x, area.y, 148.0, 44.0}, pending) {
|
||||
unused CopyCString(Call("choose"), status[:]); pending = TextUntilNul(status[:]) == "pending"
|
||||
}
|
||||
if Action(11, "Refresh", Rectangle.{area.x + 156.0, area.y, 92.0, 44.0}, pending) { unused Call("refresh"); Reload() }
|
||||
if can_up && Action(12, "Up", Rectangle.{area.x + 256.0, area.y, 54.0, 44.0}, pending) { unused Call("up"); Reload() }
|
||||
Label(13, TextUntilNul(location[:]), Rectangle.{area.x, area.y + 52.0, area.width, 26.0})
|
||||
current := TextUntilNul(status[:])
|
||||
message := "Name order - folders first"
|
||||
if current == "pending" { message = "Choose a local folder in the system window" }
|
||||
else if current == "empty" { message = "Choose a folder to browse photos on this device" }
|
||||
else if current == "cancelled" { message = "Selection cancelled - your folder is unchanged" }
|
||||
else if current == "error" { message = "Cannot read this folder. Choose it again or refresh." }
|
||||
else if current == "save-error" { message = "Could not save this selection. Your previous folder is unchanged. Try again." }
|
||||
else if current == "chooser-missing" { message = "Folder chooser unavailable. Install Zenity, then choose the folder again." }
|
||||
else if current == "unavailable" { message = "Local folders are available in the Android and desktop apps" }
|
||||
else if current == "limited" { message = "Showing first 512 items by name. Open a smaller folder." }
|
||||
else if listing.count == 0 { message = "No supported photos or albums in this folder" }
|
||||
Label(14, message, Rectangle.{area.x, area.y + 82.0, area.width, 46.0})
|
||||
columns := cast(s32)(area.width / 150.0)
|
||||
if columns < 2 { columns = 2 }
|
||||
tile := (area.width - cast(float32)(columns - 1) * 8.0) / cast(float32)columns
|
||||
height := tile + 38.0
|
||||
rows := (listing.count + columns - 1) / columns
|
||||
viewport := Rectangle.{area.x, area.y + 134.0, area.width, area.height - 134.0}
|
||||
grid := Scroll.Draw(session, Scroll.Props.{.key = KEY_BASE + 20, .bounds = viewport,
|
||||
.content_height = cast(s32)(cast(float32)rows * (height + 8.0)), .scroll_offset = grid_offset})
|
||||
grid_offset = grid.scroll_offset
|
||||
for index: 0..listing.count - 1 {
|
||||
x := grid.content.x + cast(float32)(index % columns) * (tile + 8.0)
|
||||
y := grid.content.y + cast(float32)(index / columns) * (height + 8.0)
|
||||
if y + height >= viewport.y && y < viewport.y + viewport.height {
|
||||
entry := *listing.entries[index]
|
||||
if !entry.folder { unused Picture(cast(s32)index, Rectangle.{x + 4.0, y + 4.0, tile - 8.0, tile - 8.0}, true) }
|
||||
else { Label(cast(u64)(4000 + index), "Folder", Rectangle.{x + 8.0, y + 12.0, tile - 16.0, tile - 12.0}) }
|
||||
Label(cast(u64)(6000 + index), TextUntilNul(entry.name[:]), Rectangle.{x + 8.0, y + tile, tile - 16.0, 34.0})
|
||||
if Button.Draw(session, Button.Props.{.key = cast(u64)(KEY_BASE + 100 + index), .id = cast(s32)(KEY_BASE + 100 + index),
|
||||
.bounds = Rectangle.{x, y, tile, height}, .label = TextUntilNul(entry.name[:]),
|
||||
.invisible = true, .disabled = pending}) != 0 {
|
||||
if entry.folder { unused Indexed("enter:", cast(s32)index); loaded = false; break }
|
||||
else { viewer = Model.Viewer.{.selected = cast(s32)index, .zoom = 1}; zoom_x = 0; zoom_y = 0 }
|
||||
}
|
||||
}
|
||||
}
|
||||
if grid.opened { unused End(session) }
|
||||
}
|
||||
|
||||
#program_export "GalleryMain"
|
||||
Main :: () -> s32 {
|
||||
if AppMode() == APP_IDENTIFY {
|
||||
AppIdentity("gallery"); AppDescribe("Gallery", Icon.Shape); return APP_PROTOCOL
|
||||
}
|
||||
if AppMode() == APP_BACK && viewer.selected >= 0 { viewer.selected = -1; return 1 }
|
||||
if AppMode() != APP_FRAME { return 0 }
|
||||
session = AppSession()
|
||||
if !loaded { Reload(); loaded = true }
|
||||
if TextUntilNul(status[:]) == "pending" {
|
||||
value := Call("poll")
|
||||
if value != "pending" { Reload() }
|
||||
}
|
||||
area := AppBounds()
|
||||
area.x += 12.0; area.y += 12.0; area.width -= 24.0; area.height -= 24.0
|
||||
if viewer.selected >= 0 { DrawViewer(area) } else { DrawGrid(area) }
|
||||
return 0
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
// Portable gallery state. No account, network, deletion or arbitrary-path API.
|
||||
#import "std/text_buffer"
|
||||
#import "std/byte_text_linux"
|
||||
#import "std/c_string"
|
||||
|
||||
LIMIT :: 512
|
||||
PATH_CAPACITY :: 1024
|
||||
IMAGE_BYTE_LIMIT :: 67108864
|
||||
IMAGE_PIXEL_LIMIT :: 32000000
|
||||
IMAGE_READ_ERROR :: 1
|
||||
IMAGE_FORMAT_ERROR :: 2
|
||||
IMAGE_LIMIT_ERROR :: 3
|
||||
|
||||
ImageError :: (reason: s32) -> string {
|
||||
if reason == IMAGE_READ_ERROR { return "Cannot read image. Retry or refresh the folder." }
|
||||
if reason == IMAGE_FORMAT_ERROR { return "Cannot decode image. Retry or choose another photo." }
|
||||
if reason == IMAGE_LIMIT_ERROR { return "Image exceeds the viewing limit: 64 MiB or 32 megapixels." }
|
||||
return ""
|
||||
}
|
||||
|
||||
Dimensions :: struct { width: s64; height: s64 }
|
||||
Big16 :: (bytes: []u8, at: s32) -> s64 { return cast(s64)bytes[at] * 256 + cast(s64)bytes[at + 1] }
|
||||
Little :: (bytes: []u8, at: s32, count: s32) -> s64 {
|
||||
value: s64; multiplier: s64 = 1
|
||||
for index: 0..count - 1 { value += cast(s64)bytes[at + index] * multiplier; multiplier *= 256 }
|
||||
return value
|
||||
}
|
||||
Big32 :: (bytes: []u8, at: s32) -> s64 { return Big16(bytes, at) * 65536 + Big16(bytes, at + 2) }
|
||||
PixelError :: (size: Dimensions) -> s32 {
|
||||
if size.width <= 0 || size.height <= 0 { return IMAGE_FORMAT_ERROR }
|
||||
if size.height > IMAGE_PIXEL_LIMIT || size.width > IMAGE_PIXEL_LIMIT / size.height { return IMAGE_LIMIT_ERROR }
|
||||
return 0
|
||||
}
|
||||
// Header-only bounds checks run before a native decoder allocates pixels.
|
||||
// JPEG's variable-length segments are walked by the host with bounded I/O.
|
||||
HeaderDimensions :: (bytes: []u8) -> Dimensions {
|
||||
if bytes.count < 30 { return .{} }
|
||||
if bytes[0] == 137 && bytes[1] == 80 && bytes[2] == 78 && bytes[3] == 71 && bytes[12] == 73 && bytes[13] == 72 && bytes[14] == 68 && bytes[15] == 82 {
|
||||
return Dimensions.{Big32(bytes, 16), Big32(bytes, 20)}
|
||||
}
|
||||
if bytes[0] == 71 && bytes[1] == 73 && bytes[2] == 70 { return Dimensions.{Little(bytes, 6, 2), Little(bytes, 8, 2)} }
|
||||
if bytes[0] == 66 && bytes[1] == 77 {
|
||||
height := Little(bytes, 22, 4)
|
||||
if height >= 2147483648 { height = 4294967296 - height }
|
||||
return Dimensions.{Little(bytes, 18, 4), height}
|
||||
}
|
||||
if bytes[0] == 82 && bytes[1] == 73 && bytes[2] == 70 && bytes[3] == 70 && bytes[8] == 87 && bytes[9] == 69 && bytes[10] == 66 && bytes[11] == 80 {
|
||||
if bytes[15] == 88 { return Dimensions.{Little(bytes, 24, 3) + 1, Little(bytes, 27, 3) + 1} }
|
||||
if bytes[15] == 76 && bytes[20] == 47 {
|
||||
bits := Little(bytes, 21, 4)
|
||||
return Dimensions.{(bits & 16383) + 1, ((bits >> 14) & 16383) + 1}
|
||||
}
|
||||
if bytes[15] == 32 && bytes[23] == 157 && bytes[24] == 1 && bytes[25] == 42 { return Dimensions.{Little(bytes, 26, 2) & 16383, Little(bytes, 28, 2) & 16383} }
|
||||
}
|
||||
return .{}
|
||||
}
|
||||
Entry :: struct {
|
||||
name: [256]u8
|
||||
path: [PATH_CAPACITY]u8
|
||||
folder: bool
|
||||
}
|
||||
Listing :: struct {
|
||||
entries: [LIMIT]Entry
|
||||
count: s32
|
||||
truncated: bool
|
||||
}
|
||||
Viewer :: struct {
|
||||
selected: s32
|
||||
zoom: s32
|
||||
pan_x: s32
|
||||
pan_y: s32
|
||||
}
|
||||
|
||||
ImageName :: (name: string) -> bool {
|
||||
dot: s64 = -1
|
||||
for index: 0..name.count - 1 { if name[index] == #char "." { dot = index } }
|
||||
if dot < 0 || name.count - dot > 6 { return false }
|
||||
extension: [8]u8
|
||||
for index: dot..name.count - 1 {
|
||||
byte := name[index]
|
||||
if byte >= #char "A" && byte <= #char "Z" { byte += cast(u8)32 }
|
||||
extension[index - dot] = byte
|
||||
}
|
||||
suffix := TextUntilNul(extension[:])
|
||||
return suffix == ".jpg" || suffix == ".jpeg" || suffix == ".png" || suffix == ".webp" || suffix == ".bmp" || suffix == ".gif"
|
||||
}
|
||||
|
||||
// Bytewise UTF-8 order is stable across platforms, locales and launches.
|
||||
Before :: (left: Entry, right: Entry) -> bool {
|
||||
if left.folder != right.folder { return left.folder }
|
||||
a := TextUntilNul(left.name[:]); b := TextUntilNul(right.name[:])
|
||||
count := ifx a.count < b.count then a.count else b.count
|
||||
for index: 0..count - 1 { if a[index] != b[index] { return a[index] < b[index] } }
|
||||
if a.count != b.count { return a.count < b.count }
|
||||
a = TextUntilNul(left.path[:]); b = TextUntilNul(right.path[:])
|
||||
count = ifx a.count < b.count then a.count else b.count
|
||||
for index: 0..count - 1 { if a[index] != b[index] { return a[index] < b[index] } }
|
||||
return a.count < b.count
|
||||
}
|
||||
|
||||
Add :: (listing: *Listing, name: string, path: string, folder: bool) -> bool {
|
||||
if name == "" || name == "." || name == ".." || name.count >= 256 || path == "" || path.count >= PATH_CAPACITY { return false }
|
||||
entry: Entry
|
||||
unused CopyCString(name, entry.name[:]); unused CopyCString(path, entry.path[:]); entry.folder = folder
|
||||
// Retain the first LIMIT entries in sorted order even when the provider's
|
||||
// enumeration order varies. Never silently present an arbitrary subset.
|
||||
at := listing.count
|
||||
if at == LIMIT {
|
||||
listing.truncated = true
|
||||
if !Before(entry, listing.entries[LIMIT - 1]) { return false }
|
||||
at -= 1
|
||||
} else { listing.count += 1 }
|
||||
while at > 0 && Before(entry, listing.entries[at - 1]) {
|
||||
listing.entries[at] = listing.entries[at - 1]; at -= 1
|
||||
}
|
||||
listing.entries[at] = entry
|
||||
return true
|
||||
}
|
||||
|
||||
Index :: (text: string) -> s32 {
|
||||
if text == "" { return -1 }
|
||||
result: s32 = 0
|
||||
for index: 0..text.count - 1 {
|
||||
if text[index] < #char "0" || text[index] > #char "9" || result > 10000 { return -1 }
|
||||
result = result * 10 + cast(s32)(text[index] - #char "0")
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Move :: (viewer: *Viewer, listing: *Listing, direction: s32) {
|
||||
at := viewer.selected + direction
|
||||
while at >= 0 && at < listing.count {
|
||||
if !listing.entries[at].folder {
|
||||
viewer.selected = at; viewer.zoom = 1; viewer.pan_x = 0; viewer.pan_y = 0; return
|
||||
}
|
||||
at += direction
|
||||
}
|
||||
}
|
||||
|
||||
Zoom :: (viewer: *Viewer, delta: s32) {
|
||||
viewer.zoom += delta
|
||||
if viewer.zoom < 1 { viewer.zoom = 1 }
|
||||
if viewer.zoom > 4 { viewer.zoom = 4 }
|
||||
viewer.pan_x = 0; viewer.pan_y = 0
|
||||
}
|
||||
|
||||
Within :: (root: string, path: string) -> bool {
|
||||
if root == "" || path == "" { return false }
|
||||
if root == path { return true }
|
||||
if root == "/" { return path[0] == #char "/" }
|
||||
return path.count > root.count && path[:root.count] == root && path[root.count] == #char "/"
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
{
|
||||
"format": 1,
|
||||
"packages": [
|
||||
{
|
||||
"commit": "c96f5e3de9c4488f4e6c97f59f5245f22fda22f7",
|
||||
"dependencies": {},
|
||||
"id": "p0dd67588478f9a3e",
|
||||
"name": "libsamplerate",
|
||||
"ref": "c96f5e3de9c4488f4e6c97f59f5245f22fda22f7",
|
||||
"source": true,
|
||||
"url": "https://github.com/libsndfile/libsamplerate.git"
|
||||
},
|
||||
{
|
||||
"commit": "829a65d769d935c4852f8159e964312c0957260a",
|
||||
"dependencies": {},
|
||||
"id": "p16cd0434af3dff7b",
|
||||
"name": "sdl3",
|
||||
"ref": "829a65d769d935c4852f8159e964312c0957260a",
|
||||
"source": true,
|
||||
"url": "https://github.com/libsdl-org/SDL.git"
|
||||
},
|
||||
{
|
||||
"commit": "f26a552247e2cd367fd33def6860d903cac6ab8a",
|
||||
"dependencies": {"av1": "p5d7d12505a42f7b3", "dav1d": "pb24767b9eb34d961", "image_codec": "p69c0e968ae5735d9", "libaom": "p74ab3cb6eb3b86fa", "libavif": "p57c0272208aae8db"},
|
||||
"dependency_refs": {"av1": "bd278217e2bac754d868b3d6502eac4257658d4b", "dav1d": "54706fc6bc0cdecab7e9593974a4039cc038fca7", "image_codec": "360553150917f352e49e1beb78917370792ccaef", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937", "libavif": "1aadfad932c98c069a1204261b1856f81f3bc199"},
|
||||
"id": "p274c2dd6d03a7c0c",
|
||||
"name": "avif",
|
||||
"ref": "f26a552247e2cd367fd33def6860d903cac6ab8a",
|
||||
"url": "https://github.com/ziranlang/avif.git"
|
||||
},
|
||||
{
|
||||
"commit": "ec6ed304767e10c125ab2820f3b01d6fd773e147",
|
||||
"dependencies": {"image_codec": "p69c0e968ae5735d9", "libwebp": "p3b3c785a0e17e605"},
|
||||
"dependency_refs": {"image_codec": "360553150917f352e49e1beb78917370792ccaef", "libwebp": "1844042d1ca751e62e61df7617dba19c98588339"},
|
||||
"id": "p2af20e0c835b1c63",
|
||||
"name": "webp",
|
||||
"ref": "ec6ed304767e10c125ab2820f3b01d6fd773e147",
|
||||
"url": "https://github.com/ziranlang/webp.git"
|
||||
},
|
||||
{
|
||||
"commit": "1844042d1ca751e62e61df7617dba19c98588339",
|
||||
"dependencies": {},
|
||||
"id": "p3b3c785a0e17e605",
|
||||
"name": "libwebp",
|
||||
"ref": "1844042d1ca751e62e61df7617dba19c98588339",
|
||||
"source": true,
|
||||
"url": "https://github.com/webmproject/libwebp.git"
|
||||
},
|
||||
{
|
||||
"commit": "1aadfad932c98c069a1204261b1856f81f3bc199",
|
||||
"dependencies": {},
|
||||
"id": "p57c0272208aae8db",
|
||||
"name": "libavif",
|
||||
"ref": "1aadfad932c98c069a1204261b1856f81f3bc199",
|
||||
"source": true,
|
||||
"url": "https://github.com/AOMediaCodec/libavif.git"
|
||||
},
|
||||
{
|
||||
"commit": "bd278217e2bac754d868b3d6502eac4257658d4b",
|
||||
"dependencies": {"dav1d": "pb24767b9eb34d961", "image_codec": "p69c0e968ae5735d9", "libaom": "p74ab3cb6eb3b86fa"},
|
||||
"dependency_refs": {"dav1d": "54706fc6bc0cdecab7e9593974a4039cc038fca7", "image_codec": "360553150917f352e49e1beb78917370792ccaef", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937"},
|
||||
"id": "p5d7d12505a42f7b3",
|
||||
"name": "av1",
|
||||
"ref": "bd278217e2bac754d868b3d6502eac4257658d4b",
|
||||
"url": "https://github.com/ziranlang/av1.git"
|
||||
},
|
||||
{
|
||||
"commit": "360553150917f352e49e1beb78917370792ccaef",
|
||||
"dependencies": {},
|
||||
"id": "p69c0e968ae5735d9",
|
||||
"name": "image-codec",
|
||||
"ref": "360553150917f352e49e1beb78917370792ccaef",
|
||||
"url": "https://github.com/ziranlang/image-codec.git"
|
||||
},
|
||||
{
|
||||
"commit": "b141d9c45db236335351c8a4b2a14b3ade27c937",
|
||||
"dependencies": {},
|
||||
"id": "p74ab3cb6eb3b86fa",
|
||||
"name": "libaom",
|
||||
"ref": "b141d9c45db236335351c8a4b2a14b3ade27c937",
|
||||
"source": true,
|
||||
"url": "https://aomedia.googlesource.com/aom"
|
||||
},
|
||||
{
|
||||
"commit": "54706fc6bc0cdecab7e9593974a4039cc038fca7",
|
||||
"dependencies": {},
|
||||
"id": "pb24767b9eb34d961",
|
||||
"name": "dav1d",
|
||||
"ref": "54706fc6bc0cdecab7e9593974a4039cc038fca7",
|
||||
"source": true,
|
||||
"url": "https://github.com/videolan/dav1d.git"
|
||||
},
|
||||
{
|
||||
"commit": "ce5837f80e8ce6cb8d2d9f77915095d764da3485",
|
||||
"dependencies": {"dr_libs": "pb7c2dd1c09da0c1c", "libopus": "pe1fe9bbe80bf1d6d", "libsamplerate": "p0dd67588478f9a3e", "stb": "pe4a63e2d6e0424e7"},
|
||||
"dependency_refs": {"dr_libs": "f12e197fd462e4c22873fbd70d11b1d2f2c1dc3c", "libopus": "ddbe48383984d56acd9e1ab6a090c54ca6b735a6", "libsamplerate": "c96f5e3de9c4488f4e6c97f59f5245f22fda22f7", "stb": "9600522de53973336fa033a289858a4354cbb04c"},
|
||||
"id": "pb46a53117b2530ce",
|
||||
"name": "audio",
|
||||
"ref": "ce5837f80e8ce6cb8d2d9f77915095d764da3485",
|
||||
"url": "https://github.com/ziranlang/audio.git"
|
||||
},
|
||||
{
|
||||
"commit": "f12e197fd462e4c22873fbd70d11b1d2f2c1dc3c",
|
||||
"dependencies": {},
|
||||
"id": "pb7c2dd1c09da0c1c",
|
||||
"name": "dr_libs",
|
||||
"ref": "f12e197fd462e4c22873fbd70d11b1d2f2c1dc3c",
|
||||
"source": true,
|
||||
"url": "https://github.com/mackron/dr_libs.git"
|
||||
},
|
||||
{
|
||||
"commit": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e",
|
||||
"dependencies": {},
|
||||
"id": "pcc7aa76725f2fb2f",
|
||||
"name": "raylib",
|
||||
"ref": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e",
|
||||
"source": true,
|
||||
"url": "https://github.com/raysan5/raylib.git"
|
||||
},
|
||||
{
|
||||
"commit": "9cc6872f75447c3a24c16764f9829d0f58751cb0",
|
||||
"dependencies": {},
|
||||
"id": "pe1027b9d16704793",
|
||||
"name": "mingcute",
|
||||
"ref": "master",
|
||||
"url": "https://github.com/kryonlabs/mingcute.git"
|
||||
},
|
||||
{
|
||||
"commit": "ddbe48383984d56acd9e1ab6a090c54ca6b735a6",
|
||||
"dependencies": {},
|
||||
"id": "pe1fe9bbe80bf1d6d",
|
||||
"name": "libopus",
|
||||
"ref": "ddbe48383984d56acd9e1ab6a090c54ca6b735a6",
|
||||
"source": true,
|
||||
"url": "https://github.com/xiph/opus.git"
|
||||
},
|
||||
{
|
||||
"commit": "9600522de53973336fa033a289858a4354cbb04c",
|
||||
"dependencies": {},
|
||||
"id": "pe4a63e2d6e0424e7",
|
||||
"name": "stb",
|
||||
"ref": "9600522de53973336fa033a289858a4354cbb04c",
|
||||
"source": true,
|
||||
"url": "https://github.com/nothings/stb.git"
|
||||
},
|
||||
{
|
||||
"commit": "3f72441949d4e16094834fa9220e5d7fa77a0ac0",
|
||||
"dependencies": {"audio": "pb46a53117b2530ce", "avif": "p274c2dd6d03a7c0c", "image_codec": "p69c0e968ae5735d9", "libaom": "p74ab3cb6eb3b86fa", "libavif": "p57c0272208aae8db", "libwebp": "p3b3c785a0e17e605", "raylib": "pcc7aa76725f2fb2f", "sdl3": "p16cd0434af3dff7b", "webp": "p2af20e0c835b1c63"},
|
||||
"dependency_refs": {"audio": "ce5837f80e8ce6cb8d2d9f77915095d764da3485", "avif": "f26a552247e2cd367fd33def6860d903cac6ab8a", "image_codec": "360553150917f352e49e1beb78917370792ccaef", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937", "libavif": "1aadfad932c98c069a1204261b1856f81f3bc199", "libwebp": "1844042d1ca751e62e61df7617dba19c98588339", "raylib": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e", "sdl3": "829a65d769d935c4852f8159e964312c0957260a", "webp": "ec6ed304767e10c125ab2820f3b01d6fd773e147"},
|
||||
"id": "peb1e86e2b07f33bb",
|
||||
"name": "kryon",
|
||||
"ref": "3f72441949d4e16094834fa9220e5d7fa77a0ac0",
|
||||
"url": "https://github.com/kryonlabs/kryon.git"
|
||||
}
|
||||
],
|
||||
"root": {
|
||||
"dependencies": {"kryon": "peb1e86e2b07f33bb", "mingcute": "pe1027b9d16704793"},
|
||||
"dependency_refs": {"kryon": "3f72441949d4e16094834fa9220e5d7fa77a0ac0", "mingcute": "master"},
|
||||
"name": "werk-gallery"
|
||||
},
|
||||
"toolchain": {
|
||||
"commit": "e0367fa9c5731dcf9bb84ed7f3d294570d8c0bda",
|
||||
"ref": "e0367fa9c5731dcf9bb84ed7f3d294570d8c0bda",
|
||||
"url": "https://github.com/ziranlang/ziran.git"
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
[package]
|
||||
name = "werk-gallery"
|
||||
entry = "gallery.zi"
|
||||
module_roots = ["."]
|
||||
|
||||
[toolchain]
|
||||
git = "https://github.com/ziranlang/ziran.git"
|
||||
ref = "e0367fa9c5731dcf9bb84ed7f3d294570d8c0bda"
|
||||
|
||||
[dependencies.kryon]
|
||||
git = "https://github.com/kryonlabs/kryon.git"
|
||||
ref = "3f72441949d4e16094834fa9220e5d7fa77a0ac0"
|
||||
|
||||
[dependencies.mingcute]
|
||||
git = "https://github.com/kryonlabs/mingcute.git"
|
||||
ref = "master"
|
||||
@@ -4,12 +4,20 @@
|
||||
#import "version"
|
||||
#import "c_string"
|
||||
#import "text_buffer"
|
||||
#import "cli_profiles"
|
||||
#import "cli_native"
|
||||
#if !#defined(PLAN9_BUILD) {
|
||||
#import "cli_profiles"
|
||||
#import "cli_native"
|
||||
}
|
||||
|
||||
libc :: #system_library "libc";
|
||||
Write :: (fd: s32, bytes: *u8, count: usize) -> isize #foreign libc "write";
|
||||
GetEnv :: (name: *u8) -> *u8 #foreign libc "getenv";
|
||||
Read :: (fd: s32, bytes: *u8, count: usize) -> isize #foreign libc "read";
|
||||
#if #defined(PLAN9_BUILD) {
|
||||
GetEnvRaw :: (name: *s8) -> *s8 #foreign libc "getenv";
|
||||
GetEnv :: (name: *u8) -> *u8 { return cast(*u8)GetEnvRaw(cast(*s8)name) }
|
||||
} else {
|
||||
GetEnv :: (name: *u8) -> *u8 #foreign libc "getenv";
|
||||
}
|
||||
|
||||
Usage :: #string END
|
||||
Usage: pass [OPTIONS] SITE LOGIN [MASTER_PASSWORD]
|
||||
@@ -62,6 +70,23 @@ Error :: (message: string) -> s32 {
|
||||
return 2
|
||||
}
|
||||
|
||||
ReadMaster :: (buffer: []u8) -> bool {
|
||||
used: s32 = 0
|
||||
while used < cast(s32)buffer.count - 1 {
|
||||
byte: u8
|
||||
if Read(0, *byte, cast(usize)1) != cast(isize)1 { return used > 0 }
|
||||
if byte == cast(u8)10 {
|
||||
if used > 0 && buffer[used - 1] == cast(u8)13 { used -= 1 }
|
||||
buffer[used] = cast(u8)0
|
||||
return true
|
||||
}
|
||||
if byte == cast(u8)0 { return false }
|
||||
buffer[used] = byte
|
||||
used += 1
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
#program_export
|
||||
main :: (argc: s32, argv: **u8) -> s32 {
|
||||
options: PassOptions
|
||||
@@ -128,27 +153,35 @@ main :: (argc: s32, argv: **u8) -> s32 {
|
||||
}
|
||||
if version { Print(1, "pass "); Print(1, Version); Print(1, "\n"); return 0 }
|
||||
site: string; login: string; clear_ms: s64
|
||||
// Keep the decoded profile alive until generation has finished.
|
||||
profile: LegacyProfile
|
||||
#if !#defined(PLAN9_BUILD) {
|
||||
// Keep the decoded profile alive until generation has finished.
|
||||
profile: LegacyProfile
|
||||
}
|
||||
if profile_name != "" {
|
||||
if count != 1 { return Error("expected SITE with --profile") }
|
||||
} else if count < 2 { Print(2, Usage); return 2 }
|
||||
candidate := profile_name
|
||||
if candidate == "" && count == 2 { candidate = positional[0] }
|
||||
profile = LoadLegacyProfile(candidate, profile_name != "", *options, explicit)
|
||||
if !profile.valid { return Error("invalid CLI profiles configuration or unknown profile") }
|
||||
if profile.found {
|
||||
site = ifx profile_name != "" then positional[0] else positional[1]
|
||||
login = TextUntilNul(profile.login[:])
|
||||
if (explicit & cast(u32)64) == cast(u32)0 { options.exclude = TextUntilNul(profile.exclude[:]) }
|
||||
} else { site = positional[0]; login = positional[1] }
|
||||
if !copy { copy = profile.copy }
|
||||
clear_ms = profile.clear_ms
|
||||
if clear_after != "" {
|
||||
clear_ms = DurationMilliseconds(clear_after)
|
||||
if clear_ms < 0 { return Error("invalid --clear-after duration") }
|
||||
#if !#defined(PLAN9_BUILD) {
|
||||
candidate := profile_name
|
||||
if candidate == "" && count == 2 { candidate = positional[0] }
|
||||
profile = LoadLegacyProfile(candidate, profile_name != "", *options, explicit)
|
||||
if !profile.valid { return Error("invalid CLI profiles configuration or unknown profile") }
|
||||
if profile.found {
|
||||
site = ifx profile_name != "" then positional[0] else positional[1]
|
||||
login = TextUntilNul(profile.login[:])
|
||||
if (explicit & cast(u32)64) == cast(u32)0 { options.exclude = TextUntilNul(profile.exclude[:]) }
|
||||
} else { site = positional[0]; login = positional[1] }
|
||||
if !copy { copy = profile.copy }
|
||||
clear_ms = profile.clear_ms
|
||||
if clear_after != "" {
|
||||
clear_ms = DurationMilliseconds(clear_after)
|
||||
if clear_ms < 0 { return Error("invalid --clear-after duration") }
|
||||
}
|
||||
if vault_path == "" && !prompt && count != 3 { vault_path = TextUntilNul(profile.vault[:]) }
|
||||
} else {
|
||||
if profile_name != "" || vault_path != "" || clear_after != "" { return Error("profiles and vaults require the Linux CLI") }
|
||||
if copy && !no_copy { return Error("--copy is not available on Plan 9") }
|
||||
site = positional[0]; login = positional[1]
|
||||
}
|
||||
if vault_path == "" && !prompt && count != 3 { vault_path = TextUntilNul(profile.vault[:]) }
|
||||
if vault_path != "" && (prompt || count == 3) { return Error("--vault cannot be combined with --prompt or MASTER_PASSWORD") }
|
||||
if prompt && count == 3 { return Error("MASTER_PASSWORD cannot be supplied together with --prompt") }
|
||||
master: [1024]u8
|
||||
@@ -157,9 +190,11 @@ main :: (argc: s32, argv: **u8) -> s32 {
|
||||
if !CopyText(positional[2], master[:]) { return Error("master password is too long") }
|
||||
} else {
|
||||
unlocked: bool
|
||||
if vault_path != "" {
|
||||
if !DecryptVault(vault_path, master[:]) { return Error("cannot unlock vault: wrong passphrase, unreadable or corrupted vault") }
|
||||
unlocked = true
|
||||
#if !#defined(PLAN9_BUILD) {
|
||||
if vault_path != "" {
|
||||
if !DecryptVault(vault_path, master[:]) { return Error("cannot unlock vault: wrong passphrase, unreadable or corrupted vault") }
|
||||
unlocked = true
|
||||
}
|
||||
}
|
||||
if !unlocked {
|
||||
name: [32]u8
|
||||
@@ -168,7 +203,11 @@ main :: (argc: s32, argv: **u8) -> s32 {
|
||||
if !prompt && environment != null {
|
||||
if !CopyText(TextFromCString(environment), master[:]) { return Error("master password is too long") }
|
||||
} else {
|
||||
if !ReadSecret(master[:], "Master password: ") { return Error("missing master password") }
|
||||
#if !#defined(PLAN9_BUILD) {
|
||||
if !ReadSecret(master[:], "Master password: ") { return Error("missing master password") }
|
||||
} else {
|
||||
if !ReadMaster(master[:]) { return Error("missing master password") }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -178,11 +217,13 @@ main :: (argc: s32, argv: **u8) -> s32 {
|
||||
if !generated.valid {
|
||||
Print(2, "pass: "); Print(2, generated.error); Print(2, "\n"); return 1
|
||||
}
|
||||
if copy && !no_copy {
|
||||
if !CopyPassword(TextView(generated.password[0:generated.length]), clear_ms) {
|
||||
return Error("clipboard unavailable; install xclip or use --no-copy")
|
||||
#if !#defined(PLAN9_BUILD) {
|
||||
if copy && !no_copy {
|
||||
if !CopyPassword(TextView(generated.password[0:generated.length]), clear_ms) {
|
||||
return Error("clipboard unavailable; install xclip or use --no-copy")
|
||||
}
|
||||
Print(2, "Password copied to the clipboard.\n"); return 0
|
||||
}
|
||||
Print(2, "Password copied to the clipboard.\n"); return 0
|
||||
}
|
||||
Print(1, TextView(generated.password[0:generated.length])); Print(1, "\n")
|
||||
return 0
|
||||
|
||||
@@ -19,7 +19,6 @@ NativeSetTerminal :: (fd: s32, action: s32, state: *void) -> s32 #foreign libc "
|
||||
NativeSession :: () -> s32 #foreign libc "setsid";
|
||||
NativeShutdown :: (fd: s32, direction: s32) -> s32 #foreign libc "shutdown";
|
||||
NativePipe :: (fds: *s32) -> s32 #foreign libc "pipe";
|
||||
NativeDescriptorFlags :: (fd: s32, command: s32, value: s32) -> s32 #foreign libc "fcntl";
|
||||
NativeFork :: () -> s32 #foreign libc "fork";
|
||||
NativeDup :: (source: s32, destination: s32) -> s32 #foreign libc "dup2";
|
||||
NativeExit :: (code: s32) -> void #foreign libc "_exit";
|
||||
@@ -129,37 +128,7 @@ DecryptVault :: (vault: string, output: []u8) -> bool {
|
||||
passphrase: [1024]u8
|
||||
defer { ClearBytes(passphrase[:]) }
|
||||
if !ReadSecret(passphrase[:], "Vault passphrase: ") { return false }
|
||||
// Legacy vaults may wrap their base64 with spaces, tabs or CRLF, which
|
||||
// OpenSSL 3.0 rejects. Send it without whitespace through a pipe that
|
||||
// openssl opens as its input; stdin stays the passphrase.
|
||||
encoded: [60000]u8
|
||||
file := NativeOpen(*path[0], 0)
|
||||
if file < 0 { return false }
|
||||
size: s32 = 0
|
||||
while true {
|
||||
byte: u8
|
||||
count := NativeRead(file, *byte, cast(usize)1)
|
||||
if count != cast(isize)1 { break }
|
||||
if byte == cast(u8)32 || (byte >= cast(u8)9 && byte <= cast(u8)13) { continue }
|
||||
if size >= cast(s32)encoded.count - 1 { unused NativeClose(file); return false }
|
||||
encoded[size] = byte; size += 1
|
||||
}
|
||||
unused NativeClose(file)
|
||||
encoded[size] = cast(u8)10
|
||||
pipe: [2]s32
|
||||
if NativePipe(*pipe[0]) != 0 { return false }
|
||||
// Only openssl keeps the reading end; the writer closes before it starts.
|
||||
if NativeDescriptorFlags(pipe[1], 2, 1) != 0 ||
|
||||
NativeWrite(pipe[1], *encoded[0], cast(usize)(size + 1)) != cast(isize)(size + 1) {
|
||||
unused NativeClose(pipe[0]); unused NativeClose(pipe[1]); return false
|
||||
}
|
||||
unused NativeClose(pipe[1])
|
||||
defer { unused NativeClose(pipe[0]) }
|
||||
digits: [12]u8; place: s32 = 11; number := pipe[0]
|
||||
while true { place -= 1; digits[place] = cast(u8)(48 + number % 10); number /= 10; if number == 0 { break } }
|
||||
input: [32]u8
|
||||
if AppendText(input[:], AppendText(input[:], 0, "/dev/fd/"), TextView(digits[place:11])) < 0 { return false }
|
||||
args: [16]string = .["openssl", "enc", "-d", "-aes-256-cbc", "-md", "sha512", "-a", "-A", "-pbkdf2", "-iter", "100000", "-in", TextUntilNul(input[:]), "-pass", "stdin", "-salt"]
|
||||
args: [16]string = .["openssl", "enc", "-d", "-aes-256-cbc", "-md", "sha512", "-a", "-A", "-pbkdf2", "-iter", "100000", "-in", TextUntilNul(path[:]), "-pass", "stdin", "-salt"]
|
||||
child := Channel.StartChannel(args[:], false)
|
||||
if child.error != 0 { return false }
|
||||
defer { unused Channel.CloseChannel(*child, 1000) }
|
||||
|
||||
@@ -1,25 +1,33 @@
|
||||
Spinbox :: #import "kryon/spinbox";
|
||||
Checkbox :: #import "kryon/checkbox";
|
||||
TextField :: #import "kryon/text_field";
|
||||
Scroll :: #import "kryon/scroll";
|
||||
Image :: #import "kryon/image";
|
||||
Box :: #import "kryon/box";
|
||||
Text :: #import "kryon/text";
|
||||
Button :: #import "kryon/button";
|
||||
// Pass: a stateless password generator. The same site, login, master
|
||||
// password and settings always give the same password, with no database.
|
||||
#import "kryon/session"
|
||||
#import "kryon/geometry"
|
||||
#import "kryon/control_props"
|
||||
#import "kryon/tree"
|
||||
#import "std/text_buffer"
|
||||
#import "std/utf8"
|
||||
#import "kryon/app_context"
|
||||
#import "kryon/app_protocol"
|
||||
#import "session"
|
||||
#import "geometry"
|
||||
#import "text_props"
|
||||
#import "text_widget"
|
||||
#import "text_input_props"
|
||||
#import "text_field_widget"
|
||||
#import "button_props"
|
||||
#import "button_widget"
|
||||
#import "control_props"
|
||||
#import "checkbox_props"
|
||||
#import "checkbox_widget"
|
||||
#import "spinbox_props"
|
||||
#import "spinbox_widget"
|
||||
#import "box_props"
|
||||
#import "box_widget"
|
||||
#import "image_props"
|
||||
#import "image_widget"
|
||||
#import "scroll_props"
|
||||
#import "scroll_widget"
|
||||
#import "tree"
|
||||
#import "text_buffer"
|
||||
#import "utf8"
|
||||
#import "werk_app"
|
||||
#import "app_protocol"
|
||||
#import "pass_core"
|
||||
#import "pass_state"
|
||||
#import "pass_text"
|
||||
Icon :: #import "mingcute/mingcute_regular_keyhole";
|
||||
Icon :: #import "mingcute_regular_keyhole";
|
||||
|
||||
FieldState :: struct {
|
||||
cursor: s32
|
||||
@@ -41,15 +49,15 @@ emoji: [32]u8;
|
||||
session: Session;
|
||||
|
||||
Label :: (value: string, x: float32, y: float32, width: float32, font: s32) {
|
||||
props: Text.Props
|
||||
props: TextProps
|
||||
props.bounds = Rectangle.{x, y, width, cast(float32)(font + 8)}
|
||||
props.text = value
|
||||
props.size = font
|
||||
Text.Draw(session, props)
|
||||
props.font = font
|
||||
Text(session, props)
|
||||
}
|
||||
|
||||
Action :: (id: s32, label: string, bounds: Rectangle, accent: bool, disabled: bool) -> bool {
|
||||
props: Button.Props
|
||||
props: ButtonProps
|
||||
props.key = cast(u64)id
|
||||
props.id = id
|
||||
props.bounds = bounds
|
||||
@@ -61,10 +69,10 @@ Action :: (id: s32, label: string, bounds: Rectangle, accent: bool, disabled: bo
|
||||
props.tone = ButtonTone.ButtonToneAccent
|
||||
props.emphasis = ButtonEmphasis.ButtonEmphasisFilled
|
||||
}
|
||||
return Button.Draw(session, props) == 1
|
||||
return Button(session, props) == 1
|
||||
}
|
||||
|
||||
ApplyEdit :: (buffer: []u8, edit: TextField.Edit) -> bool {
|
||||
ApplyEdit :: (buffer: []u8, edit: TextFieldEdit) -> bool {
|
||||
if !edit.changed {
|
||||
return false
|
||||
}
|
||||
@@ -113,7 +121,7 @@ Field :: (index: s32, label: string, buffer: []u8, bounds: Rectangle, secure: bo
|
||||
mask: [1024]u8
|
||||
// The views of the copies end with this block, before they are wiped.
|
||||
{
|
||||
props: TextField.Props
|
||||
props: TextFieldProps
|
||||
position: s32 = 0
|
||||
while position < cast(s32)buffer.count && position < 1023 {
|
||||
snapshot[position] = buffer[position]
|
||||
@@ -149,7 +157,7 @@ Field :: (index: s32, label: string, buffer: []u8, bounds: Rectangle, secure: bo
|
||||
if props.focused {
|
||||
props.input = AppFieldInput()
|
||||
}
|
||||
result := TextField.Draw(session, props)
|
||||
result := TextField(session, props)
|
||||
fields[index].cursor = result.cursor
|
||||
fields[index].anchor = result.anchor
|
||||
fields[index].scroll_x = result.scroll_x
|
||||
@@ -181,18 +189,18 @@ Codepoints :: (text: string) -> s32 {
|
||||
}
|
||||
|
||||
Check :: (id: s32, label: string, value: bool, bounds: Rectangle) -> bool {
|
||||
props: Checkbox.Props
|
||||
props: CheckboxProps
|
||||
props.key = cast(u64)id
|
||||
props.id = id
|
||||
props.label = label
|
||||
props.bounds = bounds
|
||||
props.checked = value
|
||||
return Checkbox.Draw(session, props).checked
|
||||
return Checkbox(session, props).checked
|
||||
}
|
||||
|
||||
Integer :: (id: s32, label: string, value: s32, low: s32, high: s32, x: float32, y: float32, width: float32) -> s32 {
|
||||
Label(label, x, y + 8.0, width - 160.0, 16)
|
||||
props: Spinbox.Props
|
||||
props: SpinboxProps
|
||||
props.key = cast(u64)id
|
||||
props.id = id
|
||||
props.label = label
|
||||
@@ -201,7 +209,7 @@ Integer :: (id: s32, label: string, value: s32, low: s32, high: s32, x: float32,
|
||||
props.min = low
|
||||
props.max = high
|
||||
props.step = 1
|
||||
return Spinbox.Draw(session, props).value
|
||||
return Spinbox(session, props).value
|
||||
}
|
||||
|
||||
CurrentOptions :: () -> PassOptions {
|
||||
@@ -242,13 +250,13 @@ Fingerprint :: (x: float32, y: float32) {
|
||||
while glyph < 63 && cast(u32)master_emoji_codepoints[glyph] != decoded.value {
|
||||
glyph += 1
|
||||
}
|
||||
props: Image.Props
|
||||
props: ImageProps
|
||||
props.asset_path = atlas
|
||||
props.alt_text = TextView(emoji[position:decoded.after])
|
||||
props.bounds = Rectangle.{x + cast(float32)index * 28.0, y, 24.0, 24.0}
|
||||
props.source = Rectangle.{cast(float32)(glyph % 8) * 64.0, cast(float32)(glyph / 8) * 64.0, 64.0, 64.0}
|
||||
props.tint = ifx AppDark() then cast(u32)0xe8e8e8ff else cast(u32)0x202c29ff
|
||||
Image.Draw(session, props)
|
||||
Image(session, props)
|
||||
position = decoded.after
|
||||
}
|
||||
}
|
||||
@@ -307,11 +315,11 @@ GenerateForm :: (x: float32, y: float32, width: float32) {
|
||||
y += 60.0
|
||||
Label("Generated password", x, y, width, 14)
|
||||
y += 28.0
|
||||
props: Box.Props
|
||||
props: BoxProps
|
||||
props.key = cast(u64)42
|
||||
props.bounds = Rectangle.{x, y, width, 54.0}
|
||||
props.radius = 8.0
|
||||
Box.Draw(session, props)
|
||||
Box(session, props)
|
||||
Label(ifx Generated() == "" then "Password will appear here" else Generated(), x + 10.0, y + 16.0, width - 20.0, 16)
|
||||
y += 68.0
|
||||
if Action(41, "Copy", Rectangle.{x, y, width, 40.0}, false, false) {
|
||||
@@ -430,13 +438,13 @@ Draw :: () {
|
||||
if view == 2 {
|
||||
content_height = 760
|
||||
}
|
||||
props: Scroll.Props
|
||||
props: ScrollProps
|
||||
props.key = cast(u64)(10 + view)
|
||||
props.bounds = Rectangle.{left, area.y + 12.0, width, height}
|
||||
props.content_height = content_height
|
||||
props.scroll_offset = scroll_offsets[view]
|
||||
props.scale = 1.0
|
||||
scroll := Scroll.Draw(session, props)
|
||||
scroll := Scroll(session, props)
|
||||
scroll_offsets[view] = scroll.scroll_offset
|
||||
if scroll.opened {
|
||||
if view == 0 {
|
||||
@@ -466,13 +474,9 @@ Draw :: () {
|
||||
#program_export "PassMain"
|
||||
Main :: () -> s32 {
|
||||
if AppMode() == APP_IDENTIFY {
|
||||
AppIdentity("pass")
|
||||
AppDescribe("Pass", Icon.Shape)
|
||||
return APP_PROTOCOL
|
||||
}
|
||||
if AppMode() != APP_FRAME {
|
||||
return 0
|
||||
}
|
||||
if !initialized {
|
||||
Initialize()
|
||||
initialized = true
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#import "crypto/sha256"
|
||||
#import "sha256"
|
||||
#if #defined(WERK_APP) {
|
||||
#import "kryon/app_context"
|
||||
#import "werk_app"
|
||||
}
|
||||
|
||||
PassOptions :: struct {
|
||||
@@ -57,14 +57,10 @@ DeriveKey :: (password: string, salt: string) -> [32]u8 {
|
||||
derive_failed = !AppPbkdf2Sha256(password, salt, 100000, output[:])
|
||||
return output
|
||||
} else {
|
||||
return Pbkdf2Sha256(password, ifx salt.count > PASS_SALT_LIMIT then salt[0:PASS_SALT_LIMIT] else salt, 100000)
|
||||
return Pbkdf2Sha256(password, salt, 100000)
|
||||
}
|
||||
}
|
||||
|
||||
// Werkzeug's key derivation has always read at most this many salt bytes,
|
||||
// and existing vault keys depend on it; the host derives the same way.
|
||||
PASS_SALT_LIMIT :: 508
|
||||
|
||||
|
||||
PassClassEmptyError :: (class_index: s32) -> string {
|
||||
if class_index == 0 {
|
||||
@@ -323,7 +319,7 @@ MasterEmoji :: (master: string, output: []u8) -> s32 {
|
||||
if output.count <= 0 { return 0 }
|
||||
output[0] = cast(u8)0
|
||||
|
||||
digest := Sha256Of(master)
|
||||
digest := Sha256(master)
|
||||
used: s32 = 0
|
||||
for index: 0..3 {
|
||||
codepoint: u32 = cast(u32)master_emoji_codepoints[
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#import "pass_core"
|
||||
#import "crypto/sha256"
|
||||
#import "sha256"
|
||||
|
||||
#program_export
|
||||
DigestMatches :: (left: [32]u8, right: [32]u8) -> bool {
|
||||
@@ -11,8 +11,8 @@ DigestMatches :: (left: [32]u8, right: [32]u8) -> bool {
|
||||
|
||||
#program_export
|
||||
Answer :: () -> s32 {
|
||||
empty := Sha256Of("")
|
||||
abc := Sha256Of("abc")
|
||||
empty := Sha256("")
|
||||
abc := Sha256("abc")
|
||||
derived := DeriveKey("password", "salt")
|
||||
if empty[0] != cast(u8)0xe3 || empty[31] != cast(u8)0x55 { return 1 }
|
||||
if abc[0] != cast(u8)0xba || abc[31] != cast(u8)0xad { return 2 }
|
||||
@@ -117,7 +117,7 @@ Answer :: () -> s32 {
|
||||
|
||||
#program_export
|
||||
PortableAnswer :: () -> s32 {
|
||||
digest := HmacSha256Of("password", "salt")
|
||||
digest := HmacSha256("password", "salt")
|
||||
if digest[0] != cast(u8)0xfc || digest[31] != cast(u8)0xd0 {
|
||||
return 1
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#import "pass_text"
|
||||
#import "text_buffer"
|
||||
#import "number_text"
|
||||
#import "kryon/app_context"
|
||||
#import "werk_app"
|
||||
|
||||
Profile :: struct {
|
||||
name: [64]u8
|
||||
|
||||
|
Before Width: | Height: | Size: 208 KiB After Width: | Height: | Size: 9.5 KiB |
@@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="512" height="512">
|
||||
<title>Werkzeug — a wrench with a keyhole</title>
|
||||
<g fill="#8254ff" fill-rule="evenodd" transform="translate(-10 10)">
|
||||
<path d="M425.9 145.5A118 118 0 1 1 366.5 86.1L288.5 164.1A42 42 0 0 0 347.9 223.5Z"/>
|
||||
<path d="M239.0 202.3L309.7 273.0L181.0 401.7A50 50 0 0 1 110.3 331.0ZM159.8 324.2a21 21 0 0 0 -11.2 38.7l-5.2 23.0h32.8l-5.2 -23.0a21 21 0 0 0 -11.2 -38.7Z"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 482 B |
|
Before Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 753 KiB |
|
Before Width: | Height: | Size: 637 KiB |
|
Before Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 675 KiB |
|
Before Width: | Height: | Size: 294 KiB |
|
Before Width: | Height: | Size: 743 KiB |
|
Before Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 819 KiB |
@@ -1,240 +0,0 @@
|
||||
# Werkzeug development and data
|
||||
|
||||
[Back to Werkzeug](../README.md).
|
||||
|
||||
## Privacy
|
||||
|
||||
Everything is computed on the device. Werkzeug makes no network requests
|
||||
unless you set up sync or explicitly request an account or device-link action.
|
||||
Each tool keeps its own files, readable only by your user:
|
||||
|
||||
| Platform | Data |
|
||||
|---|---|
|
||||
| Linux | `$XDG_DATA_HOME/werk` (or `~/.local/share/werk`) |
|
||||
| Android | the app's private storage |
|
||||
| Browser | IndexedDB on this site |
|
||||
|
||||
Auth's accounts are synced records: `otpauth` links in the private
|
||||
`records/auth.txt`, protected by the file permissions of your account or the
|
||||
Android app sandbox.
|
||||
|
||||
## Sync
|
||||
|
||||
Profile uses the shared Self bundle. Desktop Account management shows the
|
||||
public ID, alias, sync status and queued changes, and provides account creation,
|
||||
key-file import, backups, device linking and logout. Switching accounts asks
|
||||
whether to keep and merge local Auth records or replace them. A private rollback
|
||||
journal preserves the previous key and records if a switch is interrupted.
|
||||
|
||||
The account can use a [Mesh](https://github.com/ziranlang/mesh) node,
|
||||
`api.waozi.xyz` by default. Tools work locally without an account. Saved nodes
|
||||
and the preferred node live in Profile → Nodes; choosing a node preserves the
|
||||
account and its paused state. The sync switch pauses automatic synchronization
|
||||
and stays paused after restarting. Logout keeps local Auth records.
|
||||
|
||||
Desktop key backups retain Werkzeug's Auth vault key as protected recovery
|
||||
context. Use a passphrase to encrypt the backup. Importing a legacy account key
|
||||
for the already-connected identity preserves its existing vault key. The shared
|
||||
QR workflow also preserves that context and asks both devices to compare digits
|
||||
before connecting. Legacy clients cannot read the extended QR payload when
|
||||
Werkzeug vault context is included.
|
||||
|
||||
Desktop Self and participating native apps share public profile preferences only
|
||||
for the same verified account ID. Account keys and Auth records stay in the
|
||||
host's private store. Android retains its existing native Account screen and
|
||||
legacy device-link flow. In the browser, Profile opens the shared manager at
|
||||
https://entity.waozi.xyz. Public name, picture and appearance follow the active
|
||||
waozi.xyz profile. Werkzeug's browser tool data stays local; account sync for
|
||||
those tool records is unavailable.
|
||||
|
||||
The embedded web app (`/app/?mini`) shows only the tools, as large tiles,
|
||||
with no Profile; `werk --mini` does the same on the desktop. Use
|
||||
`?mini&app=pass`, `auth`, `calculator` or `clock` to open a particular tool
|
||||
first; Back returns to the tiles. Browser sync is currently unavailable.
|
||||
|
||||
- Each record is sealed on the device with XChaCha20-Poly1305 under a random
|
||||
vault key that is never sent to the node unencrypted. The seal covers the
|
||||
account, the record and the time of the change, so the server can neither
|
||||
read nor alter a record or a removal.
|
||||
- The account key (ML-DSA-44) signs in and signs each sync together with
|
||||
the device's own Ed25519 key.
|
||||
- Desktop device linking uses the shared Self QR/code exchange with X25519
|
||||
and encrypted key transfer. Confirm the matching number on both devices.
|
||||
Android's existing 12-character connection code remains available in its
|
||||
native account screen.
|
||||
- The server can still withhold changes or serve an older copy to a device
|
||||
that has not seen a newer one. A lost device keeps the keys it had: stop
|
||||
syncing there if you can, and replace two-factor secrets you care about.
|
||||
|
||||
`scripts/sync_e2e_test.sh` runs two devices against a local Mesh node.
|
||||
|
||||
## The `werk sync` and `werk auth` commands
|
||||
|
||||
On Linux, the same data works without a window, for devices without a
|
||||
screen and for scripts:
|
||||
|
||||
```text
|
||||
werk sync status | create | show | join [CODE] | key [FILE] | now
|
||||
werk auth list
|
||||
werk auth code ID
|
||||
werk auth import [FILE]
|
||||
werk auth rename ID SERVICE ACCOUNT
|
||||
werk auth sites ID [WEBSITE ...]
|
||||
werk auth remove ID
|
||||
```
|
||||
|
||||
`werk sync show` prints a code for another device to enter; `werk sync join`
|
||||
reads one from its argument or standard input. `werk sync key` signs in with
|
||||
an account key from FILE or standard input; for a key with a passphrase, give
|
||||
FILE and the passphrase on standard input. `werk auth list` prints the
|
||||
accounts as JSON with their ids and websites, never their secrets.
|
||||
`werk auth code ID` prints the current code and the seconds it stays valid.
|
||||
`werk auth import` reads a file, or standard input: otpauth links, Google
|
||||
Authenticator export links, an unencrypted Aegis export, or a PNG or JPEG of
|
||||
an export's QR code when GdkPixbuf and ZBar (`libzbar0`) are installed.
|
||||
Changes sync right away when the device has an account. `werk --app auth`
|
||||
opens the window on one tool, as Harmony's Auth entry does.
|
||||
|
||||
## Tools are separate apps
|
||||
|
||||
Each tool is built into its own portable bundle, `build/apps/<tool>.zx`:
|
||||
Pass, Calculator and Clock from `apps/<tool>/`, Auth from its own Ziran
|
||||
package ([waozixyz/auth](https://github.com/waozixyz/auth)), and Workbook from
|
||||
[kryonlabs/workbook](https://github.com/kryonlabs/workbook). All five are
|
||||
preinstalled. A tool reaches the host only through Kryon's app context (its
|
||||
private files, clipboard, clock, key derivation and device-protected
|
||||
secret), and the host checks every call a bundle asks for before it runs.
|
||||
Tools never import each other; what two need, such as SHA-256 and PBKDF2,
|
||||
comes from a Ziran package (`crypto`).
|
||||
|
||||
## Build and test
|
||||
|
||||
Dependencies and the compiler are pinned in `ziran.lock`. Desktop builds need
|
||||
SDL2, Cairo, FreeType, Fontconfig, Pango, GTK 3 and X11 development packages.
|
||||
Workbook uses its built-in spreadsheet engine on Android and the web; Linux
|
||||
also uses the installed Gnumeric library for imported documents. Linux file choosers need Zenity. Browser
|
||||
builds need Emscripten; Android builds need JDK 21 and the SDK/NDK versions in
|
||||
`droid/app/build.gradle`. Desktop tests use Xvfb, xdotool, xclip and
|
||||
ImageMagick on private displays.
|
||||
|
||||
```sh
|
||||
make gui # build/werk and the app bundles in build/apps
|
||||
make install-gui # Werkzeug and each tool in the app menu and on the desktop
|
||||
make test # Pass/CLI, Auth, Calculator and private account recovery fixtures
|
||||
make gui-smoke # light and dark home screens on a private Xvfb display
|
||||
make gui-test # every tool, clipboard and profile on a private display,
|
||||
# and werk auth without one
|
||||
make site # build/site: browser app and offline worker
|
||||
make web-smoke # private headless Chromium
|
||||
make android-debug # ARM32, ARM64 and universal APKs
|
||||
make android-fdroid # unsigned F-Droid candidate, same Android ID and version
|
||||
make android-emulator # the x86_64 APK for a private emulator
|
||||
```
|
||||
|
||||
Android input tests require an explicitly owned private emulator through
|
||||
`WERK_ANDROID_EMULATOR`. `python3 scripts/private-emulator.py make android-input-test`
|
||||
owns a headless API 31 Google APIs emulator, including Workbook's system document picker.
|
||||
CI also retains API 30 input, profile and in-place update coverage through
|
||||
`make android-profile-test`.
|
||||
|
||||
Linux installs include separate Pass, Auth, Calculator, Clock, Workbook and Gallery
|
||||
launchers, each with its own icon. They open the selected tool directly and
|
||||
share Werkzeug's existing private data. `make install-gui` also adds shortcuts
|
||||
to the desktop folder configured by `xdg-user-dir`; set `DESKTOP_DIR=` to skip
|
||||
those shortcuts. Debian packages include the same application-menu entries.
|
||||
|
||||
F-Droid metadata is maintained in `packaging/fdroid`. The `android-fdroid`
|
||||
target disables developer signing even when a release keystore is configured
|
||||
and writes `build/fdroid/werk.apk` for comparison with the signed release. It adds no version or
|
||||
package suffix, preserving existing installations and reference-APK checks.
|
||||
The unsigned candidate is for builders, not installation. Werkzeug currently
|
||||
has no built-in updater: F-Droid or your chosen installer handles updates.
|
||||
Android requires the same signing certificate for an in-place update; the
|
||||
F-Droid recipe retains the developer-signature reproducibility requirement.
|
||||
|
||||
The [F-Droid TODO](../packaging/fdroid/TODO.md) records completed checks, the
|
||||
remaining submission/reproducibility steps and the prepared merge-request text.
|
||||
|
||||
For development with the real project repositories, create an ignored
|
||||
`ziran.local.toml`:
|
||||
|
||||
```toml
|
||||
[overrides]
|
||||
kryon = "../../kryonlabs/kryon"
|
||||
ziran = "../../ziranlang/ziran"
|
||||
```
|
||||
|
||||
## The `pass` command
|
||||
|
||||
```text
|
||||
pass [OPTIONS] SITE LOGIN [MASTER_PASSWORD]
|
||||
pass [OPTIONS] PROFILE SITE
|
||||
```
|
||||
|
||||
`make cli` builds it and `make install-cli` installs it. The default password
|
||||
has 16 characters and includes lowercase letters, uppercase letters, digits
|
||||
and symbols. Length must be between 5 and 35, matching LessPass clients. The
|
||||
default counter is 1.
|
||||
|
||||
Passing a master password as an argument can expose it to process inspection
|
||||
and shell history. Omitting it is safer: `pass` first checks
|
||||
`LESSPASS_MASTER_PASSWORD`, then reads one line from standard input. Use
|
||||
`--prompt` to bypass the environment and read from standard input:
|
||||
|
||||
```sh
|
||||
pass --prompt example.com alice
|
||||
pass --length 24 --counter 2 example.com alice
|
||||
pass --no-symbols --exclude '0O1Il' example.com alice
|
||||
```
|
||||
|
||||
The Linux CLI also reads saved identities from
|
||||
`$XDG_CONFIG_HOME/pass/profiles.json` (or `~/.config/pass/profiles.json`).
|
||||
`pass w example.com` and `pass --profile w example.com` use the saved login
|
||||
and generation options. Existing OpenSSL-encrypted vaults are unlocked with
|
||||
a hidden `Vault passphrase:` prompt. A configured vault takes precedence over
|
||||
`LESSPASS_MASTER_PASSWORD`; `--prompt` bypasses it. Explicit flags override
|
||||
profile defaults. Profiles and vaults are read without changing them.
|
||||
|
||||
`--copy` or a profile's `copy` setting copies through `xclip` on X11;
|
||||
`--clear-after 90s` releases that clipboard selection after the given time
|
||||
without erasing a later copy from another application. Use `--no-copy` to
|
||||
print the generated password instead. Run `pass --help` for all flags.
|
||||
|
||||
## Source layout
|
||||
|
||||
```text
|
||||
apps/pass/ Pass: LessPass core, settings and profiles, screens, CLI
|
||||
auth (package) Auth: TOTP, otpauth links, exports, accounts and screens (waozixyz/auth)
|
||||
apps/calculator/ Calculator
|
||||
apps/clock/ Clock and stopwatch
|
||||
src/werk.zi home screen, profile screen and the bar above a tool
|
||||
src/apps.zi loads, checks and runs the app bundles
|
||||
src/platform.zi files, clock, clipboard and secrets per platform
|
||||
src/desktop.zi, src/android_main.zi, src/browser.zi platform main loops
|
||||
src/command.zi werk sync and werk auth without a window
|
||||
```
|
||||
|
||||
## Profile-picture diagnostics
|
||||
|
||||
`make entity-account-test` uses a private local HTTP fixture to fetch a
|
||||
picture through the normal background pump while Profile is closed. It checks
|
||||
the challenge and signed login, saves the returned picture locally and in the
|
||||
shared profile, and preserves another app's name. Its sanitized result is
|
||||
`build/entity-account-test/picture-sync-diagnostics.json`; it contains no account
|
||||
identifiers, keys, signatures or tokens.
|
||||
|
||||
`make gui-test` also extracts and decodes all 17 Entity picture resources in a
|
||||
private display. Its resource names, dimensions and permissions are recorded
|
||||
in `build/apps-gui-test/entity-resource-diagnostics.json`. This distinguishes
|
||||
bundled-resource failures from sync failures without reading a real account.
|
||||
|
||||
Werkzeug previously skipped starting the background picture reader when
|
||||
Profile was closed and no local picture was pending. Sync-enabled accounts
|
||||
now start it automatically. These tests cover that reproduced failure. The
|
||||
reported shared-resource failure across other apps has not been reproduced;
|
||||
the tests do not establish its server-side or cross-app cause.
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2026 Waozi. Distributed under the BSD 3-Clause License. See
|
||||
[`LICENSE`](../LICENSE).
|
||||
@@ -14,17 +14,16 @@ android {
|
||||
}
|
||||
|
||||
def getKeystorePath = { -> project.findProperty('keystore.path') ?: keystoreProps['keystore.path'] ?: System.getenv("HOME") + "/.android/pass-release.keystore" }
|
||||
def getKeystoreAlias = { -> project.findProperty('keystore.alias') ?: keystoreProps['keystore.alias'] ?: System.getenv('KEY_ALIAS') ?: "pass-key" }
|
||||
def getKeystoreAlias = { -> project.findProperty('keystore.alias') ?: keystoreProps['keystore.alias'] ?: "pass-key" }
|
||||
|
||||
def releasePassword = project.findProperty('keystore.password') ?: System.getenv('KEYSTORE_PASSWORD') ?: ""
|
||||
def releasePassword = project.findProperty('keystore.password') ?: ""
|
||||
|
||||
def releaseKeystorePath = getKeystorePath()
|
||||
def releaseKeystore = releaseKeystorePath ? file(releaseKeystorePath) : null
|
||||
// Sign release builds only when a keystore is actually available: CI and
|
||||
// local release builds pass -Pkeystore.* properties, while clean checkouts
|
||||
// (for example an F-Droid builder) produce an unsigned APK instead.
|
||||
def fdroidBuild = (project.findProperty('fDroidBuild') ?: 'false').toString().toBoolean()
|
||||
def signRelease = !fdroidBuild \
|
||||
def signRelease = !project.hasProperty('fDroidBuild') \
|
||||
&& releaseKeystore != null && releaseKeystore.exists() \
|
||||
&& releasePassword != ""
|
||||
|
||||
@@ -43,8 +42,8 @@ android {
|
||||
applicationId 'xyz.waozi.pass'
|
||||
minSdk 21
|
||||
targetSdk 36
|
||||
versionCode 21
|
||||
versionName "0.4.7"
|
||||
versionCode 13
|
||||
versionName "0.3.1"
|
||||
// Default to the two realistic phone targets; override with
|
||||
// -Pabi=x86_64 etc. for emulator builds.
|
||||
def abis = project.findProperty('abi') ?: 'armeabi-v7a,arm64-v8a'
|
||||
@@ -80,7 +79,6 @@ android {
|
||||
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
includeInBundle = false
|
||||
}
|
||||
|
||||
packaging {
|
||||
@@ -103,25 +101,15 @@ tasks.named('preBuild').configure { dependsOn prepareFonts }
|
||||
|
||||
// The tool apps are portable bundles, built once for every ABI.
|
||||
def makeApps = tasks.register('makeApps', Exec) {
|
||||
workingDir rootProject.file('..')
|
||||
if (System.getenv('WERK_ZIRAN_COMMAND')) {
|
||||
environment 'ZIRAN', System.getenv('WERK_ZIRAN_COMMAND')
|
||||
}
|
||||
commandLine 'make', 'portable-apps'
|
||||
workingDir '../..'
|
||||
commandLine 'make', 'apps'
|
||||
}
|
||||
def kryonSource = providers.environmentVariable('KRYON_DIR').orElse(providers.exec {
|
||||
workingDir rootProject.file('..')
|
||||
commandLine (System.getenv('WERK_ZIRAN_COMMAND') ?: rootProject.file('../scripts/ziran.sh').absolutePath), 'pkg', 'path', 'kryon'
|
||||
}.standardOutput.asText.map { it.trim() })
|
||||
// Entity owns the account policy; Kryon supplies the shared Android consent UI.
|
||||
apply from: new File(kryonSource.get(), 'templates/android-account-handoff.gradle')
|
||||
android.sourceSets.main.assets.srcDir(layout.buildDirectory.dir('generated/appAssets'))
|
||||
def prepareImages = tasks.register('prepareImages', Sync) {
|
||||
def prepareImages = tasks.register('prepareImages', Copy) {
|
||||
dependsOn makeApps
|
||||
from('../../assets/app/icon.png')
|
||||
from(kryonSource.map { "${it}/icons/pfp.webp" })
|
||||
from('../../assets/tools') { include '*.webp'; into 'tools' }
|
||||
from('../../build/apps') { include '*.zx'; into 'apps' }
|
||||
from("${System.getenv('KRYON_DIR')}/icons/pfp.png")
|
||||
from('../../build/apps') { include '*.zib'; into 'apps' }
|
||||
into layout.buildDirectory.dir('generated/appAssets')
|
||||
}
|
||||
tasks.named('preBuild').configure { dependsOn prepareImages }
|
||||
@@ -6,7 +6,7 @@
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<application
|
||||
android:hasCode="true"
|
||||
android:hasCode="false"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:allowBackup="false">
|
||||
|
||||
@@ -1,20 +1,30 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
project(Werkzeug C ASM)
|
||||
project(Werkzeug C)
|
||||
get_filename_component(REPO_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../../../.." ABSOLUTE)
|
||||
set(KRYON_DIR "$ENV{KRYON_DIR}" CACHE PATH "Locked Kryon source" FORCE)
|
||||
set(ZIRAN_ROOT "$ENV{ZIRAN_ROOT}" CACHE PATH "Locked Ziran toolchain" FORCE)
|
||||
set(RAYLIB_DIR "$ENV{RAYLIB_DIR}" CACHE PATH "Locked raylib source" FORCE)
|
||||
set(LIBOQS_DIR "$ENV{LIBOQS_DIR}" CACHE PATH "Locked liboqs source" FORCE)
|
||||
set(MONOCYPHER_DIR "$ENV{MONOCYPHER_DIR}" CACHE PATH "Locked Monocypher source" FORCE)
|
||||
foreach(root KRYON_DIR ZIRAN_ROOT RAYLIB_DIR LIBOQS_DIR MONOCYPHER_DIR)
|
||||
if(NOT ${root})
|
||||
message(FATAL_ERROR "Set ${root}; use make android-debug or make android-release")
|
||||
endif()
|
||||
endforeach()
|
||||
set(ZIRAN "${REPO_ROOT}/scripts/ziran.sh")
|
||||
if(DEFINED ENV{WERK_ZIRAN_COMMAND} AND NOT "$ENV{WERK_ZIRAN_COMMAND}" STREQUAL "")
|
||||
get_filename_component(ZIRAN "$ENV{WERK_ZIRAN_COMMAND}" ABSOLUTE BASE_DIR "${REPO_ROOT}")
|
||||
endif()
|
||||
set(GENERATED "${CMAKE_BINARY_DIR}/ziran")
|
||||
set(DEFINES --define ANDROID_BUILD --target-os android)
|
||||
set(DEFINES --define ANDROID_BUILD)
|
||||
if(ANDROID_ABI STREQUAL "arm64-v8a")
|
||||
list(APPEND DEFINES --define __aarch64__ --target-cpu arm64)
|
||||
list(APPEND DEFINES --define __aarch64__)
|
||||
elseif(ANDROID_ABI STREQUAL "armeabi-v7a")
|
||||
list(APPEND DEFINES --define __arm__ --target-cpu none)
|
||||
list(APPEND DEFINES --define __arm__)
|
||||
elseif(ANDROID_ABI STREQUAL "x86_64")
|
||||
list(APPEND DEFINES --define __x86_64__ --target-cpu x64)
|
||||
list(APPEND DEFINES --define __x86_64__)
|
||||
elseif(ANDROID_ABI STREQUAL "x86")
|
||||
list(APPEND DEFINES --define __i386__ --target-cpu none)
|
||||
list(APPEND DEFINES --define __i386__)
|
||||
else()
|
||||
message(FATAL_ERROR "Unsupported Android ABI: ${ANDROID_ABI}")
|
||||
endif()
|
||||
@@ -22,37 +32,12 @@ set(LOCK_FLAGS --locked)
|
||||
if(EXISTS "${REPO_ROOT}/ziran.local.toml")
|
||||
set(LOCK_FLAGS)
|
||||
endif()
|
||||
# Plain Gradle builds resolve the same packages as Make. F-Droid needs no
|
||||
# source patches or machine-specific environment variables in its recipe.
|
||||
function(werk_package variable package suffix)
|
||||
if(NOT "$ENV{${variable}}" STREQUAL "")
|
||||
set(path "$ENV{${variable}}")
|
||||
else()
|
||||
execute_process(COMMAND "${ZIRAN}" pkg path "${package}" ${LOCK_FLAGS}
|
||||
WORKING_DIRECTORY "${REPO_ROOT}" OUTPUT_VARIABLE path
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY)
|
||||
string(APPEND path "${suffix}")
|
||||
endif()
|
||||
set(${variable} "${path}" CACHE PATH "Locked ${package} source" FORCE)
|
||||
endfunction()
|
||||
werk_package(KRYON_DIR kryon "")
|
||||
werk_package(ZIRAN_ROOT ziran "")
|
||||
werk_package(WEBP_DIR libwebp "")
|
||||
werk_package(AVIF_DIR libavif "")
|
||||
werk_package(AOM_DIR libaom "")
|
||||
werk_package(LIBOQS_DIR liboqs "")
|
||||
werk_package(MONOCYPHER_DIR monocypher "")
|
||||
werk_package(WORKBOOK_DIR workbook "")
|
||||
werk_package(TASKMGR_DIR taskmgr "")
|
||||
file(GLOB_RECURSE SOURCE_INPUTS CONFIGURE_DEPENDS
|
||||
"${REPO_ROOT}/src/*.zi" "${REPO_ROOT}/apps/gallery/*.zi" "${WORKBOOK_DIR}/src/*.zi" "${TASKMGR_DIR}/src/*.zi" "${KRYON_DIR}/src/*.zi" "${ZIRAN_ROOT}/std/*.zi")
|
||||
list(APPEND SOURCE_INPUTS "${REPO_ROOT}/ziran.toml" "${REPO_ROOT}/ziran.lock" "${REPO_ROOT}/scripts/runtime_cache.py")
|
||||
"${REPO_ROOT}/src/*.zi" "${REPO_ROOT}/shared/*.zi" "${KRYON_DIR}/src/*.zi" "${ZIRAN_ROOT}/std/*.zi")
|
||||
list(APPEND SOURCE_INPUTS "${REPO_ROOT}/ziran.toml" "${REPO_ROOT}/ziran.lock")
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${SOURCE_INPUTS})
|
||||
file(REMOVE_RECURSE "${GENERATED}")
|
||||
execute_process(COMMAND "${ZIRAN}" build --project ${LOCK_FLAGS} ${DEFINES}
|
||||
# NativeActivity and JNI callbacks are native linker roots.
|
||||
--target=c --no-main -o "${GENERATED}" src/android_main.zi
|
||||
"${KRYON_DIR}/src/backend/android_fopen.zi"
|
||||
--target=c --entry android_main:main -o "${GENERATED}" src/android_main.zi
|
||||
WORKING_DIRECTORY "${REPO_ROOT}" COMMAND_ERROR_IS_FATAL ANY)
|
||||
file(GLOB GENERATED_SOURCES CONFIGURE_DEPENDS "${GENERATED}/*.c")
|
||||
# Kryon's Android glue compiles its thread configurator with the same zi2c.
|
||||
@@ -62,25 +47,19 @@ foreach(candidate "${ZIRAN_ROOT}/build/bin/zi2c" "${REPO_ROOT}/build/ziran-boots
|
||||
endif()
|
||||
endforeach()
|
||||
include("${KRYON_DIR}/cmake/KryonAndroid.cmake")
|
||||
kryon_android_codecs("${WEBP_DIR}" "${AVIF_DIR}" "${AOM_DIR}")
|
||||
kryon_android_raylib("${RAYLIB_DIR}")
|
||||
# The portable runtime that runs the app bundles, built from the locked Ziran
|
||||
# for this ABI.
|
||||
set(BUNDLE_RUNTIME_DIR "${CMAKE_BINARY_DIR}/bundle-runtime")
|
||||
# Use the host's installed GNU Make, including an SDK-provided executable.
|
||||
# All code generators run on the host; only runtime objects target the ABI.
|
||||
find_program(WERK_MAKE_COMMAND NAMES make gmake REQUIRED)
|
||||
execute_process(COMMAND "${WERK_MAKE_COMMAND}" -j4 -C "${ZIRAN_ROOT}"
|
||||
"BUILD_DIR=${BUNDLE_RUNTIME_DIR}"
|
||||
execute_process(COMMAND make -C "${ZIRAN_ROOT}" BOOTSTRAP=1 "BUILD_DIR=${BUNDLE_RUNTIME_DIR}"
|
||||
"CC=${CMAKE_C_COMPILER} --target=${CMAKE_C_COMPILER_TARGET} --sysroot=${CMAKE_SYSROOT}"
|
||||
"AR=${CMAKE_AR}" "OBJCOPY=${CMAKE_OBJCOPY}"
|
||||
"GEN_ZI2C=${ZIRAN_ROOT}/build/bin/zi2c"
|
||||
"CFLAGS=-O2 -fPIC" "FRAMEFLAGS=-Wframe-larger-than=16384"
|
||||
"${BUNDLE_RUNTIME_DIR}/libziran.a"
|
||||
"AR=${CMAKE_AR}" "OBJCOPY=${CMAKE_OBJCOPY}" "CFLAGS=-O2 -fPIC"
|
||||
"FRAMEFLAGS=-Wframe-larger-than=16384" "${BUNDLE_RUNTIME_DIR}/libziran.a"
|
||||
COMMAND_ERROR_IS_FATAL ANY)
|
||||
# Account sync: liboqs for ML-DSA-44 account keys, Monocypher for the rest.
|
||||
set(OQS_BUILD_ONLY_LIB ON CACHE BOOL "" FORCE)
|
||||
set(OQS_USE_OPENSSL OFF CACHE BOOL "" FORCE)
|
||||
set(OQS_MINIMAL_BUILD "SIG_ml_dsa_44;KEM_ml_kem_768" CACHE STRING "" FORCE)
|
||||
set(OQS_MINIMAL_BUILD "SIG_ml_dsa_44" CACHE STRING "" FORCE)
|
||||
set(OQS_DIST_BUILD OFF CACHE BOOL "" FORCE)
|
||||
set(OQS_OPT_TARGET generic CACHE STRING "" FORCE)
|
||||
foreach(oqs_x86_feature
|
||||
@@ -89,22 +68,13 @@ foreach(oqs_x86_feature
|
||||
set(OQS_USE_${oqs_x86_feature}_INSTRUCTIONS OFF CACHE BOOL "" FORCE)
|
||||
endforeach()
|
||||
add_subdirectory("${LIBOQS_DIR}" "${CMAKE_BINARY_DIR}/liboqs")
|
||||
# JNI_OnLoad is discovered by Android's loader, outside the native entry graph.
|
||||
set_source_files_properties("${GENERATED}/android_glue.c"
|
||||
PROPERTIES COMPILE_OPTIONS "-fvisibility=default")
|
||||
add_library(main SHARED ${GENERATED_SOURCES}
|
||||
"${MONOCYPHER_DIR}/src/monocypher.c" "${MONOCYPHER_DIR}/src/optional/monocypher-ed25519.c")
|
||||
target_compile_options(main PRIVATE "-iquote${GENERATED}")
|
||||
target_include_directories(main PRIVATE "${ZIRAN_ROOT}/include"
|
||||
target_include_directories(main PRIVATE "${GENERATED}" "${ZIRAN_ROOT}/include"
|
||||
"${MONOCYPHER_DIR}/src" "${MONOCYPHER_DIR}/src/optional")
|
||||
target_link_libraries(main PRIVATE oqs z kryon_android_codecs)
|
||||
target_link_libraries(main oqs)
|
||||
kryon_android_app(main)
|
||||
# Save hosted documents after the canonical NativeActivity loop returns.
|
||||
target_link_options(main PRIVATE -Wl,--wrap=android_main)
|
||||
target_link_libraries(main PRIVATE "${BUNDLE_RUNTIME_DIR}/libziran.a")
|
||||
# Linker build IDs include debug-path differences even after stripping. The
|
||||
# installed code is identical; omit this note for reproducible signed APKs.
|
||||
# https://f-droid.org/docs/Reproducible_Builds/#ndk-build-id
|
||||
target_link_options(main PRIVATE -Wl,--build-id=none)
|
||||
target_link_libraries(main "${BUNDLE_RUNTIME_DIR}/libziran.a")
|
||||
target_link_options(main PRIVATE -Wl,--wrap=pthread_attr_init)
|
||||
# Werkzeug has no handwritten native sources; every app translation unit above is
|
||||
# generated from .zi for this ABI. Kryon and the NDK own native_app_glue.
|
||||
# generated from .zi for this ABI. raylib and the NDK own native_app_glue.
|
||||
|
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 842 B |
|
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 1.6 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 3.1 KiB |
@@ -1,6 +0,0 @@
|
||||
- A new purple W logo.
|
||||
- Calculator gets a Scientific mode.
|
||||
- Auth imports Google Authenticator, Aegis and Ente Auth exports.
|
||||
- Rename an Auth account, note its websites, or remove it.
|
||||
- Choose your own Daochi node, and pause sync without losing your account.
|
||||
- Show π, √ and other symbols on phones older than Android 10.
|
||||
@@ -1,3 +0,0 @@
|
||||
- Open Pass, Auth, Calculator, Clock and Workbook directly from the Linux application menu, each with its own icon.
|
||||
- Desktop installs add shortcuts for Werkzeug and every tool to your configured desktop folder.
|
||||
- Tool windows show their own names and icons in the desktop switcher.
|
||||
@@ -1,2 +0,0 @@
|
||||
- Linux packages include the libraries needed for sync and importing QR-code pictures.
|
||||
- Packaging a new AppImage preserves previous downloads.
|
||||
@@ -1,2 +0,0 @@
|
||||
- Werkzeug uses its own Android application ID, `xyz.waozi.werk`.
|
||||
- Werkzeug installs alongside legacy Pass, preserving the older app and its data.
|
||||
@@ -1,2 +0,0 @@
|
||||
- Werkzeug updates the existing Pass Android app using its original application ID and signing certificate, keeping its saved data.
|
||||
- The app continues to appear as Werkzeug, with Pass, Auth, Calculator and Clock together.
|
||||
@@ -1 +0,0 @@
|
||||
- Fix Android opening to “Apps are unavailable”; Pass, Auth, Calculator and Clock load normally.
|
||||
@@ -1 +0,0 @@
|
||||
- Set an account alias with capitals, an @ or spaces; a taken alias now says so.
|
||||
@@ -1,2 +0,0 @@
|
||||
- Use Workbook on Android and the web as well as Linux, with formulas, sheet tabs, automatic saving and document import/export.
|
||||
- Navigate Workbook cells with touch controls, and keep Android's keyboard focused while editing a cell.
|
||||
@@ -1,14 +1,11 @@
|
||||
Werkzeug holds small private tools in one app. Everything is computed on your device and nothing is tracked. It makes no network requests unless you turn on sync.
|
||||
|
||||
• Pass derives strong, repeatable passwords. The same site, login, master password, and settings always produce the same result, so there is no password database to back up, sync, or lose. It is LessPass-compatible, with configurable length, counter, character classes and excluded characters, and an optional master password kept behind device authentication.
|
||||
• Auth shows two-factor sign-in codes (TOTP with SHA-1, SHA-256 or SHA-512). Add accounts by secret key or from otpauth links, Google Authenticator export links, unencrypted Aegis exports or Ente Auth's plain-text export. Rename an account or note the websites where it signs in. Copied codes are cleared from the clipboard after 30 seconds. Optional sync keeps them on all your devices, encrypted on the device so the server never sees them.
|
||||
• Calculator handles everyday arithmetic with brackets, powers and percent, and has a Scientific mode with trigonometry, logarithms, roots, factorials, π and e.
|
||||
• Auth shows two-factor sign-in codes (TOTP with SHA-1, SHA-256 or SHA-512). Add accounts from otpauth links, including an authenticator's plain-text export, or by secret key. Copied codes are cleared from the clipboard after 30 seconds. Optional sync keeps them on all your devices, encrypted on the device so the server never sees them.
|
||||
• Calculator handles everyday arithmetic with brackets, powers and percent.
|
||||
• Clock shows the local time and date and has a stopwatch.
|
||||
• Workbook edits spreadsheets with formulas, multiple sheets and automatic saving. Import or export a Gnumeric workbook through Android's file chooser, and use the same document on the desktop or web.
|
||||
|
||||
A profile with your name and picture sets the appearance every tool shares.
|
||||
|
||||
Every tool works without a Mesh account. In Profile → Sync you can choose your own node before connecting an account, or pause sync without forgetting your keys and local records. Sync stays off after restarting until you turn it on again.
|
||||
A profile with your name and picture sets the appearance every tool shares. Werkzeug was previously called Pass; updating keeps your profiles, settings and saved master password.
|
||||
|
||||
Pass is an independent implementation of the LessPass algorithm. Compatibility does not imply endorsement by or affiliation with the LessPass project.
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 99 KiB |
|
Before Width: | Height: | Size: 208 KiB After Width: | Height: | Size: 9.5 KiB |
|
After Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 87 KiB |
|
Before Width: | Height: | Size: 92 KiB |
|
Before Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 88 KiB |
|
Before Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
Before Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 86 KiB |
@@ -0,0 +1,20 @@
|
||||
</$objtype/mkfile
|
||||
|
||||
# Generate with `make plan9-c` on the host, then build natively with `mk`.
|
||||
CLI_FILES=`{ls build/plan9/cli/*.c}
|
||||
CLI_HEADERS=`{ls build/plan9/cli/*.h}
|
||||
CLI_OBJECTS=${CLI_FILES:%.c=%.$O}
|
||||
CFLAGS=-FTVw
|
||||
|
||||
all:V: pass
|
||||
|
||||
pass: $CLI_OBJECTS
|
||||
$LD -o $target $prereq
|
||||
|
||||
$CLI_OBJECTS: $CLI_HEADERS
|
||||
|
||||
%.$O: %.c
|
||||
$CC $CFLAGS -o $target $stem.c
|
||||
|
||||
install:V: pass
|
||||
cp pass /$objtype/bin/pass
|
||||
@@ -1,4 +0,0 @@
|
||||
/config/
|
||||
/repo/
|
||||
/tmp/
|
||||
/logs/
|
||||
@@ -1,5 +0,0 @@
|
||||
# Update Pass to Werkzeug
|
||||
|
||||
Update the existing `xyz.waozi.pass` app to Werkzeug. The package ID and signing certificate are preserved for in-place updates.
|
||||
|
||||
Listing text and screenshots are maintained upstream in Fastlane.
|
||||
@@ -1,17 +0,0 @@
|
||||
# Werkzeug F-Droid update status
|
||||
|
||||
The owner's latest request is an update of the existing Pass app. Keep `xyz.waozi.pass`, the existing author signing certificate and private app data. The visible name remains Werkzeug. Preserve any separate `xyz.waozi.werk` installation as well.
|
||||
|
||||
- [x] Prepare the original Android application ID and matching artifact verifiers.
|
||||
- [x] Prepare 0.4.4 with version code 18 through `update_version.sh`.
|
||||
- [x] Build the compatible ARM and private-emulator candidates with matching ZX dependencies and current app bundles.
|
||||
- [x] Verify both ARM native libraries match byte for byte after independent builds in different directories.
|
||||
- [ ] Publish the compatible candidate through the normal release workflow and pin its exact source revision in the recipe.
|
||||
- [ ] Complete source-build and reproducibility verification against its reference APK.
|
||||
- [ ] Resolve missing explicit dependency licenses and remaining GitLab pipeline results.
|
||||
- [ ] Obtain owner approval before marking the update ready for review.
|
||||
- [ ] Verify catalog publication after maintainers merge and F-Droid publishes it.
|
||||
|
||||
[Update draft](https://gitlab.com/fdroid/fdroiddata/-/merge_requests/53909) · [Recipe](metadata/xyz.waozi.pass.yml) · [Merge-request text](MERGE_REQUEST.md)
|
||||
|
||||
The local recipe is being prepared; its source pin still needs the verified compatible candidate. A Draft or a successful source build does not imply F-Droid catalog publication.
|
||||
@@ -1,51 +0,0 @@
|
||||
Categories:
|
||||
- Password & 2FA
|
||||
- Security
|
||||
License: BSD-3-Clause
|
||||
AuthorName: Waozi
|
||||
WebSite: https://werk.waozi.xyz
|
||||
SourceCode: https://github.com/waozixyz/werk
|
||||
IssueTracker: https://github.com/waozixyz/werk/issues
|
||||
Changelog: https://github.com/waozixyz/werk/blob/HEAD/CHANGELOG.md
|
||||
|
||||
AutoName: Werkzeug
|
||||
|
||||
RepoType: git
|
||||
Repo: https://github.com/waozixyz/werk.git
|
||||
Binaries: https://github.com/waozixyz/pass/releases/download/v%v/pass-%v.apk
|
||||
|
||||
Builds:
|
||||
- versionName: 0.2.9
|
||||
versionCode: 10
|
||||
commit: f9d721f179e54c924e048d3fd17c5e96de1047ba
|
||||
subdir: droid/app
|
||||
submodules: true
|
||||
sudo:
|
||||
- apt-get update
|
||||
- apt-get install -y gcc libc-dev
|
||||
gradle:
|
||||
- yes
|
||||
scandelete:
|
||||
- vendor/kryon/vendor
|
||||
ndk: 28.2.13676358
|
||||
|
||||
- versionName: 0.4.4
|
||||
versionCode: 18
|
||||
commit: b53050764b8402a96e2e6b9b8c90d6567a3bea77
|
||||
subdir: droid/app
|
||||
sudo:
|
||||
- apt-get update
|
||||
- apt-get install -y build-essential cmake libssl-dev
|
||||
gradle:
|
||||
- yes
|
||||
binary: https://github.com/waozixyz/werk/releases/download/v%v/werk-%v.apk
|
||||
ndk: 28.2.13676358
|
||||
gradleprops:
|
||||
- fDroidBuild=true
|
||||
|
||||
AllowedAPKSigningKeys: 1ac82db5bc8f742b8161fdd7083cefc16b39524dce7d103a7eb7f1ee19589c2d
|
||||
|
||||
AutoUpdateMode: Version
|
||||
UpdateCheckMode: Tags
|
||||
CurrentVersion: 0.4.4
|
||||
CurrentVersionCode: 18
|
||||
@@ -1,202 +0,0 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 9.4 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 12 KiB |
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
|
||||
<mime-type type="application/x-ziran-bundle">
|
||||
<comment>Ziran application bundle</comment>
|
||||
<glob pattern="*.zx"/>
|
||||
</mime-type>
|
||||
</mime-info>
|
||||
@@ -11,5 +11,5 @@
|
||||
<launchable type="desktop-id">xyz.waozi.werk.desktop</launchable>
|
||||
<url type="homepage">https://github.com/waozixyz/werk</url>
|
||||
<provides><binary>werk</binary></provides>
|
||||
<releases><release version="0.4.7" date="2026-10-28"/><release version="0.4.6" date="2026-10-27"/><release version="0.4.5" date="2026-10-26"/><release version="0.4.4" date="2026-10-23"/><release version="0.4.3" date="2026-10-23"/><release version="0.4.2" date="2026-10-23"/><release version="0.4.1" date="2026-10-23"/><release version="0.4.0" date="2026-10-15"/><release version="0.3.1" date="2026-10-13"/><release version="0.3.0" date="2026-10-13"/><release version="0.2.10" date="2026-10-05"/><release version="0.2.9" date="2026-09-05"/><release version="0.2.8" date="2026-08-26"/><release version="0.2.7" date="2026-08-24"/><release version="0.2.6" date="2026-08-24"/><release version="0.2.5" date="2026-08-24"/><release version="0.2.4" date="2026-08-22"/><release version="0.2.3" date="2026-08-21"/><release version="0.2.2" date="2026-08-20"/><release version="0.2.1" date="2026-08-19"/><release version="0.2.0" date="2026-08-18"/><release version="0.1.3" date="2026-08-17"/><release version="0.1.2" date="2026-08-17"/><release version="0.1.1" date="2026-08-17"/><release version="0.1.0" date="2026-08-17"/></releases>
|
||||
<releases><release version="0.3.1" date="2026-10-13"/><release version="0.3.0" date="2026-10-13"/><release version="0.2.10" date="2026-10-05"/><release version="0.2.9" date="2026-09-05"/><release version="0.2.8" date="2026-08-26"/><release version="0.2.7" date="2026-08-24"/><release version="0.2.6" date="2026-08-24"/><release version="0.2.5" date="2026-08-24"/><release version="0.2.4" date="2026-08-22"/><release version="0.2.3" date="2026-08-21"/><release version="0.2.2" date="2026-08-20"/><release version="0.2.1" date="2026-08-19"/><release version="0.2.0" date="2026-08-18"/><release version="0.1.3" date="2026-08-17"/><release version="0.1.2" date="2026-08-17"/><release version="0.1.1" date="2026-08-17"/><release version="0.1.0" date="2026-08-17"/></releases>
|
||||
</component>
|
||||
@@ -1,12 +0,0 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Auth
|
||||
Comment=Two-factor sign-in codes with Werkzeug
|
||||
Exec=werk --app auth
|
||||
TryExec=werk
|
||||
Icon=werk-auth
|
||||
Terminal=false
|
||||
Categories=Utility;Security;
|
||||
Keywords=Werkzeug;TOTP;2FA;Authenticator;
|
||||
StartupNotify=true
|
||||
StartupWMClass=werk-auth
|
||||
@@ -1,12 +0,0 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Calculator
|
||||
Comment=Everyday and scientific calculations with Werkzeug
|
||||
Exec=werk --app calculator
|
||||
TryExec=werk
|
||||
Icon=werk-calculator
|
||||
Terminal=false
|
||||
Categories=Utility;Calculator;
|
||||
Keywords=Werkzeug;Math;Scientific;
|
||||
StartupNotify=true
|
||||
StartupWMClass=werk-calculator
|
||||
@@ -1,12 +0,0 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Calendar
|
||||
Comment=Schedule events with Werkzeug
|
||||
Exec=werk --app calendar
|
||||
TryExec=werk
|
||||
Icon=werk-calendar
|
||||
Terminal=false
|
||||
Categories=Office;Calendar;
|
||||
Keywords=Werkzeug;Calendar;Events;Schedule;
|
||||
StartupNotify=true
|
||||
StartupWMClass=werk-calendar
|
||||
@@ -1,12 +0,0 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Clock
|
||||
Comment=Local time and stopwatch with Werkzeug
|
||||
Exec=werk --app clock
|
||||
TryExec=werk
|
||||
Icon=werk-clock
|
||||
Terminal=false
|
||||
Categories=Utility;Clock;
|
||||
Keywords=Werkzeug;Time;Stopwatch;
|
||||
StartupNotify=true
|
||||
StartupWMClass=werk-clock
|
||||
@@ -1,12 +1,9 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Werkzeug
|
||||
Comment=Private everyday tools
|
||||
Exec=werk --bundle %f
|
||||
TryExec=werk
|
||||
Comment=Passwords, two-factor codes, a calculator and a clock
|
||||
Exec=werk
|
||||
Icon=werk
|
||||
Terminal=false
|
||||
Categories=Utility;Security;
|
||||
StartupNotify=true
|
||||
StartupWMClass=werk
|
||||
MimeType=application/x-ziran-bundle;
|
||||
@@ -1,12 +0,0 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Gallery
|
||||
Comment=Browse local photo albums with Werkzeug
|
||||
Exec=werk --app gallery
|
||||
TryExec=werk
|
||||
Icon=werk-gallery
|
||||
Terminal=false
|
||||
Categories=Graphics;Photography;
|
||||
Keywords=Werkzeug;Photos;Albums;Local;
|
||||
StartupNotify=true
|
||||
StartupWMClass=werk-gallery
|
||||
@@ -1,12 +0,0 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Pass
|
||||
Comment=Generate repeatable passwords with Werkzeug
|
||||
Exec=werk --app pass
|
||||
TryExec=werk
|
||||
Icon=werk-pass
|
||||
Terminal=false
|
||||
Categories=Utility;Security;
|
||||
Keywords=Werkzeug;Password;LessPass;
|
||||
StartupNotify=true
|
||||
StartupWMClass=werk-pass
|
||||
@@ -1,12 +0,0 @@
|
||||
[Desktop Entry]
|
||||
Type=Application
|
||||
Name=Task Manager
|
||||
Comment=Monitor processes and performance with Werkzeug
|
||||
Exec=werk --app taskmgr
|
||||
TryExec=werk
|
||||
Icon=werk-taskmgr
|
||||
Terminal=false
|
||||
Categories=System;Monitor;
|
||||
Keywords=Werkzeug;Task Manager;Processes;CPU;Memory;
|
||||
StartupNotify=true
|
||||
StartupWMClass=werk-taskmgr
|
||||