From 4903bb12dd69fc7e29b28fd2d92318ba1ff23617 Mon Sep 17 00:00:00 2001 From: tajniak81 <13187254+tajniak81@users.noreply.github.com> Date: Fri, 30 Oct 2026 22:18:25 +0100 Subject: [PATCH] Scaffold Docwell monorepo with PocketBase authentication Phase 0 foundation for Docwell, an open-source knowledge base: - Database: PocketBase v0.40.6 with initial schema migrations; users is the built-in auth collection, plus a hook for token checks and env-driven app URL/SMTP settings - Server: Go API (health, version, auth endpoints forwarded to PocketBase, admin user list) with an embedded Vue admin panel - Web-App: Go static server and Vue/Tailwind app with Tiptap editor, sign-in, sign-up, password reset and email verification (EN/PL) - Desktop-App: Wails v3 host reusing the web app - Phone-App: Flutter app with sign-in - Shared packages (editor, ui, api-client), OpenAPI spec, Docker compose (separate services and all-in-one), GitHub Actions CI - Docs: feature inventory and architecture/build plan Licensed under AGPL-3.0-or-later. Co-Authored-By: Claude Opus 5.5 --- .dockerignore | 15 + .editorconfig | 18 + .gitattributes | 7 + .github/workflows/ci.yml | 97 + .gitignore | 32 + Database/Dockerfile | 24 + Database/README.md | 25 + Database/entrypoint.sh | 15 + Database/pb_hooks/docwell.pb.js | 39 + .../1761850000_initial_schema.js | 191 + Design/README.md | 5 + Desktop-App/Taskfile.yml | 70 + Desktop-App/build/Taskfile.yml | 398 ++ Desktop-App/build/android/Taskfile.yml | 464 ++ Desktop-App/build/android/app/build.gradle | 83 + .../build/android/app/proguard-rules.pro | 12 + .../android/app/src/main/AndroidManifest.xml | 63 + .../main/java/com/wails/app/MainActivity.java | 821 +++ .../main/java/com/wails/app/WailsBridge.java | 1408 +++++ .../com/wails/app/WailsForegroundService.java | 74 + .../java/com/wails/app/WailsJSBridge.java | 151 + .../java/com/wails/app/WailsPathHandler.java | 68 + .../app/src/main/res/layout/activity_main.xml | 12 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 2338 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 2338 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 1652 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 1652 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 3276 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 3276 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 5202 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 5202 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 7198 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 7198 bytes .../app/src/main/res/values/colors.xml | 8 + .../app/src/main/res/values/strings.xml | 4 + .../app/src/main/res/values/themes.xml | 14 + .../app/src/main/res/xml/file_paths.xml | 6 + Desktop-App/build/android/build.gradle | 4 + Desktop-App/build/android/gradle.properties | 26 + .../android/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 45633 bytes .../gradle/wrapper/gradle-wrapper.properties | 7 + Desktop-App/build/android/gradlew | 248 + Desktop-App/build/android/gradlew.bat | 93 + Desktop-App/build/android/main_android.go | 11 + .../android/scripts/deps/install_deps.go | 266 + Desktop-App/build/android/settings.gradle | 18 + .../appicon.icon/Assets/wails_icon_vector.svg | 9 + Desktop-App/build/appicon.icon/icon.json | 51 + Desktop-App/build/appicon.png | Bin 0 -> 31495 bytes Desktop-App/build/config.yml | 87 + Desktop-App/build/darwin/Assets.car | Bin 0 -> 1631800 bytes Desktop-App/build/darwin/Info.dev.plist | 34 + Desktop-App/build/darwin/Info.plist | 29 + Desktop-App/build/darwin/Taskfile.yml | 220 + Desktop-App/build/darwin/dmg-background.png | Bin 0 -> 26550 bytes Desktop-App/build/darwin/dmg-file-icon.icns | Bin 0 -> 1861485 bytes Desktop-App/build/darwin/dmg-file-icon.png | Bin 0 -> 1794021 bytes Desktop-App/build/darwin/icons.icns | Bin 0 -> 52216 bytes Desktop-App/build/docker/Dockerfile.cross | 225 + Desktop-App/build/docker/Dockerfile.server | 67 + Desktop-App/build/ios/Assets.xcassets | 116 + Desktop-App/build/ios/Info.dev.plist | 61 + Desktop-App/build/ios/Info.plist | 59 + Desktop-App/build/ios/LaunchScreen.storyboard | 53 + Desktop-App/build/ios/Taskfile.yml | 365 ++ Desktop-App/build/ios/app_options_default.go | 10 + Desktop-App/build/ios/app_options_ios.go | 11 + Desktop-App/build/ios/entitlements.plist | 11 + Desktop-App/build/ios/icon.png | 3 + Desktop-App/build/ios/main.m | 22 + Desktop-App/build/ios/main_ios.go | 23 + Desktop-App/build/ios/project.pbxproj | 230 + .../build/ios/scripts/deps/install_deps.go | 319 ++ Desktop-App/build/linux/Taskfile.yml | 220 + Desktop-App/build/linux/appimage/build.sh | 35 + Desktop-App/build/linux/desktop | 13 + Desktop-App/build/linux/nfpm/nfpm.yaml | 80 + .../build/linux/nfpm/scripts/postinstall.sh | 21 + .../build/linux/nfpm/scripts/postremove.sh | 1 + .../build/linux/nfpm/scripts/preinstall.sh | 1 + .../build/linux/nfpm/scripts/preremove.sh | 1 + Desktop-App/build/windows/Taskfile.yml | 195 + Desktop-App/build/windows/icon.ico | Bin 0 -> 21677 bytes Desktop-App/build/windows/info.json | 15 + .../build/windows/msix/app_manifest.xml | 55 + Desktop-App/build/windows/msix/template.xml | 54 + Desktop-App/build/windows/nsis/project.nsi | 119 + .../build/windows/nsis/wails_tools.nsh | 261 + Desktop-App/build/windows/wails.exe.manifest | 22 + .../bindings/docwell/desktop/index.ts | 11 + .../bindings/docwell/desktop/models.ts | 30 + .../docwell/desktop/settingsservice.ts | 36 + .../wailsapp/wails/v3/internal/eventcreate.ts | 9 + .../wailsapp/wails/v3/internal/eventdata.d.ts | 2 + Desktop-App/frontend/dist/.gitkeep | 0 Desktop-App/frontend/index.html | 12 + Desktop-App/frontend/package.json | 26 + Desktop-App/frontend/src/main.ts | 15 + Desktop-App/frontend/tsconfig.json | 15 + Desktop-App/frontend/vite.config.ts | 15 + Desktop-App/go.mod | 15 + Desktop-App/go.sum | 32 + Desktop-App/main.go | 55 + Desktop-App/settings.go | 67 + Desktop-App/settings_test.go | 32 + Docker-AIO/Dockerfile | 44 + Docker-AIO/docker-compose.yml | 32 + Docker-AIO/start.sh | 41 + Docker/.env.example | 24 + Docker/docker-compose.yml | 71 + LICENSE | 661 +++ Packages/api-client/package.json | 21 + Packages/api-client/src/index.test.ts | 53 + Packages/api-client/src/index.ts | 123 + Packages/api-client/src/schema.d.ts | 688 +++ Packages/editor/package.json | 22 + Packages/editor/src/DocwellEditor.vue | 32 + Packages/editor/src/editor.css | 26 + Packages/editor/src/extensions.ts | 22 + Packages/editor/src/index.ts | 2 + Packages/env.d.ts | 5 + Packages/ui/package.json | 15 + Packages/ui/src/DwButton.vue | 20 + Packages/ui/src/index.ts | 2 + Packages/ui/src/theme.css | 43 + Packages/ui/src/theme.ts | 40 + Phone-App/.gitignore | 45 + Phone-App/.metadata | 33 + Phone-App/README.md | 5 + Phone-App/analysis_options.yaml | 28 + Phone-App/android/.gitignore | 14 + Phone-App/android/app/build.gradle.kts | 45 + .../android/app/src/debug/AndroidManifest.xml | 9 + .../android/app/src/main/AndroidManifest.xml | 46 + .../docwell/docwell_mobile/MainActivity.kt | 5 + .../res/drawable-v21/launch_background.xml | 12 + .../main/res/drawable/launch_background.xml | 12 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 544 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 442 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 721 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 1031 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 1443 bytes .../app/src/main/res/values-night/styles.xml | 18 + .../app/src/main/res/values/styles.xml | 18 + .../app/src/profile/AndroidManifest.xml | 7 + Phone-App/android/build.gradle.kts | 24 + Phone-App/android/gradle.properties | 6 + .../gradle/wrapper/gradle-wrapper.properties | 5 + Phone-App/android/settings.gradle.kts | 26 + Phone-App/ios/.gitignore | 34 + Phone-App/ios/Flutter/AppFrameworkInfo.plist | 24 + Phone-App/ios/Flutter/Debug.xcconfig | 1 + Phone-App/ios/Flutter/Release.xcconfig | 1 + .../ios/Runner.xcodeproj/project.pbxproj | 644 +++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../xcshareddata/WorkspaceSettings.xcsettings | 8 + .../xcshareddata/xcschemes/Runner.xcscheme | 119 + .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../xcshareddata/WorkspaceSettings.xcsettings | 8 + Phone-App/ios/Runner/AppDelegate.swift | 16 + .../AppIcon.appiconset/Contents.json | 122 + .../Icon-App-1024x1024@1x.png | Bin 0 -> 10932 bytes .../AppIcon.appiconset/Icon-App-20x20@1x.png | Bin 0 -> 295 bytes .../AppIcon.appiconset/Icon-App-20x20@2x.png | Bin 0 -> 406 bytes .../AppIcon.appiconset/Icon-App-20x20@3x.png | Bin 0 -> 450 bytes .../AppIcon.appiconset/Icon-App-29x29@1x.png | Bin 0 -> 282 bytes .../AppIcon.appiconset/Icon-App-29x29@2x.png | Bin 0 -> 462 bytes .../AppIcon.appiconset/Icon-App-29x29@3x.png | Bin 0 -> 704 bytes .../AppIcon.appiconset/Icon-App-40x40@1x.png | Bin 0 -> 406 bytes .../AppIcon.appiconset/Icon-App-40x40@2x.png | Bin 0 -> 586 bytes .../AppIcon.appiconset/Icon-App-40x40@3x.png | Bin 0 -> 862 bytes .../AppIcon.appiconset/Icon-App-60x60@2x.png | Bin 0 -> 862 bytes .../AppIcon.appiconset/Icon-App-60x60@3x.png | Bin 0 -> 1674 bytes .../AppIcon.appiconset/Icon-App-76x76@1x.png | Bin 0 -> 762 bytes .../AppIcon.appiconset/Icon-App-76x76@2x.png | Bin 0 -> 1226 bytes .../Icon-App-83.5x83.5@2x.png | Bin 0 -> 1418 bytes .../LaunchImage.imageset/Contents.json | 23 + .../LaunchImage.imageset/LaunchImage.png | Bin 0 -> 68 bytes .../LaunchImage.imageset/LaunchImage@2x.png | Bin 0 -> 68 bytes .../LaunchImage.imageset/LaunchImage@3x.png | Bin 0 -> 68 bytes .../LaunchImage.imageset/README.md | 5 + .../Runner/Base.lproj/LaunchScreen.storyboard | 37 + .../ios/Runner/Base.lproj/Main.storyboard | 26 + Phone-App/ios/Runner/Info.plist | 70 + Phone-App/ios/Runner/Runner-Bridging-Header.h | 1 + Phone-App/ios/Runner/SceneDelegate.swift | 6 + Phone-App/ios/RunnerTests/RunnerTests.swift | 12 + Phone-App/lib/api/docwell_api.dart | 77 + Phone-App/lib/main.dart | 195 + Phone-App/pubspec.lock | 245 + Phone-App/pubspec.yaml | 90 + Phone-App/test/widget_test.dart | 56 + README.md | 100 + Server/Dockerfile | 29 + Server/admin/index.html | 12 + Server/admin/package.json | 26 + Server/admin/src/App.vue | 51 + Server/admin/src/main.ts | 27 + Server/admin/src/session.ts | 44 + Server/admin/src/style.css | 2 + Server/admin/src/views/LoginView.vue | 54 + Server/admin/src/views/OverviewView.vue | 51 + Server/admin/src/views/PlaceholderView.vue | 4 + Server/admin/src/views/UsersView.vue | 78 + Server/admin/tsconfig.json | 5 + Server/admin/vite.config.ts | 20 + Server/cmd/docwell-server/main.go | 77 + Server/go.mod | 3 + Server/internal/admin/dist/.gitkeep | 0 Server/internal/admin/embed.go | 45 + Server/internal/auth/auth.go | 444 ++ Server/internal/auth/auth_test.go | 243 + Server/internal/config/config.go | 78 + Server/internal/config/config_test.go | 68 + Server/internal/httpapi/auth.go | 199 + Server/internal/httpapi/auth_test.go | 128 + Server/internal/httpapi/router.go | 102 + Server/internal/httpapi/router_test.go | 72 + Server/internal/store/pocketbase/client.go | 228 + .../internal/store/pocketbase/client_test.go | 83 + Web-App/Dockerfile | 29 + Web-App/cmd/docwell-web/main.go | 79 + Web-App/frontend/index.html | 13 + Web-App/frontend/package.json | 38 + Web-App/frontend/public/favicon.svg | 1 + Web-App/frontend/src/App.vue | 9 + Web-App/frontend/src/api.ts | 8 + Web-App/frontend/src/app.ts | 41 + Web-App/frontend/src/components/AuthCard.vue | 21 + Web-App/frontend/src/components/FormField.vue | 22 + .../src/components/ServerStatus.test.ts | 33 + .../frontend/src/components/ServerStatus.vue | 29 + .../frontend/src/composables/useFormErrors.ts | 31 + Web-App/frontend/src/i18n.ts | 15 + Web-App/frontend/src/locales/en.json | 80 + Web-App/frontend/src/locales/pl.json | 80 + Web-App/frontend/src/main.ts | 5 + Web-App/frontend/src/platform.ts | 41 + Web-App/frontend/src/router.ts | 73 + Web-App/frontend/src/stores/auth.test.ts | 82 + Web-App/frontend/src/stores/auth.ts | 68 + Web-App/frontend/src/style.css | 6 + Web-App/frontend/src/views/HomeView.vue | 91 + Web-App/frontend/src/views/NotFoundView.vue | 8 + .../src/views/auth/ForgotPasswordView.vue | 42 + Web-App/frontend/src/views/auth/LoginView.vue | 113 + .../src/views/auth/ResetPasswordView.vue | 52 + .../frontend/src/views/auth/SignupView.vue | 55 + .../src/views/auth/VerifyEmailView.vue | 32 + Web-App/frontend/tsconfig.json | 7 + Web-App/frontend/vite.config.ts | 22 + Web-App/go.mod | 3 + Web-App/internal/spa/dist/.gitkeep | 0 Web-App/internal/spa/spa.go | 100 + Web-App/internal/spa/spa_test.go | 66 + api/openapi.yaml | 324 ++ docs/FEATURES.md | 181 + docs/PLAN.md | 223 + go.work | 7 + package-lock.json | 4515 +++++++++++++++++ package.json | 25 + tsconfig.base.json | 17 + 264 files changed, 21422 insertions(+) create mode 100644 .dockerignore create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 Database/Dockerfile create mode 100644 Database/README.md create mode 100644 Database/entrypoint.sh create mode 100644 Database/pb_hooks/docwell.pb.js create mode 100644 Database/pb_migrations/1761850000_initial_schema.js create mode 100644 Design/README.md create mode 100644 Desktop-App/Taskfile.yml create mode 100644 Desktop-App/build/Taskfile.yml create mode 100644 Desktop-App/build/android/Taskfile.yml create mode 100644 Desktop-App/build/android/app/build.gradle create mode 100644 Desktop-App/build/android/app/proguard-rules.pro create mode 100644 Desktop-App/build/android/app/src/main/AndroidManifest.xml create mode 100644 Desktop-App/build/android/app/src/main/java/com/wails/app/MainActivity.java create mode 100644 Desktop-App/build/android/app/src/main/java/com/wails/app/WailsBridge.java create mode 100644 Desktop-App/build/android/app/src/main/java/com/wails/app/WailsForegroundService.java create mode 100644 Desktop-App/build/android/app/src/main/java/com/wails/app/WailsJSBridge.java create mode 100644 Desktop-App/build/android/app/src/main/java/com/wails/app/WailsPathHandler.java create mode 100644 Desktop-App/build/android/app/src/main/res/layout/activity_main.xml create mode 100644 Desktop-App/build/android/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 Desktop-App/build/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 Desktop-App/build/android/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 Desktop-App/build/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 Desktop-App/build/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 Desktop-App/build/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 Desktop-App/build/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 Desktop-App/build/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 Desktop-App/build/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 Desktop-App/build/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 Desktop-App/build/android/app/src/main/res/values/colors.xml create mode 100644 Desktop-App/build/android/app/src/main/res/values/strings.xml create mode 100644 Desktop-App/build/android/app/src/main/res/values/themes.xml create mode 100644 Desktop-App/build/android/app/src/main/res/xml/file_paths.xml create mode 100644 Desktop-App/build/android/build.gradle create mode 100644 Desktop-App/build/android/gradle.properties create mode 100644 Desktop-App/build/android/gradle/wrapper/gradle-wrapper.jar create mode 100644 Desktop-App/build/android/gradle/wrapper/gradle-wrapper.properties create mode 100644 Desktop-App/build/android/gradlew create mode 100644 Desktop-App/build/android/gradlew.bat create mode 100644 Desktop-App/build/android/main_android.go create mode 100644 Desktop-App/build/android/scripts/deps/install_deps.go create mode 100644 Desktop-App/build/android/settings.gradle create mode 100644 Desktop-App/build/appicon.icon/Assets/wails_icon_vector.svg create mode 100644 Desktop-App/build/appicon.icon/icon.json create mode 100644 Desktop-App/build/appicon.png create mode 100644 Desktop-App/build/config.yml create mode 100644 Desktop-App/build/darwin/Assets.car create mode 100644 Desktop-App/build/darwin/Info.dev.plist create mode 100644 Desktop-App/build/darwin/Info.plist create mode 100644 Desktop-App/build/darwin/Taskfile.yml create mode 100644 Desktop-App/build/darwin/dmg-background.png create mode 100644 Desktop-App/build/darwin/dmg-file-icon.icns create mode 100644 Desktop-App/build/darwin/dmg-file-icon.png create mode 100644 Desktop-App/build/darwin/icons.icns create mode 100644 Desktop-App/build/docker/Dockerfile.cross create mode 100644 Desktop-App/build/docker/Dockerfile.server create mode 100644 Desktop-App/build/ios/Assets.xcassets create mode 100644 Desktop-App/build/ios/Info.dev.plist create mode 100644 Desktop-App/build/ios/Info.plist create mode 100644 Desktop-App/build/ios/LaunchScreen.storyboard create mode 100644 Desktop-App/build/ios/Taskfile.yml create mode 100644 Desktop-App/build/ios/app_options_default.go create mode 100644 Desktop-App/build/ios/app_options_ios.go create mode 100644 Desktop-App/build/ios/entitlements.plist create mode 100644 Desktop-App/build/ios/icon.png create mode 100644 Desktop-App/build/ios/main.m create mode 100644 Desktop-App/build/ios/main_ios.go create mode 100644 Desktop-App/build/ios/project.pbxproj create mode 100644 Desktop-App/build/ios/scripts/deps/install_deps.go create mode 100644 Desktop-App/build/linux/Taskfile.yml create mode 100644 Desktop-App/build/linux/appimage/build.sh create mode 100644 Desktop-App/build/linux/desktop create mode 100644 Desktop-App/build/linux/nfpm/nfpm.yaml create mode 100644 Desktop-App/build/linux/nfpm/scripts/postinstall.sh create mode 100644 Desktop-App/build/linux/nfpm/scripts/postremove.sh create mode 100644 Desktop-App/build/linux/nfpm/scripts/preinstall.sh create mode 100644 Desktop-App/build/linux/nfpm/scripts/preremove.sh create mode 100644 Desktop-App/build/windows/Taskfile.yml create mode 100644 Desktop-App/build/windows/icon.ico create mode 100644 Desktop-App/build/windows/info.json create mode 100644 Desktop-App/build/windows/msix/app_manifest.xml create mode 100644 Desktop-App/build/windows/msix/template.xml create mode 100644 Desktop-App/build/windows/nsis/project.nsi create mode 100644 Desktop-App/build/windows/nsis/wails_tools.nsh create mode 100644 Desktop-App/build/windows/wails.exe.manifest create mode 100644 Desktop-App/frontend/bindings/docwell/desktop/index.ts create mode 100644 Desktop-App/frontend/bindings/docwell/desktop/models.ts create mode 100644 Desktop-App/frontend/bindings/docwell/desktop/settingsservice.ts create mode 100644 Desktop-App/frontend/bindings/github.com/wailsapp/wails/v3/internal/eventcreate.ts create mode 100644 Desktop-App/frontend/bindings/github.com/wailsapp/wails/v3/internal/eventdata.d.ts create mode 100644 Desktop-App/frontend/dist/.gitkeep create mode 100644 Desktop-App/frontend/index.html create mode 100644 Desktop-App/frontend/package.json create mode 100644 Desktop-App/frontend/src/main.ts create mode 100644 Desktop-App/frontend/tsconfig.json create mode 100644 Desktop-App/frontend/vite.config.ts create mode 100644 Desktop-App/go.mod create mode 100644 Desktop-App/go.sum create mode 100644 Desktop-App/main.go create mode 100644 Desktop-App/settings.go create mode 100644 Desktop-App/settings_test.go create mode 100644 Docker-AIO/Dockerfile create mode 100644 Docker-AIO/docker-compose.yml create mode 100644 Docker-AIO/start.sh create mode 100644 Docker/.env.example create mode 100644 Docker/docker-compose.yml create mode 100644 LICENSE create mode 100644 Packages/api-client/package.json create mode 100644 Packages/api-client/src/index.test.ts create mode 100644 Packages/api-client/src/index.ts create mode 100644 Packages/api-client/src/schema.d.ts create mode 100644 Packages/editor/package.json create mode 100644 Packages/editor/src/DocwellEditor.vue create mode 100644 Packages/editor/src/editor.css create mode 100644 Packages/editor/src/extensions.ts create mode 100644 Packages/editor/src/index.ts create mode 100644 Packages/env.d.ts create mode 100644 Packages/ui/package.json create mode 100644 Packages/ui/src/DwButton.vue create mode 100644 Packages/ui/src/index.ts create mode 100644 Packages/ui/src/theme.css create mode 100644 Packages/ui/src/theme.ts create mode 100644 Phone-App/.gitignore create mode 100644 Phone-App/.metadata create mode 100644 Phone-App/README.md create mode 100644 Phone-App/analysis_options.yaml create mode 100644 Phone-App/android/.gitignore create mode 100644 Phone-App/android/app/build.gradle.kts create mode 100644 Phone-App/android/app/src/debug/AndroidManifest.xml create mode 100644 Phone-App/android/app/src/main/AndroidManifest.xml create mode 100644 Phone-App/android/app/src/main/kotlin/app/docwell/docwell_mobile/MainActivity.kt create mode 100644 Phone-App/android/app/src/main/res/drawable-v21/launch_background.xml create mode 100644 Phone-App/android/app/src/main/res/drawable/launch_background.xml create mode 100644 Phone-App/android/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 Phone-App/android/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 Phone-App/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 Phone-App/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 Phone-App/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 Phone-App/android/app/src/main/res/values-night/styles.xml create mode 100644 Phone-App/android/app/src/main/res/values/styles.xml create mode 100644 Phone-App/android/app/src/profile/AndroidManifest.xml create mode 100644 Phone-App/android/build.gradle.kts create mode 100644 Phone-App/android/gradle.properties create mode 100644 Phone-App/android/gradle/wrapper/gradle-wrapper.properties create mode 100644 Phone-App/android/settings.gradle.kts create mode 100644 Phone-App/ios/.gitignore create mode 100644 Phone-App/ios/Flutter/AppFrameworkInfo.plist create mode 100644 Phone-App/ios/Flutter/Debug.xcconfig create mode 100644 Phone-App/ios/Flutter/Release.xcconfig create mode 100644 Phone-App/ios/Runner.xcodeproj/project.pbxproj create mode 100644 Phone-App/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 Phone-App/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Phone-App/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings create mode 100644 Phone-App/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme create mode 100644 Phone-App/ios/Runner.xcworkspace/contents.xcworkspacedata create mode 100644 Phone-App/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Phone-App/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings create mode 100644 Phone-App/ios/Runner/AppDelegate.swift create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json create mode 100644 Phone-App/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png create mode 100644 Phone-App/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md create mode 100644 Phone-App/ios/Runner/Base.lproj/LaunchScreen.storyboard create mode 100644 Phone-App/ios/Runner/Base.lproj/Main.storyboard create mode 100644 Phone-App/ios/Runner/Info.plist create mode 100644 Phone-App/ios/Runner/Runner-Bridging-Header.h create mode 100644 Phone-App/ios/Runner/SceneDelegate.swift create mode 100644 Phone-App/ios/RunnerTests/RunnerTests.swift create mode 100644 Phone-App/lib/api/docwell_api.dart create mode 100644 Phone-App/lib/main.dart create mode 100644 Phone-App/pubspec.lock create mode 100644 Phone-App/pubspec.yaml create mode 100644 Phone-App/test/widget_test.dart create mode 100644 README.md create mode 100644 Server/Dockerfile create mode 100644 Server/admin/index.html create mode 100644 Server/admin/package.json create mode 100644 Server/admin/src/App.vue create mode 100644 Server/admin/src/main.ts create mode 100644 Server/admin/src/session.ts create mode 100644 Server/admin/src/style.css create mode 100644 Server/admin/src/views/LoginView.vue create mode 100644 Server/admin/src/views/OverviewView.vue create mode 100644 Server/admin/src/views/PlaceholderView.vue create mode 100644 Server/admin/src/views/UsersView.vue create mode 100644 Server/admin/tsconfig.json create mode 100644 Server/admin/vite.config.ts create mode 100644 Server/cmd/docwell-server/main.go create mode 100644 Server/go.mod create mode 100644 Server/internal/admin/dist/.gitkeep create mode 100644 Server/internal/admin/embed.go create mode 100644 Server/internal/auth/auth.go create mode 100644 Server/internal/auth/auth_test.go create mode 100644 Server/internal/config/config.go create mode 100644 Server/internal/config/config_test.go create mode 100644 Server/internal/httpapi/auth.go create mode 100644 Server/internal/httpapi/auth_test.go create mode 100644 Server/internal/httpapi/router.go create mode 100644 Server/internal/httpapi/router_test.go create mode 100644 Server/internal/store/pocketbase/client.go create mode 100644 Server/internal/store/pocketbase/client_test.go create mode 100644 Web-App/Dockerfile create mode 100644 Web-App/cmd/docwell-web/main.go create mode 100644 Web-App/frontend/index.html create mode 100644 Web-App/frontend/package.json create mode 100644 Web-App/frontend/public/favicon.svg create mode 100644 Web-App/frontend/src/App.vue create mode 100644 Web-App/frontend/src/api.ts create mode 100644 Web-App/frontend/src/app.ts create mode 100644 Web-App/frontend/src/components/AuthCard.vue create mode 100644 Web-App/frontend/src/components/FormField.vue create mode 100644 Web-App/frontend/src/components/ServerStatus.test.ts create mode 100644 Web-App/frontend/src/components/ServerStatus.vue create mode 100644 Web-App/frontend/src/composables/useFormErrors.ts create mode 100644 Web-App/frontend/src/i18n.ts create mode 100644 Web-App/frontend/src/locales/en.json create mode 100644 Web-App/frontend/src/locales/pl.json create mode 100644 Web-App/frontend/src/main.ts create mode 100644 Web-App/frontend/src/platform.ts create mode 100644 Web-App/frontend/src/router.ts create mode 100644 Web-App/frontend/src/stores/auth.test.ts create mode 100644 Web-App/frontend/src/stores/auth.ts create mode 100644 Web-App/frontend/src/style.css create mode 100644 Web-App/frontend/src/views/HomeView.vue create mode 100644 Web-App/frontend/src/views/NotFoundView.vue create mode 100644 Web-App/frontend/src/views/auth/ForgotPasswordView.vue create mode 100644 Web-App/frontend/src/views/auth/LoginView.vue create mode 100644 Web-App/frontend/src/views/auth/ResetPasswordView.vue create mode 100644 Web-App/frontend/src/views/auth/SignupView.vue create mode 100644 Web-App/frontend/src/views/auth/VerifyEmailView.vue create mode 100644 Web-App/frontend/tsconfig.json create mode 100644 Web-App/frontend/vite.config.ts create mode 100644 Web-App/go.mod create mode 100644 Web-App/internal/spa/dist/.gitkeep create mode 100644 Web-App/internal/spa/spa.go create mode 100644 Web-App/internal/spa/spa_test.go create mode 100644 api/openapi.yaml create mode 100644 docs/FEATURES.md create mode 100644 docs/PLAN.md create mode 100644 go.work create mode 100644 package-lock.json create mode 100644 package.json create mode 100644 tsconfig.base.json diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1623bd2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +**/node_modules +**/pb_data +**/bin +.git +Phone-App +Design +docs +Desktop-App/build +Desktop-App/frontend/dist +Server/internal/admin/dist/assets +Server/internal/admin/dist/index.html +Web-App/internal/spa/dist/assets +Web-App/internal/spa/dist/*.html +Web-App/internal/spa/dist/*.svg +**/.env diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..fc7ebf2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 + +[*.go] +indent_style = tab + +[{Makefile,*.mk}] +indent_style = tab + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..cf71120 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,7 @@ +* text=auto eol=lf +*.sh text eol=lf +*.bat text eol=crlf +*.cmd text eol=crlf +*.png binary +*.ico binary +*.icns binary diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bd4c465 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,97 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + +jobs: + go: + runs-on: ubuntu-latest + strategy: + matrix: + module: [Server, Web-App] + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-go@v6 + with: + go-version: "1.26" + - name: Vet and test + working-directory: ${{ matrix.module }} + env: + GOWORK: "off" + run: | + test -z "$(gofmt -l .)" || (gofmt -l . && exit 1) + go vet ./... + go test -race ./... + + frontend: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-node@v5 + with: + node-version: 24 + cache: npm + - run: npm ci + - name: API types are up to date + run: | + npm run generate -w @docwell/api-client + git diff --exit-code Packages/api-client/src/schema.d.ts + - run: npm run typecheck + - run: npm test + - run: npm run build + + desktop: + strategy: + matrix: + os: [windows-latest, macos-latest, ubuntu-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-go@v6 + with: + go-version: "1.26" + - uses: actions/setup-node@v5 + with: + node-version: 24 + cache: npm + - name: Linux webview dependencies + if: runner.os == 'Linux' + run: sudo apt-get update && sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev + - run: npm ci + - run: npm run build -w @docwell/desktop + - name: Test and build + working-directory: Desktop-App + env: + GOWORK: "off" + run: | + go test ./... + go build -o bin/ . + + mobile: + runs-on: ubuntu-latest + defaults: + run: + working-directory: Phone-App + steps: + - uses: actions/checkout@v5 + - uses: subosito/flutter-action@v2 + with: + channel: stable + - run: flutter pub get + - run: flutter analyze + - run: flutter test + + docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - name: Build and smoke-test the compose stack + working-directory: Docker + run: | + cp .env.example .env + docker compose up --build -d --wait + curl -fsS http://localhost:8080/readyz + curl -fsS http://localhost:3000/ | grep -q '
' + docker compose down -v diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dcddac8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ +# Dependencies +node_modules/ + +# Build output (embedded dist/ folders keep a .gitkeep so go:embed works on a fresh clone) +dist/* +!dist/.gitkeep +build/bin/ +*.exe +/Server/bin/ +/Web-App/bin/ +/Server/internal/admin/dist/* +!/Server/internal/admin/dist/.gitkeep +/Web-App/internal/spa/dist/* +!/Web-App/internal/spa/dist/.gitkeep +/Desktop-App/bin/ +/Desktop-App/frontend/dist/* +!/Desktop-App/frontend/dist/.gitkeep + +# PocketBase local data +pb_data/ +/Database/bin/ + +# Env and editor +.env +*.local +.DS_Store +.idea/ +.vscode/* +!.vscode/extensions.json + +# Go +coverage.out diff --git a/Database/Dockerfile b/Database/Dockerfile new file mode 100644 index 0000000..a6fae5c --- /dev/null +++ b/Database/Dockerfile @@ -0,0 +1,24 @@ +# docwell-db: the official PocketBase release plus Docwell migrations. +FROM alpine:3.22 + +ARG PB_VERSION=0.40.6 +ARG TARGETARCH=amd64 + +RUN apk add --no-cache ca-certificates unzip wget \ + && wget -q "https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_${TARGETARCH}.zip" -O /tmp/pb.zip \ + && unzip /tmp/pb.zip pocketbase -d /usr/local/bin \ + && rm /tmp/pb.zip \ + && apk del unzip wget + +COPY pb_migrations /pb_migrations +COPY pb_hooks /pb_hooks +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +VOLUME /pb_data +EXPOSE 8090 + +HEALTHCHECK --interval=10s --timeout=3s --retries=5 \ + CMD wget -qO- http://127.0.0.1:8090/api/health >/dev/null || exit 1 + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/Database/README.md b/Database/README.md new file mode 100644 index 0000000..966719a --- /dev/null +++ b/Database/README.md @@ -0,0 +1,25 @@ +# docwell-db + +The official [PocketBase](https://pocketbase.io) binary (pinned in `Dockerfile`) with Docwell's schema migrations. + +- `pb_migrations/` holds JS migrations, applied in filename order at startup. +- `pb_hooks/` holds optional JS hooks (keep these minimal). +- All collection API rules are `null`, so only superusers have access. Never expose this service publicly; only docwell-server talks to it. + +## Run locally + +Download PocketBase v0.40.6 for your OS into `Database/bin/`, then: + +```bash +./bin/pocketbase migrate up --dir ./pb_data --migrationsDir ./pb_migrations +./bin/pocketbase superuser upsert admin@docwell.test devpassword123 --dir ./pb_data +./bin/pocketbase serve --dir ./pb_data --migrationsDir ./pb_migrations --hooksDir ./pb_hooks +``` + +The PocketBase dashboard is at http://127.0.0.1:8090/_/. + +## New migration + +```bash +./bin/pocketbase migrate create "add_comments" --dir ./pb_data --migrationsDir ./pb_migrations +``` diff --git a/Database/entrypoint.sh b/Database/entrypoint.sh new file mode 100644 index 0000000..9a3ba5e --- /dev/null +++ b/Database/entrypoint.sh @@ -0,0 +1,15 @@ +#!/bin/sh +set -eu + +: "${PB_ADMIN_EMAIL:?PB_ADMIN_EMAIL is required}" +: "${PB_ADMIN_PASSWORD:?PB_ADMIN_PASSWORD is required}" + +pocketbase migrate up --dir /pb_data --migrationsDir /pb_migrations +pocketbase superuser upsert "$PB_ADMIN_EMAIL" "$PB_ADMIN_PASSWORD" --dir /pb_data + +exec pocketbase serve \ + --http 0.0.0.0:8090 \ + --dir /pb_data \ + --migrationsDir /pb_migrations \ + --hooksDir /pb_hooks \ + --automigrate=false diff --git a/Database/pb_hooks/docwell.pb.js b/Database/pb_hooks/docwell.pb.js new file mode 100644 index 0000000..cc505e9 --- /dev/null +++ b/Database/pb_hooks/docwell.pb.js @@ -0,0 +1,39 @@ +/// + +// Token check used by docwell-server: returns the "users" record that owns the +// bearer token, or 401. Unlike auth-refresh, it does not issue a new token. +routerAdd( + "GET", + "/api/docwell/auth/verify", + (e) => { + e.auth.ignoreEmailVisibility(true); + return e.json(200, e.auth); + }, + $apis.requireAuth("users"), +); + +// Instance settings come from the environment and are applied on every start, +// so changing an env var and restarting is enough. +onBootstrap((e) => { + e.next(); + + const env = (key, def) => $os.getenv(key) || def; + const settings = e.app.settings(); + + settings.meta.appName = env("DOCWELL_APP_NAME", "Docwell"); + settings.meta.appURL = env("DOCWELL_WEB_URL", "http://localhost:3000"); + settings.meta.senderName = settings.meta.appName; + settings.meta.senderAddress = env("DOCWELL_MAIL_FROM", "no-reply@docwell.localhost"); + + const smtpHost = env("DOCWELL_SMTP_HOST", ""); + settings.smtp.enabled = smtpHost !== ""; + if (smtpHost) { + settings.smtp.host = smtpHost; + settings.smtp.port = parseInt(env("DOCWELL_SMTP_PORT", "587"), 10); + settings.smtp.username = env("DOCWELL_SMTP_USERNAME", ""); + settings.smtp.password = env("DOCWELL_SMTP_PASSWORD", ""); + settings.smtp.tls = env("DOCWELL_SMTP_TLS", "false") === "true"; + } + + e.app.save(settings); +}); diff --git a/Database/pb_migrations/1761850000_initial_schema.js b/Database/pb_migrations/1761850000_initial_schema.js new file mode 100644 index 0000000..5ebb3af --- /dev/null +++ b/Database/pb_migrations/1761850000_initial_schema.js @@ -0,0 +1,191 @@ +/// + +// Initial Docwell schema. All record API rules stay null (superuser only): PocketBase +// is a private service and docwell-server is the only client allowed to use it. + +const timestamps = () => [ + { name: "created", type: "autodate", onCreate: true, onUpdate: false }, + { name: "updated", type: "autodate", onCreate: true, onUpdate: true }, +]; + +const relation = (name, collection, opts = {}) => ({ + name, + type: "relation", + collectionId: collection.id, + maxSelect: 1, + cascadeDelete: false, + ...opts, +}); + +migrate( + (app) => { + // Authentication uses PocketBase's built-in "users" auth collection + // (passwords, tokens, verification, password reset, OTP, MFA, OAuth2). + // docwell-server forwards the auth calls; signup goes through the server + // with the superuser token, so the record API rules stay closed. + const users = app.findCollectionByNameOrId("users"); + users.listRule = null; + users.viewRule = null; + users.createRule = null; + users.updateRule = null; + users.deleteRule = null; + // Disabled accounts cannot sign in with any method. + users.authRule = "status != 'disabled'"; + users.passwordAuth.enabled = true; + users.passwordAuth.identityFields = ["email"]; + + users.fields.add(new SelectField({ name: "status", values: ["active", "invited", "disabled"], maxSelect: 1 })); + users.fields.add(new BoolField({ name: "is_admin" })); + users.fields.add(new TextField({ name: "locale", max: 16 })); + users.fields.add(new SelectField({ name: "theme", values: ["system", "light", "dark"], maxSelect: 1 })); + users.fields.add(new DateField({ name: "last_seen" })); + + // Email links open docwell-web pages ({APP_URL} = DOCWELL_WEB_URL, set by + // pb_hooks/docwell.pb.js), never the private PocketBase dashboard. + users.verificationTemplate.subject = "Verify your {APP_NAME} email"; + users.verificationTemplate.body = + "

Hello,

Confirm your email address for {APP_NAME}:

" + + '

Verify email

' + + "

If you did not create an account, you can ignore this email.

"; + users.resetPasswordTemplate.subject = "Reset your {APP_NAME} password"; + users.resetPasswordTemplate.body = + "

Hello,

Someone asked to reset the password of your {APP_NAME} account:

" + + '

Choose a new password

' + + "

If it was not you, you can ignore this email.

"; + users.confirmEmailChangeTemplate.body = + "

Hello,

Confirm your new email address for {APP_NAME}:

" + + '

Confirm new email

'; + app.save(users); + + const workspaces = new Collection({ + type: "base", + name: "workspaces", + fields: [ + { name: "name", type: "text", required: true, max: 120 }, + { name: "slug", type: "text", required: true, max: 64, pattern: "^[a-z0-9-]+$" }, + { name: "logo", type: "file", maxSelect: 1, maxSize: 2097152 }, + { name: "settings", type: "json" }, + ...timestamps(), + ], + indexes: ["CREATE UNIQUE INDEX idx_workspaces_slug ON workspaces (slug)"], + }); + app.save(workspaces); + + const workspaceMembers = new Collection({ + type: "base", + name: "workspace_members", + fields: [ + relation("workspace", workspaces, { required: true, cascadeDelete: true }), + relation("user", users, { required: true, cascadeDelete: true }), + { name: "role", type: "select", values: ["owner", "admin", "member", "guest"], maxSelect: 1, required: true }, + ...timestamps(), + ], + indexes: ["CREATE UNIQUE INDEX idx_wsm_unique ON workspace_members (workspace, user)"], + }); + app.save(workspaceMembers); + + const spaces = new Collection({ + type: "base", + name: "spaces", + fields: [ + relation("workspace", workspaces, { required: true, cascadeDelete: true }), + { name: "name", type: "text", required: true, max: 120 }, + { name: "slug", type: "text", required: true, max: 64, pattern: "^[a-z0-9-]+$" }, + { name: "icon", type: "text", max: 32 }, + { name: "description", type: "text", max: 1000 }, + { name: "visibility", type: "select", values: ["open", "private"], maxSelect: 1, required: true }, + { name: "default_role", type: "select", values: ["editor", "commenter", "viewer"], maxSelect: 1 }, + ...timestamps(), + ], + indexes: ["CREATE UNIQUE INDEX idx_spaces_slug ON spaces (workspace, slug)"], + }); + app.save(spaces); + + const spaceMembers = new Collection({ + type: "base", + name: "space_members", + fields: [ + relation("space", spaces, { required: true, cascadeDelete: true }), + { name: "principal_type", type: "select", values: ["user", "group"], maxSelect: 1, required: true }, + { name: "principal_id", type: "text", required: true }, + { name: "role", type: "select", values: ["admin", "editor", "commenter", "viewer"], maxSelect: 1, required: true }, + ...timestamps(), + ], + indexes: ["CREATE UNIQUE INDEX idx_spm_unique ON space_members (space, principal_type, principal_id)"], + }); + app.save(spaceMembers); + + const pages = new Collection({ + type: "base", + name: "pages", + fields: [ + relation("workspace", workspaces, { required: true, cascadeDelete: true }), + relation("space", spaces, { required: true, cascadeDelete: true }), + { name: "title", type: "text", max: 500 }, + { name: "icon", type: "text", max: 32 }, + { name: "cover", type: "file", maxSelect: 1, maxSize: 10485760 }, + // Fractional index string for ordering siblings without renumbering. + { name: "position", type: "text", required: true, max: 128 }, + relation("creator", users), + relation("last_editor", users), + { name: "content_json", type: "json", maxSize: 20971520 }, + { name: "content_text", type: "text", max: 0 }, + { name: "word_count", type: "number", onlyInt: true, min: 0 }, + { name: "is_template", type: "bool" }, + { name: "archived_at", type: "date" }, + { name: "deleted_at", type: "date" }, + ...timestamps(), + ], + indexes: ["CREATE INDEX idx_pages_workspace ON pages (workspace, updated)"], + }); + app.save(pages); + + // Self-relation needs the collection id, so it is added after the first save. + pages.fields.add(new RelationField({ name: "parent", collectionId: pages.id, maxSelect: 1, cascadeDelete: true })); + pages.indexes = [ + "CREATE INDEX idx_pages_workspace ON pages (workspace, updated)", + "CREATE INDEX idx_pages_tree ON pages (space, parent, position)", + ]; + app.save(pages); + + const pageYdoc = new Collection({ + type: "base", + name: "page_ydoc", + fields: [ + relation("page", pages, { required: true, cascadeDelete: true }), + { name: "state", type: "file", maxSelect: 1, maxSize: 52428800, protected: true }, + { name: "state_vector", type: "text", max: 0 }, + ...timestamps(), + ], + indexes: ["CREATE UNIQUE INDEX idx_page_ydoc_page ON page_ydoc (page)"], + }); + app.save(pageYdoc); + + const pageYupdates = new Collection({ + type: "base", + name: "page_yupdates", + fields: [ + relation("page", pages, { required: true, cascadeDelete: true }), + // Base64-encoded Yjs update; compacted into page_ydoc and pruned. + { name: "update", type: "text", required: true, max: 0 }, + { name: "client_id", type: "text", max: 32 }, + ...timestamps(), + ], + indexes: ["CREATE INDEX idx_page_yupdates_page ON page_yupdates (page, created)"], + }); + app.save(pageYupdates); + }, + (app) => { + for (const name of ["page_yupdates", "page_ydoc", "pages", "space_members", "spaces", "workspace_members", "workspaces"]) { + try { + app.delete(app.findCollectionByNameOrId(name)); + } catch (_) {} + } + const users = app.findCollectionByNameOrId("users"); + for (const name of ["status", "is_admin", "locale", "theme", "last_seen"]) { + users.fields.removeByName(name); + } + users.authRule = ""; + app.save(users); + }, +); diff --git a/Design/README.md b/Design/README.md new file mode 100644 index 0000000..c33a317 --- /dev/null +++ b/Design/README.md @@ -0,0 +1,5 @@ +# Design + +Logos, icons, mockups and other design assets for Docwell. + +The UI design tokens (colors, fonts, dark mode) live in code at `Packages/ui/src/theme.css`. Keep that file and the assets here in sync. diff --git a/Desktop-App/Taskfile.yml b/Desktop-App/Taskfile.yml new file mode 100644 index 0000000..8cabb10 --- /dev/null +++ b/Desktop-App/Taskfile.yml @@ -0,0 +1,70 @@ +version: '3' + +vars: + APP_NAME: "docwell-desktop" + BIN_DIR: "bin" + PACKAGE_MANAGER: '{{.PACKAGE_MANAGER | default "npm"}}' + VITE_PORT: '{{.WAILS_VITE_PORT | default 9245}}' + # Target OS for build/package/run. Defaults to the host OS, and is overridden + # by `wails3 build GOOS=...` (or the GOOS env var) for cross-compilation. The + # tasks below dispatch to the matching platform Taskfile via this variable. + GOOS: '{{.GOOS | default OS}}' + +includes: + common: ./build/Taskfile.yml + windows: ./build/windows/Taskfile.yml + darwin: ./build/darwin/Taskfile.yml + linux: ./build/linux/Taskfile.yml + ios: ./build/ios/Taskfile.yml + android: ./build/android/Taskfile.yml + +tasks: + build: + summary: Builds the application + cmds: + - task: "{{.GOOS}}:build" + + package: + summary: Packages a production build of the application + cmds: + - task: "{{.GOOS}}:package" + + run: + summary: Runs the application + cmds: + - task: "{{.GOOS}}:run" + + dev: + summary: Runs the application in development mode + cmds: + - wails3 dev -config ./build/config.yml -port {{.VITE_PORT}} + + install:msix:tools: + summary: Installs tools required for Windows MSIX packaging + cmds: + - task: windows:install:msix:tools + + setup:docker: + summary: Builds Docker image for cross-compilation (~800MB download) + cmds: + - task: common:setup:docker + + build:server: + summary: Builds the application in server mode (no GUI, HTTP server only) + cmds: + - task: common:build:server + + run:server: + summary: Runs the application in server mode + cmds: + - task: common:run:server + + build:docker: + summary: Builds a Docker image for server mode deployment + cmds: + - task: common:build:docker + + run:docker: + summary: Builds and runs the Docker image + cmds: + - task: common:run:docker diff --git a/Desktop-App/build/Taskfile.yml b/Desktop-App/build/Taskfile.yml new file mode 100644 index 0000000..9714b9e --- /dev/null +++ b/Desktop-App/build/Taskfile.yml @@ -0,0 +1,398 @@ +version: '3' + +tasks: + go:mod:tidy: + summary: Runs `go mod tidy` + internal: true + # Universal/multi-arch builds invoke this concurrently from parallel deps; + # two `go mod tidy` processes racing on go.mod can corrupt it (#4637). + run: once + cmds: + - go mod tidy + + install:frontend:deps: + summary: Install frontend dependencies + run: once + cmds: + - task: install:frontend:deps:{{.PACKAGE_MANAGER}} + + install:frontend:deps:npm: + dir: frontend + sources: + - package.json + - package-lock.json + generates: + - node_modules + preconditions: + - sh: npm version + msg: "Looks like npm isn't installed. Npm is part of the Node installer: https://nodejs.org/en/download/" + cmds: + - npm install + + install:frontend:deps:bun: + dir: frontend + sources: + - package.json + - bun.lock + - bun.lockb + generates: + - node_modules + preconditions: + - sh: bun --version + msg: "bun not found" + cmds: + - bun install + + install:frontend:deps:pnpm: + dir: frontend + sources: + - package.json + - pnpm-lock.yaml + generates: + - node_modules + preconditions: + - sh: pnpm --version + msg: "pnpm not found" + cmds: + - pnpm install + + install:frontend:deps:yarn: + dir: frontend + sources: + - package.json + - yarn.lock + status: + - test -d node_modules || test -f .pnp.cjs + preconditions: + - sh: yarn --version + msg: "yarn not found" + cmds: + - yarn install + + build:frontend: + label: build:frontend (DEV={{.DEV}} RUNNER={{.PACKAGE_MANAGER}}) + summary: Build the frontend project + # darwin:build:universal runs its per-arch builds as parallel deps, each of + # which depends on this task. Without run:once the two executions race: + # one regenerates frontend/bindings (-clean deletes it first) while the + # other's bundler is reading it, failing intermittently with + # 'Could not resolve "./bindings/"' (#4637). + run: once + dir: frontend + sources: + - "**/*" + - exclude: node_modules/**/* + generates: + - dist/**/* + deps: + - task: install:frontend:deps + - task: generate:bindings + vars: + BUILD_FLAGS: + ref: .BUILD_FLAGS + OBFUSCATED: + ref: .OBFUSCATED + cmds: + - task: frontend:run + vars: + SCRIPT: '{{if eq .DEV "true"}}build:dev{{else}}build{{end}}' + env: + PRODUCTION: '{{if eq .DEV "true"}}false{{else}}true{{end}}' + + frontend:run: + summary: Run a frontend script with selected runner + cmds: + - task: frontend:run:{{.PACKAGE_MANAGER}} + vars: + SCRIPT: "{{.SCRIPT}}" + vars: + SCRIPT: "{{.SCRIPT}}" + + frontend:run:npm: + dir: frontend + cmds: + - npm run {{.SCRIPT}} -q + vars: + SCRIPT: "{{.SCRIPT}}" + + frontend:run:yarn: + dir: frontend + cmds: + - yarn {{.SCRIPT}} + vars: + SCRIPT: "{{.SCRIPT}}" + + frontend:run:pnpm: + dir: frontend + cmds: + - pnpm run {{.SCRIPT}} + vars: + SCRIPT: "{{.SCRIPT}}" + + frontend:run:bun: + dir: frontend + cmds: + - bun run {{.SCRIPT}} + vars: + SCRIPT: "{{.SCRIPT}}" + + frontend:vendor:puppertino: + summary: Fetches Puppertino CSS into frontend/public for consistent mobile styling + sources: + - frontend/public/puppertino/puppertino.css + generates: + - frontend/public/puppertino/puppertino.css + cmds: + - | + set -euo pipefail + mkdir -p frontend/public/puppertino + # If bundled Puppertino exists, prefer it. Otherwise, try to fetch, but don't fail build on error. + if [ ! -f frontend/public/puppertino/puppertino.css ]; then + echo "No bundled Puppertino found. Attempting to fetch from GitHub..." + if curl -fsSL https://raw.githubusercontent.com/codedgar/Puppertino/main/dist/css/full.css -o frontend/public/puppertino/puppertino.css; then + curl -fsSL https://raw.githubusercontent.com/codedgar/Puppertino/main/LICENSE -o frontend/public/puppertino/LICENSE || true + echo "Puppertino CSS downloaded to frontend/public/puppertino/puppertino.css" + else + echo "Warning: Could not fetch Puppertino CSS. Proceeding without download since template may bundle it." + fi + else + echo "Using bundled Puppertino at frontend/public/puppertino/puppertino.css" + fi + # Ensure index.html includes Puppertino CSS and button classes + INDEX_HTML=frontend/index.html + if [ -f "$INDEX_HTML" ]; then + if ! grep -q 'href="/puppertino/puppertino.css"' "$INDEX_HTML"; then + # Insert Puppertino link tag after style.css link + awk ' + /href="\/style.css"\/?/ && !x { print; print " "; x=1; next }1 + ' "$INDEX_HTML" > "$INDEX_HTML.tmp" && mv "$INDEX_HTML.tmp" "$INDEX_HTML" + fi + # Replace default .btn with Puppertino primary button classes if present + sed -E -i'' 's/class=\"btn\"/class=\"p-btn p-prim-col\"/g' "$INDEX_HTML" || true + fi + + + + generate:bindings: + summary: Generates bindings for the frontend + run: once + deps: + - task: go:mod:tidy + sources: + - "**/*.[jt]s" + - exclude: frontend/**/* + - frontend/bindings/**/* # Rerun when switching between dev/production mode causes changes in output + - "**/*.go" + - go.mod + - go.sum + generates: + - frontend/bindings/**/* + cmds: + - wails3 generate bindings -f '{{.BUILD_FLAGS}}' -clean=true{{if eq .OBFUSCATED "true"}} -obfuscated{{end}} -ts -i + + generate:icons: + summary: Generates Windows `.ico` and Mac `.icns` from an image; on macOS, `-iconcomposerinput appicon.icon -macassetdir darwin` also produces `Assets.car` from a `.icon` file (skipped on other platforms). + run: once + dir: build + sources: + - "appicon.png" + - "appicon.icon" + generates: + - "darwin/icons.icns" + - "windows/icon.ico" + cmds: + - wails3 generate icons -input appicon.png -macfilename darwin/icons.icns -windowsfilename windows/icon.ico -iconcomposerinput appicon.icon -macassetdir darwin + + dev:frontend: + summary: Runs the frontend in development mode + deps: + - task: install:frontend:deps + cmds: + - task: frontend:dev:{{.PACKAGE_MANAGER}} + + frontend:dev:npm: + dir: frontend + cmds: + - npm run dev -- --port {{.VITE_PORT}} --strictPort + + frontend:dev:yarn: + dir: frontend + cmds: + - yarn dev --port {{.VITE_PORT}} --strictPort + + frontend:dev:pnpm: + dir: frontend + cmds: + - pnpm dev --port {{.VITE_PORT}} --strictPort + + frontend:dev:bun: + dir: frontend + cmds: + - bun run dev --port {{.VITE_PORT}} --strictPort + + update:build-assets: + summary: Updates the build assets + dir: build + cmds: + - wails3 update build-assets -name "{{.APP_NAME}}" -binaryname "{{.APP_NAME}}" -config config.yml -dir . + + build:server: + summary: Builds the application in server mode (no GUI, HTTP server only) + desc: | + Builds a production server binary by default: -tags server,production, + -trimpath and a stripped binary, mirroring the desktop `build` task. + Server mode runs as a pure HTTP server without native GUI dependencies. + + Usage: task build:server [DEV=true] [OBFUSCATED=true] [EXTRA_TAGS=tag1,tag2] + DEV=true development server (-tags server, no strip, inlining kept) + OBFUSCATED=true obfuscated build via garble (requires garble installed) + EXTRA_TAGS additional comma-separated build tags + deps: + - task: build:frontend + vars: + DEV: + ref: .DEV + BUILD_FLAGS: + ref: .BUILD_FLAGS + OBFUSCATED: + ref: .OBFUSCATED + preconditions: + - sh: '{{if eq .OBFUSCATED "true"}}command -v garble >/dev/null 2>&1{{else}}true{{end}}' + msg: "garble is required for obfuscated builds. Install it with: go install mvdan.cc/garble@v0.16.0 (requires Go 1.24+). See https://github.com/burrowers/garble/releases for version/toolchain compatibility." + cmds: + - '{{if eq .OBFUSCATED "true"}}garble {{.GARBLE_ARGS}} build{{else}}go build{{end}} {{.BUILD_FLAGS}} -o "{{.BIN_DIR}}/{{.APP_NAME}}-server{{exeExt}}"' + vars: + BUILD_FLAGS: '-tags server{{if eq .DEV "true"}}{{if eq .OBFUSCATED "true"}},wails_obfuscated{{end}}{{if .EXTRA_TAGS}},{{.EXTRA_TAGS}}{{end}} -buildvcs=false -gcflags=all="-l"{{else}},production{{if eq .OBFUSCATED "true"}},wails_obfuscated{{end}}{{if .EXTRA_TAGS}},{{.EXTRA_TAGS}}{{end}} -trimpath -buildvcs=false -ldflags="-w -s"{{end}}' + + run:server: + summary: Builds and runs a development server (DEV=true) + deps: + - task: build:server + vars: + DEV: "true" + cmds: + - '"./{{.BIN_DIR}}/{{.APP_NAME}}-server{{exeExt}}"' + + build:docker: + summary: Builds a Docker image for server mode deployment + desc: | + Creates a minimal Docker image containing the production server binary. + Defaults to a pure-Go static binary on a distroless/static base. The + production frontend is built first so the embedded assets are current. + + Usage: task build:docker [TAG=myapp:latest] [CGO_ENABLED=1] [GO_IMAGE=...] [RUNTIME_IMAGE=...] + For CGO apps, set CGO_ENABLED=1 with libc-compatible builder/runtime images, e.g.: + task build:docker CGO_ENABLED=1 GO_IMAGE=golang:bookworm RUNTIME_IMAGE=gcr.io/distroless/base-debian12 + deps: + # Build the production frontend so frontend/dist (embedded by the Go build + # inside the image) is present and current in the Docker build context. + # Pass the server,production tags so binding generation analyses the same + # build the Docker image compiles, not the default-tag build. + - task: build:frontend + vars: + BUILD_FLAGS: "-tags server,production" + cmds: + - >- + docker build + --build-arg CGO_ENABLED={{.CGO_ENABLED | default "0"}} + --build-arg GO_IMAGE={{.GO_IMAGE | default "golang:alpine"}} + --build-arg RUNTIME_IMAGE={{.RUNTIME_IMAGE | default "gcr.io/distroless/static-debian12"}} + -t {{.TAG | default (printf "%s:latest" .APP_NAME)}} + -f build/docker/Dockerfile.server . + vars: + TAG: "{{.TAG}}" + preconditions: + - sh: docker info > /dev/null 2>&1 + msg: "Docker is required. Please install Docker first." + - sh: test -f build/docker/Dockerfile.server + msg: "Dockerfile.server not found. Run 'wails3 update build-assets' to generate it." + + run:docker: + summary: Builds and runs the Docker image + desc: | + Builds the Docker image and runs it, exposing port 8080. + Usage: task run:docker [TAG=myapp:latest] [PORT=8080] + Note: The internal container port is always 8080. The PORT variable + only changes the host port mapping. Ensure your app uses port 8080 + or modify the Dockerfile to match your ServerOptions.Port setting. + deps: + - task: build:docker + vars: + TAG: + ref: .TAG + cmds: + - docker run --rm -p {{.PORT | default "8080"}}:8080 {{.TAG | default (printf "%s:latest" .APP_NAME)}} + vars: + TAG: "{{.TAG}}" + PORT: "{{.PORT}}" + + setup:docker: + summary: Builds Docker image for cross-compilation (~800MB download) + desc: | + Builds the Docker image needed for cross-compiling to any platform. + Run this once to enable cross-platform builds from any OS. + cmds: + - docker build -t wails-cross -f build/docker/Dockerfile.cross build/docker/ + preconditions: + - sh: docker info > /dev/null 2>&1 + msg: "Docker is required. Please install Docker first." + + ios:device:list: + summary: Lists connected iOS devices (UDIDs) + cmds: + - xcrun xcdevice list + + ios:run:device: + summary: Build, install, and launch on a physical iPhone using Apple tools (xcodebuild/devicectl) + vars: + PROJECT: '{{.PROJECT}}' # e.g., build/ios/xcode/.xcodeproj + SCHEME: '{{.SCHEME}}' # e.g., ios.dev + CONFIG: '{{.CONFIG | default "Debug"}}' + DERIVED: '{{.DERIVED | default "build/ios/DerivedData"}}' + UDID: '{{.UDID}}' # from `task ios:device:list` + BUNDLE_ID: '{{.BUNDLE_ID}}' # e.g., com.yourco.wails.ios.dev + TEAM_ID: '{{.TEAM_ID}}' # optional, if your project is not already set up for signing + preconditions: + - sh: xcrun -f xcodebuild + msg: "xcodebuild not found. Please install Xcode." + - sh: xcrun -f devicectl + msg: "devicectl not found. Please update to Xcode 15+ (which includes devicectl)." + - sh: test -n '{{.PROJECT}}' + msg: "Set PROJECT to your .xcodeproj path (e.g., PROJECT=build/ios/xcode/App.xcodeproj)." + - sh: test -n '{{.SCHEME}}' + msg: "Set SCHEME to your app scheme (e.g., SCHEME=ios.dev)." + - sh: test -n '{{.UDID}}' + msg: "Set UDID to your device UDID (see: task ios:device:list)." + - sh: test -n '{{.BUNDLE_ID}}' + msg: "Set BUNDLE_ID to your app's bundle identifier (e.g., com.yourco.wails.ios.dev)." + cmds: + - | + set -euo pipefail + echo "Building for device: UDID={{.UDID}} SCHEME={{.SCHEME}} PROJECT={{.PROJECT}}" + XCB_ARGS=( + -project "{{.PROJECT}}" + -scheme "{{.SCHEME}}" + -configuration "{{.CONFIG}}" + -destination "id={{.UDID}}" + -derivedDataPath "{{.DERIVED}}" + -allowProvisioningUpdates + -allowProvisioningDeviceRegistration + ) + # Optionally inject signing identifiers if provided + if [ -n '{{.TEAM_ID}}' ]; then XCB_ARGS+=(DEVELOPMENT_TEAM={{.TEAM_ID}}); fi + if [ -n '{{.BUNDLE_ID}}' ]; then XCB_ARGS+=(PRODUCT_BUNDLE_IDENTIFIER={{.BUNDLE_ID}}); fi + xcodebuild "${XCB_ARGS[@]}" build | xcpretty || true + # If xcpretty isn't installed, run without it + if [ "${PIPESTATUS[0]}" -ne 0 ]; then + xcodebuild "${XCB_ARGS[@]}" build + fi + # Find built .app + APP_PATH=$(find "{{.DERIVED}}/Build/Products" -type d -name "*.app" -maxdepth 3 | head -n 1) + if [ -z "$APP_PATH" ]; then + echo "Could not locate built .app under {{.DERIVED}}/Build/Products" >&2 + exit 1 + fi + echo "Installing: $APP_PATH" + xcrun devicectl device install app --device "{{.UDID}}" "$APP_PATH" + echo "Launching: {{.BUNDLE_ID}}" + xcrun devicectl device process launch --device "{{.UDID}}" --stderr console --stdout console "{{.BUNDLE_ID}}" diff --git a/Desktop-App/build/android/Taskfile.yml b/Desktop-App/build/android/Taskfile.yml new file mode 100644 index 0000000..980b700 --- /dev/null +++ b/Desktop-App/build/android/Taskfile.yml @@ -0,0 +1,464 @@ +version: '3' + +includes: + common: ../Taskfile.yml + +vars: + APP_ID: '{{.APP_ID | default "com.wails.app"}}' + MIN_SDK: '21' + TARGET_SDK: '35' + # The emulator runs the host architecture; physical devices are arm64 + HOST_ARCH: + sh: '[ "$(uname -m)" = "x86_64" ] && echo "amd64" || echo "arm64"' + # System-image ABI for the host, used in the "create an AVD" hint below. + ANDROID_ABI: + sh: '[ "$(uname -m)" = "arm64" ] && echo "arm64-v8a" || echo "x86_64"' + # SDK location: $ANDROID_HOME / $ANDROID_SDK_ROOT, else the per-OS default + # (macOS: ~/Library/Android/sdk, Linux/other: ~/Android/Sdk) + SDK_ROOT: + sh: 'echo "${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$([ -d "$HOME/Library/Android/sdk" ] && echo "$HOME/Library/Android/sdk" || echo "$HOME/Android/Sdk")}}"' + ADB: + sh: 'command -v adb || echo "${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$([ -d "$HOME/Library/Android/sdk" ] && echo "$HOME/Library/Android/sdk" || echo "$HOME/Android/Sdk")}}/platform-tools/adb"' + EMULATOR: + sh: 'command -v emulator || echo "${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$([ -d "$HOME/Library/Android/sdk" ] && echo "$HOME/Library/Android/sdk" || echo "$HOME/Android/Sdk")}}/emulator/emulator"' + # avdmanager lives under cmdline-tools//bin; used to auto-create an + # AVD when none exists (mirrors the iOS `ensure-simulator` auto-create flow). + AVDMANAGER: + sh: 'command -v avdmanager || ls "${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$([ -d "$HOME/Library/Android/sdk" ] && echo "$HOME/Library/Android/sdk" || echo "$HOME/Android/Sdk")}}"/cmdline-tools/*/bin/avdmanager 2>/dev/null | sort -V | tail -1 || true' + +tasks: + install:deps: + summary: Check and install Android development dependencies + cmds: + - go run build/android/scripts/deps/install_deps.go + env: + TASK_FORCE_YES: '{{if .YES}}true{{else}}false{{end}}' + prompt: This will check and install Android development dependencies. Continue? + + build: + summary: Creates a debug build of the application for Android + deps: + - task: common:go:mod:tidy + - task: generate:android:overlay + - task: common:build:frontend + vars: + BUILD_FLAGS: + ref: .BUILD_FLAGS + PRODUCTION: + ref: .PRODUCTION + cmds: + - echo "Building Android app {{.APP_NAME}}..." + - task: compile:go:shared + vars: + ARCH: '{{.ARCH | default .HOST_ARCH}}' + vars: + BUILD_FLAGS: '{{if eq .PRODUCTION "true"}}-tags production,android -trimpath -buildvcs=false -ldflags="-w -s"{{else}}-tags android,debug -buildvcs=false -gcflags=all="-l"{{end}}' + env: + PRODUCTION: '{{.PRODUCTION | default "false"}}' + + compile:go:shared: + summary: Compile Go code to shared library (.so) + cmds: + - | + # Locate the NDK: $ANDROID_NDK_HOME, or the newest installed NDK + NDK_ROOT="$ANDROID_NDK_HOME" + if [ -z "$NDK_ROOT" ]; then + SDK_ROOT="{{.SDK_ROOT}}" + NDK_ROOT=$(ls -d "$SDK_ROOT"/ndk/* 2>/dev/null | sort -V | tail -1) + fi + if [ -z "$NDK_ROOT" ] || [ ! -d "$NDK_ROOT" ]; then + echo "Error: Android NDK not found" + echo "Install one with: sdkmanager 'ndk;26.3.11579264' (or set ANDROID_NDK_HOME)" + exit 1 + fi + + # Determine toolchain based on host OS + case "$(uname -s)" in + Darwin) HOST_TAG="darwin-x86_64" ;; + Linux) HOST_TAG="linux-x86_64" ;; + *) echo "Unsupported host OS"; exit 1 ;; + esac + + TOOLCHAIN="$NDK_ROOT/toolchains/llvm/prebuilt/$HOST_TAG" + + # Set compiler based on architecture + case "{{.ARCH}}" in + arm64) + export CC="$TOOLCHAIN/bin/aarch64-linux-android{{.MIN_SDK}}-clang" + export CXX="$TOOLCHAIN/bin/aarch64-linux-android{{.MIN_SDK}}-clang++" + export GOARCH=arm64 + JNI_DIR="arm64-v8a" + ;; + amd64|x86_64) + export CC="$TOOLCHAIN/bin/x86_64-linux-android{{.MIN_SDK}}-clang" + export CXX="$TOOLCHAIN/bin/x86_64-linux-android{{.MIN_SDK}}-clang++" + export GOARCH=amd64 + JNI_DIR="x86_64" + ;; + *) + echo "Unsupported architecture: {{.ARCH}}" + exit 1 + ;; + esac + + export CGO_ENABLED=1 + export GOOS=android + + mkdir -p {{.BIN_DIR}} + mkdir -p build/android/app/src/main/jniLibs/$JNI_DIR + + go build -buildmode=c-shared -overlay build/android/overlay.json {{.BUILD_FLAGS}} \ + -o build/android/app/src/main/jniLibs/$JNI_DIR/libwails.so + vars: + BUILD_FLAGS: '{{if eq .PRODUCTION "true"}}-tags production,android -trimpath -buildvcs=false -ldflags="-w -s"{{else}}-tags android,debug -buildvcs=false -gcflags=all="-l"{{end}}' + + compile:go:all-archs: + summary: Compile Go code for all Android architectures (fat APK) + cmds: + - task: compile:go:shared + vars: + ARCH: arm64 + - task: compile:go:shared + vars: + ARCH: amd64 + + package: + summary: Packages a production build of the application into a signed release APK + desc: | + Builds for arm64 by default (covers 99%+ of real devices). Set ARCH=amd64 + for emulator-only APKs, or use package:fat for a universal APK. + deps: + - task: build + vars: + PRODUCTION: "true" + ARCH: '{{.ARCH | default "arm64"}}' + cmds: + - task: assemble:apk:release + + package:fat: + summary: Packages a production build for all architectures (fat APK) + deps: + - task: build + vars: + PRODUCTION: "true" + ARCH: arm64 + cmds: + - task: compile:go:shared + vars: + ARCH: amd64 + PRODUCTION: "true" + - task: assemble:apk:release + + bundle: + summary: Packages a production AAB (Android App Bundle) for Play Store submission + desc: | + Builds for arm64 by default. Set ARCH=amd64 for emulator builds, or use + bundle:fat for a universal AAB. + deps: + - task: build + vars: + PRODUCTION: "true" + ARCH: '{{.ARCH | default "arm64"}}' + cmds: + - task: assemble:aab:release + + bundle:fat: + summary: Packages a production AAB for all architectures + deps: + - task: build + vars: + PRODUCTION: "true" + ARCH: arm64 + cmds: + - task: compile:go:shared + vars: + ARCH: amd64 + PRODUCTION: "true" + - task: assemble:aab:release + + assemble:apk: + summary: Assembles a debug APK using Gradle + preconditions: + - sh: 'command -v java >/dev/null || [ -n "$JAVA_HOME" ]' + msg: "Java not found. Install a JDK (e.g. brew install openjdk@21) and/or set JAVA_HOME" + cmds: + - | + cd build/android + # The exec bit is lost when gradlew is extracted from the embedded + # build assets, so restore it before invoking the wrapper. + chmod +x ./gradlew + ./gradlew assembleDebug + cp app/build/outputs/apk/debug/app-debug.apk "../../{{.BIN_DIR}}/{{.APP_NAME}}.apk" + echo "APK created: {{.BIN_DIR}}/{{.APP_NAME}}.apk" + + assemble:apk:release: + summary: Assembles a release APK using Gradle (signed with the debug keystore unless ANDROID_KEYSTORE_FILE is set) + preconditions: + - sh: 'command -v java >/dev/null || [ -n "$JAVA_HOME" ]' + msg: "Java not found. Install a JDK (e.g. brew install openjdk@21) and/or set JAVA_HOME" + cmds: + - | + cd build/android + # The exec bit is lost when gradlew is extracted from the embedded + # build assets, so restore it before invoking the wrapper. + chmod +x ./gradlew + ./gradlew assembleRelease + cp app/build/outputs/apk/release/app-release.apk "../../{{.BIN_DIR}}/{{.APP_NAME}}.apk" + echo "Release APK created: {{.BIN_DIR}}/{{.APP_NAME}}.apk" + + assemble:aab: + summary: Assembles a debug AAB (Android App Bundle) using Gradle + preconditions: + - sh: 'command -v java >/dev/null || [ -n "$JAVA_HOME" ]' + msg: "Java not found. Install a JDK (e.g. brew install openjdk@21) and/or set JAVA_HOME" + cmds: + - | + cd build/android + # The exec bit is lost when gradlew is extracted from the embedded + # build assets, so restore it before invoking the wrapper. + chmod +x ./gradlew + ./gradlew bundleDebug + cp app/build/outputs/bundle/debug/app-debug.aab "../../{{.BIN_DIR}}/{{.APP_NAME}}.aab" + echo "AAB created: {{.BIN_DIR}}/{{.APP_NAME}}.aab" + + assemble:aab:release: + summary: Assembles a release AAB for Play Store upload (signed with the debug keystore unless ANDROID_KEYSTORE_FILE is set) + preconditions: + - sh: 'command -v java >/dev/null || [ -n "$JAVA_HOME" ]' + msg: "Java not found. Install a JDK (e.g. brew install openjdk@21) and/or set JAVA_HOME" + cmds: + - | + # With Play App Signing, the keystore configured here is your UPLOAD + # key: Google verifies the upload with it, then re-signs the app with + # the app signing key it manages for distribution. + if [ -z "$ANDROID_KEYSTORE_FILE" ]; then + echo "WARNING: ANDROID_KEYSTORE_FILE is not set, so this AAB will be" + echo "signed with the debug keystore. Google Play rejects debug-signed" + echo "bundles. Set ANDROID_KEYSTORE_FILE, ANDROID_KEYSTORE_PASSWORD," + echo "ANDROID_KEY_ALIAS and ANDROID_KEY_PASSWORD before uploading." + fi + cd build/android + # The exec bit is lost when gradlew is extracted from the embedded + # build assets, so restore it before invoking the wrapper. + chmod +x ./gradlew + ./gradlew bundleRelease + cp app/build/outputs/bundle/release/app-release.aab "../../{{.BIN_DIR}}/{{.APP_NAME}}.aab" + echo "Release AAB created: {{.BIN_DIR}}/{{.APP_NAME}}.aab" + + generate:android:overlay: + internal: true + summary: Generate Go build overlay that registers the Android main + sources: + - build/config.yml + generates: + - build/android/overlay.json + - build/android/gen/main_android.gen.go + cmds: + - wails3 android overlay:gen -out build/android/overlay.json -config build/config.yml + + generate:android:bindings: + internal: true + summary: Generates bindings for Android + sources: + - "**/*.go" + - go.mod + - go.sum + generates: + - frontend/bindings/**/* + cmds: + # Bindings are generated from the Go AST; CGO is disabled so the NDK + # is not required for this step + - wails3 generate bindings -f '-tags android' -clean=true + env: + GOOS: android + CGO_ENABLED: 0 + + ensure-emulator: + internal: true + summary: Ensure Android Emulator is running + silent: true + cmds: + - | + # Check if an emulator is already running + if "{{.ADB}}" devices | grep -q "emulator"; then + echo "Emulator already running" + exit 0 + fi + + # Get first available AVD + AVD_NAME=$("{{.EMULATOR}}" -list-avds | tail -1) + if [ -z "$AVD_NAME" ]; then + # No AVD yet. Mirror the iOS `ensure-simulator` flow and create one + # automatically — but ONLY from a system image that is already + # installed. We never trigger an sdkmanager download from a `run` + # task (that would be a surprise multi-GB download + license prompt). + # Pick the highest-API installed image matching the host ABI. + SDK_ROOT="{{.SDK_ROOT}}" + ABI="{{.ANDROID_ABI}}" + IMG=$(ls -d "$SDK_ROOT"/system-images/android-*/*/"$ABI" 2>/dev/null | sort -V | tail -1) + AVDMANAGER="{{.AVDMANAGER}}" + if [ -n "$IMG" ] && [ -x "$AVDMANAGER" ]; then + PKG="system-images;$(echo "$IMG" | sed "s|$SDK_ROOT/system-images/||" | tr '/' ';')" + echo "No Android Virtual Devices found. Creating 'wails' from $PKG..." + echo "no" | "$AVDMANAGER" create avd --name wails --package "$PKG" --device pixel_7 --force + AVD_NAME=wails + else + echo "No Android Virtual Devices found, and no system image is installed to create one from." + echo "Install a system image and create an AVD, e.g.:" + echo " sdkmanager 'system-images;android-35;google_apis;$ABI'" + echo " avdmanager create avd --name wails --package 'system-images;android-35;google_apis;$ABI' --device pixel_7" + exit 1 + fi + fi + + echo "Starting emulator: $AVD_NAME" + # Start the emulator daemonized so it outlives this task step. go-task's + # shell tracks background jobs by PID and reaps them when the command's + # interpreter finishes (which nohup/setsid alone don't prevent — the kill + # is direct), so a bare `emulator &` is gone before the later + # install/launch steps run. Launch it from a short-lived child shell that + # backgrounds the emulator and exits immediately: the emulator is then + # reparented to init/launchd and go-task's shell has no handle to reap it. + nohup sh -c "'{{.EMULATOR}}' -avd '$AVD_NAME' -no-snapshot-load /dev/null 2>&1 &" >/dev/null 2>&1 + + # Wait for emulator to boot (max 120 seconds) + echo "Waiting for emulator to boot..." + "{{.ADB}}" wait-for-device + + for i in $(seq 1 120); do + BOOT_COMPLETED=$("{{.ADB}}" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r') + if [ "$BOOT_COMPLETED" = "1" ]; then + echo "Emulator booted successfully" + exit 0 + fi + sleep 1 + done + + echo "Emulator boot timeout" + exit 1 + preconditions: + - sh: '[ -x "{{.ADB}}" ] || command -v adb' + msg: "adb not found. Install the Android SDK platform-tools (or set ANDROID_HOME)" + - sh: '[ -x "{{.EMULATOR}}" ] || command -v emulator' + msg: "emulator not found. Install the Android SDK emulator package (or set ANDROID_HOME)" + + deploy-emulator: + summary: Deploy the packaged release APK to the Android Emulator + deps: + - task: package + vars: + ARCH: '{{.ARCH | default .HOST_ARCH}}' + cmds: + - task: ensure-emulator + - '"{{.ADB}}" uninstall {{.APP_ID}} 2>/dev/null || true' + - '"{{.ADB}}" install "{{.BIN_DIR}}/{{.APP_NAME}}.apk"' + - '"{{.ADB}}" shell am start -n {{.APP_ID}}/com.wails.app.MainActivity' + + run: + summary: Build, install and launch a debug build in the Android Emulator + deps: + - task: ensure-emulator + - task: build + cmds: + - task: assemble:apk + - '"{{.ADB}}" uninstall {{.APP_ID}} 2>/dev/null || true' + - '"{{.ADB}}" install "{{.BIN_DIR}}/{{.APP_NAME}}.apk"' + - '"{{.ADB}}" shell am start -n {{.APP_ID}}/com.wails.app.MainActivity' + + device:list: + summary: Lists connected Android devices and emulators (serials) + cmds: + - '"{{.ADB}}" devices -l' + + run:device: + summary: Build, install and launch a debug build on a connected physical Android device + deps: + - task: build + vars: + ARCH: arm64 + cmds: + - task: assemble:apk + - | + DEVICE='{{.DEVICE_ID | default ""}}' + if [ -z "$DEVICE" ]; then + DEVICE="${DEVICE_ID:-}" + fi + if [ -z "$DEVICE" ]; then + DEVICE=$("{{.ADB}}" devices | awk 'NR > 1 && $2 == "device" && $1 !~ /^emulator-/ { print $1; exit }') + fi + if [ -z "$DEVICE" ]; then + echo "Error: no connected physical Android device found." + echo "Pass DEVICE_ID= to target a device explicitly." + echo "Find connected device serials with: {{.ADB}} devices" + exit 1 + fi + + echo "Deploying {{.BIN_DIR}}/{{.APP_NAME}}.apk to device $DEVICE..." + "{{.ADB}}" -s "$DEVICE" uninstall {{.APP_ID}} 2>/dev/null || true + "{{.ADB}}" -s "$DEVICE" install "{{.BIN_DIR}}/{{.APP_NAME}}.apk" + "{{.ADB}}" -s "$DEVICE" shell am start -n {{.APP_ID}}/com.wails.app.MainActivity + preconditions: + - sh: '[ -x "{{.ADB}}" ] || command -v adb' + msg: "adb not found. Install the Android SDK platform-tools (or set ANDROID_HOME)" + + deploy-device: + summary: Deploy the packaged release APK to a connected physical Android device + deps: + - task: package + vars: + ARCH: arm64 + cmds: + - | + DEVICE='{{.DEVICE_ID | default ""}}' + if [ -z "$DEVICE" ]; then + DEVICE="${DEVICE_ID:-}" + fi + if [ -z "$DEVICE" ]; then + DEVICE=$("{{.ADB}}" devices | awk 'NR > 1 && $2 == "device" && $1 !~ /^emulator-/ { print $1; exit }') + fi + if [ -z "$DEVICE" ]; then + echo "Error: no connected physical Android device found." + echo "Pass DEVICE_ID= to target a device explicitly." + echo "Find connected device serials with: {{.ADB}} devices" + exit 1 + fi + + echo "Deploying {{.BIN_DIR}}/{{.APP_NAME}}.apk to device $DEVICE..." + "{{.ADB}}" -s "$DEVICE" uninstall {{.APP_ID}} 2>/dev/null || true + "{{.ADB}}" -s "$DEVICE" install "{{.BIN_DIR}}/{{.APP_NAME}}.apk" + "{{.ADB}}" -s "$DEVICE" shell am start -n {{.APP_ID}}/com.wails.app.MainActivity + preconditions: + - sh: '[ -x "{{.ADB}}" ] || command -v adb' + msg: "adb not found. Install the Android SDK platform-tools (or set ANDROID_HOME)" + + studio: + summary: Open the generated Android project in Android Studio + cmds: + - | + if command -v studio >/dev/null 2>&1; then + studio build/android + elif [ -d "/Applications/Android Studio.app" ]; then + open -a "Android Studio" build/android + else + echo "Android Studio not found. Install it from https://developer.android.com/studio," + echo "then open the build/android directory." + exit 1 + fi + + logs: + summary: Stream Android logcat filtered to this app + cmds: + - '"{{.ADB}}" logcat -v time | grep -E "(Wails|{{.APP_NAME}})" || true' + + logs:all: + summary: Stream all Android logcat (verbose) + cmds: + - '"{{.ADB}}" logcat -v time' + + clean: + summary: Clean build artifacts + cmds: + - rm -rf {{.BIN_DIR}} + - rm -rf build/android/app/build + - rm -rf build/android/app/src/main/jniLibs/*/libwails.so + - rm -rf build/android/.gradle diff --git a/Desktop-App/build/android/app/build.gradle b/Desktop-App/build/android/app/build.gradle new file mode 100644 index 0000000..9c69943 --- /dev/null +++ b/Desktop-App/build/android/app/build.gradle @@ -0,0 +1,83 @@ +plugins { + id 'com.android.application' +} + +android { + namespace 'com.wails.app' + compileSdk 35 + + buildFeatures { + buildConfig = true + } + + defaultConfig { + applicationId "com.wails.app" + minSdk 21 + targetSdk 35 + versionCode 1 + versionName "1.0" + + // Configure supported ABIs + ndk { + abiFilters 'arm64-v8a', 'x86_64' + } + } + + def keystoreFile = System.getenv("ANDROID_KEYSTORE_FILE") + def hasKeystore = keystoreFile != null && !keystoreFile.trim().isEmpty() + + signingConfigs { + // A real keystore can be provided via environment variables; without + // one, release builds are signed with the debug keystore so they can + // be installed for testing (not suitable for Play Store uploads). + release { + if (hasKeystore) { + storeFile file(keystoreFile) + storePassword System.getenv("ANDROID_KEYSTORE_PASSWORD") + keyAlias System.getenv("ANDROID_KEY_ALIAS") + keyPassword System.getenv("ANDROID_KEY_PASSWORD") + } + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + signingConfig hasKeystore ? signingConfigs.release : signingConfigs.debug + } + debug { + debuggable true + } + } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } + + // Source sets configuration + sourceSets { + main { + // JNI libraries are in jniLibs folder + jniLibs.srcDirs = ['src/main/jniLibs'] + // Assets for the WebView + assets.srcDirs = ['src/main/assets'] + } + } + + // Packaging options + packagingOptions { + // Don't strip Go symbols in debug builds + doNotStrip '*/arm64-v8a/libwails.so' + doNotStrip '*/x86_64/libwails.so' + } +} + +dependencies { + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'androidx.webkit:webkit:1.9.0' + implementation 'com.google.android.material:material:1.11.0' + implementation 'androidx.biometric:biometric:1.1.0' + implementation 'androidx.security:security-crypto:1.1.0-alpha06' +} diff --git a/Desktop-App/build/android/app/proguard-rules.pro b/Desktop-App/build/android/app/proguard-rules.pro new file mode 100644 index 0000000..8b88c3d --- /dev/null +++ b/Desktop-App/build/android/app/proguard-rules.pro @@ -0,0 +1,12 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. + +# Keep native methods +-keepclasseswithmembernames class * { + native ; +} + +# Keep Wails bridge classes +-keep class com.wails.app.WailsBridge { *; } +-keep class com.wails.app.WailsJSBridge { *; } diff --git a/Desktop-App/build/android/app/src/main/AndroidManifest.xml b/Desktop-App/build/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..03d343a --- /dev/null +++ b/Desktop-App/build/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Desktop-App/build/android/app/src/main/java/com/wails/app/MainActivity.java b/Desktop-App/build/android/app/src/main/java/com/wails/app/MainActivity.java new file mode 100644 index 0000000..7b71d3c --- /dev/null +++ b/Desktop-App/build/android/app/src/main/java/com/wails/app/MainActivity.java @@ -0,0 +1,821 @@ +package com.wails.app; + +import android.annotation.SuppressLint; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.res.Configuration; +import android.database.Cursor; +import android.net.ConnectivityManager; +import android.net.Network; +import android.net.NetworkCapabilities; +import android.net.Uri; +import android.os.BatteryManager; +import android.os.Build; +import android.os.Bundle; +import android.os.PowerManager; +import android.content.pm.PackageManager; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.provider.MediaStore; +import android.provider.OpenableColumns; +import android.util.Base64; +import android.util.Log; +import android.webkit.WebResourceRequest; +import android.webkit.WebResourceResponse; +import android.webkit.WebSettings; +import android.webkit.WebView; +import android.webkit.WebViewClient; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.FileProvider; +import androidx.webkit.WebViewAssetLoader; + +import org.json.JSONObject; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +/** + * MainActivity hosts the WebView and manages the Wails application lifecycle. + * It uses WebViewAssetLoader to serve assets from the Go library without + * requiring a network server. + */ +public class MainActivity extends AppCompatActivity { + private static final String TAG = "WailsActivity"; + private static final boolean DEBUG = BuildConfig.DEBUG; + private static final String WAILS_SCHEME = "https"; + private static final String WAILS_HOST = "wails.localhost"; + private static final int FILE_PICKER_REQUEST = 7001; + + private WebView webView; + private WailsBridge bridge; + // Battery: system-event receivers are registered only while the activity is + // in the foreground (onStart) and torn down in onStop, so background battery/ + // network/screen broadcasts don't wake the app. + private boolean systemReceiversRegistered = false; + private WebViewAssetLoader assetLoader; + + // The Go-side dialog ID of the in-flight file picker (-1 when idle) + private int pendingFilePickerCallbackID = -1; + private static final int PHOTO_CAPTURE_REQUEST = 7002; + private static final int VIDEO_CAPTURE_REQUEST = 7003; + private static final int CAMERA_PERMISSION_REQUEST = 7010; + private File pendingCaptureFile; + private boolean pendingCaptureIsVideo; + + // System-event sources (battery/power, screen lock, network). Registered in + // onCreate, torn down in onDestroy. Each forwards a "system:*" event to JS + // via the bridge. + private BroadcastReceiver batteryReceiver; + private BroadcastReceiver screenReceiver; + private BroadcastReceiver powerSaveReceiver; + private ConnectivityManager connectivityManager; + private ConnectivityManager.NetworkCallback networkCallback; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + // Initialize the native Go library + bridge = new WailsBridge(this); + bridge.initialize(); + + // Set up WebView + setupWebView(); + + // Load the application + loadApplication(); + } + + @SuppressLint("SetJavaScriptEnabled") + private void setupWebView() { + webView = findViewById(R.id.webview); + bridge.setWebView(webView); + + // Configure WebView settings + WebSettings settings = webView.getSettings(); + settings.setJavaScriptEnabled(true); + settings.setDomStorageEnabled(true); + settings.setDatabaseEnabled(true); + settings.setAllowFileAccess(false); + settings.setAllowContentAccess(false); + settings.setMediaPlaybackRequiresUserGesture(false); + settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW); + + // Enable debugging in debug builds + if (DEBUG) { + WebView.setWebContentsDebuggingEnabled(true); + } + + // Set up asset loader for serving local assets + assetLoader = new WebViewAssetLoader.Builder() + .setDomain(WAILS_HOST) + .addPathHandler("/", new WailsPathHandler(bridge)) + .build(); + + // Set up WebView client to intercept requests + webView.setWebViewClient(new WebViewClient() { + @Nullable + @Override + public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { + // Handle wails.localhost requests + if (request.getUrl().getHost() != null && + request.getUrl().getHost().equals(WAILS_HOST)) { + + // For wails API calls (runtime, capabilities, etc.) pass the + // full URL including the query string, because + // WebViewAssetLoader.PathHandler strips query params + String path = request.getUrl().getPath(); + if (path != null && path.startsWith("/wails/")) { + String fullPath = path; + String query = request.getUrl().getQuery(); + if (query != null && !query.isEmpty()) { + fullPath = path + "?" + query; + } + if (DEBUG) Log.d(TAG, "Wails API call: " + fullPath); + + byte[] data = bridge.serveAsset(fullPath, request.getMethod(), "{}"); + if (data != null && data.length > 0) { + java.io.InputStream inputStream = new java.io.ByteArrayInputStream(data); + java.util.Map headers = new java.util.HashMap<>(); + headers.put("Access-Control-Allow-Origin", "*"); + headers.put("Cache-Control", "no-cache"); + headers.put("Content-Type", "application/json"); + + return new WebResourceResponse( + "application/json", + "UTF-8", + 200, + "OK", + headers, + inputStream + ); + } + // Return error response if data is null + return new WebResourceResponse( + "application/json", + "UTF-8", + 500, + "Internal Error", + new java.util.HashMap<>(), + new java.io.ByteArrayInputStream("{}".getBytes()) + ); + } + + // Stream captured photos/videos from the cache with HTTP Range + // support so