Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6eeebd39ad | ||
|
|
3c1f2c7177 | ||
|
|
a9576ac141 | ||
|
|
fb4bb2a0c3 | ||
|
|
76bc312bb9 | ||
|
|
d353b5b335 | ||
|
|
3d78e0deaf | ||
|
|
41aeefc182 | ||
|
|
f9b20d51ff | ||
|
|
8be107013d | ||
|
|
ddcd799f16 | ||
|
|
7b7b892332 | ||
|
|
be3755e50e | ||
|
|
dbfc4e8d0a | ||
|
|
cd44ee3866 | ||
|
|
a0262b97b3 | ||
|
|
2da414fb3b | ||
|
|
5cad11f3f9 | ||
|
|
dbef71f830 | ||
|
|
963049add3 | ||
|
|
6179ad73e7 | ||
|
|
1e397d0211 | ||
|
|
47d38bcd4d | ||
|
|
9d06642ca6 | ||
|
|
b6290aa8ee | ||
|
|
c3836ef1a6 | ||
|
|
e223ccccc6 | ||
|
|
fe64e1f822 | ||
|
|
fc82b3e6b1 | ||
|
|
680846da72 | ||
|
|
d1f9157c05 | ||
|
|
a00207d86e | ||
|
|
fe912c9659 | ||
|
|
8e3dedf0c5 | ||
|
|
d8a4213569 | ||
|
|
e33c63d3ad | ||
|
|
96dd499e0b | ||
|
|
67753927cb | ||
|
|
55edaa0209 | ||
|
|
4d6a8bd8cd | ||
|
|
9fc0ff764c | ||
|
|
eb5d6b1f06 | ||
|
|
030f66d806 | ||
|
|
da76b89856 | ||
|
|
20952e8477 | ||
|
|
f4e911c14a | ||
|
|
47a8d565e8 | ||
|
|
581e6b27d8 | ||
|
|
ca5290015a | ||
|
|
ad0c00bade | ||
|
|
4db5a7a132 | ||
|
|
c567b229cc | ||
|
|
5a249dcf24 | ||
|
|
6b556c59d9 | ||
|
|
fca9fff4b4 | ||
|
|
bcf49ed32c | ||
|
|
39052ffe39 | ||
|
|
e1a6b2af64 | ||
|
|
5280d245ee | ||
|
|
477b372110 | ||
|
|
c129c1a2ac | ||
|
|
7f0cc308c2 | ||
|
|
8b1151e03a | ||
|
|
15f1f413d0 |
@@ -1,8 +1,10 @@
|
||||
# .gitignore
|
||||
frontend/node_modules/
|
||||
frontend/dist/
|
||||
build/bin/verstak-desktop
|
||||
build/
|
||||
verstak-desktop-res.syso
|
||||
smoke-platform
|
||||
plugins/
|
||||
vendor/
|
||||
frontend/e2e-results/
|
||||
release/
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
Verstak Desktop
|
||||
Copyright (C) 2026 Verstak contributors
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under
|
||||
the terms of the GNU Affero General Public License as published by the Free
|
||||
Software Foundation, either version 3 of the License, or (at your option) any
|
||||
later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
details.
|
||||
|
||||
The complete license text is available at:
|
||||
https://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
@@ -1,3 +1,340 @@
|
||||
# verstak-desktop
|
||||
<div align="center">
|
||||
|
||||
Verstak Core Platform + UI Shell — plugin runtime, capability registry, vault API, event bus, sync client
|
||||
<img src="packaging/linux/verstak.svg" width="112" alt="Verstak logo">
|
||||
|
||||
# Verstak
|
||||
|
||||
### Keep the context of your work together — locally.
|
||||
|
||||
Files, notes, links, browser captures, activity and work history
|
||||
in one extensible local-first workbench.
|
||||
|
||||
**English** · [Русский](README.ru.md)
|
||||
|
||||
[](https://github.com/mirivlad/verstak/releases)
|
||||

|
||||

|
||||
[](LICENSE)
|
||||
|
||||
[Download](https://github.com/mirivlad/verstak/releases/latest) ·
|
||||
[Documentation](https://github.com/mirivlad/verstak-docs) ·
|
||||
[Report an issue](https://github.com/mirivlad/verstak/issues)
|
||||
|
||||
</div>
|
||||
|
||||
> [!WARNING]
|
||||
> Verstak is currently **alpha software**. APIs, storage formats and packaging may change before the first stable release. Use a test vault and keep backups of important data.
|
||||
|
||||
## What is Verstak?
|
||||
|
||||
Verstak is a local-first workbench that keeps the context around your work in one place.
|
||||
|
||||
A **Deal** can represent almost anything:
|
||||
|
||||
* a software project;
|
||||
* a client or customer;
|
||||
* a server or infrastructure site;
|
||||
* a device under repair;
|
||||
* an article or research topic;
|
||||
* a training course;
|
||||
* a personal long-term project.
|
||||
|
||||
Normally, information about such work is scattered across directories, notes, browser tabs, task managers, password managers, terminal history and memory.
|
||||
|
||||
Verstak brings it together in a local **vault** that remains under your control.
|
||||
|
||||
No account, cloud service or sync server is required for local use.
|
||||
|
||||
## Verstak in use
|
||||
|
||||
| Overview: return to a Deal and see its recent work, captures and items that need attention. | Files: manage ordinary folders and documents inside a Deal. |
|
||||
| --- | --- |
|
||||
|  |  |
|
||||
|
||||
| Notes: keep Markdown notes next to the Deal they describe. | Journal: record a completed session and retain its context. |
|
||||
| --- | --- |
|
||||
|  |  |
|
||||
|
||||
## Main features
|
||||
|
||||
| Feature | Description |
|
||||
| ------------------------ | -------------------------------------------------------------------------------------------- |
|
||||
| **Deals** | Organize files, notes and activity around durable projects, clients and other areas of work. |
|
||||
| **Files** | Browse and manage ordinary files stored inside your vault. |
|
||||
| **Notes** | Create Markdown notes, overview pages and links between related information. |
|
||||
| **Overview** | Quickly return to recent work and see what may need attention. |
|
||||
| **Browser Inbox** | Send pages, links, selections and files from a browser into Verstak. |
|
||||
| **Activity and Journal** | Reconstruct work sessions and turn selected activity into journal entries. |
|
||||
| **Todo** | Keep optional task lists inside individual Deals and across the whole vault. |
|
||||
| **Search** | Search across notes, files and supported plugin data. |
|
||||
| **Trash** | Restore deleted items or remove them permanently from one central location. |
|
||||
| **Secrets** | Keep credentials and access information connected to the relevant Deal. |
|
||||
| **Templates** | Create repeatable Deal structures for common types of work. |
|
||||
| **Plugins** | Add, replace or disable tools without turning Verstak into one rigid monolithic application. |
|
||||
| **Optional sync** | Synchronize vaults between devices using a self-hosted Verstak Sync Server. |
|
||||
|
||||
## Download and install
|
||||
|
||||
Download the latest build from the
|
||||
[GitHub Releases page](https://github.com/mirivlad/verstak/releases/latest).
|
||||
|
||||
Release packages already include the matching official plugins.
|
||||
|
||||
| System | Download | Installation |
|
||||
| --------------------------------- | ----------------------------------------- | --------------------------------------------- |
|
||||
| Debian 13 / Ubuntu 24.04 or newer | `verstak_<version>_amd64.deb` | Install through APT. |
|
||||
| Other x86_64 Linux distributions | `verstak-linux-x86_64-<version>.AppImage` | Make the file executable and run it. |
|
||||
| Windows 10/11 x64 | `verstak-windows-amd64-<version>.zip` | Extract the archive and launch `Verstak.cmd`. |
|
||||
|
||||
### Debian and Ubuntu
|
||||
|
||||
```bash
|
||||
sudo apt install ./verstak_*_amd64.deb
|
||||
```
|
||||
|
||||
Launch Verstak from the application menu or run:
|
||||
|
||||
```bash
|
||||
verstak
|
||||
```
|
||||
|
||||
### AppImage
|
||||
|
||||
```bash
|
||||
chmod +x verstak-linux-x86_64-*.AppImage
|
||||
./verstak-linux-x86_64-*.AppImage
|
||||
```
|
||||
|
||||
On a system without FUSE support:
|
||||
|
||||
```bash
|
||||
APPIMAGE_EXTRACT_AND_RUN=1 ./verstak-linux-x86_64-*.AppImage
|
||||
```
|
||||
|
||||
### Windows portable version
|
||||
|
||||
1. Download `verstak-windows-amd64-<version>.zip`.
|
||||
2. Extract it to a local directory.
|
||||
3. Run `Verstak.cmd`.
|
||||
|
||||
Do not run Verstak directly from inside the ZIP archive or from a network share.
|
||||
|
||||
Verstak uses the Microsoft WebView2 Runtime. It is already included with Windows 11 and most current Windows 10 installations. If Verstak does not start, install the
|
||||
[Microsoft WebView2 Runtime x64](https://go.microsoft.com/fwlink/p/?LinkId=2124701).
|
||||
|
||||
## Background and tray mode
|
||||
|
||||
After the tray icon is ready, closing the main window keeps Verstak running in the system tray. One left click restores and focuses the window; a right click opens the native **Show Verstak** and **Quit** menu. **Quit** exits the application completely. If the tray cannot start, closing the window exits normally rather than leaving an unreachable process. Scheduled Todo reminders continue while the window is hidden.
|
||||
|
||||
### Verify a download
|
||||
|
||||
Each release includes a `SHA256SUMS` file.
|
||||
|
||||
On Linux:
|
||||
|
||||
```bash
|
||||
sha256sum -c SHA256SUMS --ignore-missing
|
||||
```
|
||||
|
||||
## First start
|
||||
|
||||
### 1. Create or open a vault
|
||||
|
||||
A **vault** is the root directory where Verstak stores your work.
|
||||
|
||||
Choose a writable local directory. For example:
|
||||
|
||||
```text
|
||||
Documents/
|
||||
└── Verstak/
|
||||
```
|
||||
|
||||
Your files and notes remain ordinary files that can be accessed without Verstak.
|
||||
|
||||
### 2. Create your first Deal
|
||||
|
||||
Inside the vault, create a Deal for a project, client, server, device or another area of work.
|
||||
|
||||
For example:
|
||||
|
||||
```text
|
||||
Home server
|
||||
Customer Alpha
|
||||
Verstak development
|
||||
3D printer
|
||||
Training course
|
||||
```
|
||||
|
||||
### 3. Add context
|
||||
|
||||
Open the Deal and add the information needed to return to it later:
|
||||
|
||||
* notes and decisions;
|
||||
* documents and source files;
|
||||
* useful links;
|
||||
* access information;
|
||||
* journal entries;
|
||||
* tasks;
|
||||
* materials captured from the browser.
|
||||
|
||||
### 4. Return through Overview
|
||||
|
||||
The Overview screen shows recent changes, unfinished captures, activity and other useful entry points back into your work.
|
||||
|
||||
## How Verstak stores data
|
||||
|
||||
Verstak follows several principles:
|
||||
|
||||
* your vault is local and works without an account or internet connection;
|
||||
* files and notes remain readable outside the application;
|
||||
* synchronization is optional and is not the source of truth;
|
||||
* the user should understand where data is stored and what happens to it;
|
||||
* application tools are provided by plugins rather than being permanently embedded into the core.
|
||||
|
||||
The desktop application loads plugins from a `plugins/` directory located beside the executable.
|
||||
|
||||
## Browser integration
|
||||
|
||||
The optional browser extension can send the following into Browser Inbox:
|
||||
|
||||
* the current page;
|
||||
* selected text;
|
||||
* a link;
|
||||
* a downloaded or selected file.
|
||||
|
||||
Repository:
|
||||
|
||||
[mirivlad/verstak-browser-extension](https://github.com/mirivlad/verstak-browser-extension)
|
||||
|
||||
To connect the extension:
|
||||
|
||||
1. Open Browser Inbox settings in Verstak.
|
||||
2. Copy the Receiver URL and Pairing Token.
|
||||
3. Paste them into the extension settings.
|
||||
4. Save the settings and send a test page.
|
||||
|
||||
Passive domain activity tracking is disabled by default. When enabled, it sends bounded time totals by normalized domain. It does not send page contents, keystrokes or full browsing history.
|
||||
|
||||
## Optional synchronization
|
||||
|
||||
Local use does not require a server.
|
||||
|
||||
For synchronization between devices, deploy the optional self-hosted
|
||||
[Verstak Sync Server](https://github.com/mirivlad/verstak-sync-server).
|
||||
|
||||
Each vault is connected separately. The local vault remains the primary copy of your data.
|
||||
|
||||
## Build from source
|
||||
|
||||
### Requirements
|
||||
|
||||
* Go 1.24 or newer;
|
||||
* Node.js 20 or newer with npm;
|
||||
* Python 3;
|
||||
* Git;
|
||||
* Wails v2 build dependencies;
|
||||
* WebKitGTK development packages on Linux.
|
||||
|
||||
See the
|
||||
[Wails installation documentation](https://wails.io/docs/gettingstarted/installation/)
|
||||
for distribution-specific dependencies.
|
||||
|
||||
### Clone the repositories
|
||||
|
||||
The desktop, SDK and official plugin repositories must be cloned as sibling directories:
|
||||
|
||||
```text
|
||||
verstak-source/
|
||||
├── verstak/
|
||||
├── verstak-sdk/
|
||||
└── verstak-official-plugins/
|
||||
```
|
||||
|
||||
```bash
|
||||
mkdir verstak-source
|
||||
cd verstak-source
|
||||
|
||||
git clone https://github.com/mirivlad/verstak.git
|
||||
git clone https://github.com/mirivlad/verstak-sdk.git
|
||||
git clone https://github.com/mirivlad/verstak-official-plugins.git
|
||||
```
|
||||
|
||||
### Build
|
||||
|
||||
```bash
|
||||
cd verstak-sdk
|
||||
./scripts/build.sh
|
||||
|
||||
cd ../verstak-official-plugins
|
||||
./scripts/build.sh
|
||||
|
||||
cd ../verstak
|
||||
./scripts/install-dev-plugins.sh
|
||||
./scripts/build.sh
|
||||
```
|
||||
|
||||
The resulting application will be located at:
|
||||
|
||||
```bash
|
||||
./build/bin/verstak-desktop
|
||||
```
|
||||
|
||||
Run it with additional diagnostics:
|
||||
|
||||
```bash
|
||||
./build/bin/verstak-desktop --debug
|
||||
```
|
||||
|
||||
## Build release packages locally
|
||||
|
||||
These commands create local artifacts in `release/`. They do not publish a GitHub Release.
|
||||
|
||||
### Debian package
|
||||
|
||||
```bash
|
||||
./scripts/package-deb.sh v0.1.0-alpha.1
|
||||
```
|
||||
|
||||
### AppImage
|
||||
|
||||
```bash
|
||||
./scripts/package-appimage.sh v0.1.0-alpha.1
|
||||
```
|
||||
|
||||
### Windows portable ZIP
|
||||
|
||||
The Windows archive can be cross-compiled on Linux using MinGW:
|
||||
|
||||
```bash
|
||||
sudo apt install gcc-mingw-w64-x86-64 zip
|
||||
./scripts/package-windows-portable.sh v0.1.0-alpha.1
|
||||
```
|
||||
|
||||
## Project repositories
|
||||
|
||||
| Repository | Purpose |
|
||||
| ---------------------------------------------------------------------------------- | ------------------------------------------------------ |
|
||||
| [verstak](https://github.com/mirivlad/verstak) | Desktop application, core platform and UI shell |
|
||||
| [verstak-official-plugins](https://github.com/mirivlad/verstak-official-plugins) | Official Files, Notes, Journal, Todo and other plugins |
|
||||
| [verstak-sdk](https://github.com/mirivlad/verstak-sdk) | TypeScript SDK, schemas and plugin contracts |
|
||||
| [verstak-browser-extension](https://github.com/mirivlad/verstak-browser-extension) | Browser capture and optional activity integration |
|
||||
| [verstak-sync-server](https://github.com/mirivlad/verstak-sync-server) | Optional self-hosted synchronization server |
|
||||
| [verstak-docs](https://github.com/mirivlad/verstak-docs) | Product and platform architecture documentation |
|
||||
|
||||
Compatible components should be built from the same release line.
|
||||
|
||||
## Development status
|
||||
|
||||
Verstak is under active development.
|
||||
|
||||
The current alpha is intended for testing, feedback and experimentation. Backward compatibility is not guaranteed until the first stable release.
|
||||
|
||||
Bug reports and feature discussions are welcome in
|
||||
[GitHub Issues](https://github.com/mirivlad/verstak/issues).
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2026 Verstak contributors.
|
||||
|
||||
Verstak is licensed under the
|
||||
[GNU Affero General Public License v3.0 or later](LICENSE).
|
||||
|
||||
@@ -0,0 +1,339 @@
|
||||
<div align="center">
|
||||
|
||||
<img src="packaging/linux/verstak.svg" width="112" alt="Логотип Верстака">
|
||||
|
||||
# Верстак
|
||||
|
||||
### Рабочий контекст остаётся рядом — и хранится локально.
|
||||
|
||||
Файлы, заметки, ссылки, материалы из браузера, активность и история работы
|
||||
в одной расширяемой локальной среде.
|
||||
|
||||
[English](README.md) · **Русский**
|
||||
|
||||
[](https://github.com/mirivlad/verstak/releases)
|
||||

|
||||

|
||||
[](LICENSE)
|
||||
|
||||
[Скачать](https://github.com/mirivlad/verstak/releases/latest) ·
|
||||
[Документация](https://github.com/mirivlad/verstak-docs) ·
|
||||
[Сообщить о проблеме](https://github.com/mirivlad/verstak/issues)
|
||||
|
||||
</div>
|
||||
|
||||
> [!WARNING]
|
||||
> Верстак пока находится на стадии **alpha**. До первого стабильного выпуска могут меняться API, форматы хранения и состав пакетов. Для знакомства используйте тестовый vault и сохраняйте резервные копии важных данных.
|
||||
|
||||
## Что такое Верстак
|
||||
|
||||
Верстак — это local-first рабочая среда, которая удерживает в одном месте контекст вокруг ваших дел.
|
||||
|
||||
**Делом** может быть что угодно:
|
||||
|
||||
* программный проект;
|
||||
* клиент или заказчик;
|
||||
* сервер или площадка;
|
||||
* ремонтируемое устройство;
|
||||
* статья или исследование;
|
||||
* учебный курс;
|
||||
* личный долгосрочный проект.
|
||||
|
||||
Обычно информация о таком деле расползается по папкам, заметкам, браузерным вкладкам, менеджерам задач, хранилищам паролей, истории терминала и памяти.
|
||||
|
||||
Верстак собирает её в один локальный **vault**, который остаётся под вашим контролем.
|
||||
|
||||
Для локальной работы не нужны учётная запись, облачный сервис или собственный сервер.
|
||||
|
||||
## Верстак в работе
|
||||
|
||||
| Обзор: возвращает к делу и показывает недавнюю работу, входящие и то, что требует внимания. | Файлы: обычные папки и документы прямо внутри дела. |
|
||||
| --- | --- |
|
||||
|  |  |
|
||||
|
||||
| Заметки: Markdown-заметки остаются рядом с делом, которое они описывают. | Журнал: фиксирует завершённую работу и её контекст. |
|
||||
| --- | --- |
|
||||
|  |  |
|
||||
|
||||
## Основные возможности
|
||||
|
||||
| Возможность | Что она даёт |
|
||||
| ------------------------ | ---------------------------------------------------------------------------------------------- |
|
||||
| **Дела** | Объединяют файлы, заметки и историю работы вокруг проектов, клиентов и других направлений. |
|
||||
| **Файлы** | Позволяют работать с обычными файлами, расположенными внутри vault. |
|
||||
| **Заметки** | Markdown-заметки, обзорные страницы и связи между материалами. |
|
||||
| **Обзор** | Помогает быстро вернуться к недавней работе и увидеть то, что требует внимания. |
|
||||
| **Входящие из браузера** | Принимают страницы, ссылки, выделенный текст и файлы из браузера. |
|
||||
| **Активность и журнал** | Помогают восстановить рабочие сессии и превратить выбранную активность в записи журнала. |
|
||||
| **Задачи** | Необязательные списки задач внутри отдельных дел и во всём vault. |
|
||||
| **Поиск** | Ищет по заметкам, файлам и данным поддерживаемых плагинов. |
|
||||
| **Корзина** | Позволяет восстановить удалённое или окончательно удалить его из одного общего раздела. |
|
||||
| **Секреты** | Хранит доступы и учётные данные рядом с делом, к которому они относятся. |
|
||||
| **Шаблоны** | Создают повторяемую структуру для однотипных дел. |
|
||||
| **Плагины** | Позволяют добавлять, заменять и отключать инструменты, не превращая Верстак в жёсткий монолит. |
|
||||
| **Синхронизация** | Необязательно синхронизирует vault между устройствами через собственный сервер. |
|
||||
|
||||
## Скачивание и установка
|
||||
|
||||
Готовые сборки находятся на странице
|
||||
[GitHub Releases](https://github.com/mirivlad/verstak/releases/latest).
|
||||
|
||||
В релизные пакеты уже входят совместимые версии официальных плагинов. Устанавливать их отдельно не требуется.
|
||||
|
||||
| Система | Какой файл скачать | Как установить |
|
||||
| -------------------------------- | ---------------------------------------- | -------------------------------------------- |
|
||||
| Debian 13 / Ubuntu 24.04 и новее | `verstak_<версия>_amd64.deb` | Установить через APT. |
|
||||
| Другие дистрибутивы Linux x86_64 | `verstak-linux-x86_64-<версия>.AppImage` | Сделать файл исполняемым и запустить. |
|
||||
| Windows 10/11 x64 | `verstak-windows-amd64-<версия>.zip` | Распаковать архив и запустить `Verstak.cmd`. |
|
||||
|
||||
### Debian и Ubuntu
|
||||
|
||||
```bash
|
||||
sudo apt install ./verstak_*_amd64.deb
|
||||
```
|
||||
|
||||
После установки запустите Верстак из меню приложений или командой:
|
||||
|
||||
```bash
|
||||
verstak
|
||||
```
|
||||
|
||||
### AppImage
|
||||
|
||||
```bash
|
||||
chmod +x verstak-linux-x86_64-*.AppImage
|
||||
./verstak-linux-x86_64-*.AppImage
|
||||
```
|
||||
|
||||
Если в системе нет поддержки FUSE:
|
||||
|
||||
```bash
|
||||
APPIMAGE_EXTRACT_AND_RUN=1 ./verstak-linux-x86_64-*.AppImage
|
||||
```
|
||||
|
||||
### Портативная версия для Windows
|
||||
|
||||
1. Скачайте `verstak-windows-amd64-<версия>.zip`.
|
||||
2. Распакуйте архив в локальную папку.
|
||||
3. Запустите `Verstak.cmd`.
|
||||
|
||||
Не запускайте Верстак прямо из ZIP-архива или с сетевого диска.
|
||||
|
||||
Верстак использует Microsoft WebView2 Runtime. Он уже присутствует в Windows 11 и большинстве актуальных установок Windows 10. Если приложение не запускается, установите
|
||||
[Microsoft WebView2 Runtime x64](https://go.microsoft.com/fwlink/p/?LinkId=2124701).
|
||||
|
||||
## Фоновая работа и трей
|
||||
|
||||
После готовности значка в трее закрытие главного окна не завершает Верстак. Один левый клик возвращает и фокусирует окно, правый клик открывает нативное меню **«Показать Верстак»** и **«Выйти»**. **«Выйти»** полностью завершает приложение. Если трей не удалось запустить, закрытие окна завершает приложение обычным образом и не оставляет недоступный процесс. Пока окно скрыто, напоминания Todo продолжают работать.
|
||||
|
||||
### Проверка скачанного файла
|
||||
|
||||
В каждый релиз входит файл `SHA256SUMS`.
|
||||
|
||||
Проверка в Linux:
|
||||
|
||||
```bash
|
||||
sha256sum -c SHA256SUMS --ignore-missing
|
||||
```
|
||||
|
||||
## Первый запуск
|
||||
|
||||
### 1. Создайте или откройте vault
|
||||
|
||||
**Vault** — это корневая папка, в которой Верстак хранит ваши дела.
|
||||
|
||||
Выберите доступный для записи локальный каталог. Например:
|
||||
|
||||
```text
|
||||
Документы/
|
||||
└── Верстак/
|
||||
```
|
||||
|
||||
Файлы и заметки остаются обычными файлами. Их можно открыть и без Верстака.
|
||||
|
||||
### 2. Создайте первое дело
|
||||
|
||||
Внутри vault создайте дело для проекта, клиента, сервера, устройства или другого направления работы.
|
||||
|
||||
Например:
|
||||
|
||||
```text
|
||||
Домашний сервер
|
||||
Заказчик Альфа
|
||||
Разработка Верстака
|
||||
3D-принтер
|
||||
Учебный курс
|
||||
```
|
||||
|
||||
### 3. Соберите контекст
|
||||
|
||||
Добавьте в дело всё, что поможет вернуться к нему через неделю, месяц или год:
|
||||
|
||||
* заметки и принятые решения;
|
||||
* документы и исходные файлы;
|
||||
* полезные ссылки;
|
||||
* данные для доступа;
|
||||
* записи журнала;
|
||||
* задачи;
|
||||
* материалы, отправленные из браузера.
|
||||
|
||||
### 4. Возвращайтесь через Обзор
|
||||
|
||||
Экран «Обзор» показывает недавние изменения, необработанные входящие, активность и другие подходящие точки для продолжения работы.
|
||||
|
||||
## Как Верстак хранит данные
|
||||
|
||||
Верстак придерживается нескольких принципов:
|
||||
|
||||
* vault хранится локально и доступен без учётной записи и интернета;
|
||||
* файлы и заметки остаются читаемыми вне приложения;
|
||||
* синхронизация является дополнением, а не источником истины;
|
||||
* пользователь должен понимать, где находятся его данные и что с ними происходит;
|
||||
* инструменты реализуются плагинами, а не навсегда встраиваются в ядро.
|
||||
|
||||
Настольное приложение загружает плагины из каталога `plugins/`, расположенного рядом с исполняемым файлом.
|
||||
|
||||
## Интеграция с браузером
|
||||
|
||||
Необязательное расширение позволяет отправлять во «Входящие из браузера»:
|
||||
|
||||
* текущую страницу;
|
||||
* выделенный текст;
|
||||
* ссылку;
|
||||
* выбранный или скачанный файл.
|
||||
|
||||
Репозиторий расширения:
|
||||
|
||||
[mirivlad/verstak-browser-extension](https://github.com/mirivlad/verstak-browser-extension)
|
||||
|
||||
Чтобы подключить расширение:
|
||||
|
||||
1. Откройте настройки «Входящих из браузера» в Верстаке.
|
||||
2. Скопируйте адрес приёмника и токен сопряжения.
|
||||
3. Вставьте их в настройки расширения.
|
||||
4. Сохраните настройки и отправьте тестовую страницу.
|
||||
|
||||
Пассивный учёт активности по доменам по умолчанию отключён. После включения расширение передаёт только ограниченные интервалы времени для нормализованных доменов. Оно не отправляет содержимое страниц, нажатия клавиш или полную историю посещений.
|
||||
|
||||
## Необязательная синхронизация
|
||||
|
||||
Для локального использования сервер не нужен.
|
||||
|
||||
Для синхронизации между устройствами можно развернуть собственный
|
||||
[Verstak Sync Server](https://github.com/mirivlad/verstak-sync-server).
|
||||
|
||||
Каждый vault подключается отдельно. Основной копией данных остаётся локальный vault.
|
||||
|
||||
## Сборка из исходного кода
|
||||
|
||||
### Требования
|
||||
|
||||
* Go 1.24 или новее;
|
||||
* Node.js 20 или новее и npm;
|
||||
* Python 3;
|
||||
* Git;
|
||||
* зависимости для сборки Wails v2;
|
||||
* пакеты разработки WebKitGTK в Linux.
|
||||
|
||||
Зависимости для конкретного дистрибутива перечислены в
|
||||
[документации Wails](https://wails.io/docs/gettingstarted/installation/).
|
||||
|
||||
### Клонирование репозиториев
|
||||
|
||||
Desktop, SDK и официальные плагины должны находиться в соседних каталогах:
|
||||
|
||||
```text
|
||||
verstak-source/
|
||||
├── verstak/
|
||||
├── verstak-sdk/
|
||||
└── verstak-official-plugins/
|
||||
```
|
||||
|
||||
```bash
|
||||
mkdir verstak-source
|
||||
cd verstak-source
|
||||
|
||||
git clone https://github.com/mirivlad/verstak.git
|
||||
git clone https://github.com/mirivlad/verstak-sdk.git
|
||||
git clone https://github.com/mirivlad/verstak-official-plugins.git
|
||||
```
|
||||
|
||||
### Сборка
|
||||
|
||||
```bash
|
||||
cd verstak-sdk
|
||||
./scripts/build.sh
|
||||
|
||||
cd ../verstak-official-plugins
|
||||
./scripts/build.sh
|
||||
|
||||
cd ../verstak
|
||||
./scripts/install-dev-plugins.sh
|
||||
./scripts/build.sh
|
||||
```
|
||||
|
||||
Готовое приложение появится по адресу:
|
||||
|
||||
```bash
|
||||
./build/bin/verstak-desktop
|
||||
```
|
||||
|
||||
Запуск с дополнительной диагностикой:
|
||||
|
||||
```bash
|
||||
./build/bin/verstak-desktop --debug
|
||||
```
|
||||
|
||||
## Локальная сборка релизных пакетов
|
||||
|
||||
Следующие команды создают пакеты в каталоге `release/`, но не публикуют GitHub Release.
|
||||
|
||||
### Пакет Debian
|
||||
|
||||
```bash
|
||||
./scripts/package-deb.sh v0.1.0-alpha.1
|
||||
```
|
||||
|
||||
### AppImage
|
||||
|
||||
```bash
|
||||
./scripts/package-appimage.sh v0.1.0-alpha.1
|
||||
```
|
||||
|
||||
### Портативный ZIP для Windows
|
||||
|
||||
Windows-версию можно собрать в Linux при помощи MinGW:
|
||||
|
||||
```bash
|
||||
sudo apt install gcc-mingw-w64-x86-64 zip
|
||||
./scripts/package-windows-portable.sh v0.1.0-alpha.1
|
||||
```
|
||||
|
||||
## Репозитории проекта
|
||||
|
||||
| Репозиторий | Назначение |
|
||||
| ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
|
||||
| [verstak](https://github.com/mirivlad/verstak) | Настольное приложение, ядро платформы и оболочка интерфейса |
|
||||
| [verstak-official-plugins](https://github.com/mirivlad/verstak-official-plugins) | Официальные плагины файлов, заметок, журнала, задач и других инструментов |
|
||||
| [verstak-sdk](https://github.com/mirivlad/verstak-sdk) | TypeScript SDK, схемы и контракты плагинов |
|
||||
| [verstak-browser-extension](https://github.com/mirivlad/verstak-browser-extension) | Отправка материалов из браузера и необязательный учёт активности |
|
||||
| [verstak-sync-server](https://github.com/mirivlad/verstak-sync-server) | Необязательный собственный сервер синхронизации |
|
||||
| [verstak-docs](https://github.com/mirivlad/verstak-docs) | Продуктовая и архитектурная документация |
|
||||
|
||||
Совместимые компоненты следует собирать из одной релизной линии.
|
||||
|
||||
## Состояние разработки
|
||||
|
||||
Верстак активно развивается.
|
||||
|
||||
Текущая alpha предназначена для тестирования, обратной связи и экспериментов. До первого стабильного выпуска обратная совместимость не гарантируется.
|
||||
|
||||
Сообщения об ошибках и предложения принимаются в
|
||||
[GitHub Issues](https://github.com/mirivlad/verstak/issues).
|
||||
|
||||
## Лицензия
|
||||
|
||||
Copyright © 2026 Verstak contributors.
|
||||
|
||||
Верстак распространяется на условиях
|
||||
[GNU Affero General Public License v3.0 или новее](LICENSE).
|
||||
@@ -464,7 +464,7 @@ contributions summary.
|
||||
Conflicts are rejected unless `options.overwrite` is true.
|
||||
- `files.deleteTrash(trashId)` — permanently removes a file/folder already in
|
||||
internal trash. This operation cannot be undone.
|
||||
- UI policy: the workspace `Files` plugin displays only live files and folders.
|
||||
- UI policy: the Deal `Files` plugin displays only live files and folders.
|
||||
The global official `verstak.trash` plugin owns listing, restoring, filtering,
|
||||
and permanently deleting deleted items across the vault.
|
||||
- `files.openExternal(relativePath)` — opens a vault-relative file/folder in
|
||||
@@ -635,7 +635,7 @@ bundled runtime. Это реальный runtime contract для cooperative bun
|
||||
|
||||
1. Unregister contributions всех plugins предыдущего discovery.
|
||||
2. Unregister all non-core capabilities.
|
||||
3. Re-register core capabilities + vault + workspace (если открыт).
|
||||
3. Re-register core capabilities + vault + Deal manager (если открыт).
|
||||
4. Re-scan discovery directories и повторить capability resolution.
|
||||
5. Register contributions для loaded/degraded plugins (disabled/failed — не регистрируются).
|
||||
6. Update plugins list.
|
||||
@@ -838,51 +838,52 @@ Vault plugin state хранится **внутри vault** в `.verstak/plugins.
|
||||
- `./scripts/smoke-platform.sh` — ✅ (enable/disable/plugins.json)
|
||||
- `./scripts/build.sh` — ✅
|
||||
|
||||
## Workspace Core Capability
|
||||
## Дело: core capability
|
||||
|
||||
Workspace — это физическая папка верхнего уровня внутри vault root. Filesystem
|
||||
является source of truth для списка workspaces.
|
||||
Дело — это физическая папка верхнего уровня внутри vault root. Filesystem
|
||||
является source of truth для списка Дел.
|
||||
|
||||
Пример:
|
||||
|
||||
```
|
||||
<vault>/
|
||||
Workspace/
|
||||
Deal/
|
||||
Notes/
|
||||
Project/
|
||||
ClientA/
|
||||
.verstak/
|
||||
```
|
||||
|
||||
Нет единого `<vault>/Workspace/` контейнера для всех workspaces. Папка
|
||||
`Workspace/` может быть обычным workspace, но `Project/` и `ClientA/` являются
|
||||
такими же workspace на том же уровне.
|
||||
Нет единого `<vault>/Deal/` контейнера для всех Дел. Папка `Deal/` может быть
|
||||
обычным Делом, но `Project/` и `ClientA/` являются такими же Делами на том же
|
||||
уровне.
|
||||
|
||||
### Хранение
|
||||
|
||||
Workspace existence/list хранится только в filesystem:
|
||||
Существование и список Дел хранятся только в filesystem:
|
||||
|
||||
- `ListWorkspaces()` читает top-level directories из vault root.
|
||||
- `.verstak`, reserved/internal directories, top-level files и symlinks не
|
||||
считаются workspaces.
|
||||
- `.verstak/workspace*.json` не является source of truth для списка workspaces.
|
||||
- Нет persisted workspace path mapping и нет virtual workspace tree, которое
|
||||
считаются Делами.
|
||||
- `.verstak/workspace*.json` не является source of truth для списка Дел.
|
||||
- Нет virtual workspace tree, которое
|
||||
мапится на произвольные папки.
|
||||
|
||||
`.verstak` может хранить только metadata, которая не заменяет filesystem:
|
||||
|
||||
- UI state: selected workspace, expanded folders, sort/pin state, preferences.
|
||||
- UI state: выбранное Дело, expanded folders, sort/pin state, preferences.
|
||||
- Semantic snapshot: applied template snapshot, enabled feature areas, exact
|
||||
`workspaceTools`, and folder conventions.
|
||||
|
||||
Template snapshot копируется в metadata при создании workspace. Workspace
|
||||
identity при этом остаётся именем top-level folder; `metadata.workspaceName`
|
||||
является presentation/snapshot field, not canonical identity. Если сохранённое
|
||||
значение расходится с именем папки, runtime возвращает canonical `workspaceName`
|
||||
равным имени папки без filesystem side effects.
|
||||
При создании Дела runtime генерирует UUID и сохраняет его в
|
||||
`.verstak/workspace.json`. `workspaceId` — постоянная личность Дела;
|
||||
`workspaceRootPath` и `workspaceName` — изменяемый адрес и presentation fields.
|
||||
Переименование обновляет путь, но не ID. Новая папка с прежним именем получает
|
||||
другой ID и не может перехватить старые привязки.
|
||||
|
||||
```json
|
||||
{
|
||||
"workspaceId": "1eb7cc69-52e8-4a18-ae2a-50d5229c5b60",
|
||||
"workspaceName": "Project",
|
||||
"createdFromTemplate": {
|
||||
"templateId": "project",
|
||||
@@ -921,25 +922,25 @@ identity при этом остаётся именем top-level folder; `metada
|
||||
}
|
||||
```
|
||||
|
||||
Если original template удалён или изменён позже, существующий workspace
|
||||
Если original template удалён или изменён позже, существующее Дело
|
||||
открывается по сохранённому snapshot и не мутирует автоматически. Template
|
||||
update/migration может быть только явной future feature. Если metadata
|
||||
отсутствует, workspace открывается как generic workspace минимум с `files: true`.
|
||||
отсутствует, Дело открывается как generic Deal минимум с `files: true`.
|
||||
|
||||
### API
|
||||
|
||||
- `ListWorkspaces()` — список top-level physical folders.
|
||||
- `ListWorkspaces()` — список top-level папок Дел с их `workspaceId`.
|
||||
- `ListWorkspaceTemplates()` — selectable built-in templates с presentation
|
||||
metadata и `workspaceTools`.
|
||||
- `CreateWorkspace(name, templateId?)` — создать `<vault>/<name>/`, применить
|
||||
template один раз, сохранить snapshot metadata.
|
||||
- `RenameWorkspace(oldName, newName)` — физически переименовать top-level folder
|
||||
и обновить metadata key/name.
|
||||
- `TrashWorkspace(name)` — перенести весь top-level workspace folder в internal
|
||||
- `RenameWorkspace(oldName, newName)` — физически переименовать top-level папку
|
||||
Дела и обновить metadata name, не меняя `workspaceId`.
|
||||
- `TrashWorkspace(name)` — перенести весь top-level folder Дела в internal
|
||||
trash policy.
|
||||
- `GetWorkspaceMetadata(name)` — прочитать metadata или вернуть generic fallback.
|
||||
- `UpdateWorkspaceMetadata(name, patch)` — обновить metadata без влияния на
|
||||
существование workspace.
|
||||
существование Дела.
|
||||
|
||||
Deprecated compatibility APIs:
|
||||
|
||||
@@ -949,7 +950,7 @@ Deprecated compatibility APIs:
|
||||
- `ArchiveWorkspaceNode(...)` — wrapper over `TrashWorkspace`.
|
||||
- `MoveWorkspaceNode(...)` — unsupported; old nested/mapped moves are rejected.
|
||||
- `GetCurrentWorkspaceNode()` / `SetCurrentWorkspaceNode(...)` — wrappers over
|
||||
selected top-level workspace UI state.
|
||||
selected top-level Deal UI state.
|
||||
|
||||
Эти методы существуют только для постепенного frontend/Wails cleanup. Они не
|
||||
должны создавать или сохранять nested workspace tree и не должны восстанавливать
|
||||
@@ -957,32 +958,33 @@ Deprecated compatibility APIs:
|
||||
|
||||
### Capability
|
||||
|
||||
`verstak/core/workspace/v1` — регистрируется только когда vault открыт и workspace инициализирован.
|
||||
`verstak/core/workspace/v1` — техническое имя capability; оно регистрируется
|
||||
только когда vault открыт и Deal manager инициализирован.
|
||||
|
||||
### Правила
|
||||
|
||||
- Workspace name — один safe folder name, не path.
|
||||
- Имя Дела — один safe folder name, не path.
|
||||
- Reject: empty, slash, backslash, absolute-looking paths, `..`, null byte,
|
||||
`.verstak`, reserved/internal names, symlink workspaces, conflicts.
|
||||
- WorkspaceItems получают `workspaceRootPath`, равный имени top-level папки
|
||||
`.verstak`, reserved/internal names, symlink Дел, conflicts.
|
||||
- WorkspaceItems получают техническое поле `workspaceRootPath`, равное имени top-level папки
|
||||
(`Project`, `ClientA`, etc). Files plugin показывает именно эту папку.
|
||||
- Files API остаётся raw vault-relative API: `Project/Notes/example.md`,
|
||||
`Project/docs/file.md`, `Test/readme.md`.
|
||||
- Notes are ordinary Markdown files under `<workspace>/Notes/`; нет
|
||||
- Notes are ordinary Markdown files under `<Deal>/Notes/`; нет
|
||||
`.verstak/notes`, UUID note storage или второго source of truth для note
|
||||
content.
|
||||
|
||||
### Lifecycle Events
|
||||
|
||||
Runtime publishes workspace lifecycle events after successful operations:
|
||||
Runtime publishes lifecycle events Дел после успешных операций:
|
||||
|
||||
- `workspace.created` — payload includes `operation: "create"`,
|
||||
- `workspace.created` — payload includes `operation: "create"`, `workspaceId`,
|
||||
`workspaceRootPath`, `workspaceName`, and optional `templateId`.
|
||||
- `workspace.renamed` — payload includes `operation: "rename"`, new
|
||||
`workspaceRootPath` / `workspaceName`, and previous workspace fields.
|
||||
- `workspace.trashed` — payload includes `operation: "trash"`,
|
||||
- `workspace.renamed` — payload includes `operation: "rename"`, `workspaceId`,
|
||||
new `workspaceRootPath` / `workspaceName`, and previous path fields.
|
||||
- `workspace.trashed` — payload includes `operation: "trash"`, `workspaceId`,
|
||||
`workspaceRootPath`, `workspaceName`, `trashId`, `trashPath`, and `deletedAt`.
|
||||
- `workspace.selected` — payload includes `operation: "select"`,
|
||||
- `workspace.selected` — payload includes `operation: "select"`, `workspaceId`,
|
||||
`workspaceRootPath`, and `workspaceName`.
|
||||
|
||||
Official Activity subscribes to these events and stores them through the normal
|
||||
@@ -990,11 +992,11 @@ activity provider path.
|
||||
|
||||
### UI
|
||||
|
||||
Workspace list в sidebar:
|
||||
- Flat list of top-level workspace folders.
|
||||
- Create workspace, rename workspace, trash workspace.
|
||||
- Selection is stored as selected workspace name.
|
||||
- No expand/collapse workspace tree and no case/folder node creation in core.
|
||||
Список Дел в sidebar:
|
||||
- Flat list of top-level папок Дел.
|
||||
- Создать Дело, переименовать Дело, переместить Дело в корзину.
|
||||
- Selection is stored as selected Deal name.
|
||||
- No expand/collapse tree and no case/folder node creation in core.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
# Workspace Templates
|
||||
# Deal Templates
|
||||
|
||||
Workspace templates choose which dynamic plugin workspace tabs are visible when a
|
||||
new top-level workspace is created. They do not enable or disable plugins for the
|
||||
Deal templates choose which dynamic plugin Deal tabs are visible when a new
|
||||
top-level Deal is created. They do not enable or disable plugins for the
|
||||
whole vault and do not affect global sidebar tools.
|
||||
|
||||
## Built-in templates
|
||||
|
||||
| Template | Workspace tabs |
|
||||
| Template | Deal tabs |
|
||||
| --- | --- |
|
||||
| General | Notes, Files, Journal, Activity, Browser Inbox |
|
||||
| Project | Notes, Files, Todos, Journal, Activity, Browser Inbox |
|
||||
@@ -14,27 +14,27 @@ whole vault and do not affect global sidebar tools.
|
||||
| Admin | Notes, Files, Secrets, Todos, Journal |
|
||||
| Minimal | Notes, Files |
|
||||
|
||||
The create-workspace modal displays the selected template description and its
|
||||
The create-Deal modal displays the selected template description and its
|
||||
included plugin tabs before the folder is created.
|
||||
|
||||
## Metadata and compatibility
|
||||
|
||||
Creation stores a template snapshot in `.verstak/workspaces/` metadata. The
|
||||
snapshot contains the template id, name, version, applied time, and an ordered
|
||||
`workspaceTools` list of plugin IDs. Existing workspace metadata without
|
||||
`workspaceTools` remains compatible: its workspace continues to show all globally
|
||||
enabled workspace plugins rather than unexpectedly hiding tabs.
|
||||
`workspaceTools` list of plugin IDs. Existing Deal metadata without
|
||||
`workspaceTools` remains compatible: its Deal continues to show all globally
|
||||
enabled Deal plugins rather than unexpectedly hiding tabs.
|
||||
|
||||
Templates are applied once. Editing the built-in catalog or creating another
|
||||
workspace with a different template never changes an existing workspace snapshot.
|
||||
Deal with a different template never changes an existing Deal snapshot.
|
||||
There is no template editor or post-creation template switcher yet.
|
||||
|
||||
## Global tools and unavailable plugins
|
||||
|
||||
Template visibility applies only to `workspaceItems` in the selected workspace.
|
||||
Template visibility applies only to `workspaceItems` in the selected Deal.
|
||||
Global views and sidebar items, such as global Todos, Browser Inbox, and Trash,
|
||||
remain available according to the normal plugin enablement state.
|
||||
|
||||
The workspace host intersects the snapshot with dynamically discovered, globally
|
||||
The Deal host intersects the snapshot with dynamically discovered, globally
|
||||
enabled plugin contributions. If a template references a plugin that is missing or
|
||||
disabled, that tab is simply absent; the other template tabs remain usable.
|
||||
|
||||
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 75 KiB |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 99 KiB |
|
After Width: | Height: | Size: 116 KiB |
|
After Width: | Height: | Size: 118 KiB |
|
After Width: | Height: | Size: 61 KiB |
@@ -0,0 +1,350 @@
|
||||
# Native Notifications, Tray, and Public README Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Deliver native Todo reminders and Windows/Linux tray operation, then publish updated alpha artifacts and public README documentation with real application screenshots.
|
||||
|
||||
**Architecture:** Desktop core stores and delivers plugin-owned notification schedules and controls the tray lifecycle. Todo uses the public plugin API to replace its desired reminders. A small core tray adapter keeps the Wails process alive after window close. Documentation uses the supplied English and Russian README sources plus screenshots from an actual test vault.
|
||||
|
||||
**Tech Stack:** Go 1.24, Wails v2.12 runtime notifications, `fyne.io/systray`, plain JavaScript plugin API, Node smoke tests, Playwright, bash packaging.
|
||||
|
||||
## Global constraints
|
||||
|
||||
- Support Windows and Linux only; no background daemon after an explicit Quit.
|
||||
- Closing a window hides it only after the tray reports ready; otherwise normal
|
||||
window close ends the process.
|
||||
- `verstak.todo` requires `verstak/core/notifications/v1` and `notifications.schedule`.
|
||||
- Plugins cannot receive Wails runtime access.
|
||||
- Keep Wails generated bindings out of commits.
|
||||
- Commit each independent change and immediately push it to GitHub and `mirror`.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Persisted notification scheduler
|
||||
|
||||
**Files:**
|
||||
- Create: `internal/core/notifications/manager.go`
|
||||
- Create: `internal/core/notifications/store.go`
|
||||
- Create: `internal/core/notifications/manager_test.go`
|
||||
|
||||
**Interfaces:**
|
||||
- `type Request struct { ID, DueAt, Title, Body string }`
|
||||
- `type Item struct { PluginID, ID, DueAt, Title, Body, SentForDueAt string }`
|
||||
- `type Sender interface { Send(context.Context, Item) error }`
|
||||
- `Manager.Replace(pluginID string, requests []Request) error`, `Clear(pluginID string) error`, `Start(context.Context)`, and `Stop()`.
|
||||
- Persistent state: `<vault>/.verstak/notifications/schedules.json`.
|
||||
|
||||
- [ ] **Step 1: Add failing scheduler tests**
|
||||
|
||||
```go
|
||||
func TestTickRetriesFailedSendAndAcknowledgesOneDelivery(t *testing.T) {
|
||||
sender := &fakeSender{err: errors.New("unavailable")}
|
||||
m := newTestManager(t, sender, time.Date(2026, 7, 14, 12, 0, 0, 0, time.UTC))
|
||||
requireNoError(t, m.Replace("verstak.todo", []Request{{ID: "todo-1", DueAt: "2026-07-14T11:00:00Z", Title: "Reminder"}}))
|
||||
m.Tick(context.Background())
|
||||
if sender.calls != 1 || m.Items()[0].SentForDueAt != "" { t.Fatal("failed send was acknowledged") }
|
||||
sender.err = nil
|
||||
m.Tick(context.Background())
|
||||
m.Tick(context.Background())
|
||||
if sender.calls != 2 || m.Items()[0].SentForDueAt != "2026-07-14T11:00:00Z" { t.Fatal("delivery was not exactly once") }
|
||||
}
|
||||
```
|
||||
|
||||
Also test stale records are removed by `Replace`, changing `DueAt` rearms a record, state reloads from disk, and a past-due unsent item is sent once.
|
||||
|
||||
- [ ] **Step 2: Confirm red**
|
||||
|
||||
Run: `GOCACHE=/tmp/verstak-go-cache go test ./internal/core/notifications -count=1`
|
||||
|
||||
Expected: fails because the package does not exist.
|
||||
|
||||
- [ ] **Step 3: Implement the minimal manager**
|
||||
|
||||
Use one mutex, injected clock/sender, an atomic same-directory temp-file rename, and a 30-second ticker. Preserve `SentForDueAt` only if the requested due time is unchanged. Validate non-empty unique IDs, RFC3339 UTC dates, at most 500 requests, and bounded text. Mark sent only after `Sender.Send` succeeds.
|
||||
|
||||
- [ ] **Step 4: Verify and commit**
|
||||
|
||||
Run:
|
||||
```bash
|
||||
gofmt -w internal/core/notifications/*.go
|
||||
GOCACHE=/tmp/verstak-go-cache go test ./internal/core/notifications ./internal/core/... -count=1
|
||||
git diff --check
|
||||
```
|
||||
|
||||
Commit/push:
|
||||
```bash
|
||||
git add internal/core/notifications
|
||||
git commit -m "feat: add persisted notification scheduler"
|
||||
git push https://github.com/mirivlad/verstak.git main
|
||||
git push mirror main
|
||||
```
|
||||
|
||||
### Task 2: Permission-gated core/plugin notification API
|
||||
|
||||
**Files:**
|
||||
- Modify: `main.go`
|
||||
- Modify: `internal/api/app.go`
|
||||
- Modify: `internal/api/app_test.go`
|
||||
- Modify: `internal/core/permissions/registry.go`
|
||||
- Modify: `frontend/src/lib/plugin-host/VerstakPluginAPI.js`
|
||||
- Modify: `frontend/tests/plugin-api-contributions-test.mjs`
|
||||
|
||||
**Interfaces:**
|
||||
- Core capability: `verstak/core/notifications/v1`.
|
||||
- Permission: `notifications.schedule`, non-dangerous.
|
||||
- Bound methods: `ReplacePluginNotifications(pluginID string, items []notifications.Request) string` and `ClearPluginNotifications(pluginID string) string`.
|
||||
- Plugin methods: `api.notifications.replace(items)` and `api.notifications.clear()`.
|
||||
|
||||
- [ ] **Step 1: Add failing backend and host-API tests**
|
||||
|
||||
```go
|
||||
func TestReplacePluginNotificationsRequiresCapabilityAndPermission(t *testing.T) {
|
||||
app, scheduler := newNotificationTestApp(t, manifestWithoutNotificationPermission)
|
||||
if got := app.ReplacePluginNotifications("example", []notifications.Request{{ID: "r", DueAt: "2026-07-14T10:00:00Z", Title: "R"}}); got == "" {
|
||||
t.Fatal("missing permission was accepted")
|
||||
}
|
||||
if scheduler.replaceCalls != 0 { t.Fatalf("replace calls = %d", scheduler.replaceCalls) }
|
||||
}
|
||||
```
|
||||
|
||||
The JS test mocks `App.ReplacePluginNotifications`, calls `api.notifications.replace`, and asserts both plugin ID forwarding and a namespaced rejection for a non-empty backend error.
|
||||
|
||||
- [ ] **Step 2: Confirm red**
|
||||
|
||||
```bash
|
||||
GOCACHE=/tmp/verstak-go-cache go test ./internal/api -run TestReplacePluginNotificationsRequiresCapabilityAndPermission -count=1
|
||||
node frontend/tests/plugin-api-contributions-test.mjs
|
||||
```
|
||||
|
||||
Expected: missing API methods.
|
||||
|
||||
- [ ] **Step 3: Implement guarded bridge**
|
||||
|
||||
Register the capability in `main.go`, construct the scheduler, and guard bound calls with both existing access helpers before forwarding. Add `notifications.schedule` to the registry. Add the public host methods using `callBackendErrorString`; do not expose `window.runtime` to plugins.
|
||||
|
||||
- [ ] **Step 4: Verify and commit**
|
||||
|
||||
```bash
|
||||
gofmt -w main.go internal/api/app.go internal/api/app_test.go internal/core/permissions/registry.go
|
||||
GOCACHE=/tmp/verstak-go-cache go test ./internal/api -count=1
|
||||
node frontend/tests/plugin-api-contributions-test.mjs
|
||||
git diff --check
|
||||
```
|
||||
|
||||
```bash
|
||||
git add main.go internal/api/app.go internal/api/app_test.go internal/core/permissions/registry.go frontend/src/lib/plugin-host/VerstakPluginAPI.js frontend/tests/plugin-api-contributions-test.mjs
|
||||
git commit -m "feat: expose scheduled notifications to plugins"
|
||||
git push https://github.com/mirivlad/verstak.git main
|
||||
git push mirror main
|
||||
```
|
||||
|
||||
### Task 3: Todo reminder synchronization and Wails lifecycle
|
||||
|
||||
**Files:**
|
||||
- Modify: `main.go`
|
||||
- Modify: `internal/api/app.go`
|
||||
- Modify: `internal/api/app_test.go`
|
||||
- Modify: `../verstak-official-plugins/plugins/todo/plugin.json`
|
||||
- Modify: `../verstak-official-plugins/plugins/todo/frontend/src/index.js`
|
||||
- Modify: `../verstak-official-plugins/plugins/todo/locales/en.json`
|
||||
- Modify: `../verstak-official-plugins/plugins/todo/locales/ru.json`
|
||||
- Modify: `../verstak-official-plugins/scripts/smoke-todo-plugin.js`
|
||||
|
||||
**Interfaces:**
|
||||
- `App.DomReady(ctx)` initializes Wails notifications before starting the scheduler.
|
||||
- `App.Shutdown(ctx)` stops it before Wails cleanup.
|
||||
- Todo replaces the complete reminder list only after Todo persistence succeeds and after Todo data loads.
|
||||
|
||||
- [ ] **Step 1: Add failing lifecycle and Todo smoke tests**
|
||||
|
||||
The App test uses function variables for Wails calls and proves initialize → start and stop → cleanup order. The Todo smoke mock records `notifications.replace`; it asserts one open reminder request with the Todo ID and a later empty replacement after completion or deletion.
|
||||
|
||||
- [ ] **Step 2: Confirm red**
|
||||
|
||||
```bash
|
||||
GOCACHE=/tmp/verstak-go-cache go test ./internal/api -run 'TestDomReadyInitializesNotificationsBeforeScheduler|TestShutdownStopsNotifications' -count=1
|
||||
cd ../verstak-official-plugins && node scripts/smoke-todo-plugin.js
|
||||
```
|
||||
|
||||
Expected: lifecycle methods and schedule calls are absent.
|
||||
|
||||
- [ ] **Step 3: Implement lifecycle and Todo desired state**
|
||||
|
||||
Use `runtime.InitializeNotifications`, `runtime.SendNotification`, and `runtime.CleanupNotifications` only in core. Register `OnDomReady`/ `OnShutdown` in Wails options. Todo maps open valid `reminderAt` values to ISO UTC using `new Date(todo.reminderAt).toISOString()`, localizes title/body, and calls `api.notifications.replace`. A scheduling failure reports status but never rolls back already-saved Todo data.
|
||||
|
||||
- [ ] **Step 4: Verify and commit both repositories**
|
||||
|
||||
```bash
|
||||
GOCACHE=/tmp/verstak-go-cache go test ./internal/api -count=1
|
||||
cd ../verstak-official-plugins && node scripts/smoke-todo-plugin.js && ./scripts/check.sh
|
||||
```
|
||||
|
||||
```bash
|
||||
cd ../verstak-desktop
|
||||
git add main.go internal/api/app.go internal/api/app_test.go
|
||||
git commit -m "feat: start native notifications with desktop app"
|
||||
git push https://github.com/mirivlad/verstak.git main
|
||||
git push mirror main
|
||||
cd ../verstak-official-plugins
|
||||
git add plugins/todo scripts/smoke-todo-plugin.js
|
||||
git commit -m "feat: schedule native Todo reminders"
|
||||
git push https://github.com/mirivlad/verstak-official-plugins.git main
|
||||
git push mirror main
|
||||
```
|
||||
|
||||
### Task 4: Windows/Linux tray, close policy, and single instance
|
||||
|
||||
**Files:**
|
||||
- Create: `internal/shell/tray/controller.go`
|
||||
- Create: `internal/shell/tray/controller_test.go`
|
||||
- Modify: `main.go`
|
||||
- Modify: `internal/api/app.go`
|
||||
- Modify: `internal/api/app_test.go`
|
||||
- Modify: `go.mod`
|
||||
- Modify: `go.sum`
|
||||
|
||||
**Interfaces:**
|
||||
- `tray.Start(icon []byte, actions Actions) error`, with `Actions.Show` and `Actions.Quit`.
|
||||
- `App.BeforeClose(ctx) bool` hides and returns true unless `App.Quit()` made shutdown explicit.
|
||||
- `App.ShowWindow()` reveals the existing window.
|
||||
|
||||
- [ ] **Step 1: Add failing close-policy and tray action tests**
|
||||
|
||||
```go
|
||||
func TestBeforeCloseHidesWindowUntilExplicitQuit(t *testing.T) {
|
||||
app, window := newWindowTestApp(t)
|
||||
if prevent := app.BeforeClose(context.Background()); !prevent || window.hideCalls != 1 { t.Fatal("ordinary close must hide") }
|
||||
app.Quit()
|
||||
if prevent := app.BeforeClose(context.Background()); prevent { t.Fatal("explicit quit was prevented") }
|
||||
}
|
||||
```
|
||||
|
||||
Use a fake tray adapter to assert exactly two labels, **Show Verstak** and **Quit**, and one callback invocation per click.
|
||||
|
||||
- [ ] **Step 2: Confirm red**
|
||||
|
||||
```bash
|
||||
GOCACHE=/tmp/verstak-go-cache go test ./internal/api -run TestBeforeCloseHidesWindowUntilExplicitQuit -count=1
|
||||
GOCACHE=/tmp/verstak-go-cache go test ./internal/shell/tray -count=1
|
||||
```
|
||||
|
||||
Expected: absent packages/methods.
|
||||
|
||||
- [ ] **Step 3: Implement adapter and Wails wiring**
|
||||
|
||||
Use `fyne.io/systray`. The production adapter calls `RunWithExternalLoop` so the
|
||||
Windows native message loop runs alongside Wails, embeds a multi-resolution
|
||||
ICO on Windows and PNG on Linux, routes one left click to `app.ShowWindow`, and
|
||||
leaves the platform-native right-click menu active. `main.go` registers
|
||||
`OnBeforeClose` and uses `options.SingleInstanceLock` whose second launch calls
|
||||
`app.ShowWindow`. Do not embed ignored Wails-generated files from `build/`.
|
||||
|
||||
- [ ] **Step 4: Verify and commit**
|
||||
|
||||
```bash
|
||||
gofmt -w main.go internal/api/app.go internal/api/app_test.go internal/shell/tray/*.go
|
||||
GOCACHE=/tmp/verstak-go-cache go test ./internal/shell/tray ./internal/api -count=1
|
||||
./scripts/build.sh
|
||||
! rg -n 'getlantern|appindicator' go.mod go.sum packaging scripts/build.sh
|
||||
git diff --check
|
||||
```
|
||||
|
||||
```bash
|
||||
git add main.go internal/api/app.go internal/api/app_test.go internal/shell/tray go.mod go.sum
|
||||
git commit -m "feat: keep desktop app in system tray"
|
||||
git push https://github.com/mirivlad/verstak.git main
|
||||
git push mirror main
|
||||
```
|
||||
|
||||
### Task 5: Packaging and public README screenshots
|
||||
|
||||
**Files:**
|
||||
- Modify: `packaging/deb/control`
|
||||
- Modify: `scripts/build.sh`
|
||||
- Modify: `scripts/package-appimage.sh`
|
||||
- Modify: `scripts/test-package-formats.sh`
|
||||
- Modify: `README.md`
|
||||
- Create: `README.ru.md`
|
||||
- Create: `docs/screenshots/overview.png`
|
||||
- Create: `docs/screenshots/workspace-files-notes.png`
|
||||
- Create: `docs/screenshots/activity-journal.png`
|
||||
|
||||
- [ ] **Step 1: Add failing package-contract checks**
|
||||
|
||||
Add assertions that the Linux build guidance, Debian metadata, and AppImage
|
||||
packager no longer require the removed AppIndicator backend.
|
||||
|
||||
- [ ] **Step 2: Confirm red**
|
||||
|
||||
Run: `./scripts/test-package-formats.sh`
|
||||
|
||||
Expected: the first tray dependency assertion fails.
|
||||
|
||||
- [ ] **Step 3: Implement portable package support**
|
||||
|
||||
Keep Debian and AppImage focused on the Wails/WebKitGTK runtime. Do not add a
|
||||
tray-specific AppIndicator dependency. Keep the Windows system-WebView2 policy
|
||||
unchanged.
|
||||
|
||||
- [ ] **Step 4: Install the supplied public README sources**
|
||||
|
||||
Replace this repository's `README.md` with the supplied English source at the workspace root and add the supplied Russian source as `README.ru.md`. Add an image strip after “What is Verstak?” / “Что такое Верстак?” that links to three tracked PNG screenshots and uses matching localized alt text.
|
||||
|
||||
- [ ] **Step 5: Produce real screenshots**
|
||||
|
||||
Build and run the desktop app against `/home/mirivlad/Nextcloud/Verstak/VerstakVault` on the active X display. Capture:
|
||||
1. Overview showing recent work and entry points;
|
||||
2. a populated workspace Files/Notes view;
|
||||
3. Activity with a suggested session and its Journal review.
|
||||
|
||||
Use `scrot` or ImageMagick `import`, crop only surrounding desktop chrome, inspect every PNG visually, and do not add generated mockups. Remove all non-user-safe text from the test vault before capture.
|
||||
|
||||
- [ ] **Step 6: Verify documentation and package contracts, commit, push**
|
||||
|
||||
```bash
|
||||
./scripts/test-package-formats.sh
|
||||
git diff --check
|
||||
test -s docs/screenshots/overview.png
|
||||
test -s docs/screenshots/workspace-files-notes.png
|
||||
test -s docs/screenshots/activity-journal.png
|
||||
```
|
||||
|
||||
```bash
|
||||
git add packaging/deb/control scripts/build.sh scripts/package-appimage.sh scripts/test-package-formats.sh README.md README.ru.md docs/screenshots
|
||||
git commit -m "docs: add public README and product screenshots"
|
||||
git push https://github.com/mirivlad/verstak.git main
|
||||
git push mirror main
|
||||
```
|
||||
|
||||
### Task 6: Complete verification and GitHub alpha releases
|
||||
|
||||
**Files:**
|
||||
- No source changes expected unless verification exposes a defect.
|
||||
|
||||
- [ ] **Step 1: Run all checks**
|
||||
|
||||
```bash
|
||||
GOCACHE=/tmp/verstak-go-cache ./scripts/test.sh
|
||||
./scripts/check.sh
|
||||
./scripts/test-package-formats.sh
|
||||
./scripts/test-build-windows.sh
|
||||
cd ../verstak-official-plugins && ./scripts/check.sh && ./scripts/test-package-portable.sh && ./scripts/test-publish-github-release.sh
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Build and checksum both alpha releases**
|
||||
|
||||
```bash
|
||||
cd ../verstak-official-plugins && ./scripts/release.sh v0.1.0-alpha.2 && (cd release && sha256sum --check SHA256SUMS)
|
||||
cd ../verstak-desktop && ./scripts/release.sh v0.1.0-alpha.2 && (cd release && sha256sum --check SHA256SUMS)
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Publish and inspect releases**
|
||||
|
||||
```bash
|
||||
cd ../verstak-official-plugins && ./scripts/publish-github-release.sh v0.1.0-alpha.2
|
||||
cd ../verstak-desktop && ./scripts/publish-github-release.sh v0.1.0-alpha.2
|
||||
gh release view v0.1.0-alpha.2 -R mirivlad/verstak-official-plugins
|
||||
gh release view v0.1.0-alpha.2 -R mirivlad/verstak
|
||||
```
|
||||
|
||||
The final report distinguishes automated verification from the two required real desktop manual checks: tray close/show/quit and a near-future Todo notification while the window is hidden.
|
||||
@@ -0,0 +1,182 @@
|
||||
# Native Notifications and System Tray Design
|
||||
|
||||
**Status:** implemented; tray reliability update recorded on 2026-07-15
|
||||
|
||||
## Goal
|
||||
|
||||
Deliver Todo reminders as native notifications on Windows and Linux, and keep
|
||||
Verstak running in the system tray when its main window is closed. The feature
|
||||
must work in the portable Windows archive, Debian package, and AppImage.
|
||||
|
||||
## Scope
|
||||
|
||||
- The desktop core owns notification delivery, scheduling, and tray lifetime.
|
||||
- `verstak.todo` owns the Todo-specific reminder policy and text.
|
||||
- No new official notifications plugin is introduced. A dynamic plugin cannot
|
||||
call Wails directly, so it cannot be the native-notification transport.
|
||||
- macOS is out of scope for this alpha. The interfaces remain platform-neutral
|
||||
where that costs nothing.
|
||||
|
||||
## Tray behavior
|
||||
|
||||
On Windows and Linux, a tray icon is initialized after Wails reaches
|
||||
`OnDomReady`. Its menu contains exactly two actions:
|
||||
|
||||
1. **Show Verstak** — shows and focuses the existing main window.
|
||||
2. **Quit** — exits the process deliberately.
|
||||
|
||||
One left click restores and focuses the existing main window. A native right
|
||||
click opens the menu. Closing the main window with its window-manager close
|
||||
control hides the window only after the tray has successfully initialized; it
|
||||
then keeps the process, plugins, local browser receiver, and reminder scheduler
|
||||
alive. If tray initialization fails or the native message loop exits, the
|
||||
ordinary close path exits normally rather than leaving an unreachable process.
|
||||
The quit action allows the close lifecycle to finish and exits normally.
|
||||
|
||||
The app has a single-instance lock. If a user launches the executable while an
|
||||
instance is hidden in the tray, the existing instance shows its window instead
|
||||
of creating a second process.
|
||||
|
||||
The implementation uses `fyne.io/systray` through a small
|
||||
`internal/shell/tray` adapter. `RunWithExternalLoop` starts the Windows native
|
||||
message loop without making Wails relinquish ownership of its GUI lifecycle.
|
||||
The icon is a source-controlled multi-resolution ICO on Windows (16, 20, 24,
|
||||
32, 48, and 256 pixels with transparency) and a PNG on Linux. Both are embedded
|
||||
in the binary, so a clean build does not depend on ignored Wails-generated
|
||||
files. Tray readiness is published only after icon, tooltip, and menu creation
|
||||
all succeed; lifecycle diagnostics are logged for startup, readiness, clicks,
|
||||
failure fallback, and shutdown.
|
||||
|
||||
## Notification capability and permission
|
||||
|
||||
The core registers the capability:
|
||||
|
||||
```
|
||||
verstak/core/notifications/v1
|
||||
```
|
||||
|
||||
Plugins that use it must both require that capability and declare the
|
||||
`notifications.schedule` permission. The plugin-host API exposes only two
|
||||
operations within the calling plugin namespace:
|
||||
|
||||
```
|
||||
api.notifications.replace(items)
|
||||
api.notifications.clear()
|
||||
```
|
||||
|
||||
`replace` is an atomic desired-state replacement, not an append operation. An
|
||||
item contains a plugin-local stable `id`, an ISO-8601 UTC `dueAt`, a title, and
|
||||
a body. The core supplies the plugin ID and rejects calls from disabled,
|
||||
missing-permission, or undeclared-capability plugins. It also validates empty
|
||||
IDs, duplicate IDs, invalid timestamps, and unsafe oversized text.
|
||||
|
||||
No plugin can send arbitrary immediate native notifications or address another
|
||||
plugin's schedules in this alpha.
|
||||
|
||||
## Scheduler and persistence
|
||||
|
||||
`internal/core/notifications` persists one canonical schedule file at:
|
||||
|
||||
```
|
||||
<vault>/.verstak/notifications/schedules.json
|
||||
```
|
||||
|
||||
Each record contains `{pluginId, id, dueAt, title, body, sentForDueAt}`.
|
||||
The composite `(pluginId, id)` is unique. Replacing an item with the same due
|
||||
time preserves `sentForDueAt`; changing `dueAt` clears it. Replacing a plugin's
|
||||
list removes its stale records. This provides deterministic cancellation for
|
||||
completed, deleted, and rescheduled Todos.
|
||||
|
||||
The manager starts after Wails reaches `OnDomReady`, initializes Wails native
|
||||
notifications, and evaluates the persisted schedule immediately and then at
|
||||
least every 30 seconds. A sender is injected behind an interface for unit
|
||||
tests. After a successful delivery, the manager atomically records
|
||||
`sentForDueAt`. A delivery error leaves the schedule pending and is logged for
|
||||
a later retry.
|
||||
|
||||
An expired record that has not been sent is delivered once after the next app
|
||||
start. A record already sent for its current due time is never sent again.
|
||||
Completely quitting Verstak stops the scheduler: no separate daemon or OS
|
||||
background service is added. Hiding the window in the tray does **not** stop it.
|
||||
|
||||
The core calls `CleanupNotifications` during shutdown, including on Linux where
|
||||
it releases the D-Bus connection.
|
||||
|
||||
## Todo behavior
|
||||
|
||||
`verstak.todo` adds the core notifications capability to `requires` and adds
|
||||
the `notifications.schedule` permission. After every successful Todo storage
|
||||
write, it derives the complete desired reminder list:
|
||||
|
||||
- include only open Todos with a valid `reminderAt`;
|
||||
- use the Todo ID as the stable notification ID;
|
||||
- convert local `datetime-local` input to an ISO-8601 UTC instant;
|
||||
- use the Todo title in the notification body and locale-aware reminder text;
|
||||
- call `api.notifications.replace` with the full list.
|
||||
|
||||
The same replacement runs after loading persisted Todos, so a transient
|
||||
schedule-write failure repairs itself next time the Todo view is opened. A
|
||||
schedule API failure does not roll back Todo data; the UI reports the failure
|
||||
instead. The existing in-view overdue/reminder badge remains useful context and
|
||||
is not removed.
|
||||
|
||||
## Packaging
|
||||
|
||||
`fyne.io/systray` supplies the Windows message loop and uses the session D-Bus
|
||||
on Linux. It does not require the removed AppIndicator development or runtime
|
||||
package. The Windows release build still uses `x86_64-w64-mingw32-gcc` for the
|
||||
Wails application itself.
|
||||
|
||||
The existing AppImage packager traverses `ldd` for the desktop executable and
|
||||
copies non-glibc runtime libraries; it does not require a tray-specific shared
|
||||
library.
|
||||
|
||||
## Public README and product screenshots
|
||||
|
||||
The workspace-root `README.md` and `README.ru.md` supplied by the maintainer
|
||||
become the public repository documents: the English source replaces this
|
||||
repository's `README.md`, and the Russian source is committed as
|
||||
`README.ru.md`. Their existing language links and public-release instructions
|
||||
are retained.
|
||||
|
||||
Three screenshots are captured from the real desktop application using the
|
||||
test vault, then committed under `docs/screenshots/`:
|
||||
|
||||
1. `overview.png` — returning to recent work and useful next actions;
|
||||
2. `workspace-files-notes.png` — ordinary vault files and Markdown notes in a
|
||||
workspace;
|
||||
3. `activity-journal.png` — review of a factual activity session as a Journal
|
||||
entry.
|
||||
|
||||
Both README variants include the same three images with localized alt text.
|
||||
They are factual UI captures, not generated illustrative mockups. Capture data
|
||||
must be limited to the disposable test vault and inspected before commit so no
|
||||
credentials or personal content are published.
|
||||
|
||||
## Test and manual verification
|
||||
|
||||
Automated tests cover:
|
||||
|
||||
- schedule replacement, cancellation, rescheduling, persistence, one-time
|
||||
overdue delivery, failed-send retry, and permission/capability rejection;
|
||||
- Todo desired-list derivation and calls after create/edit/status/delete;
|
||||
- close policy: ordinary close hides only after tray readiness, while explicit
|
||||
quit permits shutdown;
|
||||
- tray controller action wiring, readiness/failure fallback, idempotent stop,
|
||||
left-click reveal, and second-instance window reveal;
|
||||
- true multi-resolution Windows ICO data, Linux PNG data, and Linux/Windows
|
||||
build and package dependency expectations.
|
||||
|
||||
Manual smoke tests are required because neither unit tests nor Playwright can
|
||||
assert a real desktop notification area or OS toast:
|
||||
|
||||
1. On Linux and Windows, start Verstak, verify the tray icon and tooltip, use
|
||||
one left click to reveal the window, use the right-click menu to reveal it,
|
||||
close the window, and use **Quit** to terminate it.
|
||||
2. Set a Todo reminder for a near future time, hide the window in the tray, and
|
||||
observe one native notification.
|
||||
3. Quit before a future reminder, relaunch after it expires, and observe one
|
||||
overdue notification with no duplicate on the next scheduler scan.
|
||||
4. Inspect all three README screenshots at their committed size and confirm
|
||||
that they show only intended test-vault data and explain the feature named
|
||||
in their localized captions.
|
||||
@@ -27,6 +27,38 @@ test.describe('Activity workflow', () => {
|
||||
await expect(activity.locator('[data-activity-action="clear"]')).toBeDisabled();
|
||||
});
|
||||
|
||||
test('clearing activity requires destructive confirmation for the current case', async ({ page }) => {
|
||||
await page.evaluate(async () => {
|
||||
await window.go.api.App.WritePluginSettings('verstak.activity', {
|
||||
'events:workspace:Project': [{
|
||||
activityId: 'activity-to-clear',
|
||||
occurredAt: '2026-06-30T08:00:00.000Z',
|
||||
type: 'note.saved',
|
||||
title: 'Keep until confirmed',
|
||||
workspaceRootPath: 'Project',
|
||||
}],
|
||||
});
|
||||
});
|
||||
|
||||
await page.getByRole('tab', { name: 'Activity' }).click();
|
||||
const activity = page.locator('.activity-root');
|
||||
await expect(activity.locator('.activity-count')).toHaveText('1 event');
|
||||
|
||||
await activity.locator('[data-activity-action="clear"]').click();
|
||||
const confirmation = activity.locator('[data-activity-clear-confirmation]');
|
||||
await expect(confirmation).toBeVisible();
|
||||
await expect(confirmation).toContainText(/Project|Дело/);
|
||||
await expect(activity.locator('.activity-count')).toHaveText('1 event');
|
||||
|
||||
await confirmation.locator('[data-activity-clear-cancel]').click();
|
||||
await expect(confirmation).toHaveCount(0);
|
||||
await expect(activity.locator('.activity-count')).toHaveText('1 event');
|
||||
|
||||
await activity.locator('[data-activity-action="clear"]').click();
|
||||
await activity.locator('[data-activity-clear-confirm]').click();
|
||||
await expect(activity.locator('.activity-count')).toHaveText('0 events');
|
||||
});
|
||||
|
||||
test('workspace activity keeps raw events and renders factual work session candidates', async ({ page }) => {
|
||||
await page.evaluate(async () => {
|
||||
await window.go.api.App.WritePluginSettings('verstak.activity', {
|
||||
@@ -74,8 +106,8 @@ test.describe('Activity workflow', () => {
|
||||
await expect(candidateSection).toContainText('Possible journal entries');
|
||||
const candidate = candidateSection.locator('[data-work-session-candidate]');
|
||||
await expect(candidate).toHaveCount(1);
|
||||
await expect(candidate).toContainText('Workspace: Project');
|
||||
await expect(candidate).toContainText('Estimated duration: 20 min');
|
||||
await expect(candidate).toContainText('Deal: Project');
|
||||
await expect(candidate).toContainText('Estimated duration: 10 min');
|
||||
await expect(candidate).toContainText('Activities: 2');
|
||||
await expect(candidate).not.toContainText('Project work on');
|
||||
await expect(candidate.locator('[data-work-session-action="review"]')).toBeVisible();
|
||||
@@ -110,11 +142,11 @@ test.describe('Activity workflow', () => {
|
||||
await expect(page.getByRole('tab', { name: 'Journal' })).toHaveAttribute('aria-selected', 'true');
|
||||
const journal = page.locator('.journal-root');
|
||||
await expect(journal).toBeVisible({ timeout: 10000 });
|
||||
await expect(journal.locator('[data-journal-candidate]')).toContainText('Workspace: Project');
|
||||
await expect(journal.locator('[data-journal-candidate]')).toContainText('Estimated duration: 20 min');
|
||||
await expect(journal.locator('[data-journal-candidate]')).toContainText('Deal: Project');
|
||||
await expect(journal.locator('[data-journal-candidate]')).toContainText('Estimated duration: 10 min');
|
||||
await expect(journal.locator('[data-journal-input="title"]')).toHaveValue('');
|
||||
await expect(journal.locator('[data-journal-input="summary"]')).toHaveValue('');
|
||||
await expect(journal.locator('[data-journal-input="minutes"]')).toHaveValue('20');
|
||||
await expect(journal.locator('[data-journal-input="minutes"]')).toHaveValue('10');
|
||||
|
||||
const activityInputs = journal.locator('[data-journal-candidate-activity]');
|
||||
await expect(activityInputs).toHaveCount(2);
|
||||
@@ -126,7 +158,7 @@ test.describe('Activity workflow', () => {
|
||||
await journal.locator('[data-journal-action="save-entry"]').click();
|
||||
|
||||
await expect(journal).toContainText('Review research capture');
|
||||
await expect(journal).toContainText('20 min');
|
||||
await expect(journal).toContainText('10 min');
|
||||
const stored = await page.evaluate(async () => {
|
||||
const result = await window.go.api.App.ReadPluginSettings('verstak.journal');
|
||||
return Array.isArray(result) ? result[0]['worklog:workspace:Project'] : result['worklog:workspace:Project'];
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { waitForAppReady, setupConsoleCollector, resetMockState } from './helpers.js';
|
||||
|
||||
test.describe('Browser Inbox workflow', () => {
|
||||
test.describe('Browser workflow', () => {
|
||||
let consoleCollector;
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
@@ -16,14 +16,14 @@ test.describe('Browser Inbox workflow', () => {
|
||||
});
|
||||
|
||||
test('global inbox explains empty capture flow and exposes assignment filters', async ({ page }) => {
|
||||
await page.locator('.sidebar .plugin-item').filter({ hasText: 'Browser Inbox' }).click();
|
||||
await page.locator('.sidebar .plugin-item').filter({ hasText: 'Browser' }).click();
|
||||
|
||||
const inbox = page.locator('.browser-inbox-root');
|
||||
await expect(inbox).toBeVisible({ timeout: 10000 });
|
||||
await expect(inbox.locator('.browser-inbox-title')).toContainText('Browser Inbox');
|
||||
await expect(inbox.locator('.browser-inbox-title')).toHaveText('Browser');
|
||||
await expect(inbox.locator('.browser-inbox-count')).toHaveText('0 items');
|
||||
await expect(inbox.locator('.browser-inbox-empty')).toContainText('No browser captures yet');
|
||||
await expect(inbox.locator('.browser-inbox-empty')).toContainText('send a page, selection, link, or file from the browser extension');
|
||||
await expect(inbox.locator('.browser-inbox-empty')).toContainText('No browser materials yet');
|
||||
await expect(inbox.locator('.browser-inbox-empty')).toContainText('Send a page, selection, or link from the extension');
|
||||
await expect(inbox.locator('[data-browser-inbox-filter="status"]')).toBeVisible();
|
||||
await expect(inbox.locator('[data-browser-inbox-filter="workspace"]')).toBeVisible();
|
||||
await expect(inbox.locator('[data-browser-inbox-action="clear"]')).toBeDisabled();
|
||||
@@ -47,7 +47,7 @@ test.describe('Browser Inbox workflow', () => {
|
||||
}],
|
||||
});
|
||||
});
|
||||
await page.getByRole('tab', { name: 'Browser Inbox' }).click();
|
||||
await page.getByRole('tab', { name: 'Browser' }).click();
|
||||
|
||||
const inbox = page.locator('.browser-inbox-root');
|
||||
await expect(inbox.locator('.browser-inbox-count')).toHaveText('1 item');
|
||||
@@ -94,7 +94,7 @@ test.describe('Browser Inbox workflow', () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
await page.locator('.sidebar .plugin-item').filter({ hasText: 'Browser Inbox' }).click();
|
||||
await page.locator('.sidebar .plugin-item').filter({ hasText: 'Browser' }).click();
|
||||
|
||||
const inbox = page.locator('.browser-inbox-root');
|
||||
await expect(inbox.locator('.browser-inbox-count')).toHaveText('3 items');
|
||||
|
||||
@@ -124,4 +124,20 @@ test.describe('Command Palette', () => {
|
||||
await expect(page.locator('.modal[aria-label="Plugin Settings"]')).toBeVisible({ timeout: 10000 });
|
||||
await expect(page.locator('.modal-header h3')).toContainText('Sync');
|
||||
});
|
||||
|
||||
test('keeps technical command failures out of the palette status', async ({ page }) => {
|
||||
await page.evaluate(() => {
|
||||
window.go.api.App.PluginSyncNow = () => Promise.resolve('[plugin:verstak.sync] sync.now failed: internal service code 42');
|
||||
});
|
||||
|
||||
await page.keyboard.press(process.platform === 'darwin' ? 'Meta+K' : 'Control+K');
|
||||
const palette = page.locator('.command-palette');
|
||||
await palette.locator('[data-command-palette-input]').fill('sync now');
|
||||
await page.keyboard.press('Enter');
|
||||
|
||||
const status = page.locator('[data-command-palette-status="error"]');
|
||||
await expect(status).toContainText('Could not run Sync Now. Please try again.');
|
||||
await expect(status).not.toContainText('[plugin:');
|
||||
await expect(status).not.toContainText('sync.now');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -36,6 +36,69 @@ test.describe('F: Default Editor Plugin', () => {
|
||||
await expect(textarea).toHaveValue('Buy groceries\nWrite tests');
|
||||
});
|
||||
|
||||
test('secret link opens its exact secret and closing it restores the note preview', async ({ page }) => {
|
||||
const notePath = 'Notes/Secret Link.md';
|
||||
const noteContent = '# Secret link\n\n[Target secret](verstak-secret://target.secret)';
|
||||
|
||||
await page.evaluate(async ({ notePath, noteContent }) => {
|
||||
const writeError = await window.go.api.App.WriteVaultTextFile(
|
||||
'verstak.platform-test',
|
||||
notePath,
|
||||
noteContent,
|
||||
{ createIfMissing: true, overwrite: true },
|
||||
);
|
||||
if (writeError) throw new Error(writeError);
|
||||
const [result, openError] = await window.go.api.App.OpenWorkbenchResource('verstak.platform-test', {
|
||||
kind: 'vault-file',
|
||||
path: notePath,
|
||||
extension: '.md',
|
||||
context: { sourceView: 'notes', isInsideNotesFolder: true, notesMode: true },
|
||||
});
|
||||
if (openError) throw new Error(openError);
|
||||
window.dispatchEvent(new CustomEvent('verstak:workbench-opened', { detail: result }));
|
||||
}, { notePath, noteContent });
|
||||
|
||||
const note = page.locator('[data-editor-mode="notes-markdown"]');
|
||||
await expect(note).toBeVisible({ timeout: 10000 });
|
||||
await expect(note.locator('[data-preview]')).toContainText('Target secret');
|
||||
await note.locator('.secret-link').click();
|
||||
|
||||
const secrets = page.locator('.secrets-root');
|
||||
await expect(secrets).toBeVisible({ timeout: 10000 });
|
||||
await expect(secrets.locator('.secrets-item.active .secrets-item-title')).toHaveText('Target secret');
|
||||
await expect(secrets.locator('.secrets-card h2')).toHaveText('Target secret');
|
||||
|
||||
await page.locator('.workbench-host .close-btn').click();
|
||||
await expect(note).toBeVisible({ timeout: 10000 });
|
||||
await expect(note.locator('[data-preview]')).toContainText('Target secret');
|
||||
await expect(note.locator('[data-editor-textarea]')).toHaveCount(0);
|
||||
await expect(note.locator('[data-save-state]')).toHaveText('');
|
||||
|
||||
const storedContent = await page.evaluate(async ({ notePath }) => {
|
||||
const [content, readError] = await window.go.api.App.ReadVaultTextFile('verstak.platform-test', notePath);
|
||||
if (readError) throw new Error(readError);
|
||||
return content;
|
||||
}, { notePath });
|
||||
expect(storedContent).toBe(noteContent);
|
||||
});
|
||||
|
||||
test('unavailable secret does not fall back to the first secret', async ({ page }) => {
|
||||
await page.evaluate(async () => {
|
||||
const [result, openError] = await window.go.api.App.OpenWorkbenchResource('verstak.default-editor', {
|
||||
kind: 'secret',
|
||||
path: 'missing.secret',
|
||||
mode: 'view',
|
||||
});
|
||||
if (openError) throw new Error(openError);
|
||||
window.dispatchEvent(new CustomEvent('verstak:workbench-opened', { detail: result }));
|
||||
});
|
||||
|
||||
const secrets = page.locator('.secrets-root');
|
||||
await expect(secrets).toBeVisible({ timeout: 10000 });
|
||||
await expect(secrets.locator('.secrets-item.active')).toHaveCount(0);
|
||||
await expect(secrets.locator('.secrets-status.error')).toContainText(/unavailable|недоступен/i);
|
||||
});
|
||||
|
||||
test('editor supports markdown toolbar split save reopen and revert', async ({ page }) => {
|
||||
await page.evaluate(async () => {
|
||||
const err = await window.go.api.App.WriteVaultTextFile(
|
||||
@@ -112,10 +175,10 @@ test.describe('F: Default Editor Plugin', () => {
|
||||
const workbench = page.locator('.workbench-host');
|
||||
await expect(workbench).toBeVisible({ timeout: 10000 });
|
||||
const title = workbench.locator('.workbench-title');
|
||||
await expect(title).toHaveText('Docs/readme.md');
|
||||
await expect(title).toHaveText('readme.md');
|
||||
});
|
||||
|
||||
test('open .md with notes context routes to highest-priority provider', async ({ page }) => {
|
||||
test('opening a note uses its title rather than its technical path', async ({ page }) => {
|
||||
await page.evaluate(async () => {
|
||||
const [result, err] = await window.go.api.App.OpenWorkbenchResource('verstak.platform-test', {
|
||||
kind: 'vault-file',
|
||||
@@ -130,7 +193,7 @@ test.describe('F: Default Editor Plugin', () => {
|
||||
const workbench = page.locator('.workbench-host');
|
||||
await expect(workbench).toBeVisible({ timeout: 10000 });
|
||||
const title = workbench.locator('.workbench-title');
|
||||
await expect(title).toHaveText('Notes/Overview.md');
|
||||
await expect(title).toHaveText('Overview');
|
||||
});
|
||||
|
||||
test('default-editor plugin is listed as loaded in plugin manager', async ({ page }) => {
|
||||
|
||||
@@ -513,7 +513,7 @@ test.describe('G: Files Plugin', () => {
|
||||
|
||||
const workbench = page.locator('.workbench-host');
|
||||
await expect(workbench).toBeVisible({ timeout: 10000 });
|
||||
await expect(workbench.locator('.workbench-title')).toHaveText('Docs/readme.md');
|
||||
await expect(workbench.locator('.workbench-title')).toHaveText('readme.md');
|
||||
|
||||
const preview = page.locator('.de-preview');
|
||||
await expect(preview).toBeVisible({ timeout: 10000 });
|
||||
@@ -535,7 +535,7 @@ test.describe('G: Files Plugin', () => {
|
||||
|
||||
const workbench = page.locator('.workbench-host');
|
||||
await expect(workbench).toBeVisible({ timeout: 10000 });
|
||||
await expect(workbench.locator('.workbench-title')).toHaveText('Notes/Overview.md');
|
||||
await expect(workbench.locator('.workbench-title')).toHaveText('Overview');
|
||||
});
|
||||
|
||||
test('files plugin card shows openProviders in contributions', async ({ page }) => {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { waitForAppReady, setupConsoleCollector, resetMockState } from './helpers.js';
|
||||
|
||||
test('global Journal creates an entry in the selected Deal', async ({ page }) => {
|
||||
const consoleCollector = setupConsoleCollector(page);
|
||||
await resetMockState(page);
|
||||
await page.goto('/');
|
||||
await waitForAppReady(page);
|
||||
await page.evaluate(async () => {
|
||||
await window.go.api.App.WritePluginSettings('verstak.journal', {
|
||||
'worklog:workspace:Project': [{ entryId: 'existing-project-entry', workspaceRootPath: 'Project', date: '2026-07-14', title: 'Existing entry', minutes: 5 }],
|
||||
});
|
||||
});
|
||||
|
||||
await page.locator('.sidebar .plugin-item').filter({ hasText: 'Journal' }).click();
|
||||
const journal = page.locator('.journal-root');
|
||||
await expect(journal.locator('.journal-title')).toHaveText('Journal');
|
||||
await journal.locator('[data-journal-action="add"]').click();
|
||||
await journal.locator('[data-journal-input="workspaceRootPath"]').selectOption('Project');
|
||||
await journal.locator('[data-journal-input="title"]').fill('Prepare project handoff');
|
||||
await journal.locator('[data-journal-input="minutes"]').fill('30');
|
||||
await journal.locator('[data-journal-action="save-entry"]').click();
|
||||
|
||||
await expect.poll(async () => page.evaluate(async () => {
|
||||
const result = await window.go.api.App.ReadPluginSettings('verstak.journal');
|
||||
const settings = Array.isArray(result) ? result[0] : result;
|
||||
return settings['worklog:workspace:Project']?.[0]?.title;
|
||||
})).toBe('Prepare project handoff');
|
||||
await expect(journal).toContainText('Prepare project handoff');
|
||||
|
||||
await page.locator('.wt-label').filter({ hasText: 'Project' }).click();
|
||||
await page.getByRole('tab', { name: 'Journal' }).click();
|
||||
await expect(page.locator('.journal-root')).toContainText('Prepare project handoff');
|
||||
consoleCollector.assertNoErrors();
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { waitForAppReady, setupConsoleCollector, resetMockState } from './helpers.js';
|
||||
|
||||
test.describe('Desktop localization', () => {
|
||||
let consoleCollector;
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
consoleCollector = setupConsoleCollector(page);
|
||||
await resetMockState(page);
|
||||
await page.goto('/');
|
||||
await waitForAppReady(page);
|
||||
});
|
||||
|
||||
test.afterEach(async () => {
|
||||
consoleCollector.assertNoErrors();
|
||||
});
|
||||
|
||||
test('switches shell language live and persists the choice', async ({ page }) => {
|
||||
await page.locator('[data-settings-menu-button]').click();
|
||||
await expect(page.locator('[data-settings-language="system"]')).toHaveAttribute('aria-checked', 'true');
|
||||
await page.locator('[data-settings-language="ru"]').click();
|
||||
|
||||
await expect(page.locator('[data-settings-menu-button]')).toHaveAttribute('title', 'Настройки');
|
||||
await expect(page.locator('.vault-status')).toContainText('Хранилище: открыто');
|
||||
await expect(page.locator('.sidebar .plugin-item').filter({ hasText: 'Тест платформы' })).toBeVisible();
|
||||
await expect(page.locator('[data-status-item-id="verstak.platform-test.status"]')).toContainText('Все тесты пройдены');
|
||||
|
||||
const project = page.locator('.wt-node').filter({ hasText: 'Project' });
|
||||
await project.locator('button[title="Переименовать Дело"]').click();
|
||||
await expect(page.locator('button[title="Сохранить новое название"]')).toHaveText('Сохранить');
|
||||
await page.locator('.wt-rename').press('Escape');
|
||||
|
||||
await page.locator('[data-settings-menu-button]').click();
|
||||
await expect(page.locator('[data-settings-action="plugin-manager"]')).toContainText('Менеджер плагинов');
|
||||
await expect(page.locator('[data-settings-language="ru"]')).toHaveAttribute('aria-checked', 'true');
|
||||
await page.locator('[data-settings-action="plugin-manager"]').click();
|
||||
const pluginManager = page.locator('.plugin-manager');
|
||||
await expect(pluginManager).toContainText('Зарегистрировано возможностей:');
|
||||
await expect(pluginManager.locator('.registry-section')).toContainText('Реестр возможностей');
|
||||
await expect(pluginManager.locator('.registry-section')).toContainText('Возможность');
|
||||
await expect(pluginManager.locator('.plugin-filters')).toContainText('Фильтры');
|
||||
await expect(pluginManager.locator('[data-plugin-filter-results]')).toContainText('Показано плагинов:');
|
||||
await expect(pluginManager.locator('[data-plugin-filter="status"]')).toContainText('Выключенные');
|
||||
await expect(pluginManager).not.toContainText('Workspace-scoped');
|
||||
|
||||
await page.reload();
|
||||
await waitForAppReady(page);
|
||||
await expect(page.locator('[data-settings-menu-button]')).toHaveAttribute('title', 'Настройки');
|
||||
await page.locator('[data-settings-menu-button]').click();
|
||||
await expect(page.locator('[data-settings-language="ru"]')).toHaveAttribute('aria-checked', 'true');
|
||||
});
|
||||
|
||||
test('switches back to English without reloading', async ({ page }) => {
|
||||
await page.locator('[data-settings-menu-button]').click();
|
||||
await page.locator('[data-settings-language="ru"]').click();
|
||||
await page.locator('[data-settings-menu-button]').click();
|
||||
await page.locator('[data-settings-language="en"]').click();
|
||||
|
||||
await expect(page.locator('[data-settings-menu-button]')).toHaveAttribute('title', 'Settings');
|
||||
await expect(page.locator('.vault-status')).toContainText('Vault: open');
|
||||
});
|
||||
});
|
||||
@@ -58,7 +58,7 @@ test.describe('D: Plugin API bridge', () => {
|
||||
|
||||
const workbench = page.locator('.workbench-host');
|
||||
await expect(workbench).toBeVisible({ timeout: 10000 });
|
||||
await expect(workbench.locator('.workbench-title')).toHaveText('Notes/Overview.md');
|
||||
await expect(workbench.locator('.workbench-title')).toHaveText('Overview');
|
||||
});
|
||||
|
||||
test('workbench routes markdown files to default-editor provider', async ({ page }) => {
|
||||
@@ -76,7 +76,7 @@ test.describe('D: Plugin API bridge', () => {
|
||||
const workbench = page.locator('.workbench-host');
|
||||
await expect(workbench).toBeVisible({ timeout: 10000 });
|
||||
const title = workbench.locator('.workbench-title');
|
||||
await expect(title).toHaveText('Docs/readme.md');
|
||||
await expect(title).toHaveText('readme.md');
|
||||
});
|
||||
|
||||
test('workbench shows no-provider fallback when no provider matches', async ({ page }) => {
|
||||
@@ -91,8 +91,10 @@ test.describe('D: Plugin API bridge', () => {
|
||||
window.dispatchEvent(new CustomEvent('verstak:workbench-opened', { detail: result }));
|
||||
});
|
||||
|
||||
await expect(page.locator('[data-workbench-status="no-provider"]')).toBeVisible();
|
||||
await expect(page.locator('[data-workbench-status="no-provider"]')).toContainText('No viewer/editor available');
|
||||
const fallback = page.locator('[data-workbench-status="no-provider"]');
|
||||
await expect(fallback).toBeVisible();
|
||||
await expect(fallback).toContainText('No viewer/editor available');
|
||||
await expect(fallback).not.toContainText('generic-text');
|
||||
});
|
||||
|
||||
test('sync plugin API routes through mocked Wails bridge', async ({ page }) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { waitForAppReady, setupConsoleCollector, resetMockState, openPluginManager } from './helpers.js';
|
||||
import { waitForAppReady, setupConsoleCollector, resetMockState, openPluginManager, setPluginStatus } from './helpers.js';
|
||||
|
||||
test.describe('E: Plugin Manager layout', () => {
|
||||
let consoleCollector;
|
||||
@@ -88,6 +88,56 @@ test.describe('E: Plugin Manager layout', () => {
|
||||
await expect(risk).toContainText('elevated permissions');
|
||||
});
|
||||
|
||||
test('plugin manager filters by state, declared permissions, capabilities, settings and source', async ({ page }) => {
|
||||
await setPluginStatus(page, 'verstak.todo', 'disabled', false);
|
||||
await page.evaluate(() => window.__wailsMock.addSyntheticPlugins(1, 'third-party'));
|
||||
await openPluginManager(page);
|
||||
|
||||
const results = page.locator('[data-plugin-filter-results]');
|
||||
await expect(results).toContainText('Showing');
|
||||
const filterSelectStyle = await page.locator('[data-plugin-filter="status"]').evaluate((node) => {
|
||||
const style = getComputedStyle(node);
|
||||
return { appearance: style.appearance, backgroundImage: style.backgroundImage };
|
||||
});
|
||||
expect(filterSelectStyle.appearance).toBe('none');
|
||||
expect(filterSelectStyle.backgroundImage).not.toBe('none');
|
||||
|
||||
await page.locator('[data-plugin-filter="status"]').selectOption('disabled');
|
||||
await expect(page.locator('.plugin-card')).toHaveCount(1);
|
||||
await expect(page.locator('.plugin-card')).toContainText('Todos');
|
||||
await page.locator('button.reload-btn').click();
|
||||
await expect(page.locator('[data-plugin-filter="status"]')).toHaveValue('disabled');
|
||||
await expect(page.locator('.plugin-card')).toHaveCount(1);
|
||||
|
||||
await page.locator('[data-plugin-filter-reset]').click();
|
||||
await page.locator('[data-plugin-filter-permission="notifications.schedule"]').check();
|
||||
await expect(page.locator('.plugin-card')).toHaveCount(1);
|
||||
await expect(page.locator('.plugin-card')).toContainText('Todos');
|
||||
await page.locator('[data-plugin-filter-permission="secrets.read"]').check();
|
||||
await expect(page.locator('.plugin-card')).toHaveCount(2);
|
||||
await page.locator('[data-plugin-filter-permission="secrets.read"]').uncheck();
|
||||
|
||||
await page.locator('[data-plugin-filter-reset]').click();
|
||||
await page.locator('[data-plugin-filter-capability="verstak/core/notifications/v1"]').check();
|
||||
await expect(page.locator('.plugin-card')).toHaveCount(1);
|
||||
await expect(page.locator('.plugin-card')).toContainText('Todos');
|
||||
await page.locator('[data-plugin-filter-capability="secret-store"]').check();
|
||||
await expect(page.locator('.plugin-card')).toHaveCount(2);
|
||||
await page.locator('[data-plugin-filter-capability="secret-store"]').uncheck();
|
||||
|
||||
await page.locator('[data-plugin-filter-reset]').click();
|
||||
await page.locator('[data-plugin-filter="settings"]').selectOption('with');
|
||||
await expect(page.locator('.plugin-card').filter({ hasText: 'Platform Test' })).toBeVisible();
|
||||
await expect(page.locator('.plugin-card').filter({ hasText: 'Default Editor' })).toHaveCount(0);
|
||||
|
||||
await page.locator('[data-plugin-filter="source"]').selectOption('third-party');
|
||||
await expect(page.locator('.plugin-card')).toHaveCount(0);
|
||||
await expect(page.locator('[data-plugin-filter-empty]')).toBeVisible();
|
||||
|
||||
await page.locator('[data-plugin-filter-reset]').click();
|
||||
await expect(page.locator('.plugin-card')).toHaveCount(13);
|
||||
});
|
||||
|
||||
test('workspace selection keeps exactly one active node', async ({ page }) => {
|
||||
const selected = page.locator('.wt-node.selected .wt-label');
|
||||
await expect(selected).toHaveCount(1);
|
||||
@@ -118,15 +168,15 @@ test.describe('E: Plugin Manager layout', () => {
|
||||
});
|
||||
|
||||
test('workspace sidebar creates renames and trashes top-level workspaces', async ({ page }) => {
|
||||
await page.locator('button[title="New workspace"]').click();
|
||||
await page.locator('button[title="New Deal"]').click();
|
||||
const modal = page.locator('[data-workspace-create-modal]');
|
||||
await modal.locator('[data-workspace-name]').fill('ClientA');
|
||||
await modal.getByRole('button', { name: 'Create workspace' }).click();
|
||||
await modal.getByRole('button', { name: 'Create Deal' }).click();
|
||||
|
||||
await expect(page.locator('.wt-label').filter({ hasText: 'ClientA' })).toBeVisible();
|
||||
|
||||
const client = page.locator('.wt-node').filter({ hasText: 'ClientA' });
|
||||
await client.locator('button[title="Rename workspace"]').click();
|
||||
await client.locator('button[title="Rename Deal"]').click();
|
||||
await page.locator('.wt-rename').fill('ClientB');
|
||||
await page.locator('button[title="Save rename"]').click();
|
||||
|
||||
@@ -134,7 +184,7 @@ test.describe('E: Plugin Manager layout', () => {
|
||||
await expect(page.locator('.wt-label').filter({ hasText: 'ClientA' })).toHaveCount(0);
|
||||
|
||||
const renamed = page.locator('.wt-node').filter({ hasText: 'ClientB' });
|
||||
await renamed.locator('button[title="Trash workspace"]').click();
|
||||
await renamed.locator('button[title="Move Deal to trash"]').click();
|
||||
|
||||
await expect(page.locator('.wt-label').filter({ hasText: 'ClientB' })).toHaveCount(0);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { waitForAppReady, setupConsoleCollector, resetMockState } from './helpers.js';
|
||||
|
||||
test('global Secrets lists, filters, and creates Deal-scoped secrets', async ({ page }) => {
|
||||
const consoleCollector = setupConsoleCollector(page);
|
||||
await resetMockState(page);
|
||||
await page.goto('/');
|
||||
await waitForAppReady(page);
|
||||
|
||||
await page.evaluate(async () => {
|
||||
const [record, error] = await window.go.api.App.PluginSecretsWrite('verstak.secrets', {
|
||||
id: 'project.global-secret',
|
||||
title: 'Project API',
|
||||
username: 'project-user',
|
||||
value: 'project-value',
|
||||
scope: { kind: 'workspace', workspaceRootPath: 'Project' },
|
||||
});
|
||||
if (error || !record?.id) throw new Error(error || 'could not create a project secret');
|
||||
});
|
||||
|
||||
await page.locator('.sidebar .plugin-item').filter({ hasText: 'Secrets' }).click();
|
||||
const secrets = page.locator('.secrets-root');
|
||||
await expect(secrets).toBeVisible({ timeout: 10000 });
|
||||
await expect(secrets).toContainText('First secret');
|
||||
await expect(secrets).toContainText('Project API');
|
||||
|
||||
await secrets.locator('[data-secret-scope-filter]').selectOption('workspace:Project');
|
||||
await expect(secrets).toContainText('Project API');
|
||||
await expect(secrets).not.toContainText('First secret');
|
||||
|
||||
await secrets.locator('[data-secret-search]').fill('no matching secret');
|
||||
await expect(secrets).toContainText('No secrets');
|
||||
await secrets.locator('[data-secret-search]').fill('');
|
||||
|
||||
await secrets.locator('[data-secret-scope-filter]').selectOption('all');
|
||||
await secrets.getByRole('button', { name: 'New' }).click();
|
||||
await secrets.locator('[data-secret-title]').fill('Project deployment token');
|
||||
await secrets.locator('[data-secret-value]').fill('deployment-token-value');
|
||||
await secrets.locator('[data-secret-scope]').selectOption('workspace');
|
||||
await secrets.locator('[data-secret-workspace]').selectOption('Project');
|
||||
await secrets.locator('[data-secret-save]').click();
|
||||
|
||||
await expect.poll(async () => page.evaluate(async () => {
|
||||
const [records, error] = await window.go.api.App.PluginSecretsList('verstak.secrets');
|
||||
if (error) throw new Error(error);
|
||||
const record = records.find((item) => item.title === 'Project deployment token');
|
||||
return record && [record.scope?.kind, record.scope?.workspaceRootPath].join('|');
|
||||
})).toBe('workspace|Project');
|
||||
consoleCollector.assertNoErrors();
|
||||
});
|
||||
@@ -30,18 +30,45 @@ test.describe('B: Sidebar opens plugin view by item.view', () => {
|
||||
test('Sidebar item exists with correct label', async ({ page }) => {
|
||||
await expect(page.locator('.sidebar .nav-item').filter({ hasText: 'Plugin Manager' })).not.toBeVisible();
|
||||
await expect(page.locator('.sidebar .plugin-item').filter({ hasText: 'Activity' })).toBeVisible();
|
||||
await expect(page.locator('.sidebar .plugin-item').filter({ hasText: 'Browser Inbox' })).toBeVisible();
|
||||
await expect(page.locator('.sidebar .plugin-item').filter({ hasText: 'Browser' })).toBeVisible();
|
||||
|
||||
const sidebarItem = page.locator('.sidebar .plugin-item').filter({ hasText: 'Platform Test' });
|
||||
await expect(sidebarItem).toBeVisible();
|
||||
});
|
||||
|
||||
test('Global Activity and Browser Inbox sidebar items open plugin views', async ({ page }) => {
|
||||
test('Global Activity and Browser sidebar items open plugin views', async ({ page }) => {
|
||||
await page.locator('.sidebar .plugin-item').filter({ hasText: 'Activity' }).click();
|
||||
await expect(page.locator('.view-container .view-header h2')).toHaveText('Activity', { timeout: 10000 });
|
||||
|
||||
await page.locator('.sidebar .plugin-item').filter({ hasText: 'Browser Inbox' }).click();
|
||||
await expect(page.locator('.view-container .view-header h2')).toHaveText('Browser Inbox', { timeout: 10000 });
|
||||
await page.locator('.sidebar .plugin-item').filter({ hasText: 'Browser' }).click();
|
||||
await expect(page.locator('.view-container .view-header h2')).toHaveText('Browser', { timeout: 10000 });
|
||||
});
|
||||
|
||||
test('selected global tool remains visibly active through navigation and sidebar reloads', async ({ page }) => {
|
||||
const activity = page.locator('.sidebar .plugin-item').filter({ hasText: 'Activity' });
|
||||
const browserInbox = page.locator('.sidebar .plugin-item').filter({ hasText: 'Browser' });
|
||||
|
||||
await activity.click();
|
||||
await expect(activity).toHaveAttribute('aria-current', 'page');
|
||||
await expect(activity).toHaveClass(/is-active/);
|
||||
|
||||
await page.evaluate(() => {
|
||||
window.dispatchEvent(new CustomEvent('verstak:plugins-changed'));
|
||||
});
|
||||
await expect(activity).toHaveAttribute('aria-current', 'page');
|
||||
|
||||
await page.evaluate(() => {
|
||||
window.dispatchEvent(new CustomEvent('verstak:open-view', {
|
||||
detail: { viewId: 'verstak.browser-inbox.view', pluginId: 'verstak.browser-inbox' },
|
||||
}));
|
||||
});
|
||||
await expect(page.locator('.view-container .view-header h2')).toHaveText('Browser', { timeout: 10000 });
|
||||
await expect(browserInbox).toHaveAttribute('aria-current', 'page');
|
||||
await expect(browserInbox).toHaveClass(/is-active/);
|
||||
await expect(activity).not.toHaveAttribute('aria-current', 'page');
|
||||
|
||||
await page.locator('.wt-label').filter({ hasText: 'Project' }).click();
|
||||
await expect(browserInbox).not.toHaveAttribute('aria-current', 'page');
|
||||
});
|
||||
|
||||
test('Click sidebar item opens diagnostics view by view ID, not sidebar ID', async ({ page }) => {
|
||||
|
||||
@@ -27,7 +27,10 @@ test.describe('Todo plugin workflow', () => {
|
||||
await todos.locator('[data-todo-input="description"]').fill('Collect factual review notes.');
|
||||
await todos.locator('[data-todo-input="priority"]').selectOption('high');
|
||||
await todos.locator('[data-todo-input="dueAt"]').fill('2000-01-01');
|
||||
await todos.locator('[data-todo-input="reminderAt"]').fill('2000-01-01T09:00');
|
||||
await todos.locator('[data-todo-input="reminderDate"]').fill('2000-01-01');
|
||||
const reminderTime = todos.locator('[data-todo-input="reminderTime"]');
|
||||
await expect(reminderTime).toHaveAttribute('type', 'text');
|
||||
await reminderTime.fill('09:30');
|
||||
await todos.locator('[data-todo-action="save"]').click();
|
||||
|
||||
await expect(todos).toContainText('Overdue');
|
||||
@@ -36,13 +39,23 @@ test.describe('Todo plugin workflow', () => {
|
||||
const result = await window.go.api.App.ReadPluginSettings('verstak.todo');
|
||||
const settings = Array.isArray(result) ? result[0] : result;
|
||||
const todo = settings['todos:global'].find((item) => item.title === 'Prepare project review');
|
||||
return todo && [todo.workspaceRootPath, todo.priority, todo.dueAt, todo.reminderAt].join('|');
|
||||
})).toBe('Project|high|2000-01-01|2000-01-01T09:00');
|
||||
return todo && [todo.workspaceRootPath, todo.priority, todo.dueAt, todo.reminderDate, todo.reminderAt].join('|');
|
||||
})).toBe('Project|high|2000-01-01|2000-01-01|2000-01-01T09:30');
|
||||
|
||||
await todos.locator('[data-todo-action="edit"]').click();
|
||||
await todos.locator('[data-todo-input="title"]').fill('Prepare project review updated');
|
||||
await todos.locator('[data-todo-input="reminderTime"]').fill('not-a-time');
|
||||
await todos.locator('[data-todo-action="save"]').click();
|
||||
await expect(todos).toContainText('Enter a valid reminder time');
|
||||
await todos.locator('[data-todo-input="reminderTime"]').fill('');
|
||||
await todos.locator('[data-todo-action="save"]').click();
|
||||
await expect(todos).toContainText('Prepare project review updated');
|
||||
await expect.poll(async () => page.evaluate(async () => {
|
||||
const result = await window.go.api.App.ReadPluginSettings('verstak.todo');
|
||||
const settings = Array.isArray(result) ? result[0] : result;
|
||||
const todo = settings['todos:global'].find((item) => item.title === 'Prepare project review updated');
|
||||
return todo && [todo.reminderDate, todo.reminderAt].join('|');
|
||||
})).toBe('2000-01-01|');
|
||||
|
||||
await todos.locator('[data-todo-action="mark-done"]').click();
|
||||
await expect(todos.locator('[data-todo-action="create-journal-entry"]')).toBeVisible();
|
||||
|
||||
@@ -18,7 +18,7 @@ test.describe('UX follow-up fixes', () => {
|
||||
await expect(search).toBeVisible();
|
||||
await expect(page.locator('.sidebar [data-global-search-input]')).toBeVisible();
|
||||
|
||||
await page.locator('.sidebar .nav-item').filter({ hasText: 'Browser Inbox' }).click();
|
||||
await page.locator('.sidebar .nav-item').filter({ hasText: 'Browser' }).click();
|
||||
await expect(page.locator('.browser-inbox-root')).toBeVisible({ timeout: 10000 });
|
||||
await expect(search).toBeVisible();
|
||||
});
|
||||
@@ -67,7 +67,7 @@ test.describe('UX follow-up fixes', () => {
|
||||
|
||||
const search = page.locator('[data-global-search-input]');
|
||||
await search.fill('Research Search Result');
|
||||
const result = page.locator('[data-global-search-result-type="Browser Inbox"]').filter({ hasText: 'Research Search Result' });
|
||||
const result = page.locator('[data-global-search-result-type="Browser"]').filter({ hasText: 'Research Search Result' });
|
||||
await expect(result).toBeVisible({ timeout: 10000 });
|
||||
await result.click();
|
||||
|
||||
|
||||
@@ -38,6 +38,11 @@ test.describe('UX P0 shell flow', () => {
|
||||
await expect(page.locator('.plugin-manager')).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('Deal header does not expose the internal workspace type badge', async ({ page }) => {
|
||||
await expect(page.locator('.workspace-host')).toBeVisible({ timeout: 10000 });
|
||||
await expect(page.locator('.workspace-type')).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('status bar plugin contribution failures do not render large error panels', async ({ page }) => {
|
||||
await expect(page.locator('.workspace-host')).toBeVisible({ timeout: 10000 });
|
||||
await expect(page.getByText('Plugin View Error')).toHaveCount(0);
|
||||
|
||||
@@ -56,7 +56,7 @@ test.describe('UX Overview workspace flow', () => {
|
||||
await page.getByRole('tab', { name: 'Overview' }).click();
|
||||
await overview.locator('[data-overview-summary="captures"]').click();
|
||||
|
||||
await expect(page.getByRole('tab', { name: 'Browser Inbox' })).toHaveAttribute('aria-selected', 'true');
|
||||
await expect(page.getByRole('tab', { name: 'Browser' })).toHaveAttribute('aria-selected', 'true');
|
||||
await expect(page.locator('.browser-inbox-root')).toBeVisible({ timeout: 10000 });
|
||||
|
||||
await page.getByRole('tab', { name: 'Overview' }).click();
|
||||
@@ -70,7 +70,7 @@ test.describe('UX Overview workspace flow', () => {
|
||||
|
||||
await page.getByRole('tab', { name: 'Overview' }).click();
|
||||
await overview.locator('[data-overview-summary="attention"]').click();
|
||||
await expect(page.getByRole('tab', { name: 'Browser Inbox' })).toHaveAttribute('aria-selected', 'true');
|
||||
await expect(page.getByRole('tab', { name: 'Browser' })).toHaveAttribute('aria-selected', 'true');
|
||||
});
|
||||
|
||||
test('Overview keeps the Notes total factual when the Files plugin is unavailable', async ({ page }) => {
|
||||
@@ -80,6 +80,54 @@ test.describe('UX Overview workspace flow', () => {
|
||||
await expect(page.locator('[data-overview-summary="notes"]')).toContainText('1 total');
|
||||
});
|
||||
|
||||
test('Overview hides Browser cards and actions when the current Deal does not include it', async ({ page }) => {
|
||||
await page.locator('button[title="New Deal"]').click();
|
||||
const modal = page.locator('[data-workspace-create-modal]');
|
||||
await modal.locator('[data-workspace-name]').fill('MinimalOverview');
|
||||
await modal.locator('[data-workspace-template]').selectOption('minimal');
|
||||
await modal.getByRole('button', { name: 'Create Deal' }).click();
|
||||
await expect(page.getByRole('tab', { name: 'Browser' })).toHaveCount(0);
|
||||
|
||||
await page.evaluate(async () => {
|
||||
await window.go.api.App.WritePluginSettings('verstak.browser-inbox', {
|
||||
'captures:global': [{
|
||||
captureId: 'hidden-browser-capture',
|
||||
capturedAt: '2026-07-14T08:00:00.000Z',
|
||||
kind: 'page',
|
||||
title: 'Inbox material must stay hidden',
|
||||
workspaceRootPath: 'MinimalOverview',
|
||||
}],
|
||||
});
|
||||
});
|
||||
const overview = page.locator('[data-overview-root]');
|
||||
await overview.locator('[data-overview-action="refresh"]').click();
|
||||
|
||||
await expect(overview.locator('[data-overview-summary="captures"]')).toHaveCount(0);
|
||||
await expect(overview.locator('[data-overview-action="browser-inbox"]')).toHaveCount(0);
|
||||
await expect(overview).not.toContainText('Inbox material must stay hidden');
|
||||
});
|
||||
|
||||
test('Overview refreshes when Browser is disabled through plugin state changes', async ({ page }) => {
|
||||
await page.evaluate(async () => {
|
||||
await window.go.api.App.WritePluginSettings('verstak.browser-inbox', {
|
||||
'captures:global': [{
|
||||
captureId: 'disabled-browser-capture',
|
||||
capturedAt: '2026-07-14T08:00:00.000Z',
|
||||
kind: 'page',
|
||||
title: 'Disabled inbox material',
|
||||
workspaceRootPath: 'Project',
|
||||
}],
|
||||
});
|
||||
window.__wailsMock.setPluginStatus('verstak.browser-inbox', 'disabled', false);
|
||||
window.dispatchEvent(new CustomEvent('verstak:plugins-changed'));
|
||||
});
|
||||
|
||||
const overview = page.locator('[data-overview-root]');
|
||||
await expect(page.getByRole('tab', { name: 'Browser' })).toHaveCount(0);
|
||||
await expect(overview.locator('[data-overview-summary="captures"]')).toHaveCount(0);
|
||||
await expect(overview.locator('[data-overview-action="browser-inbox"]')).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('Overview prioritizes resume work and filters meaningful recent changes', async ({ page }) => {
|
||||
await page.evaluate(async () => {
|
||||
await window.go.api.App.WritePluginSettings('verstak.browser-inbox', {
|
||||
@@ -200,10 +248,10 @@ test.describe('UX Overview workspace flow', () => {
|
||||
await expect(overview.locator('[data-overview-summary="attention"]')).toContainText('3');
|
||||
const attention = overview.locator('[data-overview-section="attention"]');
|
||||
await expect(attention).toContainText('Possible journal entry');
|
||||
await expect(attention).toContainText('Workspace: Project · 10 min · 2 activities');
|
||||
await expect(attention).toContainText('Deal: Project · 10 min · 2 activities');
|
||||
await attention.locator('.overview-attention-row', { hasText: 'Possible journal entry' }).getByRole('button', { name: 'Review candidate' }).click();
|
||||
await expect(page.getByRole('tab', { name: 'Journal' })).toHaveAttribute('aria-selected', 'true');
|
||||
await expect(page.locator('.journal-root [data-journal-candidate]')).toContainText('Workspace: Project');
|
||||
await expect(page.locator('.journal-root [data-journal-candidate]')).toContainText('Deal: Project');
|
||||
await page.locator('.journal-modal-actions').getByRole('button', { name: 'Cancel' }).click();
|
||||
await page.getByRole('tab', { name: 'Overview' }).click();
|
||||
|
||||
@@ -216,7 +264,7 @@ test.describe('UX Overview workspace flow', () => {
|
||||
await expect(candidates.nth(3)).toContainText('Changed file "draft.md"');
|
||||
await candidates.nth(0).click();
|
||||
|
||||
await expect(page.getByRole('tab', { name: 'Browser Inbox' })).toHaveAttribute('aria-selected', 'true');
|
||||
await expect(page.getByRole('tab', { name: 'Browser' })).toHaveAttribute('aria-selected', 'true');
|
||||
await expect(page.locator('.browser-inbox-root')).toBeVisible({ timeout: 10000 });
|
||||
|
||||
await page.getByRole('tab', { name: 'Overview' }).click();
|
||||
@@ -247,4 +295,28 @@ test.describe('UX Overview workspace flow', () => {
|
||||
await expect(recent).toContainText('Added journal entry "Write project summary"');
|
||||
await expect(recent).not.toContainText('Changed file "draft.md"');
|
||||
});
|
||||
|
||||
test('Overview localizes activity labels without exposing internal event names', async ({ page }) => {
|
||||
await page.evaluate(async () => {
|
||||
await window.go.api.App.WritePluginSettings('verstak.activity', {
|
||||
'events:workspace:Project': [{
|
||||
activityId: 'overview-russian-note',
|
||||
occurredAt: '2026-06-30T08:25:00.000Z',
|
||||
type: 'note.saved',
|
||||
title: 'Локализация',
|
||||
summary: 'Project/Notes/Localization.md',
|
||||
workspaceRootPath: 'Project',
|
||||
}],
|
||||
});
|
||||
});
|
||||
await page.locator('[data-settings-menu-button]').click();
|
||||
await page.locator('[data-settings-language="ru"]').click();
|
||||
|
||||
const overview = page.locator('[data-overview-root]');
|
||||
await overview.locator('[data-overview-action="refresh"]').click();
|
||||
const recent = overview.locator('[data-overview-section="recent"]');
|
||||
await expect(recent).toContainText('Изменена заметка «Локализация»');
|
||||
await expect(recent).not.toContainText('note.saved');
|
||||
await expect(recent).not.toContainText('Edited note');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ test.describe('Workspace templates', () => {
|
||||
});
|
||||
|
||||
async function openCreateModal(page) {
|
||||
await page.locator('button[title="New workspace"]').click();
|
||||
await page.locator('button[title="New Deal"]').click();
|
||||
const modal = page.locator('[data-workspace-create-modal]');
|
||||
await expect(modal).toBeVisible();
|
||||
return modal;
|
||||
@@ -24,22 +24,24 @@ test.describe('Workspace templates', () => {
|
||||
|
||||
test('creation modal validates names, shows template tools, and persists the selected snapshot', async ({ page }) => {
|
||||
const modal = await openCreateModal(page);
|
||||
await expect(modal.locator('[data-workspace-template]')).toHaveValue('default');
|
||||
const templateSelect = modal.locator('[data-workspace-template]');
|
||||
await expect(templateSelect).toHaveValue('default');
|
||||
await expect(templateSelect).toHaveCSS('appearance', 'none');
|
||||
await expect(modal.locator('[data-workspace-template-tools]')).toContainText('Notes');
|
||||
await expect(modal.locator('[data-workspace-template-tools]')).toContainText('Browser Inbox');
|
||||
await expect(modal.locator('[data-workspace-template-tools]')).toContainText('Browser');
|
||||
|
||||
await modal.getByRole('button', { name: 'Create workspace' }).click();
|
||||
await modal.getByRole('button', { name: 'Create Deal' }).click();
|
||||
await expect(modal.locator('[data-workspace-create-error]')).toContainText('Name is required');
|
||||
|
||||
await modal.locator('[data-workspace-name]').fill('bad/name');
|
||||
await modal.getByRole('button', { name: 'Create workspace' }).click();
|
||||
await expect(modal.locator('[data-workspace-create-error]')).toContainText('invalid-workspace-name');
|
||||
await modal.getByRole('button', { name: 'Create Deal' }).click();
|
||||
await expect(modal.locator('[data-workspace-create-error]')).toContainText('Could not create the Deal. Please try again.');
|
||||
|
||||
await modal.locator('[data-workspace-name]').fill('ProjectPlan');
|
||||
await modal.locator('[data-workspace-template]').selectOption('project');
|
||||
await expect(modal.locator('[data-workspace-template-description]')).toContainText('Project planning');
|
||||
await expect(modal.locator('[data-workspace-template-tools]')).toContainText('Todos');
|
||||
await modal.getByRole('button', { name: 'Create workspace' }).click();
|
||||
await modal.getByRole('button', { name: 'Create Deal' }).click();
|
||||
|
||||
await expect(page.locator('.wt-label').filter({ hasText: 'ProjectPlan' })).toBeVisible();
|
||||
await expect.poll(async () => page.evaluate(async () => {
|
||||
@@ -63,7 +65,7 @@ test.describe('Workspace templates', () => {
|
||||
const modal = await openCreateModal(page);
|
||||
await modal.locator('[data-workspace-name]').fill('MinimalSpace');
|
||||
await modal.locator('[data-workspace-template]').selectOption('minimal');
|
||||
await modal.getByRole('button', { name: 'Create workspace' }).click();
|
||||
await modal.getByRole('button', { name: 'Create Deal' }).click();
|
||||
|
||||
await expect(page.getByRole('tab', { name: 'Overview' })).toBeVisible();
|
||||
await expect(page.getByRole('tab', { name: 'Notes' })).toBeVisible();
|
||||
@@ -72,21 +74,40 @@ test.describe('Workspace templates', () => {
|
||||
await expect(page.getByRole('tab', { name: 'Journal' })).toHaveCount(0);
|
||||
await expect(page.getByRole('tab', { name: 'Secrets' })).toHaveCount(0);
|
||||
await expect(page.locator('.sidebar .plugin-item').filter({ hasText: 'Todos' })).toBeVisible();
|
||||
await expect(page.locator('.sidebar .plugin-item').filter({ hasText: 'Browser Inbox' })).toBeVisible();
|
||||
await expect(page.locator('.sidebar .plugin-item').filter({ hasText: 'Browser' })).toBeVisible();
|
||||
});
|
||||
|
||||
test('template explains an unavailable plugin and warns after incomplete creation', async ({ page }) => {
|
||||
await page.evaluate(() => window.__wailsMock.setPluginStatus('verstak.todo', 'disabled', false));
|
||||
const modal = await openCreateModal(page);
|
||||
await modal.locator('[data-workspace-template]').selectOption('project');
|
||||
|
||||
const todo = modal.locator('[data-workspace-template-tool="verstak.todo"]');
|
||||
await expect(todo).toContainText('Todos');
|
||||
await expect(todo).toContainText('Plugin is disabled');
|
||||
await expect(todo).toHaveAttribute('data-template-tool-status', 'unavailable');
|
||||
|
||||
await modal.locator('[data-workspace-name]').fill('ProjectWithWarning');
|
||||
await modal.getByRole('button', { name: 'Create Deal' }).click();
|
||||
|
||||
const warning = page.locator('[data-workspace-template-warning]');
|
||||
await expect(warning).toContainText('ProjectWithWarning');
|
||||
await expect(warning).toContainText('Todos');
|
||||
await expect(warning).toContainText('Plugin is disabled');
|
||||
});
|
||||
|
||||
test('Admin shows Secrets when available and missing workspace plugins degrade without breaking tabs', async ({ page }) => {
|
||||
let modal = await openCreateModal(page);
|
||||
await modal.locator('[data-workspace-name]').fill('AdminSpace');
|
||||
await modal.locator('[data-workspace-template]').selectOption('admin');
|
||||
await modal.getByRole('button', { name: 'Create workspace' }).click();
|
||||
await modal.getByRole('button', { name: 'Create Deal' }).click();
|
||||
await expect(page.getByRole('tab', { name: 'Secrets' })).toBeVisible();
|
||||
|
||||
await page.evaluate(() => window.__wailsMock.setPluginStatus('verstak.todo', 'disabled', false));
|
||||
modal = await openCreateModal(page);
|
||||
await modal.locator('[data-workspace-name]').fill('ProjectWithoutTodo');
|
||||
await modal.locator('[data-workspace-template]').selectOption('project');
|
||||
await modal.getByRole('button', { name: 'Create workspace' }).click();
|
||||
await modal.getByRole('button', { name: 'Create Deal' }).click();
|
||||
|
||||
await expect(page.getByRole('tab', { name: 'Notes' })).toBeVisible();
|
||||
await expect(page.getByRole('tab', { name: 'Files' })).toBeVisible();
|
||||
|
||||
@@ -9,13 +9,19 @@
|
||||
import WorkspaceHost from './lib/shell/WorkspaceHost.svelte';
|
||||
import * as App from '../wailsjs/go/api/App';
|
||||
import { debug } from './lib/log/debug.js';
|
||||
import { onMount } from 'svelte';
|
||||
import { tick } from 'svelte';
|
||||
import { onDestroy, onMount, tick } from 'svelte';
|
||||
import { i18n } from './lib/i18n/index.js';
|
||||
|
||||
let currentView = 'workspace';
|
||||
let vaultStatus = { status: 'unknown', path: '', vaultId: '' };
|
||||
let needsVaultSelection = false;
|
||||
let loading = true;
|
||||
let locale = i18n.getLocale();
|
||||
const unsubscribeLocale = i18n.subscribe((nextLocale) => { locale = nextLocale; });
|
||||
$: tr = ((activeLocale) => (key, params, fallback) => {
|
||||
void activeLocale;
|
||||
return i18n.t(key, params, fallback);
|
||||
})(locale);
|
||||
|
||||
let activeView = null;
|
||||
let activeViewPluginId = '';
|
||||
@@ -48,6 +54,7 @@
|
||||
const name = workspaceName(workspace);
|
||||
return {
|
||||
id: name,
|
||||
workspaceId: workspace?.id || workspace?.workspaceId || '',
|
||||
type: workspace?.type || 'space',
|
||||
title: workspace?.title || name,
|
||||
name,
|
||||
@@ -212,6 +219,7 @@
|
||||
const settings = await App.GetAppSettings();
|
||||
debug.log('[App] checkVault: GetAppSettings returned', settings);
|
||||
flog('checkVault: GetAppSettings returned');
|
||||
if (settings?.debug) debug.enable({ persist: false });
|
||||
|
||||
debug.log('[App] checkVault: calling GetVaultStatus...');
|
||||
vaultStatus = await App.GetVaultStatus() || { status: 'unknown', path: '', vaultId: '' };
|
||||
@@ -375,17 +383,23 @@
|
||||
await checkVault();
|
||||
pushNavigation();
|
||||
});
|
||||
|
||||
onDestroy(unsubscribeLocale);
|
||||
</script>
|
||||
|
||||
{#if loading}
|
||||
<div class="app-loading">
|
||||
<p>Loading Verstak...</p>
|
||||
<p>{tr('app.loading')}</p>
|
||||
</div>
|
||||
{:else if needsVaultSelection}
|
||||
<VaultSelection />
|
||||
{:else}
|
||||
<main>
|
||||
<Sidebar showGlobalSearch={currentView !== 'workspace' && currentView !== 'workspace-empty'} />
|
||||
<Sidebar
|
||||
showGlobalSearch={currentView !== 'workspace' && currentView !== 'workspace-empty'}
|
||||
{activeView}
|
||||
{activeViewPluginId}
|
||||
/>
|
||||
<CommandPalette />
|
||||
|
||||
<section class="content-shell">
|
||||
|
||||
@@ -0,0 +1,308 @@
|
||||
export default {
|
||||
'app.loading': 'Loading Verstak...',
|
||||
'settings.title': 'Settings',
|
||||
'settings.language': 'Language',
|
||||
'settings.language.system': 'System / Системный',
|
||||
'settings.language.en': 'English',
|
||||
'settings.language.ru': 'Русский',
|
||||
'settings.pluginManager': 'Plugin Manager',
|
||||
'statusBar.label': 'Status bar',
|
||||
'vault.label': 'Vault: {status}',
|
||||
'vault.status.open': 'open',
|
||||
'vault.status.closed': 'closed',
|
||||
'vault.status.unknown': 'unknown',
|
||||
'sidebar.tools': 'Tools',
|
||||
'sidebar.error.contributions': 'Failed to load plugin contributions',
|
||||
'sidebar.error.load': 'Failed to load sidebar',
|
||||
'sidebar.error.ui': 'Plugin UI error',
|
||||
'workspace.overview': 'Overview',
|
||||
'workspace.search': 'Search in this Deal',
|
||||
'workspace.tools': 'Deal tools',
|
||||
'workspace.tool': 'Deal tool',
|
||||
'workspace.emptyTools': 'No Deal tools available',
|
||||
'workspace.emptyToolsHint': 'Enable plugins with Deal tools or open Plugin Manager from settings.',
|
||||
'workspace.select': 'Select a Deal',
|
||||
'workspace.selectHint': 'Use the + button in Deals to add your first project.',
|
||||
'common.details': 'Details',
|
||||
'common.plugin': 'Plugin',
|
||||
'common.component': 'Component',
|
||||
'pluginView.error': 'Plugin view error',
|
||||
'pluginView.failed': 'Plugin UI failed',
|
||||
'pluginView.noVisual': 'This plugin does not provide a visual view yet.',
|
||||
'pluginView.viewId': 'View ID',
|
||||
'pluginView.bundleUnavailable': 'Frontend bundle unavailable',
|
||||
'pluginView.unavailable': 'View is unavailable.',
|
||||
'pluginView.select': 'Select a plugin view from the sidebar',
|
||||
'pluginView.selectHint': 'Plugin views will appear here',
|
||||
'common.retry': '⟳ Retry',
|
||||
'common.save': 'Save',
|
||||
'common.source': 'Source',
|
||||
'common.status': 'Status',
|
||||
'common.capability': 'Capability',
|
||||
'common.provider': 'Provider',
|
||||
'status.loaded': 'loaded',
|
||||
'status.degraded': 'degraded',
|
||||
'status.failed': 'failed',
|
||||
'status.disabled': 'disabled',
|
||||
'status.missing': 'missing',
|
||||
'pluginManager.reloading': '⟳ Reloading...',
|
||||
'pluginManager.reload': '⟳ Reload',
|
||||
'pluginManager.scanning': 'Scanning plugin directories...',
|
||||
'pluginManager.summary.plugins': '{count} plugin(s) discovered',
|
||||
'pluginManager.summary.capabilities': '{count} capabilities registered',
|
||||
'pluginManager.summary.permissions': '{count} permissions known',
|
||||
'pluginManager.scanSummary': 'Plugin scan summary',
|
||||
'pluginManager.health': 'Plugin Health',
|
||||
'pluginManager.permissionRisk': 'Permission Risk',
|
||||
'pluginManager.elevatedPermissions': '{count} plugins request elevated permissions',
|
||||
'pluginManager.filters': 'Filters',
|
||||
'pluginManager.filterResults': 'Showing {visible} of {total} plugins',
|
||||
'pluginManager.filterReset': 'Reset filters',
|
||||
'pluginManager.filterState': 'State',
|
||||
'pluginManager.filterAll': 'All',
|
||||
'pluginManager.filterEnabled': 'Enabled',
|
||||
'pluginManager.filterDisabled': 'Disabled',
|
||||
'pluginManager.filterFailed': 'Problem',
|
||||
'pluginManager.filterDegraded': 'Degraded',
|
||||
'pluginManager.filterPermissions': 'Permissions',
|
||||
'pluginManager.filterCapabilities': 'Capabilities',
|
||||
'pluginManager.filterSettings': 'Settings',
|
||||
'pluginManager.filterWithSettings': 'With settings',
|
||||
'pluginManager.filterWithoutSettings': 'Without settings',
|
||||
'pluginManager.filterSource': 'Source',
|
||||
'pluginManager.filterOfficial': 'Official',
|
||||
'pluginManager.filterThirdParty': 'Third-party or local',
|
||||
'pluginManager.filterEmpty': 'No plugins match the selected filters.',
|
||||
'pluginManager.none': 'No plugins found',
|
||||
'pluginManager.scannedDirs': 'Plugin directories scanned:',
|
||||
'pluginManager.userPlugins': 'user plugins',
|
||||
'pluginManager.bundledPlugins': 'bundled plugins (app directory)',
|
||||
'pluginManager.installHint': 'Place a plugin folder with plugin.json in one of these directories and click Reload.',
|
||||
'pluginManager.missingTitle': 'Missing Installed Plugins',
|
||||
'pluginManager.missingHint': 'These plugins are required by this vault but their packages are not installed locally.',
|
||||
'pluginManager.missingPackage': "This plugin is listed in the vault's desired plugins but the package is not installed.",
|
||||
'pluginManager.capabilityRegistry': 'Capability Registry ({count})',
|
||||
'pluginManager.settingsError': 'Settings Error',
|
||||
'pluginManager.pluginSettings': 'Plugin Settings',
|
||||
'pluginManager.settingsBundleUnavailable': 'Settings panel frontend bundle not available',
|
||||
'common.none': 'none',
|
||||
'common.unknown': 'unknown',
|
||||
'pluginCard.count.views': '{count} view(s)',
|
||||
'pluginCard.count.commands': '{count} command(s)',
|
||||
'pluginCard.count.searchProviders': '{count} search provider(s)',
|
||||
'pluginCard.count.sidebar': '{count} sidebar item(s)',
|
||||
'pluginCard.count.statusbar': '{count} status bar item(s)',
|
||||
'pluginCard.count.openProviders': '{count} openProviders',
|
||||
'pluginCard.count.workspace': '{count} Deal tool(s)',
|
||||
'pluginCard.degraded': 'Plugin is usable, but some optional capabilities are unavailable.',
|
||||
'pluginCard.name': 'Name',
|
||||
'pluginCard.contributions': 'Contributions',
|
||||
'pluginCard.technicalDetails': 'Technical details',
|
||||
'pluginCard.apiVersion': 'API Version',
|
||||
'pluginCard.root': 'Root',
|
||||
'pluginCard.provides': 'Provides',
|
||||
'pluginCard.requires': 'Requires',
|
||||
'pluginCard.missingRequired': 'Missing required capabilities',
|
||||
'pluginCard.optionalRequires': 'Optional Requires',
|
||||
'pluginCard.optionalUnavailable': 'Optional capabilities not available — plugin running in degraded mode',
|
||||
'pluginCard.permissions': 'Permissions',
|
||||
'pluginCard.enabling': '⟳ Enabling...',
|
||||
'pluginCard.enable': '▶ Enable',
|
||||
'pluginCard.disabling': '⟳ Disabling...',
|
||||
'pluginCard.disable': '⏸ Disable',
|
||||
'pluginCard.openVault': 'Open a vault to manage plugin state',
|
||||
'pluginCard.missingUiPermission': 'Plugin has UI contributions but lacks ui.register permission',
|
||||
'common.loading': 'Loading...',
|
||||
'common.browse': 'Browse...',
|
||||
'vaultSelection.chooseNew': 'Choose or enter a folder for the new vault.',
|
||||
'vaultSelection.createError': 'Could not create the vault. Please try again.',
|
||||
'vaultSelection.openError': 'Could not open the vault. Please try again.',
|
||||
'vaultSelection.chooseExisting': 'Choose or enter an existing vault.',
|
||||
'vaultSelection.subtitle': 'Choose a vault to start working',
|
||||
'vaultSelection.createTitle': 'Create a new vault',
|
||||
'vaultSelection.createHint': 'Create a local vault folder for Deals and projects.',
|
||||
'vaultSelection.pathPlaceholder': 'Choose or enter a path...',
|
||||
'vaultSelection.creating': 'Creating...',
|
||||
'vaultSelection.create': 'Create vault',
|
||||
'vaultSelection.openTitle': 'Open an existing vault',
|
||||
'vaultSelection.openHint': 'Use a vault that is already on this computer.',
|
||||
'vaultSelection.opening': 'Opening...',
|
||||
'vaultSelection.open': 'Open existing',
|
||||
'vaultSelection.recent': 'Recent vaults',
|
||||
'common.cancel': 'Cancel',
|
||||
'common.close': 'Close',
|
||||
'workspaceTree.title': 'Deals',
|
||||
'workspaceTree.new': 'New Deal',
|
||||
'workspaceTree.nameRequired': 'Name is required',
|
||||
'workspaceTree.chooseTemplate': 'Choose a Deal template',
|
||||
'workspaceTree.saveRename': 'Save rename',
|
||||
'workspaceTree.rename': 'Rename Deal',
|
||||
'workspaceTree.trash': 'Move Deal to trash',
|
||||
'workspaceTree.create': 'Create Deal',
|
||||
'workspaceTree.namePlaceholder': 'Deal name',
|
||||
'workspaceTree.template': 'Template',
|
||||
'workspaceTree.creating': 'Creating...',
|
||||
'workspaceTree.templateAvailable': 'Available',
|
||||
'workspaceTree.templateLimited': 'Available with limitations',
|
||||
'workspaceTree.templateMissingPlugin': 'Plugin is not installed',
|
||||
'workspaceTree.templatePluginDisabled': 'Plugin is disabled',
|
||||
'workspaceTree.templateCapabilityUnavailable': 'A required capability is unavailable',
|
||||
'workspaceTree.templateIncompatible': 'Plugin is incompatible with this version of Verstak',
|
||||
'workspaceTree.templateLoadFailed': 'Plugin failed to load',
|
||||
'workspaceTree.templateNotReady': 'Plugin is not ready',
|
||||
'workspaceTree.templateToolTabs': 'Creates: {tabs}',
|
||||
'workspaceTree.templateToolNoTabs': 'No Deal tab provided',
|
||||
'workspaceTree.templateWillBeIncomplete': 'This Deal will be created without the unavailable components.',
|
||||
'workspaceTree.templateIncompleteCreated': '«{name}» was created with unavailable components.',
|
||||
'workspaceTree.templatesError': 'Could not load Deal templates. Please try again.',
|
||||
'workspaceTree.loadError': 'Could not load Deals. Please try again.',
|
||||
'workspaceTree.selectError': 'Could not select this Deal. Please try again.',
|
||||
'workspaceTree.createError': 'Could not create the Deal. Please try again.',
|
||||
'workspaceTree.renameError': 'Could not rename the Deal. Please try again.',
|
||||
'workspaceTree.trashError': 'Could not move the Deal to trash. Please try again.',
|
||||
'pluginManager.loadError': 'Could not load plugins. Please try again.',
|
||||
'pluginManager.reloadError': 'Could not reload plugins. Please try again.',
|
||||
'pluginManager.enableError': 'Could not enable the plugin. Please try again.',
|
||||
'pluginManager.disableError': 'Could not disable the plugin. Please try again.',
|
||||
'pluginManager.settingsLoadError': 'Could not load plugin settings. Please try again.',
|
||||
'pluginManager.settingsUnavailable': 'Plugin settings are unavailable.',
|
||||
'command.openOverview': 'Open Overview',
|
||||
'command.openFiles': 'Open Files',
|
||||
'command.openActivity': 'Open Activity',
|
||||
'command.openBrowserInbox': 'Open Browser',
|
||||
'command.createMarkdown': 'Create Markdown File',
|
||||
'command.createText': 'Create Text File',
|
||||
'command.syncNow': 'Sync Now',
|
||||
'command.openSyncSettings': 'Open Sync Settings',
|
||||
'command.openPluginManager': 'Open Plugin Manager',
|
||||
'command.handled': '{title} handled',
|
||||
'command.result': '{title} {status}',
|
||||
'command.failed': 'Could not run {title}. Please try again.',
|
||||
'command.statusHandled': 'handled',
|
||||
'command.palette': 'Command Palette',
|
||||
'command.run': 'Run command',
|
||||
'command.none': 'No commands',
|
||||
'search.indexing': 'Indexing...',
|
||||
'search.placeholder': 'Search',
|
||||
'search.global': 'Global search',
|
||||
'search.noResults': 'No results',
|
||||
'search.type.workspace': 'Deal',
|
||||
'search.type.tool': 'Tool',
|
||||
'search.type.folder': 'Folder',
|
||||
'search.type.file': 'File',
|
||||
'search.type.journal': 'Journal',
|
||||
'search.type.browserInbox': 'Browser',
|
||||
'search.type.activity': 'Activity',
|
||||
'workbench.noProvider': 'No provider',
|
||||
'workbench.noViewer': 'No viewer/editor available',
|
||||
'workbench.noResource': 'No resource opened',
|
||||
'bundle.noFrontend': 'Plugin has no frontend bundle',
|
||||
'bundle.notFound': 'Plugin not found',
|
||||
'bundle.loadFailed': 'Could not load the plugin interface. Please try again.',
|
||||
'bundle.emptyContent': 'empty content',
|
||||
'bundle.executionError': 'Could not start the plugin interface. Please try again.',
|
||||
'bundle.registrationMissing': 'Bundle loaded but no VerstakPluginRegister call detected',
|
||||
'bundle.componentMissing': 'The requested plugin interface is unavailable.',
|
||||
'bundle.mountError': 'Could not open the plugin interface. Please try again.',
|
||||
'bundle.mountUnavailable': 'Mount container not available',
|
||||
'bundle.unexpectedError': 'Could not open the plugin interface. Please try again.',
|
||||
'bundle.unknownError': 'Unknown error',
|
||||
'bundle.frontendEntry': 'Frontend entry',
|
||||
'bundle.availableComponents': 'Available components',
|
||||
'bundle.loading': 'Loading plugin bundle...',
|
||||
'overview.filter.all': 'All',
|
||||
'overview.filter.notes': 'Notes',
|
||||
'overview.filter.files': 'Files',
|
||||
'overview.filter.captures': 'Captures',
|
||||
'overview.filter.journal': 'Journal',
|
||||
'overview.notes': 'Notes',
|
||||
'overview.files': 'Files',
|
||||
'overview.captures': 'Captures',
|
||||
'overview.activity': 'Activity',
|
||||
'overview.journal': 'Journal',
|
||||
'overview.attention': 'Needs attention',
|
||||
'overview.openNotes': 'Open Notes',
|
||||
'overview.openFiles': 'Open Files',
|
||||
'overview.reviewInbox': 'Review Inbox',
|
||||
'overview.viewActivity': 'View Activity',
|
||||
'overview.openJournal': 'Open Journal',
|
||||
'overview.openTodos': 'Open Todos',
|
||||
'overview.reviewCandidate': 'Review candidate',
|
||||
'overview.reviewPending': 'Review pending items',
|
||||
'overview.count.totalRecent.one': '{total} total · {recent} recent change',
|
||||
'overview.count.totalRecent.many': '{total} total · {recent} recent changes',
|
||||
'overview.count.recentChanges.one': '{count} recent change',
|
||||
'overview.count.recentChanges.many': '{count} recent changes',
|
||||
'overview.count.captures.one': '{count} capture to review',
|
||||
'overview.count.captures.many': '{count} captures to review',
|
||||
'overview.count.events.one': '{count} recorded event',
|
||||
'overview.count.events.many': '{count} recorded events',
|
||||
'overview.count.journal.one': '{count} journal entry',
|
||||
'overview.count.journal.many': '{count} journal entries',
|
||||
'overview.count.pending.one': '{count} pending item',
|
||||
'overview.count.pending.many': '{count} pending items',
|
||||
'overview.loadingContext': 'Loading Deal context...',
|
||||
'overview.lastActive': 'Last active {time}',
|
||||
'overview.noRecentActivity': 'No recent Deal activity',
|
||||
'overview.refresh': 'Refresh',
|
||||
'overview.summary': 'Deal overview summary',
|
||||
'overview.continue': 'Continue working',
|
||||
'overview.continueHint': 'Pick up the next useful item in this Deal.',
|
||||
'overview.loadingSignals': 'Loading Deal signals...',
|
||||
'overview.noResume': 'No clear resume point yet',
|
||||
'overview.noResumeHint': 'Recent notes, files, captures, and journal entries will appear here.',
|
||||
'overview.recentChanges': 'Recent changes',
|
||||
'overview.recentChangesHint': 'Latest meaningful activity in this Deal.',
|
||||
'overview.event.workspaceOpened': 'Opened Deal',
|
||||
'overview.event.activity': 'Deal activity',
|
||||
'overview.event.noteEdited': 'Edited note "{name}"',
|
||||
'overview.event.noteOpened': 'Opened note "{name}"',
|
||||
'overview.event.noteCreated': 'Created note "{name}"',
|
||||
'overview.event.fileOpened': 'Opened file "{name}"',
|
||||
'overview.event.fileChanged': 'Changed file "{name}"',
|
||||
'overview.event.fileCreated': 'Created file "{name}"',
|
||||
'overview.event.fileRemoved': 'Removed file "{name}"',
|
||||
'overview.event.capturePage': 'Captured page "{name}"',
|
||||
'overview.event.captureSelection': 'Captured selection "{name}"',
|
||||
'overview.event.captureLink': 'Captured link "{name}"',
|
||||
'overview.event.captureFile': 'Captured file "{name}"',
|
||||
'overview.event.captureConverted': 'Converted capture "{name}"',
|
||||
'overview.event.capture': 'Captured {kind} "{title}"',
|
||||
'overview.event.journalAdded': 'Added journal entry "{name}"',
|
||||
'overview.event.workSessionDetected': 'Work session detected',
|
||||
'overview.event.todo': 'Todo "{title}"',
|
||||
'overview.event.reviewCapture': 'Review capture "{title}"',
|
||||
'overview.event.continueJournal': 'Continue journal entry "{title}"',
|
||||
'overview.event.possibleJournalEntry': 'Possible journal entry',
|
||||
'overview.captureKind.page': 'page',
|
||||
'overview.captureKind.selection': 'selection',
|
||||
'overview.captureKind.link': 'link',
|
||||
'overview.captureKind.file': 'file',
|
||||
'overview.captureKind.item': 'item',
|
||||
'overview.todo.reminderDue': 'Reminder due',
|
||||
'overview.todo.overdue': 'Overdue',
|
||||
'overview.todo.dueSoon': 'Due soon',
|
||||
'overview.todo.due': 'Due {date}',
|
||||
'overview.candidateMeta': 'Deal: {deal} · {minutes} min · {activities} activities',
|
||||
'overview.minutes': '{count} min',
|
||||
'overview.browserCapture': 'Browser capture',
|
||||
'overview.untitledTodo': 'Untitled todo',
|
||||
'overview.untitledCapture': 'Untitled capture',
|
||||
'overview.untitledJournal': 'Journal entry',
|
||||
'overview.unknownDeal': 'Unknown Deal',
|
||||
'overview.item': 'item',
|
||||
'overview.overviewNote': 'Deal overview note',
|
||||
'overview.recentFilter': 'Recent changes filter',
|
||||
'overview.loadingRecent': 'Loading recent changes...',
|
||||
'overview.noChanges': 'No meaningful changes for this filter yet.',
|
||||
'overview.attentionHint': 'Pending captures, urgent todos, and possible journal entries.',
|
||||
'overview.loadingPending': 'Loading pending items...',
|
||||
'overview.noPending': 'No pending captures, urgent todos, or possible journal entries.',
|
||||
'overview.keyResources': 'Key resources',
|
||||
'overview.time.none': 'No timestamp',
|
||||
'overview.time.now': 'Just now',
|
||||
'overview.time.minutes': '{count} min ago',
|
||||
'overview.time.hours': '{count}h ago',
|
||||
'overview.time.yesterday': 'Yesterday',
|
||||
'overview.time.days': '{count} days ago',
|
||||
};
|
||||
@@ -0,0 +1,308 @@
|
||||
export default {
|
||||
'app.loading': 'Загрузка Верстака...',
|
||||
'settings.title': 'Настройки',
|
||||
'settings.language': 'Язык',
|
||||
'settings.language.system': 'System / Системный',
|
||||
'settings.language.en': 'English',
|
||||
'settings.language.ru': 'Русский',
|
||||
'settings.pluginManager': 'Менеджер плагинов',
|
||||
'statusBar.label': 'Строка состояния',
|
||||
'vault.label': 'Хранилище: {status}',
|
||||
'vault.status.open': 'открыто',
|
||||
'vault.status.closed': 'закрыто',
|
||||
'vault.status.unknown': 'неизвестно',
|
||||
'sidebar.tools': 'Инструменты',
|
||||
'sidebar.error.contributions': 'Не удалось загрузить элементы плагинов',
|
||||
'sidebar.error.load': 'Не удалось загрузить боковую панель',
|
||||
'sidebar.error.ui': 'Ошибка интерфейса плагина',
|
||||
'workspace.overview': 'Обзор',
|
||||
'workspace.search': 'Поиск в Деле',
|
||||
'workspace.tools': 'Инструменты Дела',
|
||||
'workspace.tool': 'Инструмент Дела',
|
||||
'workspace.emptyTools': 'Нет доступных инструментов',
|
||||
'workspace.emptyToolsHint': 'Включите плагины с инструментами Дела или откройте Менеджер плагинов в настройках.',
|
||||
'workspace.select': 'Выберите Дело',
|
||||
'workspace.selectHint': 'Используйте кнопку + в разделе Дел, чтобы добавить первый проект.',
|
||||
'common.details': 'Подробнее',
|
||||
'common.plugin': 'Плагин',
|
||||
'common.component': 'Компонент',
|
||||
'pluginView.error': 'Ошибка представления плагина',
|
||||
'pluginView.failed': 'Ошибка интерфейса плагина',
|
||||
'pluginView.noVisual': 'Этот плагин пока не предоставляет визуальное представление.',
|
||||
'pluginView.viewId': 'ID представления',
|
||||
'pluginView.bundleUnavailable': 'Frontend bundle недоступен',
|
||||
'pluginView.unavailable': 'Представление недоступно.',
|
||||
'pluginView.select': 'Выберите представление плагина на боковой панели',
|
||||
'pluginView.selectHint': 'Представления плагинов появятся здесь',
|
||||
'common.retry': '⟳ Повторить',
|
||||
'common.save': 'Сохранить',
|
||||
'common.source': 'Источник',
|
||||
'common.status': 'Состояние',
|
||||
'common.capability': 'Возможность',
|
||||
'common.provider': 'Поставщик',
|
||||
'status.loaded': 'загружено',
|
||||
'status.degraded': 'ограничено',
|
||||
'status.failed': 'ошибка',
|
||||
'status.disabled': 'выключено',
|
||||
'status.missing': 'отсутствует',
|
||||
'pluginManager.reloading': '⟳ Обновление...',
|
||||
'pluginManager.reload': '⟳ Обновить',
|
||||
'pluginManager.scanning': 'Сканирование каталогов плагинов...',
|
||||
'pluginManager.summary.plugins': 'Обнаружено плагинов: {count}',
|
||||
'pluginManager.summary.capabilities': 'Зарегистрировано возможностей: {count}',
|
||||
'pluginManager.summary.permissions': 'Известно разрешений: {count}',
|
||||
'pluginManager.scanSummary': 'Сводка проверки плагинов',
|
||||
'pluginManager.health': 'Состояние плагинов',
|
||||
'pluginManager.permissionRisk': 'Риск разрешений',
|
||||
'pluginManager.elevatedPermissions': 'Плагинов с повышенными разрешениями: {count}',
|
||||
'pluginManager.filters': 'Фильтры',
|
||||
'pluginManager.filterResults': 'Показано плагинов: {visible} из {total}',
|
||||
'pluginManager.filterReset': 'Сбросить фильтры',
|
||||
'pluginManager.filterState': 'Состояние',
|
||||
'pluginManager.filterAll': 'Все',
|
||||
'pluginManager.filterEnabled': 'Включённые',
|
||||
'pluginManager.filterDisabled': 'Выключенные',
|
||||
'pluginManager.filterFailed': 'С проблемами',
|
||||
'pluginManager.filterDegraded': 'Ограниченные',
|
||||
'pluginManager.filterPermissions': 'Разрешения',
|
||||
'pluginManager.filterCapabilities': 'Возможности',
|
||||
'pluginManager.filterSettings': 'Настройки',
|
||||
'pluginManager.filterWithSettings': 'С настройками',
|
||||
'pluginManager.filterWithoutSettings': 'Без настроек',
|
||||
'pluginManager.filterSource': 'Источник',
|
||||
'pluginManager.filterOfficial': 'Официальные',
|
||||
'pluginManager.filterThirdParty': 'Сторонние или локальные',
|
||||
'pluginManager.filterEmpty': 'Нет плагинов, соответствующих выбранным фильтрам.',
|
||||
'pluginManager.none': 'Плагины не найдены',
|
||||
'pluginManager.scannedDirs': 'Проверенные каталоги плагинов:',
|
||||
'pluginManager.userPlugins': 'пользовательские плагины',
|
||||
'pluginManager.bundledPlugins': 'встроенные плагины (каталог приложения)',
|
||||
'pluginManager.installHint': 'Поместите папку плагина с plugin.json в один из этих каталогов и нажмите «Обновить».',
|
||||
'pluginManager.missingTitle': 'Отсутствующие установленные плагины',
|
||||
'pluginManager.missingHint': 'Эти плагины требуются хранилищу, но их пакеты не установлены на этом устройстве.',
|
||||
'pluginManager.missingPackage': 'Плагин указан среди желаемых плагинов хранилища, но его пакет не установлен.',
|
||||
'pluginManager.capabilityRegistry': 'Реестр возможностей ({count})',
|
||||
'pluginManager.settingsError': 'Ошибка настроек',
|
||||
'pluginManager.pluginSettings': 'Настройки плагина',
|
||||
'pluginManager.settingsBundleUnavailable': 'Frontend bundle панели настроек недоступен',
|
||||
'common.none': 'нет',
|
||||
'common.unknown': 'неизвестно',
|
||||
'pluginCard.count.views': 'представлений: {count}',
|
||||
'pluginCard.count.commands': 'команд: {count}',
|
||||
'pluginCard.count.searchProviders': 'поставщиков поиска: {count}',
|
||||
'pluginCard.count.sidebar': 'элементов боковой панели: {count}',
|
||||
'pluginCard.count.statusbar': 'элементов строки состояния: {count}',
|
||||
'pluginCard.count.openProviders': 'обработчиков открытия: {count}',
|
||||
'pluginCard.count.workspace': 'инструментов Дела: {count}',
|
||||
'pluginCard.degraded': 'Плагин работает, но некоторые необязательные возможности недоступны.',
|
||||
'pluginCard.name': 'Название',
|
||||
'pluginCard.contributions': 'Элементы интерфейса',
|
||||
'pluginCard.technicalDetails': 'Технические сведения',
|
||||
'pluginCard.apiVersion': 'Версия API',
|
||||
'pluginCard.root': 'Корневой каталог',
|
||||
'pluginCard.provides': 'Предоставляет',
|
||||
'pluginCard.requires': 'Требует',
|
||||
'pluginCard.missingRequired': 'Отсутствуют обязательные возможности',
|
||||
'pluginCard.optionalRequires': 'Необязательные зависимости',
|
||||
'pluginCard.optionalUnavailable': 'Необязательные возможности недоступны — плагин работает в ограниченном режиме',
|
||||
'pluginCard.permissions': 'Разрешения',
|
||||
'pluginCard.enabling': '⟳ Включение...',
|
||||
'pluginCard.enable': '▶ Включить',
|
||||
'pluginCard.disabling': '⟳ Выключение...',
|
||||
'pluginCard.disable': '⏸ Выключить',
|
||||
'pluginCard.openVault': 'Откройте хранилище для управления состоянием плагина',
|
||||
'pluginCard.missingUiPermission': 'Плагин добавляет элементы интерфейса, но не имеет разрешения ui.register',
|
||||
'common.loading': 'Загрузка...',
|
||||
'common.browse': 'Обзор...',
|
||||
'vaultSelection.chooseNew': 'Выберите или введите папку для нового хранилища.',
|
||||
'vaultSelection.createError': 'Не удалось создать хранилище. Повторите попытку.',
|
||||
'vaultSelection.openError': 'Не удалось открыть хранилище. Повторите попытку.',
|
||||
'vaultSelection.chooseExisting': 'Выберите или введите существующее хранилище.',
|
||||
'vaultSelection.subtitle': 'Выберите хранилище, чтобы начать работу',
|
||||
'vaultSelection.createTitle': 'Создать новое хранилище',
|
||||
'vaultSelection.createHint': 'Создайте локальную папку хранилища для Дел и проектов.',
|
||||
'vaultSelection.pathPlaceholder': 'Выберите или введите путь...',
|
||||
'vaultSelection.creating': 'Создание...',
|
||||
'vaultSelection.create': 'Создать хранилище',
|
||||
'vaultSelection.openTitle': 'Открыть существующее хранилище',
|
||||
'vaultSelection.openHint': 'Используйте хранилище, которое уже находится на этом компьютере.',
|
||||
'vaultSelection.opening': 'Открытие...',
|
||||
'vaultSelection.open': 'Открыть',
|
||||
'vaultSelection.recent': 'Недавние хранилища',
|
||||
'common.cancel': 'Отмена',
|
||||
'common.close': 'Закрыть',
|
||||
'workspaceTree.title': 'Дела',
|
||||
'workspaceTree.new': 'Новое Дело',
|
||||
'workspaceTree.nameRequired': 'Введите название',
|
||||
'workspaceTree.chooseTemplate': 'Выберите шаблон Дела',
|
||||
'workspaceTree.saveRename': 'Сохранить новое название',
|
||||
'workspaceTree.rename': 'Переименовать Дело',
|
||||
'workspaceTree.trash': 'Переместить Дело в корзину',
|
||||
'workspaceTree.create': 'Создать Дело',
|
||||
'workspaceTree.namePlaceholder': 'Название Дела',
|
||||
'workspaceTree.template': 'Шаблон',
|
||||
'workspaceTree.creating': 'Создание...',
|
||||
'workspaceTree.templateAvailable': 'Доступен',
|
||||
'workspaceTree.templateLimited': 'Доступен с ограничениями',
|
||||
'workspaceTree.templateMissingPlugin': 'Плагин не установлен',
|
||||
'workspaceTree.templatePluginDisabled': 'Плагин выключен',
|
||||
'workspaceTree.templateCapabilityUnavailable': 'Не хватает обязательной возможности',
|
||||
'workspaceTree.templateIncompatible': 'Плагин несовместим с этой версией Верстака',
|
||||
'workspaceTree.templateLoadFailed': 'Плагин не удалось загрузить',
|
||||
'workspaceTree.templateNotReady': 'Плагин ещё не готов к работе',
|
||||
'workspaceTree.templateToolTabs': 'Создаёт вкладки: {tabs}',
|
||||
'workspaceTree.templateToolNoTabs': 'Не предоставляет вкладку Дела',
|
||||
'workspaceTree.templateWillBeIncomplete': 'Дело будет создано без недоступных компонентов.',
|
||||
'workspaceTree.templateIncompleteCreated': 'Дело «{name}» создано с недоступными компонентами.',
|
||||
'workspaceTree.templatesError': 'Не удалось загрузить шаблоны Дел. Повторите попытку.',
|
||||
'workspaceTree.loadError': 'Не удалось загрузить Дела. Повторите попытку.',
|
||||
'workspaceTree.selectError': 'Не удалось выбрать это Дело. Повторите попытку.',
|
||||
'workspaceTree.createError': 'Не удалось создать Дело. Повторите попытку.',
|
||||
'workspaceTree.renameError': 'Не удалось переименовать Дело. Повторите попытку.',
|
||||
'workspaceTree.trashError': 'Не удалось переместить Дело в корзину. Повторите попытку.',
|
||||
'pluginManager.loadError': 'Не удалось загрузить плагины. Повторите попытку.',
|
||||
'pluginManager.reloadError': 'Не удалось перезагрузить плагины. Повторите попытку.',
|
||||
'pluginManager.enableError': 'Не удалось включить плагин. Повторите попытку.',
|
||||
'pluginManager.disableError': 'Не удалось выключить плагин. Повторите попытку.',
|
||||
'pluginManager.settingsLoadError': 'Не удалось загрузить настройки плагина. Повторите попытку.',
|
||||
'pluginManager.settingsUnavailable': 'Настройки плагина недоступны.',
|
||||
'command.openOverview': 'Открыть обзор',
|
||||
'command.openFiles': 'Открыть файлы',
|
||||
'command.openActivity': 'Открыть активность',
|
||||
'command.openBrowserInbox': 'Открыть Браузер',
|
||||
'command.createMarkdown': 'Создать файл Markdown',
|
||||
'command.createText': 'Создать текстовый файл',
|
||||
'command.syncNow': 'Синхронизировать сейчас',
|
||||
'command.openSyncSettings': 'Открыть настройки синхронизации',
|
||||
'command.openPluginManager': 'Открыть менеджер плагинов',
|
||||
'command.handled': 'Выполнено: {title}',
|
||||
'command.result': '{title}: {status}',
|
||||
'command.failed': 'Не удалось выполнить команду «{title}». Повторите попытку.',
|
||||
'command.statusHandled': 'выполнено',
|
||||
'command.palette': 'Палитра команд',
|
||||
'command.run': 'Выполнить команду',
|
||||
'command.none': 'Команды не найдены',
|
||||
'search.indexing': 'Индексирование...',
|
||||
'search.placeholder': 'Поиск',
|
||||
'search.global': 'Глобальный поиск',
|
||||
'search.noResults': 'Ничего не найдено',
|
||||
'search.type.workspace': 'Дело',
|
||||
'search.type.tool': 'Инструмент',
|
||||
'search.type.folder': 'Папка',
|
||||
'search.type.file': 'Файл',
|
||||
'search.type.journal': 'Журнал',
|
||||
'search.type.browserInbox': 'Браузер',
|
||||
'search.type.activity': 'Активность',
|
||||
'workbench.noProvider': 'Нет обработчика',
|
||||
'workbench.noViewer': 'Нет доступного средства просмотра или редактора',
|
||||
'workbench.noResource': 'Ресурс не открыт',
|
||||
'bundle.noFrontend': 'У плагина нет frontend bundle',
|
||||
'bundle.notFound': 'Плагин не найден',
|
||||
'bundle.loadFailed': 'Не удалось загрузить интерфейс плагина. Повторите попытку.',
|
||||
'bundle.emptyContent': 'пустое содержимое',
|
||||
'bundle.executionError': 'Не удалось запустить интерфейс плагина. Повторите попытку.',
|
||||
'bundle.registrationMissing': 'Bundle загружен, но вызов VerstakPluginRegister не обнаружен',
|
||||
'bundle.componentMissing': 'Запрошенный интерфейс плагина недоступен.',
|
||||
'bundle.mountError': 'Не удалось открыть интерфейс плагина. Повторите попытку.',
|
||||
'bundle.mountUnavailable': 'Контейнер для подключения недоступен',
|
||||
'bundle.unexpectedError': 'Не удалось открыть интерфейс плагина. Повторите попытку.',
|
||||
'bundle.unknownError': 'Неизвестная ошибка',
|
||||
'bundle.frontendEntry': 'Точка входа frontend',
|
||||
'bundle.availableComponents': 'Доступные компоненты',
|
||||
'bundle.loading': 'Загрузка bundle плагина...',
|
||||
'overview.filter.all': 'Все',
|
||||
'overview.filter.notes': 'Заметки',
|
||||
'overview.filter.files': 'Файлы',
|
||||
'overview.filter.captures': 'Сохранённое',
|
||||
'overview.filter.journal': 'Журнал',
|
||||
'overview.notes': 'Заметки',
|
||||
'overview.files': 'Файлы',
|
||||
'overview.captures': 'Сохранённое',
|
||||
'overview.activity': 'Активность',
|
||||
'overview.journal': 'Журнал',
|
||||
'overview.attention': 'Требует внимания',
|
||||
'overview.openNotes': 'Открыть заметки',
|
||||
'overview.openFiles': 'Открыть файлы',
|
||||
'overview.reviewInbox': 'Разобрать входящие',
|
||||
'overview.viewActivity': 'Открыть активность',
|
||||
'overview.openJournal': 'Открыть журнал',
|
||||
'overview.openTodos': 'Открыть задачи',
|
||||
'overview.reviewCandidate': 'Просмотреть запись',
|
||||
'overview.reviewPending': 'Разобрать ожидающее',
|
||||
'overview.count.totalRecent.one': 'Всего: {total} · недавних изменений: {recent}',
|
||||
'overview.count.totalRecent.many': 'Всего: {total} · недавних изменений: {recent}',
|
||||
'overview.count.recentChanges.one': 'Недавних изменений: {count}',
|
||||
'overview.count.recentChanges.many': 'Недавних изменений: {count}',
|
||||
'overview.count.captures.one': 'На разбор: {count}',
|
||||
'overview.count.captures.many': 'На разбор: {count}',
|
||||
'overview.count.events.one': 'Событий: {count}',
|
||||
'overview.count.events.many': 'Событий: {count}',
|
||||
'overview.count.journal.one': 'Записей журнала: {count}',
|
||||
'overview.count.journal.many': 'Записей журнала: {count}',
|
||||
'overview.count.pending.one': 'Ожидают: {count}',
|
||||
'overview.count.pending.many': 'Ожидают: {count}',
|
||||
'overview.loadingContext': 'Загрузка данных Дела...',
|
||||
'overview.lastActive': 'Последняя активность: {time}',
|
||||
'overview.noRecentActivity': 'В Деле пока нет недавней активности',
|
||||
'overview.refresh': 'Обновить',
|
||||
'overview.summary': 'Сводка Дела',
|
||||
'overview.continue': 'Продолжить работу',
|
||||
'overview.continueHint': 'Вернитесь к следующему полезному делу в этом Деле.',
|
||||
'overview.loadingSignals': 'Загрузка данных Дела...',
|
||||
'overview.noResume': 'Пока неясно, с чего продолжить',
|
||||
'overview.noResumeHint': 'Здесь появятся недавние заметки, файлы, сохранённое и записи журнала.',
|
||||
'overview.recentChanges': 'Недавние изменения',
|
||||
'overview.recentChangesHint': 'Последняя важная активность в этом Деле.',
|
||||
'overview.event.workspaceOpened': 'Открыто Дело',
|
||||
'overview.event.activity': 'Активность Дела',
|
||||
'overview.event.noteEdited': 'Изменена заметка «{name}»',
|
||||
'overview.event.noteOpened': 'Открыта заметка «{name}»',
|
||||
'overview.event.noteCreated': 'Создана заметка «{name}»',
|
||||
'overview.event.fileOpened': 'Открыт файл «{name}»',
|
||||
'overview.event.fileChanged': 'Изменён файл «{name}»',
|
||||
'overview.event.fileCreated': 'Создан файл «{name}»',
|
||||
'overview.event.fileRemoved': 'Удалён файл «{name}»',
|
||||
'overview.event.capturePage': 'Сохранена страница «{name}»',
|
||||
'overview.event.captureSelection': 'Сохранено выделение «{name}»',
|
||||
'overview.event.captureLink': 'Сохранена ссылка «{name}»',
|
||||
'overview.event.captureFile': 'Сохранён файл «{name}»',
|
||||
'overview.event.captureConverted': 'Сохранённое преобразовано: «{name}»',
|
||||
'overview.event.capture': 'Сохранено: {kind} «{title}»',
|
||||
'overview.event.journalAdded': 'Добавлена запись в журнал «{name}»',
|
||||
'overview.event.workSessionDetected': 'Обнаружена рабочая сессия',
|
||||
'overview.event.todo': 'Задача «{title}»',
|
||||
'overview.event.reviewCapture': 'Разобрать сохранённое «{title}»',
|
||||
'overview.event.continueJournal': 'Продолжить запись журнала «{title}»',
|
||||
'overview.event.possibleJournalEntry': 'Возможная запись в журнал',
|
||||
'overview.captureKind.page': 'страница',
|
||||
'overview.captureKind.selection': 'выделение',
|
||||
'overview.captureKind.link': 'ссылка',
|
||||
'overview.captureKind.file': 'файл',
|
||||
'overview.captureKind.item': 'элемент',
|
||||
'overview.todo.reminderDue': 'Пора напомнить',
|
||||
'overview.todo.overdue': 'Просрочено',
|
||||
'overview.todo.dueSoon': 'Скоро срок',
|
||||
'overview.todo.due': 'Срок: {date}',
|
||||
'overview.candidateMeta': 'Дело: {deal} · {minutes} мин. · активностей: {activities}',
|
||||
'overview.minutes': '{count} мин.',
|
||||
'overview.browserCapture': 'Сохранённое из браузера',
|
||||
'overview.untitledTodo': 'Задача без названия',
|
||||
'overview.untitledCapture': 'Сохранённое без названия',
|
||||
'overview.untitledJournal': 'Запись журнала',
|
||||
'overview.unknownDeal': 'Неизвестное Дело',
|
||||
'overview.item': 'элемент',
|
||||
'overview.overviewNote': 'Обзорная заметка Дела',
|
||||
'overview.recentFilter': 'Фильтр недавних изменений',
|
||||
'overview.loadingRecent': 'Загрузка недавних изменений...',
|
||||
'overview.noChanges': 'Для этого фильтра пока нет важных изменений.',
|
||||
'overview.attentionHint': 'Неразобранное сохранённое, срочные задачи и возможные записи журнала.',
|
||||
'overview.loadingPending': 'Загрузка ожидающих элементов...',
|
||||
'overview.noPending': 'Нет неразобранного сохранённого, срочных задач или возможных записей журнала.',
|
||||
'overview.keyResources': 'Ключевые ресурсы',
|
||||
'overview.time.none': 'Время не указано',
|
||||
'overview.time.now': 'Только что',
|
||||
'overview.time.minutes': '{count} мин. назад',
|
||||
'overview.time.hours': '{count} ч. назад',
|
||||
'overview.time.yesterday': 'Вчера',
|
||||
'overview.time.days': '{count} дн. назад',
|
||||
};
|
||||
@@ -0,0 +1,200 @@
|
||||
import englishShellCatalog from './catalogs/en.js';
|
||||
import russianShellCatalog from './catalogs/ru.js';
|
||||
|
||||
const LANGUAGE_PREFERENCES = new Set(['system', 'en', 'ru']);
|
||||
const CONTRIBUTION_TEXT_FIELDS = {
|
||||
views: 'title',
|
||||
commands: 'title',
|
||||
settingsPanels: 'title',
|
||||
sidebarItems: 'title',
|
||||
fileActions: 'label',
|
||||
noteActions: 'label',
|
||||
contextMenuEntries: 'label',
|
||||
searchProviders: 'label',
|
||||
statusBarItems: 'label',
|
||||
openProviders: 'title',
|
||||
workspaceItems: 'title',
|
||||
};
|
||||
|
||||
function normalizeSystemLanguages(languages) {
|
||||
const values = Array.isArray(languages) ? languages : [languages];
|
||||
return values.map((value) => String(value || '').trim().toLowerCase()).filter(Boolean);
|
||||
}
|
||||
|
||||
export function resolveLocale(preference, systemLanguages = []) {
|
||||
if (!LANGUAGE_PREFERENCES.has(preference)) {
|
||||
throw new Error(`unsupported language preference: ${preference}`);
|
||||
}
|
||||
if (preference === 'en' || preference === 'ru') return preference;
|
||||
return normalizeSystemLanguages(systemLanguages).some((locale) => locale === 'ru' || locale.startsWith('ru-'))
|
||||
? 'ru'
|
||||
: 'en';
|
||||
}
|
||||
|
||||
function interpolate(message, params) {
|
||||
if (!params) return message;
|
||||
return message.replace(/\{([A-Za-z0-9_.-]+)\}/g, (placeholder, name) => (
|
||||
Object.prototype.hasOwnProperty.call(params, name) ? String(params[name]) : placeholder
|
||||
));
|
||||
}
|
||||
|
||||
function browserLanguages() {
|
||||
if (typeof navigator === 'undefined') return ['en'];
|
||||
if (Array.isArray(navigator.languages) && navigator.languages.length > 0) return navigator.languages;
|
||||
return [navigator.language || 'en'];
|
||||
}
|
||||
|
||||
export function createI18n(options = {}) {
|
||||
const shellCatalogs = options.shellCatalogs || { en: {}, ru: {} };
|
||||
let systemLanguages = options.systemLanguages || browserLanguages;
|
||||
let catalogLoader = options.loadPluginCatalog || (async () => ({}));
|
||||
let preference = 'system';
|
||||
let locale = 'en';
|
||||
const listeners = new Set();
|
||||
const pluginConfigs = new Map();
|
||||
const pluginCatalogs = new Map();
|
||||
|
||||
function configure(next = {}) {
|
||||
if (next.systemLanguages) systemLanguages = next.systemLanguages;
|
||||
if (next.loadPluginCatalog) catalogLoader = next.loadPluginCatalog;
|
||||
}
|
||||
|
||||
function notify() {
|
||||
listeners.forEach((listener) => listener(locale));
|
||||
}
|
||||
|
||||
async function initialize(initialPreference = 'system') {
|
||||
preference = LANGUAGE_PREFERENCES.has(initialPreference) ? initialPreference : 'system';
|
||||
locale = resolveLocale(preference, systemLanguages());
|
||||
}
|
||||
|
||||
async function loadCatalog(pluginId, catalogLocale) {
|
||||
if (!catalogLocale) return;
|
||||
let catalogs = pluginCatalogs.get(pluginId);
|
||||
if (!catalogs) {
|
||||
catalogs = new Map();
|
||||
pluginCatalogs.set(pluginId, catalogs);
|
||||
}
|
||||
if (catalogs.has(catalogLocale)) return;
|
||||
const messages = await catalogLoader(pluginId, catalogLocale);
|
||||
catalogs.set(catalogLocale, { ...(messages || {}) });
|
||||
}
|
||||
|
||||
async function loadPlugin(pluginId, localization) {
|
||||
if (!pluginId || !localization || !localization.defaultLocale || !localization.locales) return;
|
||||
pluginConfigs.set(pluginId, localization);
|
||||
const requested = localization.locales[locale] ? locale : '';
|
||||
const defaultLocale = localization.defaultLocale;
|
||||
await Promise.all(Array.from(new Set([requested, defaultLocale].filter(Boolean))).map((item) => loadCatalog(pluginId, item)));
|
||||
}
|
||||
|
||||
async function setLanguagePreference(nextPreference) {
|
||||
const nextLocale = resolveLocale(nextPreference, systemLanguages());
|
||||
preference = nextPreference;
|
||||
locale = nextLocale;
|
||||
await Promise.all(Array.from(pluginConfigs.entries()).map(([pluginId, config]) => (
|
||||
loadPlugin(pluginId, config).catch((error) => {
|
||||
console.warn(`[i18n] failed to load ${pluginId} catalog for ${nextLocale}:`, error);
|
||||
})
|
||||
)));
|
||||
notify();
|
||||
}
|
||||
|
||||
function t(key, params, fallback) {
|
||||
const message = shellCatalogs[locale]?.[key]
|
||||
?? shellCatalogs.en?.[key]
|
||||
?? fallback
|
||||
?? key;
|
||||
return interpolate(message, params);
|
||||
}
|
||||
|
||||
function translatePlugin(pluginId, key, params, fallback) {
|
||||
const config = pluginConfigs.get(pluginId);
|
||||
const catalogs = pluginCatalogs.get(pluginId);
|
||||
const message = catalogs?.get(locale)?.[key]
|
||||
?? catalogs?.get(config?.defaultLocale)?.[key]
|
||||
?? fallback
|
||||
?? key;
|
||||
return interpolate(message, params);
|
||||
}
|
||||
|
||||
function localizeContributions(pluginId, contributions) {
|
||||
if (!contributions) return contributions;
|
||||
const localized = { ...contributions };
|
||||
Object.entries(CONTRIBUTION_TEXT_FIELDS).forEach(([point, field]) => {
|
||||
if (!Array.isArray(contributions[point])) return;
|
||||
localized[point] = contributions[point].map((item) => ({
|
||||
...item,
|
||||
[field]: translatePlugin(
|
||||
pluginId,
|
||||
`contributions.${point}.${item.id}.${field}`,
|
||||
undefined,
|
||||
item[field],
|
||||
),
|
||||
}));
|
||||
});
|
||||
return localized;
|
||||
}
|
||||
|
||||
function localizePlugin(plugin) {
|
||||
if (!plugin) return plugin;
|
||||
const hasStateWrapper = !!plugin.manifest;
|
||||
const manifest = hasStateWrapper ? plugin.manifest : plugin;
|
||||
const pluginId = manifest.id;
|
||||
const localizedManifest = {
|
||||
...manifest,
|
||||
name: translatePlugin(pluginId, 'manifest.name', undefined, manifest.name),
|
||||
description: translatePlugin(pluginId, 'manifest.description', undefined, manifest.description),
|
||||
contributes: localizeContributions(pluginId, manifest.contributes),
|
||||
};
|
||||
return hasStateWrapper ? { ...plugin, manifest: localizedManifest } : localizedManifest;
|
||||
}
|
||||
|
||||
function localizeContributionSummary(summary) {
|
||||
if (!summary) return summary;
|
||||
const localized = { ...summary };
|
||||
Object.entries(CONTRIBUTION_TEXT_FIELDS).forEach(([point, field]) => {
|
||||
if (!Array.isArray(summary[point])) return;
|
||||
localized[point] = summary[point].map((item) => ({
|
||||
...item,
|
||||
[field]: translatePlugin(
|
||||
item.pluginId,
|
||||
`contributions.${point}.${item.id}.${field}`,
|
||||
undefined,
|
||||
item[field],
|
||||
),
|
||||
}));
|
||||
});
|
||||
return localized;
|
||||
}
|
||||
|
||||
function subscribe(listener) {
|
||||
listeners.add(listener);
|
||||
listener(locale);
|
||||
return () => listeners.delete(listener);
|
||||
}
|
||||
|
||||
return {
|
||||
configure,
|
||||
initialize,
|
||||
getLanguagePreference: () => preference,
|
||||
getLocale: () => locale,
|
||||
setLanguagePreference,
|
||||
t,
|
||||
subscribe,
|
||||
loadPlugin,
|
||||
translatePlugin,
|
||||
localizeContributions,
|
||||
localizePlugin,
|
||||
localizeContributionSummary,
|
||||
};
|
||||
}
|
||||
|
||||
export const i18n = createI18n({
|
||||
shellCatalogs: {
|
||||
en: englishShellCatalog,
|
||||
ru: russianShellCatalog,
|
||||
},
|
||||
});
|
||||
|
||||
export const t = (...args) => i18n.t(...args);
|
||||
@@ -127,9 +127,11 @@ export var debug = {
|
||||
log: log,
|
||||
logf: logf,
|
||||
isEnabled: function () { return ENABLED; },
|
||||
enable: function () {
|
||||
enable: function (options) {
|
||||
ENABLED = true;
|
||||
try { localStorage.setItem('verstak-debug', 'true'); } catch (e) {}
|
||||
if (!options || options.persist !== false) {
|
||||
try { localStorage.setItem('verstak-debug', 'true'); } catch (e) {}
|
||||
}
|
||||
},
|
||||
disable: function () {
|
||||
ENABLED = false;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import * as App from '../../../wailsjs/go/api/App';
|
||||
import Icon from '../ui/Icon.svelte';
|
||||
import { i18n } from '../i18n/index.js';
|
||||
|
||||
import { createPluginAPI } from './VerstakPluginAPI.js';
|
||||
|
||||
@@ -18,6 +19,13 @@
|
||||
let currentComponent = null;
|
||||
let currentAPI = null;
|
||||
let currentPropsKey = '';
|
||||
let locale = i18n.getLocale();
|
||||
let unsubscribeLocale = null;
|
||||
|
||||
$: tr = ((activeLocale) => (key, params, fallback) => {
|
||||
void activeLocale;
|
||||
return i18n.t(key, params, fallback);
|
||||
})(locale);
|
||||
|
||||
$: activePluginId = pluginId || viewPluginId;
|
||||
$: activeComponent = componentId;
|
||||
@@ -32,9 +40,14 @@
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
unsubscribeLocale?.();
|
||||
cleanup();
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
unsubscribeLocale = i18n.subscribe((nextLocale) => locale = nextLocale);
|
||||
});
|
||||
|
||||
function cleanup() {
|
||||
if (currentAPI && typeof currentAPI.dispose === 'function') {
|
||||
try {
|
||||
@@ -70,6 +83,11 @@
|
||||
return { value: result, error: '' };
|
||||
}
|
||||
|
||||
function reportError(key, fallback, details) {
|
||||
console.warn('[PluginBundleHost] ' + key + ':', details);
|
||||
return tr(key, undefined, fallback);
|
||||
}
|
||||
|
||||
async function loadAndMount(pId, compId, nextPropsKey) {
|
||||
// If same plugin+component and already mounted, skip
|
||||
if (currentPluginId === pId && currentComponent === compId && currentPropsKey === nextPropsKey && loadState === 'loaded') {
|
||||
@@ -93,11 +111,17 @@
|
||||
if (!info || info.status === 'no-frontend' || info.status === 'not-found') {
|
||||
loadState = 'error';
|
||||
errorText = info.status === 'no-frontend'
|
||||
? 'Plugin has no frontend bundle'
|
||||
: 'Plugin not found';
|
||||
? tr('bundle.noFrontend')
|
||||
: tr('bundle.notFound');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await i18n.loadPlugin(pId, info.localization);
|
||||
} catch (catalogError) {
|
||||
console.warn(`[PluginBundleHost] localization unavailable for ${pId}:`, catalogError);
|
||||
}
|
||||
|
||||
// Check if bundle already loaded for this plugin
|
||||
const reg = window.__VERSTAK_PLUGIN_REGISTRY__ || {};
|
||||
if (!reg[pId]) {
|
||||
@@ -106,7 +130,7 @@
|
||||
const content = assetResult.value;
|
||||
if (assetResult.error || !content) {
|
||||
loadState = 'error';
|
||||
errorText = 'Failed to load bundle: ' + (assetResult.error || 'empty content');
|
||||
errorText = reportError('bundle.loadFailed', 'Could not load the plugin interface. Please try again.', assetResult.error || tr('bundle.emptyContent'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -117,15 +141,14 @@
|
||||
fn();
|
||||
} catch (e) {
|
||||
loadState = 'error';
|
||||
errorText = 'Bundle execution error: ' + e.message;
|
||||
console.error('[PluginBundleHost] bundle exec error:', e);
|
||||
errorText = reportError('bundle.executionError', 'Could not start the plugin interface. Please try again.', e);
|
||||
return;
|
||||
}
|
||||
|
||||
// Verify registration happened
|
||||
if (!window.__VERSTAK_PLUGIN_REGISTRY__[pId]) {
|
||||
loadState = 'error';
|
||||
errorText = 'Bundle loaded but no VerstakPluginRegister call detected';
|
||||
errorText = tr('bundle.registrationMissing');
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -135,8 +158,7 @@
|
||||
const comp = components[compId];
|
||||
if (!comp || !comp.mount) {
|
||||
loadState = 'error';
|
||||
errorText = 'Component "' + compId + '" not found in bundle. Available: '
|
||||
+ (Object.keys(components).join(', ') || 'none');
|
||||
errorText = tr('bundle.componentMissing', undefined, 'The requested plugin interface is unavailable.');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -156,17 +178,15 @@
|
||||
errorText = '';
|
||||
} catch (e) {
|
||||
loadState = 'error';
|
||||
errorText = 'Component mount error: ' + e.message;
|
||||
console.error('[PluginBundleHost] mount error:', e);
|
||||
errorText = reportError('bundle.mountError', 'Could not open the plugin interface. Please try again.', e);
|
||||
}
|
||||
} else {
|
||||
loadState = 'error';
|
||||
errorText = 'Mount container not available';
|
||||
errorText = tr('bundle.mountUnavailable');
|
||||
}
|
||||
} catch (e) {
|
||||
loadState = 'error';
|
||||
errorText = 'Unexpected error: ' + (e.message || e);
|
||||
console.error('[PluginBundleHost] error:', e);
|
||||
errorText = reportError('bundle.unexpectedError', 'Could not open the plugin interface. Please try again.', e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,31 +200,32 @@
|
||||
<div class="plugin-bundle-host">
|
||||
{#if loadState === 'idle'}
|
||||
<div class="host-state idle">
|
||||
<p>Select a plugin view from the sidebar</p>
|
||||
<p>{tr('pluginView.select')}</p>
|
||||
</div>
|
||||
|
||||
{:else if loadState === 'error'}
|
||||
<div class="host-state error">
|
||||
<Icon name="warning" size={24} class="error-icon" />
|
||||
<p class="error-title">Plugin View Error</p>
|
||||
<div class="error-details">
|
||||
<p><strong>Plugin:</strong> {currentPluginId || 'unknown'}</p>
|
||||
<p><strong>Component:</strong> {currentComponent || 'unknown'}</p>
|
||||
<p class="error-message">{errorText || 'Unknown error'}</p>
|
||||
<p class="error-title">{tr('pluginView.error')}</p>
|
||||
<p class="error-message">{errorText || tr('bundle.unknownError')}</p>
|
||||
<details class="error-details">
|
||||
<summary>{tr('common.details')}</summary>
|
||||
<p><strong>{tr('common.plugin')}:</strong> {currentPluginId || tr('common.unknown')}</p>
|
||||
<p><strong>{tr('common.component')}:</strong> {currentComponent || tr('common.unknown')}</p>
|
||||
{#if pluginInfo}
|
||||
<p class="error-meta">Frontend entry: {pluginInfo.entry || 'none'}</p>
|
||||
<p class="error-meta">{tr('bundle.frontendEntry')}: {pluginInfo.entry || tr('common.none')}</p>
|
||||
{/if}
|
||||
{#if getComponentList().length > 0}
|
||||
<p class="error-meta">Available components: {getComponentList().join(', ')}</p>
|
||||
<p class="error-meta">{tr('bundle.availableComponents')}: {getComponentList().join(', ')}</p>
|
||||
{/if}
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
{:else}
|
||||
{#if loadState === 'loading'}
|
||||
<div class="host-state loading">
|
||||
<div class="spinner"></div>
|
||||
<p>Loading plugin bundle...</p>
|
||||
<p>{tr('bundle.loading')}</p>
|
||||
</div>
|
||||
{/if}
|
||||
<div
|
||||
@@ -282,11 +303,21 @@
|
||||
max-width: 400px;
|
||||
text-align: left;
|
||||
background: #16213e;
|
||||
padding: 1rem;
|
||||
padding: 0.5rem 0.75rem;
|
||||
border-radius: 6px;
|
||||
border: 1px solid #0f3460;
|
||||
}
|
||||
|
||||
.error-details[open] {
|
||||
padding: 0.75rem 1rem;
|
||||
}
|
||||
|
||||
.error-details summary {
|
||||
cursor: pointer;
|
||||
color: #e0e0f0;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.error-details p {
|
||||
margin: 0.3rem 0;
|
||||
}
|
||||
@@ -297,12 +328,8 @@
|
||||
|
||||
.error-message {
|
||||
color: #e94560;
|
||||
font-family: monospace;
|
||||
font-size: 0.8rem;
|
||||
margin-top: 0.5rem !important;
|
||||
padding: 0.5rem;
|
||||
background: rgba(233, 69, 96, 0.1);
|
||||
border-radius: 4px;
|
||||
max-width: 400px;
|
||||
margin: 0 0 0.75rem;
|
||||
}
|
||||
|
||||
.error-meta {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as App from '../../../wailsjs/go/api/App';
|
||||
import { i18n } from '../i18n/index.js';
|
||||
|
||||
window.__VERSTAK_PLUGIN_REGISTRY__ = window.__VERSTAK_PLUGIN_REGISTRY__ || {};
|
||||
window.__VERSTAK_EVENT_HANDLERS__ = window.__VERSTAK_EVENT_HANDLERS__ || {};
|
||||
@@ -144,6 +145,24 @@ export function createPluginAPI(pluginId) {
|
||||
return {
|
||||
pluginId: pluginId,
|
||||
|
||||
i18n: {
|
||||
getLocale: function() {
|
||||
assertActive('i18n.getLocale');
|
||||
return i18n.getLocale();
|
||||
},
|
||||
t: function(key, params, fallback) {
|
||||
assertActive('i18n.t(' + key + ')');
|
||||
return i18n.translatePlugin(pluginId, key, params, fallback);
|
||||
},
|
||||
onDidChangeLocale: function(listener) {
|
||||
assertActive('i18n.onDidChangeLocale');
|
||||
if (typeof listener !== 'function') {
|
||||
throw new Error('i18n.onDidChangeLocale requires a listener function');
|
||||
}
|
||||
return trackCleanup(i18n.subscribe(listener));
|
||||
}
|
||||
},
|
||||
|
||||
ui: {
|
||||
openSettings: function(panelId) {
|
||||
assertActive('ui.openSettings');
|
||||
@@ -201,6 +220,24 @@ export function createPluginAPI(pluginId) {
|
||||
}
|
||||
},
|
||||
|
||||
notifications: {
|
||||
replace: function(items) {
|
||||
assertActive('notifications.replace');
|
||||
if (!Array.isArray(items)) {
|
||||
throw new Error('notifications.replace requires an array');
|
||||
}
|
||||
return callBackendErrorString(pluginId, 'notifications.replace', function() {
|
||||
return App.ReplacePluginNotifications(pluginId, items);
|
||||
});
|
||||
},
|
||||
clear: function() {
|
||||
assertActive('notifications.clear');
|
||||
return callBackendErrorString(pluginId, 'notifications.clear', function() {
|
||||
return App.ClearPluginNotifications(pluginId);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
settings: {
|
||||
read: async function(key) {
|
||||
assertActive('settings.read');
|
||||
@@ -217,12 +254,10 @@ export function createPluginAPI(pluginId) {
|
||||
if (!key) {
|
||||
throw new Error('settings.write requires a key');
|
||||
}
|
||||
const settings = await this.read();
|
||||
settings[key] = value;
|
||||
await callBackendErrorString(pluginId, 'settings.write(' + key + ')', function() {
|
||||
return App.WritePluginSettings(pluginId, settings);
|
||||
return App.WritePluginSetting(pluginId, key, value);
|
||||
});
|
||||
return settings;
|
||||
return this.read();
|
||||
},
|
||||
writeAll: function(settings) {
|
||||
assertActive('settings.writeAll');
|
||||
@@ -245,6 +280,26 @@ export function createPluginAPI(pluginId) {
|
||||
return data || {};
|
||||
});
|
||||
},
|
||||
readNDJSON: function(name) {
|
||||
assertActive('storage.data.readNDJSON(' + name + ')');
|
||||
if (!name) {
|
||||
throw new Error('storage.data.readNDJSON requires a name');
|
||||
}
|
||||
return callBackend(pluginId, 'storage.data.readNDJSON(' + name + ')', function() {
|
||||
return App.ReadPluginDataNDJSON(pluginId, name);
|
||||
}).then(function(records) {
|
||||
return Array.isArray(records) ? records : [];
|
||||
});
|
||||
},
|
||||
writeNDJSON: function(name, records) {
|
||||
assertActive('storage.data.writeNDJSON(' + name + ')');
|
||||
if (!name) {
|
||||
throw new Error('storage.data.writeNDJSON requires a name');
|
||||
}
|
||||
return callBackendErrorString(pluginId, 'storage.data.writeNDJSON(' + name + ')', function() {
|
||||
return App.WritePluginDataNDJSON(pluginId, name, Array.isArray(records) ? records : []);
|
||||
});
|
||||
},
|
||||
write: function(name, data) {
|
||||
assertActive('storage.data.write(' + name + ')');
|
||||
if (!name) {
|
||||
@@ -392,6 +447,12 @@ export function createPluginAPI(pluginId) {
|
||||
return App.OpenVaultPathExternal(pluginId, relativePath);
|
||||
});
|
||||
},
|
||||
openURL: function(url) {
|
||||
assertActive('files.openURL');
|
||||
return callBackendErrorString(pluginId, 'files.openURL', function() {
|
||||
return App.OpenExternalURL(pluginId, String(url == null ? '' : url));
|
||||
});
|
||||
},
|
||||
showInFolder: function(relativePath) {
|
||||
assertActive('files.showInFolder(' + relativePath + ')');
|
||||
return callBackendErrorString(pluginId, 'files.showInFolder(' + relativePath + ')', function() {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<script>
|
||||
import Icon from '../ui/Icon.svelte';
|
||||
import { onDestroy } from 'svelte';
|
||||
import { i18n } from '../i18n/index.js';
|
||||
export let p = {};
|
||||
export let capabilities = [];
|
||||
export let permissions = [];
|
||||
@@ -8,6 +10,13 @@
|
||||
export let settingsPanels = [];
|
||||
export let onEnable = () => {};
|
||||
export let onDisable = () => {};
|
||||
let locale = i18n.getLocale();
|
||||
const unsubscribeLocale = i18n.subscribe((nextLocale) => { locale = nextLocale; });
|
||||
$: tr = ((activeLocale) => (key, params, fallback) => {
|
||||
void activeLocale;
|
||||
return i18n.t(key, params, fallback);
|
||||
})(locale);
|
||||
onDestroy(unsubscribeLocale);
|
||||
|
||||
$: m = p.manifest || {};
|
||||
$: pluginId = m.id || 'unknown';
|
||||
@@ -39,14 +48,14 @@
|
||||
|
||||
$: contribSummary = (() => {
|
||||
const parts = [];
|
||||
if (contribCounts.views > 0) parts.push(contribCounts.views + ' view' + (contribCounts.views !== 1 ? 's' : ''));
|
||||
if (contribCounts.commands > 0) parts.push(contribCounts.commands + ' command' + (contribCounts.commands !== 1 ? 's' : ''));
|
||||
if (contribCounts.searchProviders > 0) parts.push(contribCounts.searchProviders + ' searchProvider' + (contribCounts.searchProviders !== 1 ? 's' : ''));
|
||||
if (contribCounts.sidebar > 0) parts.push(contribCounts.sidebar + ' sidebar' + (contribCounts.sidebar !== 1 ? 's' : ''));
|
||||
if (contribCounts.statusbar > 0) parts.push(contribCounts.statusbar + ' statusbar' + (contribCounts.statusbar !== 1 ? 's' : ''));
|
||||
if (contribCounts.openProviders > 0) parts.push(contribCounts.openProviders + ' openProvider' + (contribCounts.openProviders !== 1 ? 's' : ''));
|
||||
if (contribCounts.workspaceItems > 0) parts.push(contribCounts.workspaceItems + ' workspace' + (contribCounts.workspaceItems !== 1 ? 's' : ''));
|
||||
return parts.length > 0 ? parts.join(', ') : 'none';
|
||||
if (contribCounts.views > 0) parts.push(tr('pluginCard.count.views', { count: contribCounts.views }));
|
||||
if (contribCounts.commands > 0) parts.push(tr('pluginCard.count.commands', { count: contribCounts.commands }));
|
||||
if (contribCounts.searchProviders > 0) parts.push(tr('pluginCard.count.searchProviders', { count: contribCounts.searchProviders }));
|
||||
if (contribCounts.sidebar > 0) parts.push(tr('pluginCard.count.sidebar', { count: contribCounts.sidebar }));
|
||||
if (contribCounts.statusbar > 0) parts.push(tr('pluginCard.count.statusbar', { count: contribCounts.statusbar }));
|
||||
if (contribCounts.openProviders > 0) parts.push(tr('pluginCard.count.openProviders', { count: contribCounts.openProviders }));
|
||||
if (contribCounts.workspaceItems > 0) parts.push(tr('pluginCard.count.workspace', { count: contribCounts.workspaceItems }));
|
||||
return parts.length > 0 ? parts.join(', ') : tr('common.none');
|
||||
})();
|
||||
|
||||
$: dangerousPermissions = (m.permissions || []).filter(name => {
|
||||
@@ -81,11 +90,11 @@
|
||||
<strong>{pluginId}</strong>
|
||||
<span class="version">v{m.version || '?'}</span>
|
||||
</div>
|
||||
<span class="status-badge" style="color: {statusColor}">{p.status}</span>
|
||||
<span class="status-badge" style="color: {statusColor}">{tr(`status.${p.status}`, undefined, p.status)}</span>
|
||||
</div>
|
||||
|
||||
{#if p.status === 'degraded'}
|
||||
<p class="degraded-text">Plugin is usable, but some optional capabilities are unavailable.</p>
|
||||
<p class="degraded-text">{tr('pluginCard.degraded')}</p>
|
||||
{/if}
|
||||
|
||||
{#if m.description}
|
||||
@@ -94,34 +103,34 @@
|
||||
|
||||
<div class="card-meta">
|
||||
<div class="meta-row">
|
||||
<span class="label">Name:</span>
|
||||
<span class="label">{tr('pluginCard.name')}:</span>
|
||||
<span>{m.name || '-'}</span>
|
||||
</div>
|
||||
<div class="meta-row">
|
||||
<span class="label">Source:</span>
|
||||
<span>{m.source || 'unknown'}</span>
|
||||
<span class="label">{tr('common.source')}:</span>
|
||||
<span>{m.source || tr('common.unknown')}</span>
|
||||
</div>
|
||||
<div class="meta-row">
|
||||
<span class="label">Contributions:</span>
|
||||
<span class="label">{tr('pluginCard.contributions')}:</span>
|
||||
<span>{contribSummary}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<details class="plugin-details">
|
||||
<summary>Technical details</summary>
|
||||
<summary>{tr('pluginCard.technicalDetails')}</summary>
|
||||
<div class="card-meta technical-meta">
|
||||
<div class="meta-row">
|
||||
<span class="label">API Version:</span>
|
||||
<span class="label">{tr('pluginCard.apiVersion')}:</span>
|
||||
<span>{m.apiVersion || '-'}</span>
|
||||
</div>
|
||||
<div class="meta-row">
|
||||
<span class="label">Root:</span>
|
||||
<span class="label">{tr('pluginCard.root')}:</span>
|
||||
<span class="path">{p.rootPath || '-'}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="section">
|
||||
<span class="section-title">Provides</span>
|
||||
<span class="section-title">{tr('pluginCard.provides')}</span>
|
||||
<div class="tags">
|
||||
{#each m.provides || [] as cap}
|
||||
<span class="tag provides">{cap}</span>
|
||||
@@ -131,7 +140,7 @@
|
||||
|
||||
{#if m.requires && m.requires.length > 0}
|
||||
<div class="section">
|
||||
<span class="section-title">Requires</span>
|
||||
<span class="section-title">{tr('pluginCard.requires')}</span>
|
||||
<div class="tags">
|
||||
{#each m.requires as req}
|
||||
{@const found = capabilities.some(c => c.name === req)}
|
||||
@@ -142,14 +151,14 @@
|
||||
{/each}
|
||||
</div>
|
||||
{#if missingRequired.length > 0}
|
||||
<p class="warning"><Icon name="warning" size={12} /> Missing required capabilities: {missingRequired.join(', ')}</p>
|
||||
<p class="warning"><Icon name="warning" size={12} /> {tr('pluginCard.missingRequired')}: {missingRequired.join(', ')}</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if m.optionalRequires && m.optionalRequires.length > 0}
|
||||
<div class="section">
|
||||
<span class="section-title">Optional Requires</span>
|
||||
<span class="section-title">{tr('pluginCard.optionalRequires')}</span>
|
||||
<div class="tags">
|
||||
{#each m.optionalRequires as opt}
|
||||
{@const found = capabilities.some(c => c.name === opt)}
|
||||
@@ -160,14 +169,14 @@
|
||||
{/each}
|
||||
</div>
|
||||
{#if missingOptional.length > 0}
|
||||
<p class="info"><Icon name="warning" size={12} /> Optional capabilities not available — plugin running in degraded mode</p>
|
||||
<p class="info"><Icon name="warning" size={12} /> {tr('pluginCard.optionalUnavailable')}</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if m.permissions && m.permissions.length > 0}
|
||||
<div class="section">
|
||||
<span class="section-title">Permissions</span>
|
||||
<span class="section-title">{tr('pluginCard.permissions')}</span>
|
||||
<div class="tags">
|
||||
{#each m.permissions as perm}
|
||||
{@const isDangerous = dangerousPermissions.includes(perm)}
|
||||
@@ -190,28 +199,28 @@
|
||||
<div class="card-actions">
|
||||
{#if hasSettingsPanel}
|
||||
<button class="btn-settings" on:click={() => window.dispatchEvent(new CustomEvent('verstak:open-settings', { detail: { pluginId: m.id, panelId: settingsPanels[0]?.id } }))} type="button" disabled={isDisabled || p.status === 'failed'}>
|
||||
<Icon name="gear" size={14} /> Settings
|
||||
<Icon name="gear" size={14} /> {tr('settings.title')}
|
||||
</button>
|
||||
{/if}
|
||||
{#if vaultOpen && canToggle}
|
||||
{#if isDisabled}
|
||||
<button class="btn-enable" on:click={() => onEnable(m.id)} type="button" disabled={isBusy}>
|
||||
{#if busyAction === 'enabling'}⟳ Enabling...{:else}▶ Enable{/if}
|
||||
{#if busyAction === 'enabling'}{tr('pluginCard.enabling')}{:else}{tr('pluginCard.enable')}{/if}
|
||||
</button>
|
||||
{:else}
|
||||
<button class="btn-disable" on:click={() => onDisable(m.id)} type="button" disabled={isBusy}>
|
||||
{#if busyAction === 'disabling'}⟳ Disabling...{:else}⏸ Disable{/if}
|
||||
{#if busyAction === 'disabling'}{tr('pluginCard.disabling')}{:else}{tr('pluginCard.disable')}{/if}
|
||||
</button>
|
||||
{/if}
|
||||
{/if}
|
||||
{#if !vaultOpen && canToggle}
|
||||
<span class="vault-hint">Open a vault to manage plugin state</span>
|
||||
<span class="vault-hint">{tr('pluginCard.openVault')}</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<!-- Permission warnings -->
|
||||
{#if !hasUIPermission && m.contributes && ((m.contributes.views || []).length > 0 || (m.contributes.sidebarItems || []).length > 0 || (m.contributes.settingsPanels || []).length > 0)}
|
||||
<p class="warning"><Icon name="warning" size={12} /> Plugin has UI contributions but lacks ui.register permission</p>
|
||||
<p class="warning"><Icon name="warning" size={12} /> {tr('pluginCard.missingUiPermission')}</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
import Icon from '../ui/Icon.svelte';
|
||||
import PluginCard from './PluginCard.svelte';
|
||||
import PluginBundleHost from '../plugin-host/PluginBundleHost.svelte';
|
||||
import { onMount, tick } from 'svelte';
|
||||
import { onDestroy, onMount, tick } from 'svelte';
|
||||
import { GetPlugins, GetCapabilities, GetPermissions, GetContributions, ReloadPlugins, GetVaultStatus, GetVaultPluginState, EnablePlugin, DisablePlugin, ReadPluginSettings, WritePluginSettings, GetPluginFrontendInfo, WriteFrontendLog } from '../../../wailsjs/go/api/App';
|
||||
import { debug } from '../log/debug.js';
|
||||
import { i18n } from '../i18n/index.js';
|
||||
|
||||
let plugins = [];
|
||||
let capabilities = [];
|
||||
@@ -20,12 +21,23 @@
|
||||
let settingsError = null;
|
||||
let settingsPluginInfo = null;
|
||||
let lastOpenedKey = '';
|
||||
let locale = i18n.getLocale();
|
||||
let unsubscribeLocale = null;
|
||||
$: tr = ((activeLocale) => (key, params, fallback) => {
|
||||
void activeLocale;
|
||||
return i18n.t(key, params, fallback);
|
||||
})(locale);
|
||||
|
||||
// Per-action loading state — shows feedback on specific buttons without hiding the whole list
|
||||
let actionFeedback = {}; // { [pluginId]: 'enabling' | 'disabling' | null }
|
||||
let reloading = false;
|
||||
let toastMessage = '';
|
||||
let toastType = 'success'; // 'success' | 'error' | 'info'
|
||||
let statusFilter = 'all';
|
||||
let permissionFilters = [];
|
||||
let capabilityFilters = [];
|
||||
let settingsFilter = 'all';
|
||||
let sourceFilter = 'all';
|
||||
|
||||
export let activeSettingsPluginId = '';
|
||||
export let activeSettingsPanelId = '';
|
||||
@@ -46,6 +58,12 @@
|
||||
}, 4000);
|
||||
}
|
||||
|
||||
function reportError(key, fallback, details) {
|
||||
debug.log('[PluginManager] ' + key + ':', String(details));
|
||||
WriteFrontendLog('PluginManager', key + ': ' + String(details)).catch(() => {});
|
||||
return tr(key, undefined, fallback);
|
||||
}
|
||||
|
||||
function notifyPluginsChanged() {
|
||||
window.dispatchEvent(new CustomEvent('verstak:plugins-changed'));
|
||||
}
|
||||
@@ -82,14 +100,14 @@
|
||||
ReadPluginSettings(pluginId).then(result => {
|
||||
const unpacked = unpackBackendResult(result);
|
||||
if (unpacked.error) {
|
||||
settingsError = unpacked.error;
|
||||
settingsError = reportError('pluginManager.settingsLoadError', 'Could not load plugin settings. Please try again.', unpacked.error);
|
||||
settingsData = {};
|
||||
return;
|
||||
}
|
||||
settingsData = unpacked.value || {};
|
||||
}).catch(() => { settingsData = {}; });
|
||||
} else {
|
||||
settingsError = `Settings panel not found for plugin "${pluginId}". Check that the plugin is enabled and has settingsPanels in its manifest.`;
|
||||
settingsError = tr('pluginManager.settingsUnavailable', undefined, 'Plugin settings are unavailable.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +127,10 @@
|
||||
try {
|
||||
debug.log('[PluginManager] loadAll: calling GetPlugins...');
|
||||
const p = await GetPlugins();
|
||||
plugins = p || [];
|
||||
await Promise.all((p || []).map((plugin) => (
|
||||
i18n.loadPlugin(plugin.manifest?.id, plugin.manifest?.localization).catch(() => {})
|
||||
)));
|
||||
plugins = (p || []).map((plugin) => i18n.localizePlugin(plugin));
|
||||
debug.log('[PluginManager] loadAll: GetPlugins returned', plugins.length, 'plugins');
|
||||
for (var i = 0; i < plugins.length; i++) {
|
||||
debug.log('[PluginManager] loadAll: plugin[' + i + ']:', plugins[i].manifest?.id, 'status:', plugins[i].status, 'enabled:', plugins[i].enabled);
|
||||
@@ -117,7 +138,7 @@
|
||||
} catch (e) {
|
||||
debug.log('[PluginManager] loadAll: GetPlugins ERROR:', String(e));
|
||||
WriteFrontendLog('PluginManager', 'loadAll: GetPlugins ERROR: ' + String(e));
|
||||
error = 'GetPlugins: ' + String(e);
|
||||
error = reportError('pluginManager.loadError', 'Could not load plugins. Please try again.', e);
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
@@ -133,7 +154,7 @@
|
||||
vaultStatus = v || { status: 'unknown', path: '', vaultId: '' };
|
||||
capabilities = caps || [];
|
||||
permissions = perms || [];
|
||||
contributions = contribs || {};
|
||||
contributions = i18n.localizeContributionSummary(contribs || {});
|
||||
debug.log('[PluginManager] loadAll: vault=' + vaultStatus.status + ' caps=' + capabilities.length + ' perms=' + permissions.length);
|
||||
WriteFrontendLog('PluginManager', 'loadAll: vault=' + vaultStatus.status + ' caps=' + capabilities.length + ' perms=' + permissions.length);
|
||||
} catch (e) {
|
||||
@@ -156,7 +177,18 @@
|
||||
WriteFrontendLog('PluginManager', 'loadAll: END, loading=false');
|
||||
}
|
||||
|
||||
onMount(() => { loadAll(); });
|
||||
onMount(() => {
|
||||
unsubscribeLocale = i18n.subscribe((nextLocale) => {
|
||||
const changed = locale !== nextLocale;
|
||||
locale = nextLocale;
|
||||
if (changed) loadAll();
|
||||
});
|
||||
loadAll();
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
if (unsubscribeLocale) unsubscribeLocale();
|
||||
});
|
||||
|
||||
async function reload() {
|
||||
debug.log('[PluginManager] reload: START');
|
||||
@@ -170,7 +202,7 @@
|
||||
resultMsg = `Reloaded ${count} plugin(s). ${summary}`;
|
||||
} catch (e) {
|
||||
debug.log('[PluginManager] reload: ReloadPlugins ERROR:', String(e));
|
||||
error = 'Reload: ' + String(e);
|
||||
error = reportError('pluginManager.reloadError', 'Could not reload plugins. Please try again.', e);
|
||||
reloading = false;
|
||||
return;
|
||||
}
|
||||
@@ -190,7 +222,7 @@
|
||||
if (err) {
|
||||
debug.log('[PluginManager] enablePlugin: ERROR:', err);
|
||||
actionFeedback = { ...actionFeedback, [pluginId]: null };
|
||||
error = 'Enable: ' + err;
|
||||
error = reportError('pluginManager.enableError', 'Could not enable the plugin. Please try again.', err);
|
||||
return;
|
||||
}
|
||||
debug.log('[PluginManager] enablePlugin: success, reloading...');
|
||||
@@ -211,7 +243,7 @@
|
||||
if (err) {
|
||||
debug.log('[PluginManager] disablePlugin: ERROR:', err);
|
||||
actionFeedback = { ...actionFeedback, [pluginId]: null };
|
||||
error = 'Disable: ' + err;
|
||||
error = reportError('pluginManager.disableError', 'Could not disable the plugin. Please try again.', err);
|
||||
return;
|
||||
}
|
||||
debug.log('[PluginManager] disablePlugin: success, reloading...');
|
||||
@@ -229,6 +261,11 @@
|
||||
$: totalPerms = permissions.length;
|
||||
$: statusSummary = computeStatusSummary(plugins);
|
||||
$: elevatedPermissionPluginCount = computeElevatedPermissionPluginCount(plugins, permissions);
|
||||
$: filterPermissions = collectManifestValues(plugins, 'permissions');
|
||||
$: filterCapabilities = collectCapabilities(plugins);
|
||||
$: hasReliableSourceMetadata = plugins.some((plugin) => sourceGroup(plugin) !== '');
|
||||
$: visiblePlugins = filterPlugins(plugins, statusFilter, permissionFilters, capabilityFilters, settingsFilter, sourceFilter, contributions);
|
||||
$: filtersActive = statusFilter !== 'all' || permissionFilters.length > 0 || capabilityFilters.length > 0 || settingsFilter !== 'all' || sourceFilter !== 'all';
|
||||
|
||||
function computeStatusSummary(pluginRows) {
|
||||
return pluginRows.reduce((summary, plugin) => {
|
||||
@@ -247,6 +284,69 @@
|
||||
return (pluginRows || []).filter(plugin => (plugin?.manifest?.permissions || []).some(permission => dangerous.has(permission))).length;
|
||||
}
|
||||
|
||||
function collectManifestValues(pluginRows, key) {
|
||||
return Array.from(new Set((pluginRows || []).flatMap((plugin) => plugin?.manifest?.[key] || [])))
|
||||
.sort((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
function collectCapabilities(pluginRows) {
|
||||
return Array.from(new Set((pluginRows || []).flatMap((plugin) => [
|
||||
...(plugin?.manifest?.provides || []),
|
||||
...(plugin?.manifest?.requires || []),
|
||||
...(plugin?.manifest?.optionalRequires || []),
|
||||
]))).sort((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
function pluginStatusGroup(plugin) {
|
||||
const status = plugin?.status || '';
|
||||
if (status === 'failed' || status === 'incompatible' || status === 'missing-required-capability') return 'failed';
|
||||
if (status === 'degraded') return 'degraded';
|
||||
if (status === 'disabled' || plugin?.enabled === false) return 'disabled';
|
||||
return 'enabled';
|
||||
}
|
||||
|
||||
function sourceGroup(plugin) {
|
||||
const source = plugin?.manifest?.source;
|
||||
if (source === 'official') return 'official';
|
||||
if (source === 'local' || source === 'third-party') return 'third-party';
|
||||
return '';
|
||||
}
|
||||
|
||||
function hasSettings(plugin, activeContributions) {
|
||||
const pluginId = plugin?.manifest?.id;
|
||||
return Boolean(pluginId && (activeContributions.settingsPanels || []).some((panel) => panel.pluginId === pluginId));
|
||||
}
|
||||
|
||||
function includesAny(values, expected) {
|
||||
return expected.length === 0 || expected.some((value) => values.includes(value));
|
||||
}
|
||||
|
||||
function filterPlugins(pluginRows, activeStatusFilter, activePermissionFilters, activeCapabilityFilters, activeSettingsFilter, activeSourceFilter, activeContributions) {
|
||||
return pluginRows.filter((plugin) => matchesFilters(plugin, activeStatusFilter, activePermissionFilters, activeCapabilityFilters, activeSettingsFilter, activeSourceFilter, activeContributions));
|
||||
}
|
||||
|
||||
function matchesFilters(plugin, activeStatusFilter, activePermissionFilters, activeCapabilityFilters, activeSettingsFilter, activeSourceFilter, activeContributions) {
|
||||
if (activeStatusFilter !== 'all' && pluginStatusGroup(plugin) !== activeStatusFilter) return false;
|
||||
if (!includesAny(plugin?.manifest?.permissions || [], activePermissionFilters)) return false;
|
||||
const declaredCapabilities = [
|
||||
...(plugin?.manifest?.provides || []),
|
||||
...(plugin?.manifest?.requires || []),
|
||||
...(plugin?.manifest?.optionalRequires || []),
|
||||
];
|
||||
if (!includesAny(declaredCapabilities, activeCapabilityFilters)) return false;
|
||||
if (activeSettingsFilter === 'with' && !hasSettings(plugin, activeContributions)) return false;
|
||||
if (activeSettingsFilter === 'without' && hasSettings(plugin, activeContributions)) return false;
|
||||
return activeSourceFilter === 'all' || sourceGroup(plugin) === activeSourceFilter;
|
||||
}
|
||||
|
||||
function resetFilters() {
|
||||
statusFilter = 'all';
|
||||
permissionFilters = [];
|
||||
capabilityFilters = [];
|
||||
settingsFilter = 'all';
|
||||
sourceFilter = 'all';
|
||||
}
|
||||
|
||||
function closeSettings() {
|
||||
settingsPanel = null;
|
||||
settingsPluginId = '';
|
||||
@@ -272,52 +372,116 @@
|
||||
|
||||
<header>
|
||||
<div class="header-left">
|
||||
<h2>Plugin Manager</h2>
|
||||
<h2>{tr('settings.pluginManager')}</h2>
|
||||
{#if vaultStatus.status !== 'unknown'}
|
||||
<span class="vault-badge" class:vault-open={vaultStatus.status === 'open'} class:vault-not-created={vaultStatus.status === 'not-created'} class:vault-closed={vaultStatus.status === 'closed'} class:vault-error={vaultStatus.status === 'error'}>
|
||||
Vault: {vaultStatus.status}{#if vaultStatus.path} ({vaultStatus.path}){/if}
|
||||
{tr('vault.label', { status: tr(`vault.status.${vaultStatus.status}`, undefined, vaultStatus.status) })}{#if vaultStatus.path} ({vaultStatus.path}){/if}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
<button class="reload-btn" on:click={reload} type="button" disabled={loading || reloading}>
|
||||
{reloading ? '⟳ Reloading...' : '⟳ Reload'}
|
||||
{reloading ? tr('pluginManager.reloading') : tr('pluginManager.reload')}
|
||||
</button>
|
||||
</header>
|
||||
|
||||
{#if loading}
|
||||
<div class="loading">Scanning plugin directories...</div>
|
||||
<div class="loading">{tr('pluginManager.scanning')}</div>
|
||||
{:else if error}
|
||||
<div class="error">
|
||||
<Icon name="warning" size={24} class="error-icon" />
|
||||
<div class="error-message">{error}</div>
|
||||
<button class="retry-btn" on:click={loadAll} type="button">⟳ Retry</button>
|
||||
<button class="retry-btn" on:click={loadAll} type="button">{tr('common.retry')}</button>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="summary">
|
||||
<span class="badge">{totalPlugins} plugin(s) discovered</span>
|
||||
<span class="badge">{totalCaps} capabilities registered</span>
|
||||
<span class="badge">{totalPerms} permissions known</span>
|
||||
<span class="badge">{tr('pluginManager.summary.plugins', { count: totalPlugins })}</span>
|
||||
<span class="badge">{tr('pluginManager.summary.capabilities', { count: totalCaps })}</span>
|
||||
<span class="badge">{tr('pluginManager.summary.permissions', { count: totalPerms })}</span>
|
||||
</div>
|
||||
|
||||
<div class="scan-summary" aria-label="Plugin scan summary">
|
||||
<div class="scan-summary" aria-label={tr('pluginManager.scanSummary')}>
|
||||
<section class="scan-card" data-plugin-manager-summary="health">
|
||||
<div class="scan-card-title">Plugin Health</div>
|
||||
<div class="scan-card-title">{tr('pluginManager.health')}</div>
|
||||
<div class="scan-metrics">
|
||||
<span data-plugin-status-summary="loaded"><strong>{statusSummary.loaded}</strong> loaded</span>
|
||||
<span data-plugin-status-summary="degraded"><strong>{statusSummary.degraded}</strong> degraded</span>
|
||||
<span data-plugin-status-summary="failed"><strong>{statusSummary.failed}</strong> failed</span>
|
||||
<span data-plugin-status-summary="disabled"><strong>{statusSummary.disabled}</strong> disabled</span>
|
||||
<span data-plugin-status-summary="loaded"><strong>{statusSummary.loaded}</strong> {tr('status.loaded')}</span>
|
||||
<span data-plugin-status-summary="degraded"><strong>{statusSummary.degraded}</strong> {tr('status.degraded')}</span>
|
||||
<span data-plugin-status-summary="failed"><strong>{statusSummary.failed}</strong> {tr('status.failed')}</span>
|
||||
<span data-plugin-status-summary="disabled"><strong>{statusSummary.disabled}</strong> {tr('status.disabled')}</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="scan-card" data-plugin-manager-summary="risk">
|
||||
<div class="scan-card-title">Permission Risk</div>
|
||||
<div class="scan-card-title">{tr('pluginManager.permissionRisk')}</div>
|
||||
<div class="scan-metrics">
|
||||
<span data-plugin-risk-summary="elevated-permissions"><strong>{elevatedPermissionPluginCount}</strong> plugins request elevated permissions</span>
|
||||
<span data-plugin-risk-summary="elevated-permissions">{tr('pluginManager.elevatedPermissions', { count: elevatedPermissionPluginCount })}</span>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="plugin-filters" aria-label={tr('pluginManager.filters')}>
|
||||
<div class="filter-header">
|
||||
<div>
|
||||
<h3>{tr('pluginManager.filters')}</h3>
|
||||
<p data-plugin-filter-results>{tr('pluginManager.filterResults', { visible: visiblePlugins.length, total: totalPlugins })}</p>
|
||||
</div>
|
||||
<button class="filter-reset" data-plugin-filter-reset type="button" on:click={resetFilters} disabled={!filtersActive}>{tr('pluginManager.filterReset')}</button>
|
||||
</div>
|
||||
<div class="filter-grid">
|
||||
<label class="filter-select-label">
|
||||
<span>{tr('pluginManager.filterState')}</span>
|
||||
<select class="filter-select" data-plugin-filter="status" bind:value={statusFilter}>
|
||||
<option value="all">{tr('pluginManager.filterAll')}</option>
|
||||
<option value="enabled">{tr('pluginManager.filterEnabled')}</option>
|
||||
<option value="disabled">{tr('pluginManager.filterDisabled')}</option>
|
||||
<option value="failed">{tr('pluginManager.filterFailed')}</option>
|
||||
<option value="degraded">{tr('pluginManager.filterDegraded')}</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label class="filter-select-label">
|
||||
<span>{tr('pluginManager.filterSettings')}</span>
|
||||
<select class="filter-select" data-plugin-filter="settings" bind:value={settingsFilter}>
|
||||
<option value="all">{tr('pluginManager.filterAll')}</option>
|
||||
<option value="with">{tr('pluginManager.filterWithSettings')}</option>
|
||||
<option value="without">{tr('pluginManager.filterWithoutSettings')}</option>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
{#if hasReliableSourceMetadata}
|
||||
<label class="filter-select-label">
|
||||
<span>{tr('pluginManager.filterSource')}</span>
|
||||
<select class="filter-select" data-plugin-filter="source" bind:value={sourceFilter}>
|
||||
<option value="all">{tr('pluginManager.filterAll')}</option>
|
||||
<option value="official">{tr('pluginManager.filterOfficial')}</option>
|
||||
<option value="third-party">{tr('pluginManager.filterThirdParty')}</option>
|
||||
</select>
|
||||
</label>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if filterPermissions.length > 0}
|
||||
<fieldset class="filter-options">
|
||||
<legend>{tr('pluginManager.filterPermissions')}</legend>
|
||||
<div class="filter-option-list">
|
||||
{#each filterPermissions as permission}
|
||||
<label><input data-plugin-filter-permission={permission} type="checkbox" bind:group={permissionFilters} value={permission} /> <code>{permission}</code></label>
|
||||
{/each}
|
||||
</div>
|
||||
</fieldset>
|
||||
{/if}
|
||||
|
||||
{#if filterCapabilities.length > 0}
|
||||
<fieldset class="filter-options">
|
||||
<legend>{tr('pluginManager.filterCapabilities')}</legend>
|
||||
<div class="filter-option-list">
|
||||
{#each filterCapabilities as capability}
|
||||
<label><input data-plugin-filter-capability={capability} type="checkbox" bind:group={capabilityFilters} value={capability} /> <code>{capability}</code></label>
|
||||
{/each}
|
||||
</div>
|
||||
</fieldset>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
{#if plugins.length === 0 && missingInstalled.length === 0}
|
||||
<div class="empty">
|
||||
<div class="empty-icon">
|
||||
@@ -325,17 +489,21 @@
|
||||
<path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<p>No plugins found</p>
|
||||
<p class="hint">Plugin directories scanned:</p>
|
||||
<p>{tr('pluginManager.none')}</p>
|
||||
<p class="hint">{tr('pluginManager.scannedDirs')}</p>
|
||||
<ul class="hint-list">
|
||||
<li><code>~/.config/verstak/plugins/</code> — user plugins</li>
|
||||
<li><code>./plugins/</code> — bundled plugins (app directory)</li>
|
||||
<li><code>~/.config/verstak/plugins/</code> — {tr('pluginManager.userPlugins')}</li>
|
||||
<li><code>./plugins/</code> — {tr('pluginManager.bundledPlugins')}</li>
|
||||
</ul>
|
||||
<p class="hint">Place a plugin folder with <code>plugin.json</code> in one of these directories and click Reload.</p>
|
||||
<p class="hint">{tr('pluginManager.installHint')}</p>
|
||||
</div>
|
||||
{:else if visiblePlugins.length === 0}
|
||||
<div class="empty filter-empty" data-plugin-filter-empty>
|
||||
<p>{tr('pluginManager.filterEmpty')}</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="plugin-list">
|
||||
{#each plugins as p}
|
||||
{#each visiblePlugins as p}
|
||||
<PluginCard {p} {capabilities} {permissions} {contributions} {vaultOpen} {actionFeedback} settingsPanels={(contributions.settingsPanels || []).filter(sp => sp.pluginId === p.manifest?.id)} onEnable={enablePlugin} onDisable={disablePlugin} />
|
||||
{/each}
|
||||
</div>
|
||||
@@ -343,8 +511,8 @@
|
||||
|
||||
{#if missingInstalled.length > 0}
|
||||
<div class="missing-section">
|
||||
<h3>Missing Installed Plugins</h3>
|
||||
<p class="missing-hint">These plugins are required by this vault but their packages are not installed locally.</p>
|
||||
<h3>{tr('pluginManager.missingTitle')}</h3>
|
||||
<p class="missing-hint">{tr('pluginManager.missingHint')}</p>
|
||||
<div class="plugin-list">
|
||||
{#each missingInstalled as mp}
|
||||
<div class="plugin-card missing-card">
|
||||
@@ -354,12 +522,12 @@
|
||||
<strong>{mp.id}</strong>
|
||||
{#if mp.version}<span class="version">v{mp.version}</span>{/if}
|
||||
</div>
|
||||
<span class="status-badge" style="color: #e94560">missing</span>
|
||||
<span class="status-badge" style="color: #e94560">{tr('status.missing')}</span>
|
||||
</div>
|
||||
<p class="missing-text">
|
||||
This plugin is listed in the vault's desired plugins but the package is not installed.
|
||||
{tr('pluginManager.missingPackage')}
|
||||
{#if mp.source && mp.source !== 'unknown'}
|
||||
<span class="source-hint">Source: {mp.source}</span>
|
||||
<span class="source-hint">{tr('common.source')}: {mp.source}</span>
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
@@ -370,10 +538,10 @@
|
||||
|
||||
{#if capabilities.length > 0}
|
||||
<details class="registry-section">
|
||||
<summary>Capability Registry ({totalCaps})</summary>
|
||||
<summary>{tr('pluginManager.capabilityRegistry', { count: totalCaps })}</summary>
|
||||
<table>
|
||||
<thead>
|
||||
<tr><th>Capability</th><th>Provider</th><th>Source</th><th>Status</th></tr>
|
||||
<tr><th>{tr('common.capability')}</th><th>{tr('common.provider')}</th><th>{tr('common.source')}</th><th>{tr('common.status')}</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each capabilities as cap}
|
||||
@@ -394,9 +562,9 @@
|
||||
{#key `settings-${settingsPluginId}`}
|
||||
{#if settingsError}
|
||||
<div class="modal-overlay" on:click|self={closeSettings} on:keydown|self={(e) => e.key === 'Escape' && closeSettings()} role="presentation">
|
||||
<div class="modal" role="dialog" aria-modal="true" aria-label="Settings Error">
|
||||
<div class="modal" role="dialog" aria-modal="true" aria-label={tr('pluginManager.settingsError')}>
|
||||
<div class="modal-header">
|
||||
<h3>Settings Error</h3>
|
||||
<h3>{tr('pluginManager.settingsError')}</h3>
|
||||
<button class="modal-close" on:click={closeSettings} type="button">✕</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@@ -406,21 +574,21 @@
|
||||
</div>
|
||||
{:else if settingsPanel}
|
||||
<div class="modal-overlay" on:click|self={closeSettings} on:keydown|self={(e) => e.key === 'Escape' && closeSettings()} role="presentation">
|
||||
<div class="modal" role="dialog" aria-modal="true" aria-label="Plugin Settings">
|
||||
<div class="modal" role="dialog" aria-modal="true" aria-label={tr('pluginManager.pluginSettings')}>
|
||||
<div class="modal-header">
|
||||
<h3>{settingsPanel.title}</h3>
|
||||
<button class="modal-close" on:click={closeSettings} type="button">✕</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p class="settings-hint">Plugin: <code>{settingsPluginId}</code></p>
|
||||
<p class="settings-hint">{tr('common.plugin')}: <code>{settingsPluginId}</code></p>
|
||||
{#if settingsPluginInfo && settingsPluginInfo.entry}
|
||||
<PluginBundleHost
|
||||
pluginId={settingsPluginId}
|
||||
componentId={settingsPanel.component || settingsPanel.id}
|
||||
/>
|
||||
{:else}
|
||||
<p class="settings-hint">Component: <code>{settingsPanel.component}</code></p>
|
||||
<p class="placeholder">Settings panel frontend bundle not available</p>
|
||||
<p class="settings-hint">{tr('common.component')}: <code>{settingsPanel.component}</code></p>
|
||||
<p class="placeholder">{tr('pluginManager.settingsBundleUnavailable')}</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -550,6 +718,105 @@
|
||||
color: #f4f7fb;
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
.plugin-filters {
|
||||
margin-bottom: 1rem;
|
||||
padding: 0.75rem;
|
||||
border: 1px solid #0f3460;
|
||||
border-radius: 8px;
|
||||
background: #121a2c;
|
||||
}
|
||||
.filter-header {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
.filter-header h3 {
|
||||
margin: 0;
|
||||
color: #e0e0f0;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.filter-header p {
|
||||
margin: 0.2rem 0 0;
|
||||
color: #a0a0b8;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.filter-reset {
|
||||
flex: 0 0 auto;
|
||||
padding: 0.35rem 0.65rem;
|
||||
border: 1px solid #533483;
|
||||
border-radius: 5px;
|
||||
background: #16213e;
|
||||
color: #e0e0e0;
|
||||
cursor: pointer;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
.filter-reset:hover:not(:disabled) { background: #0f3460; }
|
||||
.filter-reset:disabled { cursor: not-allowed; opacity: 0.5; }
|
||||
.filter-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.65rem;
|
||||
}
|
||||
.filter-select-label {
|
||||
display: grid;
|
||||
gap: 0.28rem;
|
||||
min-width: 10rem;
|
||||
color: #a0a0b8;
|
||||
font-size: 0.76rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
.filter-select {
|
||||
min-height: 2rem;
|
||||
padding: 0.3rem 1.9rem 0.3rem 0.55rem;
|
||||
border: 1px solid #0f3460;
|
||||
border-radius: 5px;
|
||||
background: #16213e;
|
||||
background-image: linear-gradient(45deg, transparent 50%, #a0a0b8 50%), linear-gradient(135deg, #a0a0b8 50%, transparent 50%);
|
||||
background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
|
||||
background-size: 5px 5px, 5px 5px;
|
||||
background-repeat: no-repeat;
|
||||
color: #e0e0e0;
|
||||
font: inherit;
|
||||
appearance: none;
|
||||
}
|
||||
.filter-select option { background: #16213e; color: #e0e0e0; }
|
||||
.filter-select:focus { outline: 2px solid #533483; outline-offset: 1px; }
|
||||
.filter-options {
|
||||
min-width: 0;
|
||||
margin: 0.75rem 0 0;
|
||||
padding: 0.55rem 0.65rem 0.65rem;
|
||||
border: 1px solid rgba(15, 52, 96, 0.85);
|
||||
border-radius: 6px;
|
||||
}
|
||||
.filter-options legend {
|
||||
padding: 0 0.25rem;
|
||||
color: #a0a0b8;
|
||||
font-size: 0.76rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
.filter-option-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.4rem 0.75rem;
|
||||
}
|
||||
.filter-option-list label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.28rem;
|
||||
min-width: 0;
|
||||
color: #c6c6d8;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
.filter-option-list input { accent-color: #6c4fa3; }
|
||||
.filter-option-list code {
|
||||
max-width: min(31rem, 72vw);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.filter-empty { margin-bottom: 1.5rem; }
|
||||
.empty {
|
||||
padding: 2rem; text-align: center; color: #a0a0b8;
|
||||
background: #16213e; border-radius: 8px; border: 1px dashed #0f3460;
|
||||
@@ -558,7 +825,6 @@
|
||||
.hint { font-size: 0.85rem; margin-top: 0.5rem; opacity: 0.7; }
|
||||
.hint-list { list-style: none; padding: 0; margin: 0.5rem 0; font-size: 0.8rem; opacity: 0.7; }
|
||||
.hint-list li { margin: 0.25rem 0; }
|
||||
.hint code { background: #0f3460; padding: 0.1rem 0.3rem; border-radius: 3px; }
|
||||
.plugin-list { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.5rem; min-width: 0; }
|
||||
|
||||
.missing-section { margin-bottom: 1.5rem; }
|
||||
@@ -625,6 +891,19 @@
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.filter-header {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.filter-reset {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.filter-select-label {
|
||||
flex: 1 1 10rem;
|
||||
}
|
||||
|
||||
.modal {
|
||||
width: min(880px, calc(100vw - 2rem));
|
||||
height: min(680px, calc(100vh - 2rem));
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<script>
|
||||
import { onDestroy, tick } from 'svelte';
|
||||
import { onDestroy, onMount, tick } from 'svelte';
|
||||
import * as App from '../../../wailsjs/go/api/App';
|
||||
import { executePluginCommand } from '../plugin-host/VerstakPluginAPI.js';
|
||||
import { i18n } from '../i18n/index.js';
|
||||
import { debug } from '../log/debug.js';
|
||||
|
||||
let open = false;
|
||||
let query = '';
|
||||
@@ -10,18 +12,25 @@
|
||||
let inputEl = null;
|
||||
let statusMessage = '';
|
||||
let statusType = '';
|
||||
let locale = i18n.getLocale();
|
||||
let unsubscribeLocale = null;
|
||||
|
||||
$: tr = ((activeLocale) => (key, params, fallback) => {
|
||||
void activeLocale;
|
||||
return i18n.t(key, params, fallback);
|
||||
})(locale);
|
||||
|
||||
const inactiveStatuses = new Set(['disabled', 'failed', 'incompatible', 'missing-required-capability']);
|
||||
const shellCommands = [
|
||||
{ id: 'verstak.shell.open-overview', title: 'Open Overview', pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 10, shellAction: 'overview' },
|
||||
{ id: 'verstak.shell.open-files', title: 'Open Files', pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 20, shellAction: 'files' },
|
||||
{ id: 'verstak.shell.open-activity', title: 'Open Activity', pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 30, shellAction: 'activity' },
|
||||
{ id: 'verstak.shell.open-browser-inbox', title: 'Open Browser Inbox', pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 40, shellAction: 'browser-inbox' },
|
||||
{ id: 'verstak.shell.create-markdown', title: 'Create Markdown File', pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 50, shellAction: 'create-markdown' },
|
||||
{ id: 'verstak.shell.create-text', title: 'Create Text File', pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 60, shellAction: 'create-text' },
|
||||
{ id: 'verstak.shell.sync-now', title: 'Sync Now', pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 70, shellAction: 'sync-now' },
|
||||
{ id: 'verstak.shell.open-sync-settings', title: 'Open Sync Settings', pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 80, shellAction: 'sync-settings' },
|
||||
{ id: 'verstak.shell.open-plugin-manager', title: 'Open Plugin Manager', pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 90, shellAction: 'plugin-manager' },
|
||||
$: shellCommands = [
|
||||
{ id: 'verstak.shell.open-overview', title: tr('command.openOverview'), pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 10, shellAction: 'overview' },
|
||||
{ id: 'verstak.shell.open-files', title: tr('command.openFiles'), pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 20, shellAction: 'files' },
|
||||
{ id: 'verstak.shell.open-activity', title: tr('command.openActivity'), pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 30, shellAction: 'activity' },
|
||||
{ id: 'verstak.shell.open-browser-inbox', title: tr('command.openBrowserInbox'), pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 40, shellAction: 'browser-inbox' },
|
||||
{ id: 'verstak.shell.create-markdown', title: tr('command.createMarkdown'), pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 50, shellAction: 'create-markdown' },
|
||||
{ id: 'verstak.shell.create-text', title: tr('command.createText'), pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 60, shellAction: 'create-text' },
|
||||
{ id: 'verstak.shell.sync-now', title: tr('command.syncNow'), pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 70, shellAction: 'sync-now' },
|
||||
{ id: 'verstak.shell.open-sync-settings', title: tr('command.openSyncSettings'), pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 80, shellAction: 'sync-settings' },
|
||||
{ id: 'verstak.shell.open-plugin-manager', title: tr('command.openPluginManager'), pluginId: 'verstak.shell', pluginName: 'Verstak', priority: 90, shellAction: 'plugin-manager' },
|
||||
];
|
||||
|
||||
$: normalizedQuery = query.trim().toLowerCase();
|
||||
@@ -44,14 +53,21 @@
|
||||
App.GetContributions().catch(() => ({})),
|
||||
]);
|
||||
const pluginById = new Map((plugins || []).map((plugin) => [plugin.manifest?.id, plugin]));
|
||||
const pluginCommands = (contributions.commands || [])
|
||||
await Promise.all((plugins || []).map((plugin) => i18n.loadPlugin(
|
||||
plugin.manifest?.id,
|
||||
plugin.manifest?.localization,
|
||||
).catch(() => {})));
|
||||
const localizedPlugins = (plugins || []).map((plugin) => i18n.localizePlugin(plugin));
|
||||
const localizedPluginById = new Map(localizedPlugins.map((plugin) => [plugin.manifest?.id, plugin]));
|
||||
const localizedContributions = i18n.localizeContributionSummary(contributions || {});
|
||||
const pluginCommands = (localizedContributions.commands || [])
|
||||
.filter((command) => {
|
||||
const plugin = pluginById.get(command.pluginId);
|
||||
if (!plugin) return false;
|
||||
return !inactiveStatuses.has(plugin.status);
|
||||
})
|
||||
.map((command) => {
|
||||
const plugin = pluginById.get(command.pluginId);
|
||||
const plugin = localizedPluginById.get(command.pluginId);
|
||||
return {
|
||||
...command,
|
||||
pluginName: plugin?.manifest?.name || command.pluginId,
|
||||
@@ -170,16 +186,21 @@
|
||||
if (command.shellAction) {
|
||||
await runShellCommand(command);
|
||||
closePalette();
|
||||
setStatus('success', `${command.title || command.id} handled`);
|
||||
setStatus('success', tr('command.handled', { title: command.title || command.id }));
|
||||
return;
|
||||
}
|
||||
const result = await executePluginCommand(command.pluginId, command.id, {
|
||||
source: 'command-palette',
|
||||
});
|
||||
closePalette();
|
||||
setStatus('success', `${command.title || command.id} ${result.status || 'handled'}`);
|
||||
setStatus('success', tr('command.result', { title: command.title || command.id, status: result.status || tr('command.statusHandled') }));
|
||||
} catch (err) {
|
||||
setStatus('error', `${command.title || command.id}: ${err?.message || String(err)}`);
|
||||
const details = err?.message || String(err);
|
||||
debug.log('[CommandPalette] command failed:', details);
|
||||
App.WriteFrontendLog('CommandPalette', `command failed: ${details}`).catch(() => {});
|
||||
setStatus('error', tr('command.failed', {
|
||||
title: command.title || command.id,
|
||||
}, `Could not run ${command.title || command.id}. Please try again.`));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +242,16 @@
|
||||
window.addEventListener('keydown', onWindowKeydown);
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
unsubscribeLocale = i18n.subscribe((nextLocale) => {
|
||||
const changed = locale !== nextLocale;
|
||||
locale = nextLocale;
|
||||
if (changed && open) loadCommands();
|
||||
});
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
unsubscribeLocale?.();
|
||||
if (typeof window !== 'undefined') {
|
||||
window.removeEventListener('keydown', onWindowKeydown);
|
||||
window.clearTimeout(setStatus.timer);
|
||||
@@ -240,19 +270,19 @@
|
||||
|
||||
{#if open}
|
||||
<div class="command-palette-overlay" role="presentation" on:mousedown={onOverlayMouseDown}>
|
||||
<section class="command-palette" role="dialog" aria-modal="true" aria-label="Command Palette">
|
||||
<section class="command-palette" role="dialog" aria-modal="true" aria-label={tr('command.palette')}>
|
||||
<input
|
||||
bind:this={inputEl}
|
||||
bind:value={query}
|
||||
class="command-palette-input"
|
||||
data-command-palette-input
|
||||
placeholder="Run command"
|
||||
aria-label="Run command"
|
||||
placeholder={tr('command.run')}
|
||||
aria-label={tr('command.run')}
|
||||
/>
|
||||
|
||||
<div class="command-palette-list" role="listbox">
|
||||
{#if filteredCommands.length === 0}
|
||||
<div class="command-palette-empty">No commands</div>
|
||||
<div class="command-palette-empty">{tr('command.none')}</div>
|
||||
{:else}
|
||||
{#each filteredCommands as command, index}
|
||||
<button
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { onMount } from 'svelte';
|
||||
import * as App from '../../../wailsjs/go/api/App';
|
||||
import Icon from '../ui/Icon.svelte';
|
||||
import { i18n } from '../i18n/index.js';
|
||||
|
||||
const TEXT_EXTENSIONS = new Set(['txt', 'md', 'markdown', 'log', 'json', 'csv', 'yaml', 'yml', 'toml']);
|
||||
const FILE_INDEX_LIMIT = 220;
|
||||
@@ -16,12 +17,26 @@
|
||||
let loading = true;
|
||||
let searchTimer = null;
|
||||
let buildSeq = 0;
|
||||
let locale = i18n.getLocale();
|
||||
|
||||
$: tr = ((activeLocale) => (key, params, fallback) => {
|
||||
void activeLocale;
|
||||
return i18n.t(key, params, fallback);
|
||||
})(locale);
|
||||
|
||||
$: scheduleSearch(query);
|
||||
|
||||
onMount(() => {
|
||||
const unsubscribeLocale = i18n.subscribe((nextLocale) => {
|
||||
const changed = locale !== nextLocale;
|
||||
locale = nextLocale;
|
||||
if (changed) buildIndex();
|
||||
});
|
||||
buildIndex();
|
||||
return () => clearTimeout(searchTimer);
|
||||
return () => {
|
||||
unsubscribeLocale();
|
||||
clearTimeout(searchTimer);
|
||||
};
|
||||
});
|
||||
|
||||
function normalize(value) {
|
||||
@@ -160,8 +175,9 @@
|
||||
nodes.forEach(node => {
|
||||
next.push({
|
||||
type: 'Workspace',
|
||||
typeLabel: tr('search.type.workspace'),
|
||||
title: workspaceTitle(node),
|
||||
subtitle: 'Workspace',
|
||||
subtitle: tr('search.type.workspace'),
|
||||
keywords: `${node.id || ''} ${node.rootPath || ''}`,
|
||||
rank: 10,
|
||||
action: 'workspace',
|
||||
@@ -170,7 +186,15 @@
|
||||
});
|
||||
});
|
||||
|
||||
const contributions = await resultOrEmpty(App.GetContributions(), {});
|
||||
const [rawPlugins, rawContributions] = await Promise.all([
|
||||
resultOrEmpty(App.GetPlugins(), []),
|
||||
resultOrEmpty(App.GetContributions(), {}),
|
||||
]);
|
||||
await Promise.all((rawPlugins || []).map((plugin) => i18n.loadPlugin(
|
||||
plugin.manifest?.id,
|
||||
plugin.manifest?.localization,
|
||||
).catch(() => {})));
|
||||
const contributions = i18n.localizeContributionSummary(rawContributions || {});
|
||||
const viewByPluginId = new Map();
|
||||
(contributions.views || []).forEach(view => {
|
||||
if (view.pluginId && !viewByPluginId.has(view.pluginId)) viewByPluginId.set(view.pluginId, view);
|
||||
@@ -178,6 +202,7 @@
|
||||
(contributions.sidebarItems || []).forEach(item => {
|
||||
next.push({
|
||||
type: 'Tool',
|
||||
typeLabel: tr('search.type.tool'),
|
||||
title: item.title || item.id,
|
||||
subtitle: item.pluginId || '',
|
||||
keywords: `${item.id || ''} ${item.view || ''}`,
|
||||
@@ -194,6 +219,7 @@
|
||||
const snippet = await readFileSnippet(path);
|
||||
next.push({
|
||||
type: entry.type === 'folder' ? 'Folder' : 'File',
|
||||
typeLabel: tr(entry.type === 'folder' ? 'search.type.folder' : 'search.type.file'),
|
||||
title: path.split('/').pop() || path,
|
||||
subtitle: path,
|
||||
keywords: snippet,
|
||||
@@ -205,9 +231,9 @@
|
||||
}
|
||||
|
||||
const pluginItems = await Promise.all([
|
||||
indexPluginSettings('verstak.journal', 'Journal', 50, viewByPluginId.get('verstak.journal'), nodes),
|
||||
indexPluginSettings('verstak.browser-inbox', 'Browser Inbox', 55, viewByPluginId.get('verstak.browser-inbox'), nodes),
|
||||
indexPluginSettings('verstak.activity', 'Activity', 60, viewByPluginId.get('verstak.activity'), nodes),
|
||||
indexPluginSettings('verstak.journal', tr('search.type.journal'), 50, viewByPluginId.get('verstak.journal'), nodes),
|
||||
indexPluginSettings('verstak.browser-inbox', tr('search.type.browserInbox'), 55, viewByPluginId.get('verstak.browser-inbox'), nodes),
|
||||
indexPluginSettings('verstak.activity', tr('search.type.activity'), 60, viewByPluginId.get('verstak.activity'), nodes),
|
||||
]);
|
||||
|
||||
if (seq !== buildSeq) return;
|
||||
@@ -293,8 +319,8 @@
|
||||
on:focus={handleFocus}
|
||||
on:blur={() => setTimeout(() => focused = false, 120)}
|
||||
type="search"
|
||||
placeholder={loading ? 'Indexing...' : 'Search'}
|
||||
aria-label="Global search"
|
||||
placeholder={loading ? tr('search.indexing') : tr('search.placeholder')}
|
||||
aria-label={tr('search.global')}
|
||||
data-global-search-input
|
||||
/>
|
||||
</div>
|
||||
@@ -310,11 +336,11 @@
|
||||
on:mousedown|preventDefault={() => openResult(item)}
|
||||
>
|
||||
<span class="global-search-result-title">{item.title}</span>
|
||||
<span class="global-search-result-meta">{item.type} · {item.subtitle}</span>
|
||||
<span class="global-search-result-meta">{item.typeLabel || item.type} · {item.subtitle}</span>
|
||||
</button>
|
||||
{/each}
|
||||
{:else}
|
||||
<div class="global-search-empty vt-empty-title">No results</div>
|
||||
<div class="global-search-empty vt-empty-title">{tr('search.noResults')}</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
import GlobalSearch from './GlobalSearch.svelte';
|
||||
import Icon from '../ui/Icon.svelte';
|
||||
import { debug } from '../log/debug.js';
|
||||
import { i18n } from '../i18n/index.js';
|
||||
|
||||
export let showGlobalSearch = true;
|
||||
export let activeView = null;
|
||||
export let activeViewPluginId = '';
|
||||
|
||||
function flog(msg) {
|
||||
App.WriteFrontendLog('Sidebar', msg);
|
||||
@@ -16,8 +19,16 @@
|
||||
let vaultStatus = { status: 'unknown', path: '', vaultId: '' };
|
||||
let sidebarItems = [];
|
||||
let errorMessage = '';
|
||||
let locale = i18n.getLocale();
|
||||
let unsubscribeLocale = null;
|
||||
|
||||
$: tr = ((activeLocale) => (key, params, fallback) => {
|
||||
void activeLocale;
|
||||
return i18n.t(key, params, fallback);
|
||||
})(locale);
|
||||
|
||||
$: vaultOpen = vaultStatus.status === 'open';
|
||||
$: activeSidebarKey = activeView ? `${activeViewPluginId}:${activeView}` : '';
|
||||
|
||||
async function loadSidebar() {
|
||||
debug.log('[Sidebar] onMount: START');
|
||||
@@ -31,14 +42,18 @@
|
||||
App.GetVaultStatus().catch(() => ({ status: 'unknown', path: '', vaultId: '' })),
|
||||
App.GetContributions().catch(() => { contribErr = true; return {}; }),
|
||||
]);
|
||||
plugins = p || [];
|
||||
await Promise.all((p || []).map((plugin) => (
|
||||
i18n.loadPlugin(plugin.manifest?.id, plugin.manifest?.localization).catch(() => {})
|
||||
)));
|
||||
plugins = (p || []).map((plugin) => i18n.localizePlugin(plugin));
|
||||
const localizedContributions = i18n.localizeContributionSummary(contribs || {});
|
||||
vaultStatus = v;
|
||||
debug.log('[Sidebar] onMount: plugins=' + plugins.length + ' vault=' + vaultStatus.status);
|
||||
flog('onMount: plugins=' + plugins.length + ' vault=' + vaultStatus.status);
|
||||
if (contribErr) {
|
||||
errorMessage = 'Failed to load plugin contributions';
|
||||
errorMessage = tr('sidebar.error.contributions');
|
||||
}
|
||||
sidebarItems = (contribs.sidebarItems || []).filter(item => {
|
||||
sidebarItems = (localizedContributions.sidebarItems || []).filter(item => {
|
||||
const plugin = plugins.find(p => p.manifest?.id === item.pluginId);
|
||||
if (!plugin) return false;
|
||||
return plugin.status !== 'disabled' && plugin.status !== 'failed' && plugin.status !== 'incompatible' && plugin.status !== 'missing-required-capability';
|
||||
@@ -50,18 +65,24 @@
|
||||
debug.log('[Sidebar] onMount: ERROR:', String(e));
|
||||
flog('onMount: ERROR: ' + String(e));
|
||||
console.error('[Sidebar] load error:', e);
|
||||
errorMessage = 'Failed to load sidebar';
|
||||
errorMessage = tr('sidebar.error.load');
|
||||
}
|
||||
debug.log('[Sidebar] onMount: END');
|
||||
flog('onMount: END');
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
unsubscribeLocale = i18n.subscribe((nextLocale) => {
|
||||
const changed = locale !== nextLocale;
|
||||
locale = nextLocale;
|
||||
if (changed) loadSidebar();
|
||||
});
|
||||
loadSidebar();
|
||||
window.addEventListener('verstak:plugins-changed', loadSidebar);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
if (unsubscribeLocale) unsubscribeLocale();
|
||||
window.removeEventListener('verstak:plugins-changed', loadSidebar);
|
||||
});
|
||||
|
||||
@@ -85,10 +106,12 @@
|
||||
|
||||
{#if sidebarItems.length > 0}
|
||||
<div class="sidebar-section">
|
||||
<span class="section-label">Tools</span>
|
||||
<span class="section-label">{tr('sidebar.tools')}</span>
|
||||
{#each sidebarItems as item}
|
||||
<button
|
||||
class="nav-item plugin-item vt-list-row"
|
||||
class:is-active={activeSidebarKey === `${item.pluginId || ''}:${item.view || item.id}`}
|
||||
aria-current={activeSidebarKey === `${item.pluginId || ''}:${item.view || item.id}` ? 'page' : undefined}
|
||||
on:click={() => handleSidebarItem(item)}
|
||||
type="button"
|
||||
>
|
||||
@@ -107,7 +130,7 @@
|
||||
{#if errorMessage}
|
||||
<span class="sidebar-error">
|
||||
<Icon name="warning" size={10} class="sidebar-error-icon" />
|
||||
Plugin UI error
|
||||
{tr('sidebar.error.ui')}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -192,6 +215,16 @@
|
||||
color: var(--vt-color-text-primary);
|
||||
}
|
||||
|
||||
.nav-item.is-active {
|
||||
background: var(--vt-color-surface-selected);
|
||||
color: var(--vt-color-accent);
|
||||
}
|
||||
|
||||
.nav-item.is-active :global(.nav-icon.icon-plugin) {
|
||||
color: currentColor;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
:global(.nav-icon) {
|
||||
width: 0.9rem;
|
||||
height: 0.9rem;
|
||||
|
||||
@@ -2,26 +2,41 @@
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import * as App from '../../../wailsjs/go/api/App';
|
||||
import Icon from '../ui/Icon.svelte';
|
||||
import { i18n } from '../i18n/index.js';
|
||||
|
||||
let items = [];
|
||||
let settingsPanels = [];
|
||||
let vaultStatus = { status: 'unknown', path: '', vaultId: '' };
|
||||
let settingsOpen = false;
|
||||
let locale = i18n.getLocale();
|
||||
let selectedLanguage = i18n.getLanguagePreference();
|
||||
let unsubscribeLocale = null;
|
||||
|
||||
$: tr = ((activeLocale) => (key, params, fallback) => {
|
||||
void activeLocale;
|
||||
return i18n.t(key, params, fallback);
|
||||
})(locale);
|
||||
|
||||
$: leftItems = items.filter((item) => item.position === 'left');
|
||||
$: centerItems = items.filter((item) => item.position === 'center');
|
||||
$: rightItems = items.filter((item) => item.position === 'right');
|
||||
$: vaultOpen = vaultStatus.status === 'open';
|
||||
$: vaultLabel = vaultStatus.status && vaultStatus.status !== 'unknown' ? 'Vault: ' + vaultStatus.status : 'Vault: unknown';
|
||||
$: vaultStatusLabel = tr(`vault.status.${vaultStatus.status || 'unknown'}`, undefined, vaultStatus.status || 'unknown');
|
||||
$: vaultLabel = tr('vault.label', { status: vaultStatusLabel });
|
||||
|
||||
const inactiveStatuses = new Set(['disabled', 'failed', 'incompatible', 'missing-required-capability']);
|
||||
|
||||
async function loadStatusBar() {
|
||||
const [plugins, contributions, vault] = await Promise.all([
|
||||
const [rawPlugins, rawContributions, vault] = await Promise.all([
|
||||
App.GetPlugins().catch(() => []),
|
||||
App.GetContributions().catch(() => ({})),
|
||||
App.GetVaultStatus().catch(() => ({ status: 'unknown', path: '', vaultId: '' })),
|
||||
]);
|
||||
await Promise.all((rawPlugins || []).map((plugin) => (
|
||||
i18n.loadPlugin(plugin.manifest?.id, plugin.manifest?.localization).catch(() => {})
|
||||
)));
|
||||
const plugins = (rawPlugins || []).map((plugin) => i18n.localizePlugin(plugin));
|
||||
const contributions = i18n.localizeContributionSummary(rawContributions || {});
|
||||
const pluginById = new Map((plugins || []).map((plugin) => [plugin.manifest?.id, plugin]));
|
||||
vaultStatus = vault || { status: 'unknown', path: '', vaultId: '' };
|
||||
items = (contributions.statusBarItems || [])
|
||||
@@ -56,6 +71,16 @@
|
||||
}));
|
||||
}
|
||||
|
||||
async function selectLanguage(language) {
|
||||
const err = await App.UpdateAppSettings({ language });
|
||||
if (err) {
|
||||
throw new Error(err);
|
||||
}
|
||||
await i18n.setLanguagePreference(language);
|
||||
selectedLanguage = language;
|
||||
settingsOpen = false;
|
||||
}
|
||||
|
||||
function toggleSettings(event) {
|
||||
event.stopPropagation();
|
||||
settingsOpen = !settingsOpen;
|
||||
@@ -66,6 +91,12 @@
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
unsubscribeLocale = i18n.subscribe((nextLocale) => {
|
||||
const changed = locale !== nextLocale;
|
||||
locale = nextLocale;
|
||||
selectedLanguage = i18n.getLanguagePreference();
|
||||
if (changed) loadStatusBar();
|
||||
});
|
||||
loadStatusBar();
|
||||
window.addEventListener('verstak:plugins-changed', loadStatusBar);
|
||||
window.addEventListener('verstak:vault-opened', loadStatusBar);
|
||||
@@ -73,13 +104,14 @@
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
if (unsubscribeLocale) unsubscribeLocale();
|
||||
window.removeEventListener('verstak:plugins-changed', loadStatusBar);
|
||||
window.removeEventListener('verstak:vault-opened', loadStatusBar);
|
||||
window.removeEventListener('click', closeSettings);
|
||||
});
|
||||
</script>
|
||||
|
||||
<footer class="status-bar" aria-label="Status bar">
|
||||
<footer class="status-bar" aria-label={tr('statusBar.label')}>
|
||||
<div class="status-bar-group status-left">
|
||||
<span
|
||||
class="vault-status"
|
||||
@@ -132,7 +164,7 @@
|
||||
class="settings-button"
|
||||
class:active={settingsOpen}
|
||||
type="button"
|
||||
title="Settings"
|
||||
title={tr('settings.title')}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={settingsOpen}
|
||||
data-settings-menu-button
|
||||
@@ -143,6 +175,22 @@
|
||||
</button>
|
||||
{#if settingsOpen}
|
||||
<div class="settings-menu" role="menu">
|
||||
<div class="settings-menu-heading">{tr('settings.language')}</div>
|
||||
{#each ['system', 'en', 'ru'] as language}
|
||||
<button
|
||||
class="settings-menu-item language-item"
|
||||
class:active-language={selectedLanguage === language}
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={selectedLanguage === language}
|
||||
data-settings-language={language}
|
||||
on:click={() => selectLanguage(language)}
|
||||
>
|
||||
<span class="language-check" aria-hidden="true">{selectedLanguage === language ? '✓' : ''}</span>
|
||||
<span>{tr(`settings.language.${language}`)}</span>
|
||||
</button>
|
||||
{/each}
|
||||
<div class="settings-menu-separator"></div>
|
||||
<button
|
||||
class="settings-menu-item"
|
||||
type="button"
|
||||
@@ -151,7 +199,7 @@
|
||||
on:click={openPluginManager}
|
||||
>
|
||||
<Icon name="puzzle" size={14} class="settings-menu-icon" />
|
||||
<span>Plugin Manager</span>
|
||||
<span>{tr('settings.pluginManager')}</span>
|
||||
</button>
|
||||
{#if settingsPanels.length > 0}
|
||||
<div class="settings-menu-separator"></div>
|
||||
@@ -320,6 +368,25 @@
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.settings-menu-heading {
|
||||
padding: 0.25rem 0.45rem 0.2rem;
|
||||
color: #7f8aa3;
|
||||
font-size: 0.68rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.04em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.language-check {
|
||||
width: 0.9rem;
|
||||
color: #4ecca3;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.active-language {
|
||||
background: rgba(78, 204, 163, 0.1);
|
||||
}
|
||||
|
||||
.settings-menu-separator {
|
||||
height: 1px;
|
||||
margin: 0.25rem 0.2rem;
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
<script>
|
||||
import { createEventDispatcher, onMount } from 'svelte';
|
||||
import { createEventDispatcher, onDestroy, onMount } from 'svelte';
|
||||
import * as App from '../../../wailsjs/go/api/App';
|
||||
import { i18n } from '../i18n/index.js';
|
||||
|
||||
export let workspaceRootPath = '';
|
||||
export let availableTools = [];
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
const FILTERS = [
|
||||
{ key: 'all', label: 'All' },
|
||||
{ key: 'notes', label: 'Notes' },
|
||||
{ key: 'files', label: 'Files' },
|
||||
{ key: 'captures', label: 'Captures' },
|
||||
{ key: 'journal', label: 'Journal' },
|
||||
];
|
||||
const LOW_VALUE_RECENT_TYPES = new Set([
|
||||
'workspace.selected',
|
||||
'case.selected',
|
||||
@@ -36,11 +30,34 @@
|
||||
let keyResources = [];
|
||||
let totalNotes = 0;
|
||||
let loadedWorkspaceRoot = '';
|
||||
let loadedToolKey = '';
|
||||
let toolProbe = 0;
|
||||
let locale = i18n.getLocale();
|
||||
let unsubscribeLocale = null;
|
||||
|
||||
$: tr = ((activeLocale) => (key, params, fallback) => {
|
||||
void activeLocale;
|
||||
return i18n.t(key, params, fallback);
|
||||
})(locale);
|
||||
function countText(key, count, params = {}) {
|
||||
return tr(`${key}.${count === 1 ? 'one' : 'many'}`, { count, ...params });
|
||||
}
|
||||
|
||||
$: hasNotes = hasTool('notes', availableTools);
|
||||
$: hasFiles = hasTool('files', availableTools);
|
||||
$: hasBrowserInbox = hasTool('browser-inbox', availableTools);
|
||||
$: hasActivity = hasTool('activity', availableTools);
|
||||
$: hasJournal = hasTool('journal', availableTools);
|
||||
$: hasTodos = hasTool('todo', availableTools);
|
||||
$: recentChanges = buildRecentChanges(activityEvents, captures, journalEntries);
|
||||
$: overviewToolKey = [hasNotes, hasFiles, hasBrowserInbox, hasActivity, hasJournal, hasTodos].join('|');
|
||||
$: FILTERS = ['all']
|
||||
.concat(hasNotes ? ['notes'] : [])
|
||||
.concat(hasFiles ? ['files'] : [])
|
||||
.concat(hasBrowserInbox ? ['captures'] : [])
|
||||
.concat(hasJournal ? ['journal'] : [])
|
||||
.map((key) => ({ key, label: tr(`overview.filter.${key}`) }));
|
||||
$: if (!FILTERS.some(filter => filter.key === activeFilter)) activeFilter = 'all';
|
||||
$: recentChanges = filterAvailableItems(buildRecentChanges(activityEvents, captures, journalEntries), overviewToolKey);
|
||||
$: filteredRecentChanges = activeFilter === 'all'
|
||||
? recentChanges
|
||||
: recentChanges.filter(item => item.category === activeFilter);
|
||||
@@ -50,24 +67,28 @@
|
||||
$: linkedCandidateIds = new Set(journalEntries.map(item => String(item?.sourceCandidateId || '')).filter(Boolean));
|
||||
$: pendingWorkSessionCandidates = workSessionCandidates.filter(item => !linkedCandidateIds.has(String(item?.candidateId || '')));
|
||||
$: urgentTodos = hasTodos ? todos.filter(item => todoAttentionState(item)) : [];
|
||||
$: needsAttention = buildNeedsAttention(unprocessedCaptures, pendingWorkSessionCandidates, urgentTodos);
|
||||
$: continueItems = buildContinueItems(activityEvents, unprocessedCaptures, journalEntries, urgentTodos);
|
||||
$: attentionActionKind = needsAttention[0]?.actionKind || 'browser-inbox';
|
||||
$: needsAttention = filterAvailableItems(buildNeedsAttention(unprocessedCaptures, pendingWorkSessionCandidates, urgentTodos), overviewToolKey);
|
||||
$: continueItems = filterAvailableItems(buildContinueItems(activityEvents, unprocessedCaptures, journalEntries, urgentTodos), overviewToolKey);
|
||||
$: hasAttentionTools = hasBrowserInbox || hasTodos || (hasActivity && hasJournal);
|
||||
$: attentionActionKind = needsAttention[0]?.actionKind || fallbackAttentionAction();
|
||||
$: lastActive = lastActiveDate([...recentChanges, ...continueItems], captures, journalEntries, todos);
|
||||
$: summaryItems = [
|
||||
{ key: 'notes', label: 'Notes', count: totalNotes, detail: totalAndRecentLabel(totalNotes, noteRecentChanges), actionKind: 'notes', actionLabel: 'Open Notes' },
|
||||
{ key: 'files', label: 'Files', count: fileRecentChanges, detail: countLabel(fileRecentChanges, 'recent change'), actionKind: 'files', actionLabel: 'Open Files' },
|
||||
{ key: 'captures', label: 'Captures', count: unprocessedCaptures.length, detail: captureReviewLabel(unprocessedCaptures.length), actionKind: 'browser-inbox', actionLabel: 'Review Inbox' },
|
||||
{ key: 'activity', label: 'Activity', count: activityEvents.length, detail: countLabel(activityEvents.length, 'recorded event'), actionKind: 'activity', actionLabel: 'View Activity' },
|
||||
{ key: 'journal', label: 'Journal', count: journalEntries.length, detail: journalEntryLabel(journalEntries.length), actionKind: 'journal', actionLabel: 'Open Journal' },
|
||||
{ key: 'attention', label: 'Needs attention', count: needsAttention.length, detail: countLabel(needsAttention.length, 'pending item'), actionKind: attentionActionKind, actionLabel: 'Review pending items' },
|
||||
];
|
||||
hasNotes ? { key: 'notes', label: tr('overview.notes'), count: totalNotes, detail: countText('overview.count.totalRecent', noteRecentChanges, { total: totalNotes, recent: noteRecentChanges }), actionKind: 'notes', actionLabel: tr('overview.openNotes') } : null,
|
||||
hasFiles ? { key: 'files', label: tr('overview.files'), count: fileRecentChanges, detail: countText('overview.count.recentChanges', fileRecentChanges), actionKind: 'files', actionLabel: tr('overview.openFiles') } : null,
|
||||
hasBrowserInbox ? { key: 'captures', label: tr('overview.captures'), count: unprocessedCaptures.length, detail: countText('overview.count.captures', unprocessedCaptures.length), actionKind: 'browser-inbox', actionLabel: tr('overview.reviewInbox') } : null,
|
||||
hasActivity ? { key: 'activity', label: tr('overview.activity'), count: activityEvents.length, detail: countText('overview.count.events', activityEvents.length), actionKind: 'activity', actionLabel: tr('overview.viewActivity') } : null,
|
||||
hasJournal ? { key: 'journal', label: tr('overview.journal'), count: journalEntries.length, detail: countText('overview.count.journal', journalEntries.length), actionKind: 'journal', actionLabel: tr('overview.openJournal') } : null,
|
||||
hasAttentionTools ? { key: 'attention', label: tr('overview.attention'), count: needsAttention.length, detail: countText('overview.count.pending', needsAttention.length), actionKind: attentionActionKind, actionLabel: tr('overview.reviewPending') } : null,
|
||||
].filter(Boolean);
|
||||
|
||||
onMount(() => {
|
||||
unsubscribeLocale = i18n.subscribe((nextLocale) => locale = nextLocale);
|
||||
toolProbe += 1;
|
||||
});
|
||||
|
||||
$: if (workspaceRootPath && workspaceRootPath !== loadedWorkspaceRoot) {
|
||||
onDestroy(() => unsubscribeLocale?.());
|
||||
|
||||
$: if (workspaceRootPath && (workspaceRootPath !== loadedWorkspaceRoot || overviewToolKey !== loadedToolKey)) {
|
||||
loadOverview();
|
||||
}
|
||||
|
||||
@@ -78,11 +99,29 @@
|
||||
const label = `${tool?.title || ''} ${tool?.id || ''} ${tool?.pluginId || ''}`.toLowerCase();
|
||||
return label.includes(name);
|
||||
});
|
||||
if (fromProps) return true;
|
||||
if (typeof document === 'undefined') return false;
|
||||
return Array.from(document.querySelectorAll('.workspace-tabs [role="tab"]')).some(tab => {
|
||||
return String(tab.textContent || '').trim().toLowerCase().includes(name);
|
||||
});
|
||||
return fromProps;
|
||||
}
|
||||
|
||||
function actionIsAvailable(kind) {
|
||||
if (kind === 'notes') return hasNotes;
|
||||
if (kind === 'files') return hasFiles;
|
||||
if (kind === 'browser-inbox') return hasBrowserInbox;
|
||||
if (kind === 'activity') return hasActivity;
|
||||
if (kind === 'journal') return hasJournal;
|
||||
if (kind === 'todo') return hasTodos;
|
||||
return false;
|
||||
}
|
||||
|
||||
function filterAvailableItems(items, _toolKey) {
|
||||
void _toolKey;
|
||||
return (items || []).filter(item => actionIsAvailable(item?.actionKind));
|
||||
}
|
||||
|
||||
function fallbackAttentionAction() {
|
||||
if (hasBrowserInbox) return 'browser-inbox';
|
||||
if (hasTodos) return 'todo';
|
||||
if (hasActivity && hasJournal) return 'journal';
|
||||
return '';
|
||||
}
|
||||
|
||||
function decodeTuple(response, fallback) {
|
||||
@@ -125,6 +164,7 @@
|
||||
].flatMap(key => normalizeRows(settings?.[key])).filter(item => {
|
||||
const tagged = String(item.workspaceRootPath || item.workspaceName || item.workspaceNodeId || '').trim();
|
||||
if (tagged !== workspace) return false;
|
||||
if (String(item.globalState || 'inbox') === 'archived') return false;
|
||||
const captureId = String(item.captureId || '');
|
||||
if (!captureId || seen.has(captureId)) return !captureId;
|
||||
seen.add(captureId);
|
||||
@@ -155,7 +195,7 @@
|
||||
}
|
||||
|
||||
function todoTitle(item) {
|
||||
return String(item?.title || item?.name || 'Untitled todo').trim() || 'Untitled todo';
|
||||
return String(item?.title || item?.name || tr('overview.untitledTodo')).trim() || tr('overview.untitledTodo');
|
||||
}
|
||||
|
||||
function todoAttentionState(item) {
|
||||
@@ -163,9 +203,9 @@
|
||||
const now = Date.now();
|
||||
const dueAt = todoDateMs(item?.dueAt);
|
||||
const reminderAt = todoDateMs(item?.reminderAt);
|
||||
if (reminderAt && reminderAt <= now) return 'Reminder due';
|
||||
if (dueAt && dueAt < now) return 'Overdue';
|
||||
if (dueAt && dueAt <= now + 3 * 24 * 60 * 60 * 1000) return 'Due soon';
|
||||
if (reminderAt && reminderAt <= now) return tr('overview.todo.reminderDue');
|
||||
if (dueAt && dueAt < now) return tr('overview.todo.overdue');
|
||||
if (dueAt && dueAt <= now + 3 * 24 * 60 * 60 * 1000) return tr('overview.todo.dueSoon');
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -198,17 +238,12 @@
|
||||
return fileName(path).replace(/\.(md|markdown|txt)$/i, '').replace(/_/g, ' ') || 'Untitled';
|
||||
}
|
||||
|
||||
function quoted(value) {
|
||||
const clean = String(value || '').trim();
|
||||
return clean ? `"${clean}"` : '';
|
||||
}
|
||||
|
||||
function entityName(item) {
|
||||
const payload = item?.payload && typeof item.payload === 'object' ? item.payload : {};
|
||||
const path = payload.path || payload.notePath || item?.path || item?.relativePath || looksLikePath(item?.summary);
|
||||
const title = String(item?.title || payload.title || '').trim();
|
||||
if (path && (!title || /^(saved note|file opened|file changed|activity event)$/i.test(title))) return titleFromPath(path);
|
||||
return title || titleFromPath(path) || String(item?.summary || item?.activityId || 'item');
|
||||
return title || titleFromPath(path) || String(item?.summary || item?.activityId || tr('overview.item'));
|
||||
}
|
||||
|
||||
function looksLikePath(value) {
|
||||
@@ -218,11 +253,11 @@
|
||||
}
|
||||
|
||||
function captureTitle(capture) {
|
||||
return capture?.title || capture?.fileName || capture?.url || capture?.captureId || 'Untitled capture';
|
||||
return capture?.title || capture?.fileName || capture?.url || capture?.captureId || tr('overview.untitledCapture');
|
||||
}
|
||||
|
||||
function journalTitle(entry) {
|
||||
return entry?.title || entry?.summary || entry?.date || entry?.entryId || 'Journal entry';
|
||||
return entry?.title || entry?.summary || entry?.date || entry?.entryId || tr('overview.untitledJournal');
|
||||
}
|
||||
|
||||
function itemTimeLabel(item) {
|
||||
@@ -245,17 +280,17 @@
|
||||
|
||||
function relativeTime(value) {
|
||||
const ms = timeMs({ occurredAt: value });
|
||||
if (!ms) return 'No timestamp';
|
||||
if (!ms) return tr('overview.time.none');
|
||||
const diff = Date.now() - ms;
|
||||
if (diff < 0) return absoluteTime(value);
|
||||
const minute = 60 * 1000;
|
||||
const hour = 60 * minute;
|
||||
const day = 24 * hour;
|
||||
if (diff < minute) return 'Just now';
|
||||
if (diff < hour) return `${Math.floor(diff / minute)} min ago`;
|
||||
if (diff < day) return `${Math.floor(diff / hour)}h ago`;
|
||||
if (diff < 2 * day) return 'Yesterday';
|
||||
if (diff < 7 * day) return `${Math.floor(diff / day)} days ago`;
|
||||
if (diff < minute) return tr('overview.time.now');
|
||||
if (diff < hour) return tr('overview.time.minutes', { count: Math.floor(diff / minute) });
|
||||
if (diff < day) return tr('overview.time.hours', { count: Math.floor(diff / hour) });
|
||||
if (diff < 2 * day) return tr('overview.time.yesterday');
|
||||
if (diff < 7 * day) return tr('overview.time.days', { count: Math.floor(diff / day) });
|
||||
const date = new Date(ms);
|
||||
return date.toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: date.getFullYear() === new Date().getFullYear() ? undefined : 'numeric' });
|
||||
}
|
||||
@@ -272,30 +307,39 @@
|
||||
function activityTitle(item) {
|
||||
const type = String(item?.type || '').toLowerCase();
|
||||
const name = entityName(item);
|
||||
if (type === 'note.saved' || type === 'note.edited') return `Edited note ${quoted(name)}`;
|
||||
if (type === 'note.opened') return `Opened note ${quoted(name)}`;
|
||||
if (type === 'note.created') return `Created note ${quoted(name)}`;
|
||||
if (type === 'file.opened') return `Opened file ${quoted(name)}`;
|
||||
if (type === 'file.changed') return `Changed file ${quoted(name)}`;
|
||||
if (type === 'file.created') return `Created file ${quoted(name)}`;
|
||||
if (type === 'file.deleted' || type === 'file.trashed') return `Removed file ${quoted(name)}`;
|
||||
if (type === 'browser.capture.page') return `Captured page ${quoted(name)}`;
|
||||
if (type === 'browser.capture.selection') return `Captured selection ${quoted(name)}`;
|
||||
if (type === 'browser.capture.link') return `Captured link ${quoted(name)}`;
|
||||
if (type === 'browser.capture.file') return `Captured file ${quoted(name)}`;
|
||||
if (type === 'browser.capture.converted') return `Converted capture ${quoted(name)}`;
|
||||
if (type === 'journal.entry.added' || type === 'worklog.entry.added') return `Added journal entry ${quoted(name)}`;
|
||||
if (type === 'action.started') return 'Work session detected';
|
||||
if (type === 'workspace.opened') return 'Workspace opened';
|
||||
return item?.title || item?.summary || 'Workspace activity';
|
||||
if (type === 'note.saved' || type === 'note.edited') return tr('overview.event.noteEdited', { name });
|
||||
if (type === 'note.opened') return tr('overview.event.noteOpened', { name });
|
||||
if (type === 'note.created') return tr('overview.event.noteCreated', { name });
|
||||
if (type === 'file.opened') return tr('overview.event.fileOpened', { name });
|
||||
if (type === 'file.changed') return tr('overview.event.fileChanged', { name });
|
||||
if (type === 'file.created') return tr('overview.event.fileCreated', { name });
|
||||
if (type === 'file.deleted' || type === 'file.trashed') return tr('overview.event.fileRemoved', { name });
|
||||
if (type === 'browser.capture.page') return tr('overview.event.capturePage', { name });
|
||||
if (type === 'browser.capture.selection') return tr('overview.event.captureSelection', { name });
|
||||
if (type === 'browser.capture.link') return tr('overview.event.captureLink', { name });
|
||||
if (type === 'browser.capture.file') return tr('overview.event.captureFile', { name });
|
||||
if (type === 'browser.capture.converted') return tr('overview.event.captureConverted', { name });
|
||||
if (type === 'journal.entry.added' || type === 'worklog.entry.added') return tr('overview.event.journalAdded', { name });
|
||||
if (type === 'action.started') return tr('overview.event.workSessionDetected');
|
||||
if (type === 'workspace.opened') return tr('overview.event.workspaceOpened');
|
||||
return item?.title || item?.summary || tr('overview.event.activity');
|
||||
}
|
||||
|
||||
function captureKindLabel(capture) {
|
||||
const kind = String(capture?.kind || '').toLowerCase();
|
||||
if (kind === 'page') return tr('overview.captureKind.page');
|
||||
if (kind === 'selection') return tr('overview.captureKind.selection');
|
||||
if (kind === 'link') return tr('overview.captureKind.link');
|
||||
if (kind === 'file') return tr('overview.captureKind.file');
|
||||
return tr('overview.captureKind.item');
|
||||
}
|
||||
|
||||
function actionForCategory(category) {
|
||||
if (category === 'notes') return { kind: 'notes', label: 'Open Notes' };
|
||||
if (category === 'files') return { kind: 'files', label: 'Open Files' };
|
||||
if (category === 'captures') return { kind: 'browser-inbox', label: 'Review Inbox' };
|
||||
if (category === 'journal') return { kind: 'journal', label: 'Open Journal' };
|
||||
return { kind: 'activity', label: 'View Activity' };
|
||||
if (category === 'notes') return { kind: 'notes', label: tr('overview.openNotes') };
|
||||
if (category === 'files') return { kind: 'files', label: tr('overview.openFiles') };
|
||||
if (category === 'captures') return { kind: 'browser-inbox', label: tr('overview.reviewInbox') };
|
||||
if (category === 'journal') return { kind: 'journal', label: tr('overview.openJournal') };
|
||||
return { kind: 'activity', label: tr('overview.viewActivity') };
|
||||
}
|
||||
|
||||
function buildRecentChanges(events, captureRows, journalRows) {
|
||||
@@ -308,7 +352,7 @@
|
||||
id: item.activityId || `${item.type}:${timeValue(item)}`,
|
||||
category,
|
||||
title: activityTitle(item),
|
||||
meta: `${itemTimeLabel(item)}${item.sourcePluginId ? ' · ' + item.sourcePluginId.replace('verstak.', '') : ''}`,
|
||||
meta: itemTimeLabel(item),
|
||||
time: timeValue(item),
|
||||
absolute: absoluteTime(timeValue(item)),
|
||||
actionKind: action.kind,
|
||||
@@ -318,22 +362,22 @@
|
||||
const captureItems = captureRows.map(item => ({
|
||||
id: item.captureId || `capture:${timeValue(item)}`,
|
||||
category: 'captures',
|
||||
title: `Captured ${item.kind || 'item'} ${quoted(captureTitle(item))}`,
|
||||
meta: `${itemTimeLabel(item)} · ${item.domain || item.url || 'Browser capture'}`,
|
||||
title: tr('overview.event.capture', { kind: captureKindLabel(item), title: captureTitle(item) }),
|
||||
meta: `${itemTimeLabel(item)} · ${item.domain || item.url || tr('overview.browserCapture')}`,
|
||||
time: timeValue(item),
|
||||
absolute: absoluteTime(timeValue(item)),
|
||||
actionKind: 'browser-inbox',
|
||||
actionLabel: 'Review Inbox',
|
||||
actionLabel: tr('overview.reviewInbox'),
|
||||
}));
|
||||
const journalItems = journalRows.map(item => ({
|
||||
id: item.entryId || `journal:${timeValue(item)}`,
|
||||
category: 'journal',
|
||||
title: `Added journal entry ${quoted(journalTitle(item))}`,
|
||||
meta: `${itemTimeLabel(item)}${item.minutes ? ' · ' + item.minutes + ' min' : ''}`,
|
||||
title: tr('overview.event.journalAdded', { name: journalTitle(item) }),
|
||||
meta: `${itemTimeLabel(item)}${item.minutes ? ' · ' + tr('overview.minutes', { count: item.minutes }) : ''}`,
|
||||
time: timeValue(item),
|
||||
absolute: absoluteTime(timeValue(item)),
|
||||
actionKind: 'journal',
|
||||
actionLabel: 'Open Journal',
|
||||
actionLabel: tr('overview.openJournal'),
|
||||
}));
|
||||
return sortByTime([...activityItems, ...captureItems, ...journalItems]).slice(0, 12);
|
||||
}
|
||||
@@ -369,22 +413,22 @@
|
||||
const todoCandidates = [...todoRows].sort((a, b) => todoDateMs(todoTimeValue(a)) - todoDateMs(todoTimeValue(b))).map(item => ({
|
||||
id: item.id || `todo:${todoTitle(item)}`,
|
||||
category: 'todo',
|
||||
title: `Todo ${quoted(todoTitle(item))}`,
|
||||
meta: `${todoAttentionState(item)}${item.dueAt ? ` · Due ${item.dueAt}` : ''}`,
|
||||
title: tr('overview.event.todo', { title: todoTitle(item) }),
|
||||
meta: `${todoAttentionState(item)}${item.dueAt ? ` · ${tr('overview.todo.due', { date: item.dueAt })}` : ''}`,
|
||||
time: todoTimeValue(item),
|
||||
absolute: absoluteTime(todoTimeValue(item)),
|
||||
actionKind: 'todo',
|
||||
actionLabel: 'Open Todos',
|
||||
actionLabel: tr('overview.openTodos'),
|
||||
}));
|
||||
const captureCandidates = sortByTime(captureRows).map(item => ({
|
||||
id: item.captureId || `capture:${timeValue(item)}`,
|
||||
category: 'captures',
|
||||
title: `Review capture ${quoted(captureTitle(item))}`,
|
||||
meta: `${itemTimeLabel(item)} · ${item.domain || item.kind || 'Browser capture'}`,
|
||||
title: tr('overview.event.reviewCapture', { title: captureTitle(item) }),
|
||||
meta: `${itemTimeLabel(item)} · ${item.domain || captureKindLabel(item) || tr('overview.browserCapture')}`,
|
||||
time: timeValue(item),
|
||||
absolute: absoluteTime(timeValue(item)),
|
||||
actionKind: 'browser-inbox',
|
||||
actionLabel: 'Review Inbox',
|
||||
actionLabel: tr('overview.reviewInbox'),
|
||||
}));
|
||||
const noteCandidates = sortByTime(events)
|
||||
.filter(item => isResumeEvent(item) && activityCategory(item) === 'notes')
|
||||
@@ -395,12 +439,12 @@
|
||||
const journalCandidates = sortByTime(journalRows).map(item => ({
|
||||
id: item.entryId || `journal:${timeValue(item)}`,
|
||||
category: 'journal',
|
||||
title: `Continue journal entry ${quoted(journalTitle(item))}`,
|
||||
title: tr('overview.event.continueJournal', { title: journalTitle(item) }),
|
||||
meta: itemTimeLabel(item),
|
||||
time: timeValue(item),
|
||||
absolute: absoluteTime(timeValue(item)),
|
||||
actionKind: 'journal',
|
||||
actionLabel: 'Open Journal',
|
||||
actionLabel: tr('overview.openJournal'),
|
||||
}));
|
||||
return [...todoCandidates, ...captureCandidates, ...noteCandidates, ...fileCandidates, ...journalCandidates].slice(0, 4);
|
||||
}
|
||||
@@ -409,24 +453,28 @@
|
||||
const captureItems = sortByTime(captureRows).slice(0, 4).map(item => ({
|
||||
id: item.captureId || `capture:${timeValue(item)}`,
|
||||
title: captureTitle(item),
|
||||
meta: `${item.kind || 'capture'} · ${itemTimeLabel(item)}`,
|
||||
meta: `${captureKindLabel(item)} · ${itemTimeLabel(item)}`,
|
||||
actionKind: 'browser-inbox',
|
||||
actionLabel: 'Review Inbox',
|
||||
actionLabel: tr('overview.reviewInbox'),
|
||||
}));
|
||||
const candidateItems = sortByTime(candidates).slice(0, 4).map(item => ({
|
||||
id: item.candidateId || `work-session:${timeValue(item)}`,
|
||||
title: 'Possible journal entry',
|
||||
meta: `Workspace: ${item.workspaceRootPath || workspaceRootPath || 'Unknown'} · ${item.estimatedMinutes || 0} min · ${item.activityCount || (item.activityIds || []).length || 0} activities`,
|
||||
title: tr('overview.event.possibleJournalEntry'),
|
||||
meta: tr('overview.candidateMeta', {
|
||||
deal: item.workspaceRootPath || workspaceRootPath || tr('overview.unknownDeal'),
|
||||
minutes: item.estimatedMinutes || 0,
|
||||
activities: item.activityCount || (item.activityIds || []).length || 0,
|
||||
}),
|
||||
actionKind: 'journal',
|
||||
actionLabel: 'Review candidate',
|
||||
actionLabel: tr('overview.reviewCandidate'),
|
||||
toolRequest: { type: 'work-session-candidate', candidate: item },
|
||||
}));
|
||||
const todoItems = [...todoRows].sort((a, b) => todoDateMs(todoTimeValue(a)) - todoDateMs(todoTimeValue(b))).slice(0, 4).map(item => ({
|
||||
id: item.id || `todo:${todoTitle(item)}`,
|
||||
title: todoTitle(item),
|
||||
meta: `${todoAttentionState(item)}${item.dueAt ? ` · Due ${item.dueAt}` : ''}`,
|
||||
meta: `${todoAttentionState(item)}${item.dueAt ? ` · ${tr('overview.todo.due', { date: item.dueAt })}` : ''}`,
|
||||
actionKind: 'todo',
|
||||
actionLabel: 'Open Todos',
|
||||
actionLabel: tr('overview.openTodos'),
|
||||
}));
|
||||
return [...todoItems, ...captureItems, ...candidateItems].slice(0, 6);
|
||||
}
|
||||
@@ -465,12 +513,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function loadWorkspaceResources() {
|
||||
async function loadWorkspaceResources(toolState) {
|
||||
const workspace = String(workspaceRootPath || '').trim();
|
||||
if (!workspace) return { keyResources: [], totalNotes: 0 };
|
||||
const [rootEntries, notesEntries] = await Promise.all([
|
||||
listFiles('verstak.files', workspace),
|
||||
listFiles('verstak.notes', `${workspace}/Notes`),
|
||||
toolState.files ? listFiles('verstak.files', workspace) : Promise.resolve([]),
|
||||
toolState.notes ? listFiles('verstak.notes', `${workspace}/Notes`) : Promise.resolve([]),
|
||||
]);
|
||||
const noteFiles = notesEntries.filter(item => item?.type === 'file');
|
||||
const overview = [...notesEntries, ...rootEntries].find(item => /(^|\/)overview\.md$/i.test(String(item.relativePath || item.name || '')));
|
||||
@@ -479,40 +527,54 @@
|
||||
keyResources: overview ? [{
|
||||
id: overview.relativePath || overview.name,
|
||||
title: overview.name || fileName(overview.relativePath) || 'Overview.md',
|
||||
meta: overview.relativePath || 'Workspace overview note',
|
||||
actionKind: hasNotes ? 'notes' : 'files',
|
||||
actionLabel: hasNotes ? 'Open Notes' : 'Open Files',
|
||||
meta: overview.relativePath || tr('overview.overviewNote'),
|
||||
actionKind: toolState.notes ? 'notes' : 'files',
|
||||
actionLabel: toolState.notes ? tr('overview.openNotes') : tr('overview.openFiles'),
|
||||
}] : [],
|
||||
};
|
||||
}
|
||||
|
||||
async function loadOverview() {
|
||||
const workspaceAtStart = String(workspaceRootPath || '').trim();
|
||||
const toolKeyAtStart = overviewToolKey;
|
||||
const toolState = {
|
||||
notes: hasNotes,
|
||||
files: hasFiles,
|
||||
browserInbox: hasBrowserInbox,
|
||||
activity: hasActivity,
|
||||
journal: hasJournal,
|
||||
todos: hasTodos,
|
||||
};
|
||||
loadedWorkspaceRoot = workspaceAtStart;
|
||||
loadedToolKey = toolKeyAtStart;
|
||||
loading = true;
|
||||
const [browserSettings, activitySettings, journalSettings, todoSettings, resources] = await Promise.all([
|
||||
readPluginSettings('verstak.browser-inbox'),
|
||||
readPluginSettings('verstak.activity'),
|
||||
readPluginSettings('verstak.journal'),
|
||||
readPluginSettings('verstak.todo'),
|
||||
loadWorkspaceResources(),
|
||||
const [browserSettings, activitySettings, activityRecords, journalSettings, todoSettings, resources] = await Promise.all([
|
||||
toolState.browserInbox ? readPluginSettings('verstak.browser-inbox') : Promise.resolve({}),
|
||||
toolState.activity ? readPluginSettings('verstak.activity') : Promise.resolve({}),
|
||||
toolState.activity && App.ReadPluginDataNDJSON
|
||||
? App.ReadPluginDataNDJSON('verstak.activity', 'activity-events')
|
||||
.then(value => decodeTuple(value, []))
|
||||
.catch(() => [])
|
||||
: Promise.resolve([]),
|
||||
toolState.journal ? readPluginSettings('verstak.journal') : Promise.resolve({}),
|
||||
toolState.todos ? readPluginSettings('verstak.todo') : Promise.resolve({}),
|
||||
loadWorkspaceResources(toolState),
|
||||
]);
|
||||
if (workspaceAtStart !== String(workspaceRootPath || '').trim()) return;
|
||||
if (workspaceAtStart !== String(workspaceRootPath || '').trim() || toolKeyAtStart !== overviewToolKey) return;
|
||||
|
||||
captures = browserCaptureRowsForWorkspace(browserSettings);
|
||||
activityEvents = rowsFor(activitySettings, [
|
||||
workspaceKey('events:workspace:'),
|
||||
'events:global',
|
||||
'events',
|
||||
]);
|
||||
journalEntries = rowsFor(journalSettings, [
|
||||
captures = toolState.browserInbox ? browserCaptureRowsForWorkspace(browserSettings) : [];
|
||||
activityEvents = toolState.activity ? normalizeRows(activityRecords).filter(item => {
|
||||
const tagged = String(item.workspaceRootPath || item.workspaceName || item.workspaceNodeId || '').trim();
|
||||
return !tagged || tagged === workspaceAtStart;
|
||||
}) : [];
|
||||
journalEntries = toolState.journal ? rowsFor(journalSettings, [
|
||||
workspaceKey('worklog:workspace:'),
|
||||
'worklog',
|
||||
]);
|
||||
todos = todoRowsForWorkspace(todoSettings);
|
||||
workSessionCandidates = rowsFor(activitySettings, [
|
||||
]) : [];
|
||||
todos = toolState.todos ? todoRowsForWorkspace(todoSettings) : [];
|
||||
workSessionCandidates = toolState.activity && toolState.journal ? rowsFor(activitySettings, [
|
||||
workspaceKey('work-session-candidates:workspace:'),
|
||||
]);
|
||||
]) : [];
|
||||
keyResources = resources.keyResources;
|
||||
totalNotes = resources.totalNotes;
|
||||
loading = false;
|
||||
@@ -523,24 +585,24 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="today-root overview-root" aria-label="Overview" data-overview-root>
|
||||
<div class="today-root overview-root" aria-label={tr('workspace.overview')} data-overview-root>
|
||||
<div class="today-header overview-header">
|
||||
<div>
|
||||
<h2>Overview</h2>
|
||||
<h2>{tr('workspace.overview')}</h2>
|
||||
<p title={lastActive ? absoluteTime(lastActive) : ''}>
|
||||
{#if loading}
|
||||
Loading workspace context...
|
||||
{tr('overview.loadingContext')}
|
||||
{:else if lastActive}
|
||||
Last active {relativeTime(lastActive)}
|
||||
{tr('overview.lastActive', { time: relativeTime(lastActive) })}
|
||||
{:else}
|
||||
No recent workspace activity
|
||||
{tr('overview.noRecentActivity')}
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
<button type="button" data-overview-action="refresh" on:click={loadOverview}>Refresh</button>
|
||||
<button type="button" data-overview-action="refresh" on:click={loadOverview}>{tr('overview.refresh')}</button>
|
||||
</div>
|
||||
|
||||
<div class="today-summary overview-summary" aria-label="Workspace overview summary">
|
||||
<div class="today-summary overview-summary" aria-label={tr('overview.summary')}>
|
||||
{#each summaryItems as item}
|
||||
<button
|
||||
type="button"
|
||||
@@ -553,7 +615,7 @@
|
||||
>
|
||||
<strong>{loading ? '...' : item.count}</strong>
|
||||
<span>{item.label}</span>
|
||||
<small>{loading ? 'Loading...' : item.detail}</small>
|
||||
<small>{loading ? tr('common.loading') : item.detail}</small>
|
||||
<em>{item.actionLabel}</em>
|
||||
</button>
|
||||
{/each}
|
||||
@@ -563,11 +625,11 @@
|
||||
<main class="overview-main">
|
||||
<section class="today-resume overview-continue" data-overview-section="continue">
|
||||
<div class="today-resume-copy overview-continue-copy">
|
||||
<span>Continue working</span>
|
||||
<h3>Pick up the next useful item in this workspace.</h3>
|
||||
<span>{tr('overview.continue')}</span>
|
||||
<h3>{tr('overview.continueHint')}</h3>
|
||||
</div>
|
||||
{#if loading}
|
||||
<p class="today-empty compact">Loading workspace signals...</p>
|
||||
<p class="today-empty compact">{tr('overview.loadingSignals')}</p>
|
||||
{:else if continueItems.length}
|
||||
<div class="overview-continue-list">
|
||||
{#each continueItems as item}
|
||||
@@ -588,8 +650,8 @@
|
||||
</div>
|
||||
{:else}
|
||||
<div class="overview-continue-empty">
|
||||
<strong>No clear resume point yet</strong>
|
||||
<p>Recent notes, files, captures, and journal entries will appear here.</p>
|
||||
<strong>{tr('overview.noResume')}</strong>
|
||||
<p>{tr('overview.noResumeHint')}</p>
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
@@ -597,10 +659,10 @@
|
||||
<section class="today-panel overview-panel overview-recent" data-overview-section="recent">
|
||||
<div class="today-panel-head overview-panel-head">
|
||||
<div>
|
||||
<h3>Recent changes</h3>
|
||||
<p>Latest meaningful activity in this workspace.</p>
|
||||
<h3>{tr('overview.recentChanges')}</h3>
|
||||
<p>{tr('overview.recentChangesHint')}</p>
|
||||
</div>
|
||||
<div class="overview-filters" aria-label="Recent changes filter">
|
||||
<div class="overview-filters" aria-label={tr('overview.recentFilter')}>
|
||||
{#each FILTERS as filter}
|
||||
<button
|
||||
type="button"
|
||||
@@ -615,7 +677,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{#if loading}
|
||||
<p class="today-empty">Loading recent changes...</p>
|
||||
<p class="today-empty">{tr('overview.loadingRecent')}</p>
|
||||
{:else if filteredRecentChanges.length}
|
||||
<div class="today-list overview-list">
|
||||
{#each filteredRecentChanges as item}
|
||||
@@ -635,22 +697,22 @@
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<p class="today-empty">No meaningful changes for this filter yet.</p>
|
||||
<p class="today-empty">{tr('overview.noChanges')}</p>
|
||||
{/if}
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<aside class="overview-side">
|
||||
{#if needsAttention.length || !loading}
|
||||
{#if hasAttentionTools && (needsAttention.length || !loading)}
|
||||
<section class="today-panel overview-panel" data-overview-section="attention">
|
||||
<div class="today-panel-head overview-panel-head">
|
||||
<div>
|
||||
<h3>Needs attention</h3>
|
||||
<p>Pending captures, urgent todos, and possible journal entries.</p>
|
||||
<h3>{tr('overview.attention')}</h3>
|
||||
<p>{tr('overview.attentionHint')}</p>
|
||||
</div>
|
||||
</div>
|
||||
{#if loading}
|
||||
<p class="today-empty">Loading pending items...</p>
|
||||
<p class="today-empty">{tr('overview.loadingPending')}</p>
|
||||
{:else if needsAttention.length}
|
||||
<div class="today-list overview-list compact">
|
||||
{#each needsAttention as item}
|
||||
@@ -662,7 +724,7 @@
|
||||
{/each}
|
||||
</div>
|
||||
{:else}
|
||||
<p class="today-empty compact">No pending captures, urgent todos, or possible journal entries.</p>
|
||||
<p class="today-empty compact">{tr('overview.noPending')}</p>
|
||||
{/if}
|
||||
</section>
|
||||
{/if}
|
||||
@@ -670,7 +732,7 @@
|
||||
{#if keyResources.length}
|
||||
<section class="today-panel overview-panel secondary" data-overview-section="key-resources">
|
||||
<div class="today-panel-head overview-panel-head">
|
||||
<h3>Key resources</h3>
|
||||
<h3>{tr('overview.keyResources')}</h3>
|
||||
</div>
|
||||
<div class="today-list overview-list compact">
|
||||
{#each keyResources as item}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import * as App from '../../../wailsjs/go/api/App';
|
||||
import Icon from '../ui/Icon.svelte';
|
||||
import { i18n } from '../i18n/index.js';
|
||||
|
||||
let appSettings = {};
|
||||
let recentVaults = [];
|
||||
@@ -11,6 +12,19 @@
|
||||
let opening = false;
|
||||
let newVaultPath = '';
|
||||
let openVaultPath = '';
|
||||
let locale = i18n.getLocale();
|
||||
const unsubscribeLocale = i18n.subscribe((nextLocale) => { locale = nextLocale; });
|
||||
$: tr = ((activeLocale) => (key, params, fallback) => {
|
||||
void activeLocale;
|
||||
return i18n.t(key, params, fallback);
|
||||
})(locale);
|
||||
|
||||
function reportError(key, fallback, details) {
|
||||
console.warn('[VaultSelection] operation failed:', details);
|
||||
return tr(key, undefined, fallback);
|
||||
}
|
||||
|
||||
onDestroy(unsubscribeLocale);
|
||||
|
||||
onMount(async () => {
|
||||
try {
|
||||
@@ -39,20 +53,20 @@
|
||||
async function createVault() {
|
||||
error = '';
|
||||
if (!newVaultPath.trim()) {
|
||||
error = 'Choose or enter a folder for the new vault.';
|
||||
error = tr('vaultSelection.chooseNew');
|
||||
return;
|
||||
}
|
||||
creating = true;
|
||||
try {
|
||||
const createErr = await App.CreateVault(newVaultPath.trim());
|
||||
if (createErr) {
|
||||
error = 'Could not create vault: ' + createErr;
|
||||
error = reportError('vaultSelection.createError', 'Could not create the vault. Please try again.', createErr);
|
||||
creating = false;
|
||||
return;
|
||||
}
|
||||
const openErr = await App.OpenVault(newVaultPath.trim());
|
||||
if (openErr) {
|
||||
error = 'Could not open vault: ' + openErr;
|
||||
error = reportError('vaultSelection.openError', 'Could not open the vault. Please try again.', openErr);
|
||||
creating = false;
|
||||
return;
|
||||
}
|
||||
@@ -62,7 +76,7 @@
|
||||
}
|
||||
window.dispatchEvent(new CustomEvent('verstak:vault-opened'));
|
||||
} catch (e) {
|
||||
error = String(e);
|
||||
error = reportError('vaultSelection.createError', 'Could not create the vault. Please try again.', e);
|
||||
creating = false;
|
||||
}
|
||||
}
|
||||
@@ -70,14 +84,14 @@
|
||||
async function openExistingVault() {
|
||||
error = '';
|
||||
if (!openVaultPath.trim()) {
|
||||
error = 'Choose or enter an existing vault.';
|
||||
error = tr('vaultSelection.chooseExisting');
|
||||
return;
|
||||
}
|
||||
opening = true;
|
||||
try {
|
||||
const openErr = await App.OpenVault(openVaultPath.trim());
|
||||
if (openErr) {
|
||||
error = 'Could not open vault: ' + openErr;
|
||||
error = reportError('vaultSelection.openError', 'Could not open the vault. Please try again.', openErr);
|
||||
opening = false;
|
||||
return;
|
||||
}
|
||||
@@ -87,7 +101,7 @@
|
||||
}
|
||||
window.dispatchEvent(new CustomEvent('verstak:vault-opened'));
|
||||
} catch (e) {
|
||||
error = String(e);
|
||||
error = reportError('vaultSelection.openError', 'Could not open the vault. Please try again.', e);
|
||||
opening = false;
|
||||
}
|
||||
}
|
||||
@@ -98,7 +112,7 @@
|
||||
try {
|
||||
const openErr = await App.OpenVault(path);
|
||||
if (openErr) {
|
||||
error = 'Could not open vault: ' + openErr;
|
||||
error = reportError('vaultSelection.openError', 'Could not open the vault. Please try again.', openErr);
|
||||
opening = false;
|
||||
return;
|
||||
}
|
||||
@@ -108,7 +122,7 @@
|
||||
}
|
||||
window.dispatchEvent(new CustomEvent('verstak:vault-opened'));
|
||||
} catch (e) {
|
||||
error = String(e);
|
||||
error = reportError('vaultSelection.openError', 'Could not open the vault. Please try again.', e);
|
||||
opening = false;
|
||||
}
|
||||
}
|
||||
@@ -117,7 +131,7 @@
|
||||
{#if loading}
|
||||
<div class="vault-selection">
|
||||
<div class="vault-selection-inner">
|
||||
<p class="loading-text">Loading...</p>
|
||||
<p class="loading-text">{tr('common.loading')}</p>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
@@ -130,7 +144,7 @@
|
||||
<line x1="9" y1="14" x2="15" y2="14"/>
|
||||
</svg>
|
||||
<h1>Verstak</h1>
|
||||
<p class="subtitle">Choose a vault to start working</p>
|
||||
<p class="subtitle">{tr('vaultSelection.subtitle')}</p>
|
||||
</div>
|
||||
|
||||
{#if error}
|
||||
@@ -142,43 +156,43 @@
|
||||
|
||||
<div class="actions">
|
||||
<div class="action-card">
|
||||
<h3>Create a new vault</h3>
|
||||
<p class="hint">Create a local vault folder for workspaces and projects.</p>
|
||||
<h3>{tr('vaultSelection.createTitle')}</h3>
|
||||
<p class="hint">{tr('vaultSelection.createHint')}</p>
|
||||
<div class="input-row">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={newVaultPath}
|
||||
placeholder="Choose or enter a path..."
|
||||
placeholder={tr('vaultSelection.pathPlaceholder')}
|
||||
disabled={creating}
|
||||
/>
|
||||
<button class="btn-secondary" on:click={browseNewVault} type="button" disabled={creating}>
|
||||
Browse...
|
||||
{tr('common.browse')}
|
||||
</button>
|
||||
</div>
|
||||
<div class="button-row">
|
||||
<button class="btn-primary" on:click={createVault} type="button" disabled={creating}>
|
||||
{creating ? 'Creating...' : 'Create vault'}
|
||||
{creating ? tr('vaultSelection.creating') : tr('vaultSelection.create')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="action-card">
|
||||
<h3>Open an existing vault</h3>
|
||||
<p class="hint">Use a vault that is already on this computer.</p>
|
||||
<h3>{tr('vaultSelection.openTitle')}</h3>
|
||||
<p class="hint">{tr('vaultSelection.openHint')}</p>
|
||||
<div class="input-row">
|
||||
<input
|
||||
type="text"
|
||||
bind:value={openVaultPath}
|
||||
placeholder="Choose or enter a path..."
|
||||
placeholder={tr('vaultSelection.pathPlaceholder')}
|
||||
disabled={opening}
|
||||
/>
|
||||
<button class="btn-secondary" on:click={browseOpenVault} type="button" disabled={opening}>
|
||||
Browse...
|
||||
{tr('common.browse')}
|
||||
</button>
|
||||
</div>
|
||||
<div class="button-row">
|
||||
<button class="btn-secondary open-existing-btn" on:click={openExistingVault} type="button" disabled={opening}>
|
||||
{opening ? 'Opening...' : 'Open existing'}
|
||||
{opening ? tr('vaultSelection.opening') : tr('vaultSelection.open')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -186,7 +200,7 @@
|
||||
|
||||
{#if recentVaults.length > 0}
|
||||
<div class="recent-section">
|
||||
<h3>Recent vaults</h3>
|
||||
<h3>{tr('vaultSelection.recent')}</h3>
|
||||
<ul class="recent-list">
|
||||
{#each recentVaults as path}
|
||||
<li>
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<script>
|
||||
import PluginBundleHost from '../plugin-host/PluginBundleHost.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import * as App from '../../../wailsjs/go/api/App';
|
||||
import Icon from '../ui/Icon.svelte';
|
||||
import { i18n } from '../i18n/index.js';
|
||||
|
||||
export let activeView = null;
|
||||
export let activeViewPluginId = null;
|
||||
@@ -10,18 +11,40 @@
|
||||
let views = [];
|
||||
let plugins = [];
|
||||
let renderError = null;
|
||||
let locale = i18n.getLocale();
|
||||
let unsubscribeLocale = null;
|
||||
$: tr = ((activeLocale) => (key, params, fallback) => {
|
||||
void activeLocale;
|
||||
return i18n.t(key, params, fallback);
|
||||
})(locale);
|
||||
|
||||
onMount(async () => {
|
||||
async function loadViews() {
|
||||
try {
|
||||
const [contribs, pluginList] = await Promise.all([
|
||||
App.GetContributions().catch(() => ({ views: [] })),
|
||||
App.GetPlugins().catch(() => []),
|
||||
]);
|
||||
views = contribs.views || [];
|
||||
plugins = pluginList;
|
||||
await Promise.all((pluginList || []).map((plugin) => (
|
||||
i18n.loadPlugin(plugin.manifest?.id, plugin.manifest?.localization).catch(() => {})
|
||||
)));
|
||||
views = i18n.localizeContributionSummary(contribs || {}).views || [];
|
||||
plugins = (pluginList || []).map((plugin) => i18n.localizePlugin(plugin));
|
||||
} catch (e) {
|
||||
console.error('[ViewContainer] load error:', e);
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
unsubscribeLocale = i18n.subscribe((nextLocale) => {
|
||||
const changed = locale !== nextLocale;
|
||||
locale = nextLocale;
|
||||
if (changed) loadViews();
|
||||
});
|
||||
loadViews();
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
if (unsubscribeLocale) unsubscribeLocale();
|
||||
});
|
||||
|
||||
$: currentView = views.find(v => v.id === activeView && v.pluginId === activeViewPluginId);
|
||||
@@ -39,7 +62,7 @@
|
||||
}
|
||||
|
||||
function onHostError(e) {
|
||||
renderError = e.detail?.message || 'Plugin view error';
|
||||
renderError = e.detail?.message || tr('pluginView.error');
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -49,9 +72,9 @@
|
||||
<div class="error-boundary">
|
||||
<div class="error-fallback vt-inline-alert error">
|
||||
<Icon name="warning" size={24} class="error-icon" />
|
||||
<p class="error-title">Plugin UI failed</p>
|
||||
<p class="error-title">{tr('pluginView.failed')}</p>
|
||||
<details class="error-details">
|
||||
<summary>Details</summary>
|
||||
<summary>{tr('common.details')}</summary>
|
||||
<p class="error-text">{renderError}</p>
|
||||
</details>
|
||||
</div>
|
||||
@@ -72,14 +95,14 @@
|
||||
/>
|
||||
{:else}
|
||||
<div class="placeholder">
|
||||
<p class="placeholder-label">This plugin does not provide a visual view yet.</p>
|
||||
<p class="placeholder-label">{tr('pluginView.noVisual')}</p>
|
||||
<details class="placeholder-details">
|
||||
<summary>Details</summary>
|
||||
<p class="placeholder-info"><span class="placeholder-key">Plugin:</span> <strong>{currentView.pluginId}</strong></p>
|
||||
<p class="placeholder-info"><span class="placeholder-key">View ID:</span> <code>{currentView.id}</code></p>
|
||||
<p class="placeholder-info"><span class="placeholder-key">Component:</span> <code>{currentView.component}</code></p>
|
||||
<summary>{tr('common.details')}</summary>
|
||||
<p class="placeholder-info"><span class="placeholder-key">{tr('common.plugin')}:</span> <strong>{currentView.pluginId}</strong></p>
|
||||
<p class="placeholder-info"><span class="placeholder-key">{tr('pluginView.viewId')}:</span> <code>{currentView.id}</code></p>
|
||||
<p class="placeholder-info"><span class="placeholder-key">{tr('common.component')}:</span> <code>{currentView.component}</code></p>
|
||||
</details>
|
||||
<p class="placeholder-badge vt-badge">Frontend bundle unavailable</p>
|
||||
<p class="placeholder-badge vt-badge">{tr('pluginView.bundleUnavailable')}</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -87,12 +110,12 @@
|
||||
</div>
|
||||
{:else if activeView}
|
||||
<div class="view-container empty">
|
||||
<p>View is unavailable.</p>
|
||||
<p>{tr('pluginView.unavailable')}</p>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="view-container empty">
|
||||
<p>Select a plugin view from the sidebar</p>
|
||||
<p class="sub">Plugin views will appear here</p>
|
||||
<p>{tr('pluginView.select')}</p>
|
||||
<p class="sub">{tr('pluginView.selectHint')}</p>
|
||||
</div>
|
||||
{/if}
|
||||
{/key}
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
<script>
|
||||
import { onDestroy } from 'svelte';
|
||||
import PluginBundleHost from '../plugin-host/PluginBundleHost.svelte';
|
||||
import Icon from '../ui/Icon.svelte';
|
||||
import { i18n } from '../i18n/index.js';
|
||||
import { debug } from '../log/debug.js';
|
||||
|
||||
export let openedResource = null;
|
||||
let locale = i18n.getLocale();
|
||||
const unsubscribeLocale = i18n.subscribe((nextLocale) => locale = nextLocale);
|
||||
|
||||
$: tr = ((activeLocale) => (key, params, fallback) => {
|
||||
void activeLocale;
|
||||
return i18n.t(key, params, fallback);
|
||||
})(locale);
|
||||
|
||||
$: providerPluginId = openedResource?.providerPluginId || '';
|
||||
$: providerComponent = openedResource?.providerComponent || '';
|
||||
@@ -12,6 +22,7 @@
|
||||
$: requestContext = openedResource?.request?.context?.notesMode || openedResource?.request?.context?.isInsideNotesFolder
|
||||
? 'notes-markdown'
|
||||
: ((openedResource?.request?.extension === '.md' || openedResource?.request?.extension === '.markdown') ? 'generic-markdown' : 'generic-text');
|
||||
$: resourceTitle = resourceDisplayTitle(resourcePath, requestContext);
|
||||
$: componentProps = openedResource || {};
|
||||
$: mountKey = [
|
||||
providerPluginId,
|
||||
@@ -21,29 +32,40 @@
|
||||
requestContext,
|
||||
].join(':');
|
||||
|
||||
function resourceDisplayTitle(path, context) {
|
||||
const fileName = String(path || '').split('/').filter(Boolean).pop() || String(path || '');
|
||||
return context === 'notes-markdown' ? fileName.replace(/\.(md|markdown)$/i, '') : fileName;
|
||||
}
|
||||
|
||||
function closeWorkbench() {
|
||||
window.dispatchEvent(new CustomEvent('verstak:close-workbench', { cancelable: true }));
|
||||
}
|
||||
|
||||
onDestroy(unsubscribeLocale);
|
||||
</script>
|
||||
|
||||
<div class="workbench-host vt-page">
|
||||
{#if openedResource?.status === 'no-provider'}
|
||||
<div class="workbench-header vt-page-header">
|
||||
<span class="workbench-title vt-page-title">{resourcePath}</span>
|
||||
<span class="workbench-provider vt-badge">No provider</span>
|
||||
<button class="close-btn btn-ghost btn-icon" type="button" title="Close" aria-label="Close" on:click={closeWorkbench}>
|
||||
<span class="workbench-title vt-page-title">{resourceTitle}</span>
|
||||
<span class="workbench-provider vt-badge">{tr('workbench.noProvider')}</span>
|
||||
<button class="close-btn btn-ghost btn-icon" type="button" title={tr('common.close')} aria-label={tr('common.close')} on:click={closeWorkbench}>
|
||||
<Icon name="x" size={18} />
|
||||
</button>
|
||||
</div>
|
||||
<div class="workbench-empty no-provider vt-empty-state" data-workbench-status="no-provider">
|
||||
<p class="vt-empty-title">No viewer/editor available</p>
|
||||
<p class="workbench-meta">{requestMode} · {requestContext}</p>
|
||||
<p class="vt-empty-title">{tr('workbench.noViewer')}</p>
|
||||
{#if debug.isEnabled()}
|
||||
<p class="workbench-meta">{requestMode} · {requestContext}</p>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if openedResource}
|
||||
<div class="workbench-header vt-page-header">
|
||||
<span class="workbench-title vt-page-title">{resourcePath}</span>
|
||||
<span class="workbench-provider vt-badge accent">{providerId}</span>
|
||||
<button class="close-btn btn-ghost btn-icon" type="button" title="Close" aria-label="Close" on:click={closeWorkbench}>
|
||||
<span class="workbench-title vt-page-title">{resourceTitle}</span>
|
||||
{#if debug.isEnabled() && providerId}
|
||||
<span class="workbench-provider vt-badge accent" data-debug-provider>{providerId}</span>
|
||||
{/if}
|
||||
<button class="close-btn btn-ghost btn-icon" type="button" title={tr('common.close')} aria-label={tr('common.close')} on:click={closeWorkbench}>
|
||||
<Icon name="x" size={18} />
|
||||
</button>
|
||||
</div>
|
||||
@@ -58,7 +80,7 @@
|
||||
</div>
|
||||
{:else}
|
||||
<div class="workbench-empty vt-empty-state">
|
||||
<p class="vt-empty-title">No resource opened</p>
|
||||
<p class="vt-empty-title">{tr('workbench.noResource')}</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import TodaySurface from './TodaySurface.svelte';
|
||||
import * as App from '../../../wailsjs/go/api/App';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { i18n } from '../i18n/index.js';
|
||||
|
||||
export let selectedWorkspaceName = '';
|
||||
export let nodes = [];
|
||||
@@ -20,8 +21,14 @@
|
||||
let requestedToolRequest = null;
|
||||
let activeToolRequest = null;
|
||||
let requestedWorkspaceRoot = '';
|
||||
let locale = i18n.getLocale();
|
||||
let unsubscribeLocale = null;
|
||||
$: tr = ((activeLocale) => (key, params, fallback) => {
|
||||
void activeLocale;
|
||||
return i18n.t(key, params, fallback);
|
||||
})(locale);
|
||||
// TODO: Rename TodaySurface.svelte to OverviewSurface.svelte in a refactor-only follow-up.
|
||||
const overviewTool = { id: '__overview', title: 'Overview', pluginId: 'verstak.shell', component: 'TodaySurface', shell: true };
|
||||
$: overviewTool = { id: '__overview', title: tr('workspace.overview'), pluginId: 'verstak.shell', component: 'TodaySurface', shell: true };
|
||||
|
||||
const toolOrder = new Map([
|
||||
['notes', 10],
|
||||
@@ -36,8 +43,8 @@
|
||||
|
||||
$: selectedWorkspace = nodes.find(n => n.id === selectedWorkspaceName || n.name === selectedWorkspaceName || n.rootPath === selectedWorkspaceName) || null;
|
||||
$: workspaceRootPath = selectedWorkspace?.rootPath || selectedWorkspace?.name || selectedWorkspace?.id || '';
|
||||
$: workspaceId = selectedWorkspace?.workspaceId || '';
|
||||
$: workspaceTitle = selectedWorkspace?.title || selectedWorkspace?.name || selectedWorkspace?.id || selectedWorkspaceName;
|
||||
$: workspaceType = selectedWorkspace?.type || 'workspace';
|
||||
$: if (workspaceRootPath !== metadataWorkspaceRoot) {
|
||||
metadataWorkspaceRoot = workspaceRootPath;
|
||||
workspaceMetadata = null;
|
||||
@@ -66,11 +73,19 @@
|
||||
$: if (selectedWorkspaceName) loadTools();
|
||||
|
||||
onMount(() => {
|
||||
unsubscribeLocale = i18n.subscribe((nextLocale) => {
|
||||
const changed = locale !== nextLocale;
|
||||
locale = nextLocale;
|
||||
if (changed && selectedWorkspaceName) loadTools();
|
||||
});
|
||||
window.addEventListener('verstak:workspace-open-tool', handleWorkspaceOpenTool);
|
||||
window.addEventListener('verstak:plugins-changed', handlePluginsChanged);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
if (unsubscribeLocale) unsubscribeLocale();
|
||||
window.removeEventListener('verstak:workspace-open-tool', handleWorkspaceOpenTool);
|
||||
window.removeEventListener('verstak:plugins-changed', handlePluginsChanged);
|
||||
});
|
||||
|
||||
function toolKey(tool) {
|
||||
@@ -156,6 +171,10 @@
|
||||
requestWorkspaceTool(event?.detail?.kind, event?.detail?.toolRequest || null);
|
||||
}
|
||||
|
||||
function handlePluginsChanged() {
|
||||
if (selectedWorkspaceName) loadTools();
|
||||
}
|
||||
|
||||
async function loadTools() {
|
||||
try {
|
||||
toolsLoaded = false;
|
||||
@@ -163,8 +182,11 @@
|
||||
App.GetContributions().catch(() => ({})),
|
||||
App.GetPlugins().catch(() => []),
|
||||
]);
|
||||
contributions = c || {};
|
||||
plugins = p || [];
|
||||
await Promise.all((p || []).map((plugin) => (
|
||||
i18n.loadPlugin(plugin.manifest?.id, plugin.manifest?.localization).catch(() => {})
|
||||
)));
|
||||
contributions = i18n.localizeContributionSummary(c || {});
|
||||
plugins = (p || []).map((plugin) => i18n.localizePlugin(plugin));
|
||||
|
||||
const enabledIds = new Set(
|
||||
plugins.filter(pl => pl.enabled && (pl.status === 'loaded' || pl.status === 'degraded')).map(pl => pl.manifest?.id)
|
||||
@@ -184,15 +206,14 @@
|
||||
<div class="workspace-header vt-page-header">
|
||||
<div class="workspace-title-group">
|
||||
<span class="workspace-title vt-page-title">{workspaceTitle}</span>
|
||||
<span class="workspace-type vt-badge accent">{workspaceType}</span>
|
||||
</div>
|
||||
<div class="workspace-search" aria-label="Workspace search">
|
||||
<div class="workspace-search" aria-label={tr('workspace.search')}>
|
||||
<GlobalSearch />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if displayedTools.length > 0}
|
||||
<div class="workspace-tabs vt-tabbar" role="tablist" aria-label="Workspace tools">
|
||||
<div class="workspace-tabs vt-tabbar" role="tablist" aria-label={tr('workspace.tools')}>
|
||||
{#each displayedTools as tool (tool.id + tool.pluginId)}
|
||||
<button
|
||||
class="vt-tab"
|
||||
@@ -207,7 +228,7 @@
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
<div class="workspace-tool-content" role="tabpanel" aria-label={activeTool?.title || activeTool?.id || 'Workspace tool'}>
|
||||
<div class="workspace-tool-content" role="tabpanel" aria-label={activeTool?.title || activeTool?.id || tr('workspace.tool')}>
|
||||
{#if activeTool}
|
||||
{#if activeTool.shell}
|
||||
<TodaySurface
|
||||
@@ -219,21 +240,21 @@
|
||||
<PluginBundleHost
|
||||
pluginId={activeTool.pluginId}
|
||||
componentId={activeTool.component}
|
||||
componentProps={{ workspaceName: selectedWorkspaceName, workspaceNodeId: selectedWorkspaceName, workspaceNode: selectedWorkspace, workspaceRootPath, toolRequest: activeToolRequest }}
|
||||
componentProps={{ workspaceName: selectedWorkspaceName, workspaceNodeId: selectedWorkspaceName, workspaceNode: selectedWorkspace, workspaceRootPath, workspaceId, toolRequest: activeToolRequest }}
|
||||
/>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<div class="workspace-empty vt-empty-state">
|
||||
<p class="vt-empty-title">No workspace tools available</p>
|
||||
<p class="workspace-hint">Enable plugins with workspace tools or open Plugin Manager from settings.</p>
|
||||
<p class="vt-empty-title">{tr('workspace.emptyTools')}</p>
|
||||
<p class="workspace-hint">{tr('workspace.emptyToolsHint')}</p>
|
||||
</div>
|
||||
{/if}
|
||||
{:else}
|
||||
<div class="workspace-empty vt-empty-state">
|
||||
<p class="vt-empty-title">Select a workspace</p>
|
||||
<p class="workspace-hint">Use the + button in Workspaces to add your first project.</p>
|
||||
<p class="vt-empty-title">{tr('workspace.select')}</p>
|
||||
<p class="workspace-hint">{tr('workspace.selectHint')}</p>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -271,14 +292,6 @@
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.workspace-type {
|
||||
color: var(--vt-color-accent);
|
||||
font-size: 0.75rem;
|
||||
padding: 0.1rem 0.4rem;
|
||||
border-radius: var(--vt-radius-sm);
|
||||
background: var(--vt-color-accent-muted);
|
||||
}
|
||||
|
||||
.workspace-search {
|
||||
width: min(27rem, 46vw);
|
||||
min-width: 16rem;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import * as App from '../../../wailsjs/go/api/App';
|
||||
import Icon from '../ui/Icon.svelte';
|
||||
import { i18n } from '../i18n/index.js';
|
||||
|
||||
let loading = true;
|
||||
let localError = '';
|
||||
@@ -17,21 +18,41 @@
|
||||
let newWorkspaceName = '';
|
||||
let workspaceTemplates = [];
|
||||
let templatePluginNames = {};
|
||||
let templatePlugins = {};
|
||||
let templateCapabilities = new Set();
|
||||
let selectedTemplateId = 'default';
|
||||
let createError = '';
|
||||
let templateWarning = null;
|
||||
let templatesLoading = false;
|
||||
let creating = false;
|
||||
let renamingId = '';
|
||||
let renameValue = '';
|
||||
let busyId = '';
|
||||
let locale = i18n.getLocale();
|
||||
let unsubscribeLocale = null;
|
||||
$: tr = ((activeLocale) => (key, params, fallback) => {
|
||||
void activeLocale;
|
||||
return i18n.t(key, params, fallback);
|
||||
})(locale);
|
||||
|
||||
function reportError(key, fallback, details) {
|
||||
console.warn('[WorkspaceTree] operation failed:', details);
|
||||
return tr(key, undefined, fallback);
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
unsubscribeLocale = i18n.subscribe((nextLocale) => {
|
||||
const changed = locale !== nextLocale;
|
||||
locale = nextLocale;
|
||||
if (changed) loadWorkspaceTemplates();
|
||||
});
|
||||
loadWorkspaces();
|
||||
loadWorkspaceTemplates();
|
||||
window.addEventListener('verstak:workspace-active-changed', onActiveWorkspaceChanged);
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
if (unsubscribeLocale) unsubscribeLocale();
|
||||
window.removeEventListener('verstak:workspace-active-changed', onActiveWorkspaceChanged);
|
||||
});
|
||||
|
||||
@@ -48,36 +69,97 @@
|
||||
}
|
||||
|
||||
$: selectedTemplate = workspaceTemplates.find(template => template.id === selectedTemplateId) || workspaceTemplates[0] || null;
|
||||
$: selectedTemplateTools = (selectedTemplate?.workspaceTools || []).map((pluginId) => (
|
||||
templateToolState(pluginId, templatePlugins, templateCapabilities, templatePluginNames, tr)
|
||||
));
|
||||
$: selectedTemplateIssues = selectedTemplateTools.filter(tool => tool.status !== 'available');
|
||||
|
||||
function toolLabel(pluginId) {
|
||||
return templatePluginNames[pluginId] || String(pluginId || '').replace(/^verstak\./, '');
|
||||
function toolLabel(pluginId, names = templatePluginNames) {
|
||||
return names[pluginId] || String(pluginId || '').replace(/^verstak\./, '');
|
||||
}
|
||||
|
||||
function templateToolState(pluginId, plugins, capabilities, names, translate) {
|
||||
const plugin = plugins[pluginId];
|
||||
if (!plugin) {
|
||||
return {
|
||||
pluginId,
|
||||
name: toolLabel(pluginId, names),
|
||||
tabs: [],
|
||||
status: 'unavailable',
|
||||
reason: translate('workspaceTree.templateMissingPlugin'),
|
||||
};
|
||||
}
|
||||
|
||||
const manifest = plugin.manifest || {};
|
||||
const tabs = Array.isArray(manifest.contributes?.workspaceItems)
|
||||
? manifest.contributes.workspaceItems.map(item => item?.title || item?.id).filter(Boolean)
|
||||
: [];
|
||||
const pluginStatus = String(plugin.status || '').toLowerCase();
|
||||
const missingCapability = Array.isArray(manifest.requires)
|
||||
&& manifest.requires.some(capabilityId => !capabilities.has(capabilityId));
|
||||
let status = 'available';
|
||||
let reason = translate('workspaceTree.templateAvailable');
|
||||
|
||||
if (!plugin.enabled || pluginStatus === 'disabled') {
|
||||
status = 'unavailable';
|
||||
reason = translate('workspaceTree.templatePluginDisabled');
|
||||
} else if (pluginStatus === 'missing-required-capability' || missingCapability) {
|
||||
status = 'unavailable';
|
||||
reason = translate('workspaceTree.templateCapabilityUnavailable');
|
||||
} else if (pluginStatus === 'incompatible') {
|
||||
status = 'unavailable';
|
||||
reason = translate('workspaceTree.templateIncompatible');
|
||||
} else if (pluginStatus === 'failed') {
|
||||
status = 'unavailable';
|
||||
reason = translate('workspaceTree.templateLoadFailed');
|
||||
} else if (pluginStatus === 'degraded') {
|
||||
status = 'limited';
|
||||
reason = translate('workspaceTree.templateLimited');
|
||||
} else if (pluginStatus !== 'loaded') {
|
||||
status = 'unavailable';
|
||||
reason = translate('workspaceTree.templateNotReady');
|
||||
}
|
||||
|
||||
return { pluginId, name: manifest.name || toolLabel(pluginId, names), tabs, status, reason };
|
||||
}
|
||||
|
||||
async function loadWorkspaceTemplates() {
|
||||
templatesLoading = true;
|
||||
try {
|
||||
const [templates, plugins] = await Promise.all([
|
||||
const [templates, plugins, capabilities] = await Promise.all([
|
||||
App.ListWorkspaceTemplates ? App.ListWorkspaceTemplates() : [],
|
||||
App.GetPlugins ? App.GetPlugins() : [],
|
||||
App.GetCapabilities ? App.GetCapabilities() : [],
|
||||
]);
|
||||
const [list, err] = resultOrError(templates, []);
|
||||
if (err) {
|
||||
createError = err;
|
||||
createError = reportError('workspaceTree.templatesError', 'Could not load Deal templates. Please try again.', err);
|
||||
workspaceTemplates = [];
|
||||
return;
|
||||
}
|
||||
workspaceTemplates = Array.isArray(list) ? list : [];
|
||||
templatePluginNames = (Array.isArray(plugins) ? plugins : []).reduce((names, plugin) => {
|
||||
await Promise.all((Array.isArray(plugins) ? plugins : []).map((plugin) => (
|
||||
i18n.loadPlugin(plugin.manifest?.id, plugin.manifest?.localization).catch(() => {})
|
||||
)));
|
||||
const localizedPlugins = (Array.isArray(plugins) ? plugins : []).map((plugin) => i18n.localizePlugin(plugin));
|
||||
templatePluginNames = localizedPlugins.reduce((names, plugin) => {
|
||||
const id = plugin?.manifest?.id;
|
||||
const name = plugin?.manifest?.name;
|
||||
if (id && name) names[id] = name;
|
||||
return names;
|
||||
}, {});
|
||||
templatePlugins = localizedPlugins.reduce((result, plugin) => {
|
||||
const id = plugin?.manifest?.id;
|
||||
if (id) result[id] = plugin;
|
||||
return result;
|
||||
}, {});
|
||||
const [capabilityList] = resultOrError(capabilities, []);
|
||||
templateCapabilities = new Set((Array.isArray(capabilityList) ? capabilityList : []).map(capability => capability?.name).filter(Boolean));
|
||||
if (!workspaceTemplates.some(template => template.id === selectedTemplateId)) {
|
||||
selectedTemplateId = workspaceTemplates[0]?.id || '';
|
||||
}
|
||||
} catch (error) {
|
||||
createError = String(error);
|
||||
createError = reportError('workspaceTree.templatesError', 'Could not load Deal templates. Please try again.', error);
|
||||
workspaceTemplates = [];
|
||||
} finally {
|
||||
templatesLoading = false;
|
||||
@@ -111,7 +193,7 @@
|
||||
try {
|
||||
const [list, err] = resultOrError(await App.ListWorkspaces(), []);
|
||||
if (err) {
|
||||
localError = err;
|
||||
localError = reportError('workspaceTree.loadError', 'Could not load Deals. Please try again.', err);
|
||||
workspaces = [];
|
||||
} else {
|
||||
workspaces = list || [];
|
||||
@@ -132,7 +214,7 @@
|
||||
activeWorkspaceId.set(currentWorkspaceId);
|
||||
}
|
||||
} catch (e) {
|
||||
localError = String(e);
|
||||
localError = reportError('workspaceTree.loadError', 'Could not load Deals. Please try again.', e);
|
||||
}
|
||||
loading = false;
|
||||
}
|
||||
@@ -141,7 +223,7 @@
|
||||
const id = wsName(workspace);
|
||||
const err = await App.SetCurrentWorkspace(id);
|
||||
if (err) {
|
||||
localError = err;
|
||||
localError = reportError('workspaceTree.selectError', 'Could not select this Deal. Please try again.', err);
|
||||
return;
|
||||
}
|
||||
currentWorkspaceId = id;
|
||||
@@ -154,18 +236,23 @@
|
||||
async function doCreate() {
|
||||
const name = newWorkspaceName.trim();
|
||||
if (!name) {
|
||||
createError = 'Name is required';
|
||||
createError = tr('workspaceTree.nameRequired');
|
||||
return;
|
||||
}
|
||||
if (!selectedTemplate) {
|
||||
createError = 'Choose a workspace template';
|
||||
createError = tr('workspaceTree.chooseTemplate');
|
||||
return;
|
||||
}
|
||||
const creationIssues = selectedTemplateIssues.map(tool => ({
|
||||
pluginId: tool.pluginId,
|
||||
name: tool.name,
|
||||
reason: tool.reason,
|
||||
}));
|
||||
creating = true;
|
||||
createError = '';
|
||||
const [, err] = resultOrError(await App.CreateWorkspace(name, selectedTemplate.id), null);
|
||||
if (err) {
|
||||
createError = err;
|
||||
createError = reportError('workspaceTree.createError', 'Could not create the Deal. Please try again.', err);
|
||||
creating = false;
|
||||
return;
|
||||
}
|
||||
@@ -175,13 +262,14 @@
|
||||
await loadWorkspaces();
|
||||
const created = workspaces.find((ws) => wsName(ws) === name);
|
||||
if (created) await selectWorkspace(created);
|
||||
templateWarning = creationIssues.length > 0 ? { workspaceName: name, issues: creationIssues } : null;
|
||||
}
|
||||
|
||||
function openCreateDialog() {
|
||||
async function openCreateDialog() {
|
||||
showCreate = true;
|
||||
newWorkspaceName = '';
|
||||
createError = '';
|
||||
if (!workspaceTemplates.length && !templatesLoading) loadWorkspaceTemplates();
|
||||
await loadWorkspaceTemplates();
|
||||
}
|
||||
|
||||
function closeCreateDialog() {
|
||||
@@ -191,6 +279,10 @@
|
||||
createError = '';
|
||||
}
|
||||
|
||||
function dismissTemplateWarning() {
|
||||
templateWarning = null;
|
||||
}
|
||||
|
||||
function startRename(workspace) {
|
||||
renamingId = wsName(workspace);
|
||||
renameValue = renamingId;
|
||||
@@ -212,7 +304,7 @@
|
||||
busyId = oldName;
|
||||
const err = await App.RenameWorkspace(oldName, newName);
|
||||
if (err) {
|
||||
localError = err;
|
||||
localError = reportError('workspaceTree.renameError', 'Could not rename the Deal. Please try again.', err);
|
||||
busyId = '';
|
||||
return;
|
||||
}
|
||||
@@ -230,7 +322,7 @@
|
||||
busyId = name;
|
||||
const [, err] = resultOrError(await App.TrashWorkspace(name), null);
|
||||
if (err) {
|
||||
localError = err;
|
||||
localError = reportError('workspaceTree.trashError', 'Could not move the Deal to trash. Please try again.', err);
|
||||
busyId = '';
|
||||
return;
|
||||
}
|
||||
@@ -246,12 +338,12 @@
|
||||
|
||||
<div class="wt">
|
||||
<div class="wt-header">
|
||||
<span class="wt-title">Workspaces</span>
|
||||
<button class="wt-btn" on:click={openCreateDialog} title="New workspace" type="button">+</button>
|
||||
<span class="wt-title">{tr('workspaceTree.title')}</span>
|
||||
<button class="wt-btn" on:click={openCreateDialog} title={tr('workspaceTree.new')} type="button">+</button>
|
||||
</div>
|
||||
|
||||
{#if loading}
|
||||
<div class="wt-loading">Loading...</div>
|
||||
<div class="wt-loading">{tr('common.loading')}</div>
|
||||
{:else if localError}
|
||||
<div class="wt-error">{localError}</div>
|
||||
{/if}
|
||||
@@ -272,14 +364,14 @@
|
||||
if (e.key === 'Escape') cancelRename();
|
||||
}}
|
||||
/>
|
||||
<button class="wt-btn wt-btn-small wt-always" on:click={() => commitRename(workspace)} title="Save rename" type="button" disabled={busyId === id}>OK</button>
|
||||
<button class="wt-btn wt-btn-small wt-always" on:click={cancelRename} title="Cancel rename" type="button" disabled={busyId === id}>Cancel</button>
|
||||
<button class="wt-btn wt-btn-small wt-always" on:click={() => commitRename(workspace)} title={tr('workspaceTree.saveRename')} type="button" disabled={busyId === id}>{tr('common.save')}</button>
|
||||
<button class="wt-btn wt-btn-small wt-always" on:click={cancelRename} title={tr('common.cancel')} type="button" disabled={busyId === id}>{tr('common.cancel')}</button>
|
||||
{:else}
|
||||
<button class="wt-label" on:click={() => selectWorkspace(workspace)} type="button">{id}</button>
|
||||
<button class="wt-icon-btn" on:click={() => startRename(workspace)} title="Rename workspace" type="button" disabled={busyId === id}>
|
||||
<button class="wt-icon-btn" on:click={() => startRename(workspace)} title={tr('workspaceTree.rename')} type="button" disabled={busyId === id}>
|
||||
<Icon name="edit" size={12} />
|
||||
</button>
|
||||
<button class="wt-icon-btn danger" on:click={() => trashWorkspace(workspace)} title="Trash workspace" type="button" disabled={busyId === id}>
|
||||
<button class="wt-icon-btn danger" on:click={() => trashWorkspace(workspace)} title={tr('workspaceTree.trash')} type="button" disabled={busyId === id}>
|
||||
<Icon name="trash" size={12} />
|
||||
</button>
|
||||
{/if}
|
||||
@@ -288,21 +380,33 @@
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
{#if templateWarning}
|
||||
<section class="workspace-template-warning" data-workspace-template-warning role="alert">
|
||||
<div>
|
||||
<strong>{tr('workspaceTree.templateIncompleteCreated', { name: templateWarning.workspaceName })}</strong>
|
||||
{#each templateWarning.issues as issue (issue.pluginId)}
|
||||
<div class="workspace-template-warning-item">{issue.name}: {issue.reason}</div>
|
||||
{/each}
|
||||
</div>
|
||||
<button class="wt-btn" type="button" on:click={dismissTemplateWarning} title={tr('common.close')}>{tr('common.close')}</button>
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
{#if showCreate}
|
||||
<div class="workspace-create-overlay" data-workspace-create-modal role="dialog" aria-modal="true" aria-label="Create workspace">
|
||||
<div class="workspace-create-overlay" data-workspace-create-modal role="dialog" aria-modal="true" aria-label={tr('workspaceTree.create')}>
|
||||
<div class="workspace-create-modal">
|
||||
<div class="workspace-create-header">
|
||||
<div>
|
||||
<h2>New workspace</h2>
|
||||
<h2>{tr('workspaceTree.new')}</h2>
|
||||
</div>
|
||||
<button class="wt-btn" on:click={closeCreateDialog} type="button" disabled={creating}>Close</button>
|
||||
<button class="wt-btn" on:click={closeCreateDialog} type="button" disabled={creating}>{tr('common.close')}</button>
|
||||
</div>
|
||||
<label class="workspace-create-field">
|
||||
<span>Name</span>
|
||||
<input data-workspace-name type="text" bind:value={newWorkspaceName} placeholder="Workspace name" disabled={creating} on:keydown={(event) => event.key === 'Enter' && doCreate()} />
|
||||
<span>{tr('pluginCard.name')}</span>
|
||||
<input data-workspace-name type="text" bind:value={newWorkspaceName} placeholder={tr('workspaceTree.namePlaceholder')} disabled={creating} on:keydown={(event) => event.key === 'Enter' && doCreate()} />
|
||||
</label>
|
||||
<label class="workspace-create-field">
|
||||
<span>Template</span>
|
||||
<span>{tr('workspaceTree.template')}</span>
|
||||
<select data-workspace-template bind:value={selectedTemplateId} disabled={creating || templatesLoading || !workspaceTemplates.length}>
|
||||
{#each workspaceTemplates as template (template.id)}
|
||||
<option value={template.id}>{template.name}</option>
|
||||
@@ -313,18 +417,31 @@
|
||||
<div class="workspace-template-summary">
|
||||
<p data-workspace-template-description>{selectedTemplate.description}</p>
|
||||
<div class="workspace-template-tools" data-workspace-template-tools>
|
||||
{#each selectedTemplate.workspaceTools || [] as pluginId (pluginId)}
|
||||
<span>{toolLabel(pluginId)}</span>
|
||||
{#each selectedTemplateTools as tool (tool.pluginId)}
|
||||
<div
|
||||
class="workspace-template-tool"
|
||||
class:limited={tool.status === 'limited'}
|
||||
class:unavailable={tool.status === 'unavailable'}
|
||||
data-workspace-template-tool={tool.pluginId}
|
||||
data-template-tool-status={tool.status}
|
||||
>
|
||||
<span class="workspace-template-tool-name">{tool.name}</span>
|
||||
<span class="workspace-template-tool-tabs">{tool.tabs.length ? tr('workspaceTree.templateToolTabs', { tabs: tool.tabs.join(', ') }) : tr('workspaceTree.templateToolNoTabs')}</span>
|
||||
<span class="workspace-template-tool-reason">{tool.reason}</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{#if selectedTemplateIssues.length > 0}
|
||||
<p class="workspace-template-incomplete" data-workspace-template-incomplete>{tr('workspaceTree.templateWillBeIncomplete')}</p>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{#if createError}
|
||||
<p class="workspace-create-error" data-workspace-create-error role="alert">{createError}</p>
|
||||
{/if}
|
||||
<div class="workspace-create-actions">
|
||||
<button class="wt-btn-primary" on:click={doCreate} type="button" disabled={creating || templatesLoading || !selectedTemplate}>{creating ? 'Creating...' : 'Create workspace'}</button>
|
||||
<button class="wt-btn" on:click={closeCreateDialog} type="button" disabled={creating}>Cancel</button>
|
||||
<button class="wt-btn-primary" on:click={doCreate} type="button" disabled={creating || templatesLoading || !selectedTemplate}>{creating ? tr('workspaceTree.creating') : tr('workspaceTree.create')}</button>
|
||||
<button class="wt-btn" on:click={closeCreateDialog} type="button" disabled={creating}>{tr('common.cancel')}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -362,11 +479,25 @@
|
||||
.workspace-create-header h2 { margin: 0; font-size: 1rem; }
|
||||
.workspace-create-field { display: grid; gap: 0.35rem; color: var(--vt-color-text-muted); font-size: 0.75rem; }
|
||||
.workspace-create-field input, .workspace-create-field select { width: 100%; min-height: 2rem; box-sizing: border-box; border: 1px solid var(--vt-color-border-strong); border-radius: var(--vt-radius-sm); background: #0f1424; color: var(--vt-color-text-primary); padding: 0.35rem 0.5rem; font: inherit; font-size: 0.84rem; }
|
||||
.workspace-create-field select { appearance: none; background-color: #0f1424; background-image: linear-gradient(45deg, transparent 50%, var(--vt-color-text-muted) 50%), linear-gradient(135deg, var(--vt-color-text-muted) 50%, transparent 50%); background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 1.7rem; }
|
||||
.workspace-create-field select option { background: #0f1424; color: var(--vt-color-text-primary); }
|
||||
.workspace-create-field input:focus, .workspace-create-field select:focus { outline: none; border-color: var(--vt-color-accent); box-shadow: var(--vt-focus-ring); }
|
||||
.workspace-template-summary { display: grid; gap: 0.55rem; padding: 0.75rem; border: 1px solid var(--vt-color-border); border-radius: var(--vt-radius-md); background: var(--vt-color-surface-muted); }
|
||||
.workspace-template-summary p { margin: 0; color: var(--vt-color-text-secondary); font-size: 0.8rem; line-height: 1.45; }
|
||||
.workspace-template-tools { display: flex; flex-wrap: wrap; gap: 0.35rem; }
|
||||
.workspace-template-tools span { min-height: 1.35rem; display: inline-flex; align-items: center; padding: 0 0.35rem; border: 1px solid var(--vt-color-border-strong); border-radius: var(--vt-radius-sm); color: var(--vt-color-text-secondary); font-size: 0.72rem; }
|
||||
.workspace-template-tools { display: grid; gap: 0.4rem; }
|
||||
.workspace-template-tool { display: grid; grid-template-columns: minmax(7rem, 1fr) minmax(0, 1.4fr) minmax(0, 1.2fr); gap: 0.5rem; align-items: center; padding: 0.45rem 0.55rem; border: 1px solid var(--vt-color-border-strong); border-radius: var(--vt-radius-sm); color: var(--vt-color-text-secondary); font-size: 0.72rem; }
|
||||
.workspace-template-tool-name { color: var(--vt-color-text-primary); font-weight: 600; }
|
||||
.workspace-template-tool-tabs { color: var(--vt-color-text-muted); }
|
||||
.workspace-template-tool-reason { color: var(--vt-color-accent); }
|
||||
.workspace-template-tool.limited { border-color: rgba(220, 164, 57, 0.58); background: rgba(220, 164, 57, 0.08); }
|
||||
.workspace-template-tool.limited .workspace-template-tool-reason { color: #e8bc63; }
|
||||
.workspace-template-tool.unavailable { border-color: rgba(233, 69, 96, 0.58); background: var(--vt-color-danger-muted); }
|
||||
.workspace-template-tool.unavailable .workspace-template-tool-reason { color: var(--vt-color-danger); }
|
||||
.workspace-template-incomplete { color: var(--vt-color-danger) !important; }
|
||||
.workspace-template-warning { display: flex; gap: 0.5rem; align-items: flex-start; justify-content: space-between; margin: 0.25rem 0.6rem 0.5rem; padding: 0.6rem; border: 1px solid rgba(233, 69, 96, 0.58); border-radius: var(--vt-radius-md); background: var(--vt-color-danger-muted); color: var(--vt-color-text-secondary); font-size: 0.73rem; line-height: 1.4; }
|
||||
.workspace-template-warning strong { color: var(--vt-color-danger); }
|
||||
.workspace-template-warning-item { margin-top: 0.2rem; }
|
||||
@media (max-width: 700px) { .workspace-template-tool { grid-template-columns: 1fr; gap: 0.18rem; } }
|
||||
.workspace-create-error { margin: 0; color: var(--vt-color-danger); font-size: 0.78rem; line-height: 1.4; }
|
||||
.workspace-create-actions { display: flex; gap: 0.4rem; justify-content: flex-end; }
|
||||
.wt-btn-primary { background: var(--vt-color-accent); color: #101827; border: none; padding: 0.3rem 0.6rem; border-radius: var(--vt-radius-sm); cursor: pointer; font-size: 0.75rem; font-weight: 600; }
|
||||
|
||||
@@ -4,6 +4,12 @@
|
||||
* Каждый метод возвращает Promise с данными, совместимыми с Wails-контрактом.
|
||||
* Состояние мутабельно — тесты могут менять его между сценариями.
|
||||
*/
|
||||
import defaultEditorSource from '../../../../../verstak-official-plugins/plugins/default-editor/frontend/src/index.js?raw';
|
||||
import secretsSource from '../../../../../verstak-official-plugins/plugins/secrets/frontend/src/index.js?raw';
|
||||
import activitySource from '../../../../../verstak-official-plugins/plugins/activity/frontend/src/index.js?raw';
|
||||
import todoSource from '../../../../../verstak-official-plugins/plugins/todo/frontend/src/index.js?raw';
|
||||
import journalSource from '../../../../../verstak-official-plugins/plugins/journal/frontend/src/index.js?raw';
|
||||
|
||||
(function () {
|
||||
if (window.__wailsMockReady) return;
|
||||
|
||||
@@ -144,7 +150,7 @@
|
||||
name: 'Notes',
|
||||
version: '0.1.0',
|
||||
apiVersion: '0.1.0',
|
||||
description: 'Workspace-scoped notes manager.',
|
||||
description: 'Deal-scoped notes manager.',
|
||||
source: 'official',
|
||||
icon: 'edit',
|
||||
provides: ['verstak/notes/v1'],
|
||||
@@ -191,7 +197,7 @@
|
||||
name: 'Activity',
|
||||
version: '0.1.0',
|
||||
apiVersion: '0.1.0',
|
||||
description: 'Workspace-scoped activity log for public plugin events.',
|
||||
description: 'Deal-scoped activity log for public plugin events.',
|
||||
source: 'official',
|
||||
icon: 'activity',
|
||||
provides: ['activity.log', 'activity.provider', 'activity.reconstruction'],
|
||||
@@ -215,11 +221,11 @@
|
||||
name: 'Journal',
|
||||
version: '0.1.0',
|
||||
apiVersion: '0.1.0',
|
||||
description: 'Workspace-scoped journal with user-authored entries and optional Activity links.',
|
||||
description: 'Deal-scoped journal with user-authored entries and optional Activity links.',
|
||||
source: 'official',
|
||||
icon: 'book-open',
|
||||
provides: ['worklog', 'journal', 'report.worklog'],
|
||||
permissions: ['storage.namespace', 'ui.register'],
|
||||
permissions: ['events.publish', 'files.read', 'storage.namespace', 'ui.register'],
|
||||
frontend: { entry: 'frontend/dist/index.js' },
|
||||
contributes: {
|
||||
views: [{ id: 'verstak.journal.view', title: 'Journal', icon: 'book-open', component: 'JournalView' }],
|
||||
@@ -236,19 +242,19 @@
|
||||
manifest: {
|
||||
schemaVersion: 1,
|
||||
id: 'verstak.browser-inbox',
|
||||
name: 'Browser Inbox',
|
||||
name: 'Browser',
|
||||
version: '0.1.0',
|
||||
apiVersion: '0.1.0',
|
||||
description: 'Global browser capture queue with explicit workspace assignment.',
|
||||
description: 'Global browser materials with explicit Deal assignment.',
|
||||
source: 'official',
|
||||
icon: 'inbox',
|
||||
provides: ['browser.inbox'],
|
||||
permissions: ['events.subscribe', 'files.read', 'storage.namespace', 'ui.register'],
|
||||
frontend: { entry: 'frontend/dist/index.js' },
|
||||
contributes: {
|
||||
views: [{ id: 'verstak.browser-inbox.view', title: 'Browser Inbox', icon: 'inbox', component: 'BrowserInboxView' }],
|
||||
sidebarItems: [{ id: 'verstak.browser-inbox.sidebar', title: 'Browser Inbox', icon: 'inbox', view: 'verstak.browser-inbox.view', position: 30 }],
|
||||
workspaceItems: [{ id: 'verstak.browser-inbox.workspace', title: 'Browser Inbox', icon: 'inbox', component: 'BrowserInboxView' }]
|
||||
views: [{ id: 'verstak.browser-inbox.view', title: 'Browser', icon: 'inbox', component: 'BrowserInboxView' }],
|
||||
sidebarItems: [{ id: 'verstak.browser-inbox.sidebar', title: 'Browser', icon: 'inbox', view: 'verstak.browser-inbox.view', position: 30 }],
|
||||
workspaceItems: [{ id: 'verstak.browser-inbox.workspace', title: 'Browser', icon: 'inbox', component: 'BrowserInboxView' }]
|
||||
}
|
||||
},
|
||||
rootPath: '/tmp/verstak-test/plugins/browser-inbox',
|
||||
@@ -265,7 +271,7 @@
|
||||
name: 'Search',
|
||||
version: '0.1.0',
|
||||
apiVersion: '0.1.0',
|
||||
description: 'Workspace-scoped vault text search provider.',
|
||||
description: 'Deal-scoped vault text search provider.',
|
||||
source: 'official',
|
||||
icon: 'search',
|
||||
provides: ['verstak/search/v1', 'search.provider'],
|
||||
@@ -283,6 +289,64 @@
|
||||
}
|
||||
};
|
||||
|
||||
var russianPluginNames = {
|
||||
'verstak.platform-test': 'Тест платформы',
|
||||
'verstak.default-editor': 'Стандартный редактор',
|
||||
'verstak.files': 'Файлы',
|
||||
'verstak.notes': 'Заметки',
|
||||
'verstak.sync': 'Синхронизация',
|
||||
'verstak.activity': 'Активность',
|
||||
'verstak.journal': 'Журнал',
|
||||
'verstak.browser-inbox': 'Браузер',
|
||||
'verstak.search': 'Поиск',
|
||||
'verstak.trash': 'Корзина',
|
||||
'verstak.todo': 'Задачи',
|
||||
'verstak.secrets': 'Секреты'
|
||||
};
|
||||
var russianContributionLabels = {
|
||||
'verstak.platform-test.diagnostics': 'Диагностика платформы',
|
||||
'verstak.platform-test.run-tests': 'Запустить тесты платформы',
|
||||
'verstak.platform-test.show-version': 'Показать сведения о версии',
|
||||
'verstak.platform-test.sidebar': 'Тест платформы',
|
||||
'verstak.platform-test.status': '[OK] Все тесты пройдены',
|
||||
'verstak.platform-test.settings': 'Настройки теста платформы',
|
||||
'verstak.platform-test.markdown-diagnostic': 'Диагностика Markdown платформы',
|
||||
'verstak.search.searchVaultText': 'Искать текст в хранилище',
|
||||
'verstak.search.vault-text': 'Поиск по тексту хранилища'
|
||||
};
|
||||
Object.keys(pluginStates).forEach(function (pluginId) {
|
||||
var manifest = pluginStates[pluginId].manifest;
|
||||
manifest.localization = {
|
||||
defaultLocale: 'en',
|
||||
locales: { en: 'locales/en.json', ru: 'locales/ru.json' }
|
||||
};
|
||||
});
|
||||
|
||||
function mockPluginCatalog(pluginId, locale) {
|
||||
var state = pluginStates[pluginId];
|
||||
if (!state || !state.manifest) return {};
|
||||
var manifest = state.manifest;
|
||||
var translatedName = locale === 'ru' ? (russianPluginNames[pluginId] || manifest.name) : manifest.name;
|
||||
var catalog = {
|
||||
'manifest.name': translatedName,
|
||||
'manifest.description': manifest.description || ''
|
||||
};
|
||||
var contributionFields = {
|
||||
views: 'title', commands: 'title', settingsPanels: 'title', sidebarItems: 'title',
|
||||
fileActions: 'label', noteActions: 'label', contextMenuEntries: 'label',
|
||||
searchProviders: 'label', statusBarItems: 'label', openProviders: 'title', workspaceItems: 'title'
|
||||
};
|
||||
Object.keys(contributionFields).forEach(function (point) {
|
||||
var field = contributionFields[point];
|
||||
((manifest.contributes || {})[point] || []).forEach(function (item) {
|
||||
catalog['contributions.' + point + '.' + item.id + '.' + field] = locale === 'ru'
|
||||
? (russianContributionLabels[item.id] || translatedName)
|
||||
: item[field];
|
||||
});
|
||||
});
|
||||
return catalog;
|
||||
}
|
||||
|
||||
var vaultStatus = { status: 'open', path: '/tmp/verstak-test/vault', vaultId: 'test-vault-001' };
|
||||
var vaultPluginState = { enabledPlugins: ['verstak.platform-test', 'verstak.default-editor', 'verstak.files', 'verstak.notes', 'verstak.sync', 'verstak.activity', 'verstak.journal', 'verstak.browser-inbox', 'verstak.search'], disabledPlugins: [], desiredPlugins: [{ id: 'verstak.platform-test', version: '0.1.0', source: 'official' }, { id: 'verstak.default-editor', version: '0.1.0', source: 'official' }, { id: 'verstak.files', version: '0.1.0', source: 'official' }, { id: 'verstak.notes', version: '0.1.0', source: 'official' }, { id: 'verstak.sync', version: '0.1.0', source: 'official' }, { id: 'verstak.activity', version: '0.1.0', source: 'official' }, { id: 'verstak.journal', version: '0.1.0', source: 'official' }, { id: 'verstak.browser-inbox', version: '0.1.0', source: 'official' }, { id: 'verstak.search', version: '0.1.0', source: 'official' }] };
|
||||
vaultPluginState.enabledPlugins.push('verstak.trash');
|
||||
@@ -291,13 +355,19 @@
|
||||
vaultPluginState.desiredPlugins.push({ id: 'verstak.todo', version: '0.1.0', source: 'official' });
|
||||
vaultPluginState.enabledPlugins.push('verstak.secrets');
|
||||
vaultPluginState.desiredPlugins.push({ id: 'verstak.secrets', version: '0.1.0', source: 'official' });
|
||||
var appSettings = { currentVaultPath: '/tmp/verstak-test/vault', recentVaults: [] };
|
||||
var appSettings = {
|
||||
currentVaultPath: '/tmp/verstak-test/vault',
|
||||
recentVaults: [],
|
||||
language: localStorage.getItem('verstak-test-language') || 'system'
|
||||
};
|
||||
var workbenchPreferences = {};
|
||||
var openedResources = [];
|
||||
var pluginSettings = {
|
||||
'verstak.platform-test': { savedText: 'initial value' }
|
||||
};
|
||||
var pluginNotifications = {};
|
||||
var pluginData = {};
|
||||
var secretRecords = makeDefaultSecretRecords();
|
||||
var vaultFiles = makeDefaultVaultFiles();
|
||||
var externalOpens = [];
|
||||
var trashEntries = [];
|
||||
@@ -342,12 +412,33 @@
|
||||
return JSON.parse(JSON.stringify(value));
|
||||
}
|
||||
|
||||
function makeDefaultSecretRecords() {
|
||||
return [
|
||||
{
|
||||
id: 'first.secret',
|
||||
title: 'First secret',
|
||||
username: 'first-user',
|
||||
value: 'first-value',
|
||||
scope: { kind: 'global' },
|
||||
updatedAt: '2026-07-14T00:00:00Z'
|
||||
},
|
||||
{
|
||||
id: 'target.secret',
|
||||
title: 'Target secret',
|
||||
username: 'target-user',
|
||||
value: 'target-value',
|
||||
scope: { kind: 'global' },
|
||||
updatedAt: '2026-07-14T00:00:00Z'
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
function builtInWorkspaceTemplates() {
|
||||
return [
|
||||
{
|
||||
id: 'default',
|
||||
name: 'General',
|
||||
description: 'Everyday workspace with notes, files, journal, activity, and browser captures.',
|
||||
description: 'Everyday Deal with notes, files, journal, activity, and browser captures.',
|
||||
version: 2,
|
||||
workspaceTools: ['verstak.notes', 'verstak.files', 'verstak.journal', 'verstak.activity', 'verstak.browser-inbox'],
|
||||
folders: ['Notes', 'Files'],
|
||||
@@ -365,7 +456,7 @@
|
||||
{
|
||||
id: 'writing',
|
||||
name: 'Writing',
|
||||
description: 'Focused notes, files, and journal workspace for documentation and writing.',
|
||||
description: 'Focused notes, files, and journal Deal for documentation and writing.',
|
||||
version: 1,
|
||||
workspaceTools: ['verstak.notes', 'verstak.files', 'verstak.journal'],
|
||||
folders: ['Notes', 'Files'],
|
||||
@@ -374,7 +465,7 @@
|
||||
{
|
||||
id: 'admin',
|
||||
name: 'Admin',
|
||||
description: 'Infrastructure workspace with secrets, todos, and journal.',
|
||||
description: 'Infrastructure Deal with secrets, todos, and journal.',
|
||||
version: 1,
|
||||
workspaceTools: ['verstak.notes', 'verstak.files', 'verstak.secrets', 'verstak.todo', 'verstak.journal'],
|
||||
folders: ['Notes', 'Files', 'Secrets'],
|
||||
@@ -383,7 +474,7 @@
|
||||
{
|
||||
id: 'minimal',
|
||||
name: 'Minimal',
|
||||
description: 'Only notes and files for a lightweight workspace.',
|
||||
description: 'Only notes and files for a lightweight Deal.',
|
||||
version: 1,
|
||||
workspaceTools: ['verstak.notes', 'verstak.files'],
|
||||
folders: ['Notes', 'Files'],
|
||||
@@ -479,11 +570,12 @@
|
||||
name: 'Todos',
|
||||
version: '0.1.0',
|
||||
apiVersion: '0.1.0',
|
||||
description: 'Global and workspace todo tracking with due and reminder metadata.',
|
||||
description: 'Global and Deal-scoped todo tracking with due and reminder metadata.',
|
||||
source: 'official',
|
||||
icon: 'list-todo',
|
||||
provides: ['todo.list', 'todo.workspace'],
|
||||
permissions: ['files.read', 'storage.namespace', 'ui.register'],
|
||||
requires: ['verstak/core/notifications/v1'],
|
||||
permissions: ['files.read', 'storage.namespace', 'ui.register', 'notifications.schedule'],
|
||||
frontend: { entry: 'frontend/dist/index.js' },
|
||||
contributes: {
|
||||
views: [{ id: 'verstak.todo.view', title: 'Todos', icon: 'list-todo', component: 'TodoView' }],
|
||||
@@ -506,13 +598,22 @@
|
||||
name: 'Secrets',
|
||||
version: '0.1.0',
|
||||
apiVersion: '0.1.0',
|
||||
description: 'Encrypted global and workspace-scoped secret manager.',
|
||||
description: 'Encrypted global and Deal-scoped secret manager.',
|
||||
source: 'official',
|
||||
icon: 'key-round',
|
||||
provides: ['secret-store', 'secrets.read-ui', 'secrets.write-ui'],
|
||||
permissions: ['secrets.read', 'secrets.write', 'ui.register'],
|
||||
frontend: { entry: 'frontend/dist/index.js' },
|
||||
permissions: ['files.read', 'secrets.read', 'secrets.write', 'ui.register'],
|
||||
frontend: { entry: 'frontend/src/index.js' },
|
||||
contributes: {
|
||||
views: [{ id: 'verstak.secrets.view', title: 'Secrets', icon: 'key-round', component: 'SecretsView' }],
|
||||
sidebarItems: [{ id: 'verstak.secrets.sidebar', title: 'Secrets', icon: 'key-round', view: 'verstak.secrets.view', position: 45 }],
|
||||
openProviders: [{
|
||||
id: 'verstak.secrets.secret',
|
||||
title: 'Secrets',
|
||||
priority: 100,
|
||||
component: 'SecretsView',
|
||||
supports: [{ kind: 'secret', modes: ['view'] }]
|
||||
}],
|
||||
workspaceItems: [{ id: 'verstak.secrets.workspace', title: 'Secrets', icon: 'key-round', component: 'SecretsView' }]
|
||||
}
|
||||
},
|
||||
@@ -616,6 +717,7 @@
|
||||
caps.push({ name: 'verstak/core/files/v1', description: 'Files API', pluginId: 'verstak-desktop', status: 'stable' });
|
||||
caps.push({ name: 'verstak/core/workbench/v1', description: 'Workbench routing', pluginId: 'verstak-desktop', status: 'stable' });
|
||||
caps.push({ name: 'verstak/core/sync/v1', description: 'Sync API', pluginId: 'verstak-desktop', status: 'stable' });
|
||||
caps.push({ name: 'verstak/core/notifications/v1', description: 'Native notifications', pluginId: 'verstak-desktop', status: 'stable' });
|
||||
for (var id in pluginStates) {
|
||||
var s = pluginStates[id];
|
||||
if (s.status === 'loaded' && s.enabled && s.manifest && s.manifest.provides) {
|
||||
@@ -2354,7 +2456,7 @@
|
||||
}
|
||||
|
||||
function title(capture) {
|
||||
return capture.title || capture.fileName || capture.url || capture.captureId || 'Untitled capture';
|
||||
return capture.title || capture.fileName || capture.url || capture.captureId || 'Untitled material';
|
||||
}
|
||||
|
||||
function renderBrowserInbox(containerEl, props, api) {
|
||||
@@ -2371,7 +2473,7 @@
|
||||
containerEl.innerHTML = '';
|
||||
var root = el('div', { className: 'browser-inbox-root', 'data-plugin-id': PLUGIN_ID });
|
||||
var toolbar = el('div', { className: 'browser-inbox-toolbar' });
|
||||
var titleEl = el('span', { className: 'browser-inbox-title', textContent: rootPath ? 'Browser Inbox · ' + rootPath : 'Browser Inbox' });
|
||||
var titleEl = el('span', { className: 'browser-inbox-title', textContent: rootPath ? 'Browser · ' + rootPath : 'Browser' });
|
||||
var countEl = el('span', { className: 'browser-inbox-count' });
|
||||
var statusEl = el('span', { className: 'browser-inbox-status' });
|
||||
var filtersEl = el('div', { className: 'browser-inbox-filters' });
|
||||
@@ -2455,7 +2557,7 @@
|
||||
function renderWorkspaceFilterOptions() {
|
||||
if (rootPath) return;
|
||||
workspaceFilterEl.innerHTML = '';
|
||||
workspaceFilterEl.appendChild(option('', 'All workspaces'));
|
||||
workspaceFilterEl.appendChild(option('', 'All Deals'));
|
||||
workspaceRoots().forEach(function (workspace) {
|
||||
workspaceFilterEl.appendChild(option(workspace, workspace));
|
||||
});
|
||||
@@ -2528,7 +2630,7 @@
|
||||
}) : captures).map(function (capture) { return capture.captureId; });
|
||||
captures = captures.filter(function (capture) { return ids.indexOf(capture.captureId) === -1; });
|
||||
selectedId = '';
|
||||
statusText = rootPath ? 'Workspace captures cleared' : 'Inbox cleared';
|
||||
statusText = rootPath ? 'Deal materials cleared' : 'Inbox cleared';
|
||||
return persist();
|
||||
}
|
||||
|
||||
@@ -2570,7 +2672,7 @@
|
||||
listEl.appendChild(el('div', {
|
||||
className: 'browser-inbox-empty',
|
||||
textContent: captures.length === 0
|
||||
? 'No browser captures yet. Keep this view open, then send a page, selection, link, or file from the browser extension.'
|
||||
? 'No browser materials yet. Send a page, selection, or link from the extension.'
|
||||
: 'No captures match the current filters.'
|
||||
}));
|
||||
return;
|
||||
@@ -2615,7 +2717,7 @@
|
||||
el('div', { className: 'browser-inbox-meta-value', textContent: capture.domain || '-' }),
|
||||
el('div', { className: 'browser-inbox-meta-label', textContent: 'Browser' }),
|
||||
el('div', { className: 'browser-inbox-meta-value', textContent: capture.browserName || capture.source || '-' }),
|
||||
el('div', { className: 'browser-inbox-meta-label', textContent: 'Workspace' }),
|
||||
el('div', { className: 'browser-inbox-meta-label', textContent: 'Deal' }),
|
||||
el('div', { className: 'browser-inbox-meta-value', textContent: capture.workspaceRootPath || 'Unassigned' }),
|
||||
el('div', { className: 'browser-inbox-meta-label', textContent: 'Status' }),
|
||||
el('div', { className: 'browser-inbox-meta-value', textContent: capture.processed ? 'Processed' : 'Unprocessed' })
|
||||
@@ -3263,6 +3365,46 @@
|
||||
}
|
||||
return Promise.resolve({});
|
||||
},
|
||||
GetPluginLocalization: function (pluginId, locale) {
|
||||
return Promise.resolve([mockPluginCatalog(pluginId, locale), '']);
|
||||
},
|
||||
PluginSecretsStatus: function () {
|
||||
return Promise.resolve([{ initialized: true, unlocked: true }, '']);
|
||||
},
|
||||
PluginSecretsUnlock: function () {
|
||||
return Promise.resolve('');
|
||||
},
|
||||
PluginSecretsList: function () {
|
||||
return Promise.resolve([secretRecords.map(function (record) {
|
||||
var listed = cloneJson(record);
|
||||
delete listed.value;
|
||||
return listed;
|
||||
}), '']);
|
||||
},
|
||||
PluginSecretsRead: function (_pluginId, secretID) {
|
||||
var record = secretRecords.find(function (item) { return item.id === secretID; });
|
||||
if (!record) return Promise.resolve([{}, 'not-found: secret ' + secretID]);
|
||||
return Promise.resolve([cloneJson(record), '']);
|
||||
},
|
||||
PluginSecretsWrite: function (_pluginId, nextRecord) {
|
||||
var record = Object.assign({}, nextRecord || {});
|
||||
if (!record.id) return Promise.resolve([{}, 'secret id is required']);
|
||||
record.scope = record.scope || { kind: 'global' };
|
||||
record.updatedAt = new Date().toISOString();
|
||||
var index = secretRecords.findIndex(function (item) { return item.id === record.id; });
|
||||
if (index === -1) secretRecords.push(record);
|
||||
else secretRecords[index] = record;
|
||||
return Promise.resolve([cloneJson(record), '']);
|
||||
},
|
||||
PluginSecretsDelete: function (_pluginId, secretID) {
|
||||
secretRecords = secretRecords.filter(function (record) { return record.id !== secretID; });
|
||||
return Promise.resolve('');
|
||||
},
|
||||
PluginSecretsCopyLink: function (_pluginId, secretID) {
|
||||
var record = secretRecords.find(function (item) { return item.id === secretID; });
|
||||
if (!record) return Promise.resolve(['', 'not-found: secret ' + secretID]);
|
||||
return Promise.resolve(['[' + (record.title || record.id) + '](verstak-secret://' + encodeURIComponent(record.id) + ')', '']);
|
||||
},
|
||||
ReadPluginSettings: function (pluginId) {
|
||||
return Promise.resolve([Object.assign({}, pluginSettings[pluginId] || {}), '']);
|
||||
},
|
||||
@@ -3270,17 +3412,48 @@
|
||||
pluginSettings[pluginId] = Object.assign({}, settings || {});
|
||||
return Promise.resolve('');
|
||||
},
|
||||
ReadPluginSetting: function () { return Promise.resolve(null); },
|
||||
WritePluginSetting: function () { return Promise.resolve(null); },
|
||||
ReadPluginSetting: function (pluginId, key) {
|
||||
return Promise.resolve([pluginSettings[pluginId] && pluginSettings[pluginId][key], '']);
|
||||
},
|
||||
WritePluginSetting: function (pluginId, key, value) {
|
||||
pluginSettings[pluginId] = pluginSettings[pluginId] || {};
|
||||
pluginSettings[pluginId][key] = value;
|
||||
return Promise.resolve('');
|
||||
},
|
||||
ReplacePluginNotifications: function (pluginId, items) {
|
||||
pluginNotifications[pluginId] = Array.isArray(items) ? items.slice() : [];
|
||||
return Promise.resolve('');
|
||||
},
|
||||
ClearPluginNotifications: function (pluginId) {
|
||||
delete pluginNotifications[pluginId];
|
||||
return Promise.resolve('');
|
||||
},
|
||||
ReadPluginDataJSON: function (pluginId, name) {
|
||||
var data = (pluginData[pluginId] && pluginData[pluginId][name]) || {};
|
||||
return Promise.resolve([Object.assign({}, data), '']);
|
||||
},
|
||||
ReadPluginDataNDJSON: function (pluginId, name) {
|
||||
var data = (pluginData[pluginId] && pluginData[pluginId][name]) || [];
|
||||
if (!Array.isArray(data) && pluginId === 'verstak.activity' && name === 'activity-events') data = [];
|
||||
if (!data.length && pluginId === 'verstak.activity' && name === 'activity-events') {
|
||||
data = Object.keys(pluginSettings[pluginId] || {}).filter(function (key) {
|
||||
return key === 'events' || key === 'events:global' || key.indexOf('events:workspace:') === 0;
|
||||
}).flatMap(function (key) {
|
||||
return Array.isArray(pluginSettings[pluginId][key]) ? pluginSettings[pluginId][key] : [];
|
||||
});
|
||||
}
|
||||
return Promise.resolve([Array.isArray(data) ? data.slice() : [], '']);
|
||||
},
|
||||
WritePluginDataJSON: function (pluginId, name, data) {
|
||||
pluginData[pluginId] = pluginData[pluginId] || {};
|
||||
pluginData[pluginId][name] = Object.assign({}, data || {});
|
||||
return Promise.resolve('');
|
||||
},
|
||||
WritePluginDataNDJSON: function (pluginId, name, records) {
|
||||
pluginData[pluginId] = pluginData[pluginId] || {};
|
||||
pluginData[pluginId][name] = Array.isArray(records) ? records.slice() : [];
|
||||
return Promise.resolve('');
|
||||
},
|
||||
OpenWorkbenchResource: function (pluginId, request) {
|
||||
return openWorkbenchResource(pluginId, request || {}, '');
|
||||
},
|
||||
@@ -3373,8 +3546,8 @@
|
||||
if (pluginId === 'verstak.platform-test' && assetPath === 'frontend/dist/index.js') {
|
||||
return Promise.resolve(platformTestBundle());
|
||||
}
|
||||
if (pluginId === 'verstak.default-editor' && assetPath === 'frontend/dist/index.js') {
|
||||
return Promise.resolve(defaultEditorBundle());
|
||||
if (pluginId === 'verstak.default-editor') {
|
||||
return Promise.resolve(defaultEditorSource);
|
||||
}
|
||||
if (pluginId === 'verstak.files' && assetPath === 'frontend/dist/index.js') {
|
||||
return Promise.resolve(filesPluginBundle());
|
||||
@@ -3385,20 +3558,20 @@
|
||||
if (pluginId === 'verstak.notes' && assetPath === 'frontend/dist/index.js') {
|
||||
return Promise.resolve(simplePluginBundle('verstak.notes', 'NotesView', 'notes-root', 'Notes'));
|
||||
}
|
||||
if (pluginId === 'verstak.activity' && assetPath === 'frontend/dist/index.js') {
|
||||
return Promise.resolve(activityBundle());
|
||||
if (pluginId === 'verstak.activity') {
|
||||
return Promise.resolve(activitySource);
|
||||
}
|
||||
if (pluginId === 'verstak.journal' && assetPath === 'frontend/dist/index.js') {
|
||||
return Promise.resolve(journalBundle());
|
||||
return Promise.resolve(journalSource);
|
||||
}
|
||||
if (pluginId === 'verstak.browser-inbox' && assetPath === 'frontend/dist/index.js') {
|
||||
return Promise.resolve(browserInboxBundle());
|
||||
}
|
||||
if (pluginId === 'verstak.todo' && assetPath === 'frontend/dist/index.js') {
|
||||
return Promise.resolve(todoBundle());
|
||||
return Promise.resolve(todoSource);
|
||||
}
|
||||
if (pluginId === 'verstak.secrets' && assetPath === 'frontend/dist/index.js') {
|
||||
return Promise.resolve(simplePluginBundle('verstak.secrets', 'SecretsView', 'secrets-root', 'Secrets'));
|
||||
if (pluginId === 'verstak.secrets') {
|
||||
return Promise.resolve(secretsSource);
|
||||
}
|
||||
if (pluginId === 'verstak.search' && assetPath === 'frontend/dist/index.js') {
|
||||
return Promise.resolve(searchPluginBundle());
|
||||
@@ -3613,6 +3786,13 @@
|
||||
window.__wailsMockExternalOpens = externalOpens.slice();
|
||||
return Promise.resolve('');
|
||||
},
|
||||
OpenExternalURL: function (pluginId, rawURL) {
|
||||
var err = requirePluginPermission(pluginId, 'files.openExternal');
|
||||
if (err) return Promise.resolve(err);
|
||||
externalOpens.push({ action: 'url', path: String(rawURL || '') });
|
||||
window.__wailsMockExternalOpens = externalOpens.slice();
|
||||
return Promise.resolve('');
|
||||
},
|
||||
ShowVaultPathInFolder: function (pluginId, relativePath) {
|
||||
var err = requirePluginPermission(pluginId, 'files.openExternal');
|
||||
if (err) return Promise.resolve(err);
|
||||
@@ -3736,7 +3916,11 @@
|
||||
OpenVault: function () { return Promise.resolve(null); },
|
||||
CloseVault: function () { return Promise.resolve(null); },
|
||||
SetCurrentVault: function () { return Promise.resolve(''); },
|
||||
UpdateAppSettings: function () { return Promise.resolve(''); },
|
||||
UpdateAppSettings: function (patch) {
|
||||
appSettings = Object.assign({}, appSettings, patch || {});
|
||||
if (patch && patch.language) localStorage.setItem('verstak-test-language', patch.language);
|
||||
return Promise.resolve('');
|
||||
},
|
||||
RecordDesiredPlugin: function () { return Promise.resolve(''); },
|
||||
WriteFrontendLog: function () { return Promise.resolve(); },
|
||||
|
||||
@@ -3920,7 +4104,7 @@
|
||||
name: 'Notes',
|
||||
version: '0.1.0',
|
||||
apiVersion: '0.1.0',
|
||||
description: 'Workspace-scoped notes manager.',
|
||||
description: 'Deal-scoped notes manager.',
|
||||
source: 'official',
|
||||
icon: 'edit',
|
||||
provides: ['verstak/notes/v1'],
|
||||
@@ -3967,7 +4151,7 @@
|
||||
name: 'Activity',
|
||||
version: '0.1.0',
|
||||
apiVersion: '0.1.0',
|
||||
description: 'Workspace-scoped activity log for public plugin events.',
|
||||
description: 'Deal-scoped activity log for public plugin events.',
|
||||
source: 'official',
|
||||
icon: 'activity',
|
||||
provides: ['activity.log', 'activity.provider', 'activity.reconstruction'],
|
||||
@@ -3991,11 +4175,11 @@
|
||||
name: 'Journal',
|
||||
version: '0.1.0',
|
||||
apiVersion: '0.1.0',
|
||||
description: 'Workspace-scoped journal with user-authored entries and optional Activity links.',
|
||||
description: 'Deal-scoped journal with user-authored entries and optional Activity links.',
|
||||
source: 'official',
|
||||
icon: 'book-open',
|
||||
provides: ['worklog', 'journal', 'report.worklog'],
|
||||
permissions: ['storage.namespace', 'ui.register'],
|
||||
permissions: ['events.publish', 'files.read', 'storage.namespace', 'ui.register'],
|
||||
frontend: { entry: 'frontend/dist/index.js' },
|
||||
contributes: {
|
||||
views: [{ id: 'verstak.journal.view', title: 'Journal', icon: 'book-open', component: 'JournalView' }],
|
||||
@@ -4012,19 +4196,19 @@
|
||||
manifest: {
|
||||
schemaVersion: 1,
|
||||
id: 'verstak.browser-inbox',
|
||||
name: 'Browser Inbox',
|
||||
name: 'Browser',
|
||||
version: '0.1.0',
|
||||
apiVersion: '0.1.0',
|
||||
description: 'Global browser capture queue with explicit workspace assignment.',
|
||||
description: 'Global browser materials with explicit Deal assignment.',
|
||||
source: 'official',
|
||||
icon: 'inbox',
|
||||
provides: ['browser.inbox'],
|
||||
permissions: ['events.subscribe', 'files.read', 'storage.namespace', 'ui.register'],
|
||||
frontend: { entry: 'frontend/dist/index.js' },
|
||||
contributes: {
|
||||
views: [{ id: 'verstak.browser-inbox.view', title: 'Browser Inbox', icon: 'inbox', component: 'BrowserInboxView' }],
|
||||
sidebarItems: [{ id: 'verstak.browser-inbox.sidebar', title: 'Browser Inbox', icon: 'inbox', view: 'verstak.browser-inbox.view', position: 30 }],
|
||||
workspaceItems: [{ id: 'verstak.browser-inbox.workspace', title: 'Browser Inbox', icon: 'inbox', component: 'BrowserInboxView' }]
|
||||
views: [{ id: 'verstak.browser-inbox.view', title: 'Browser', icon: 'inbox', component: 'BrowserInboxView' }],
|
||||
sidebarItems: [{ id: 'verstak.browser-inbox.sidebar', title: 'Browser', icon: 'inbox', view: 'verstak.browser-inbox.view', position: 30 }],
|
||||
workspaceItems: [{ id: 'verstak.browser-inbox.workspace', title: 'Browser', icon: 'inbox', component: 'BrowserInboxView' }]
|
||||
}
|
||||
},
|
||||
rootPath: '/tmp/verstak-test/plugins/browser-inbox',
|
||||
@@ -4041,7 +4225,7 @@
|
||||
name: 'Search',
|
||||
version: '0.1.0',
|
||||
apiVersion: '0.1.0',
|
||||
description: 'Workspace-scoped vault text search provider.',
|
||||
description: 'Deal-scoped vault text search provider.',
|
||||
source: 'official',
|
||||
icon: 'search',
|
||||
provides: ['verstak/search/v1', 'search.provider'],
|
||||
@@ -4066,10 +4250,13 @@
|
||||
vaultPluginState.desiredPlugins.push({ id: 'verstak.todo', version: '0.1.0', source: 'official' });
|
||||
vaultPluginState.enabledPlugins.push('verstak.secrets');
|
||||
vaultPluginState.desiredPlugins.push({ id: 'verstak.secrets', version: '0.1.0', source: 'official' });
|
||||
appSettings = { currentVaultPath: '/tmp/verstak-test/vault', recentVaults: [] };
|
||||
localStorage.removeItem('verstak-test-language');
|
||||
appSettings = { currentVaultPath: '/tmp/verstak-test/vault', recentVaults: [], language: 'system' };
|
||||
workbenchPreferences = {};
|
||||
openedResources = [];
|
||||
pluginSettings = { 'verstak.platform-test': { savedText: 'initial value' } };
|
||||
pluginNotifications = {};
|
||||
secretRecords = makeDefaultSecretRecords();
|
||||
vaultFiles = makeDefaultVaultFiles();
|
||||
externalOpens = [];
|
||||
trashEntries = [];
|
||||
@@ -4089,8 +4276,9 @@
|
||||
getPluginState: function (pluginId) {
|
||||
return pluginStates[pluginId] ? Object.assign({}, pluginStates[pluginId]) : null;
|
||||
},
|
||||
addSyntheticPlugins: function (count) {
|
||||
addSyntheticPlugins: function (count, source) {
|
||||
var total = Number(count || 0);
|
||||
var pluginSource = source === 'official' || source === 'local' || source === 'third-party' ? source : 'third-party';
|
||||
for (var i = 1; i <= total; i++) {
|
||||
var id = 'verstak.synthetic-layout-' + String(i).padStart(2, '0');
|
||||
pluginStates[id] = {
|
||||
@@ -4103,7 +4291,7 @@
|
||||
version: '0.0.' + i,
|
||||
apiVersion: '0.1.0',
|
||||
description: 'Synthetic plugin used by frontend layout tests.',
|
||||
source: 'test',
|
||||
source: pluginSource,
|
||||
provides: ['verstak/synthetic-layout-' + i + '/v1'],
|
||||
requires: [],
|
||||
optionalRequires: [],
|
||||
@@ -4123,7 +4311,7 @@
|
||||
vaultPluginState.enabledPlugins.push(id);
|
||||
}
|
||||
if (!vaultPluginState.desiredPlugins.some(function (p) { return p.id === id; })) {
|
||||
vaultPluginState.desiredPlugins.push({ id: id, version: '0.0.' + i, source: 'test' });
|
||||
vaultPluginState.desiredPlugins.push({ id: id, version: '0.0.' + i, source: pluginSource });
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,7 +1,33 @@
|
||||
import App from './App.svelte';
|
||||
import * as Backend from '../wailsjs/go/api/App';
|
||||
import { i18n } from './lib/i18n/index.js';
|
||||
|
||||
const app = new App({
|
||||
target: document.getElementById('app'),
|
||||
function unpack(result) {
|
||||
if (Array.isArray(result) && result.length === 2 && (typeof result[1] === 'string' || result[1] == null)) {
|
||||
if (result[1]) throw new Error(result[1]);
|
||||
return result[0];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
i18n.configure({
|
||||
loadPluginCatalog: async (pluginId, locale) => unpack(await Backend.GetPluginLocalization(pluginId, locale)),
|
||||
});
|
||||
|
||||
async function start() {
|
||||
try {
|
||||
const settings = await Backend.GetAppSettings();
|
||||
await i18n.initialize(settings?.language || 'system');
|
||||
} catch (error) {
|
||||
console.error('[i18n] initialization failed:', error);
|
||||
await i18n.initialize('system');
|
||||
}
|
||||
|
||||
return new App({
|
||||
target: document.getElementById('app'),
|
||||
});
|
||||
}
|
||||
|
||||
const app = start();
|
||||
|
||||
export default app;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import vm from 'node:vm';
|
||||
|
||||
const source = fs.readFileSync(path.resolve('frontend/src/lib/log/debug.js'), 'utf8');
|
||||
const values = new Map();
|
||||
const localStorage = {
|
||||
getItem(key) { return values.has(key) ? values.get(key) : null; },
|
||||
setItem(key, value) { values.set(key, String(value)); },
|
||||
removeItem(key) { values.delete(key); },
|
||||
};
|
||||
const context = vm.createContext({
|
||||
console: { log() {} },
|
||||
localStorage,
|
||||
window: { location: { search: '' } },
|
||||
});
|
||||
const module = new vm.SourceTextModule(source, { context, identifier: 'debug.js' });
|
||||
await module.link(() => { throw new Error('debug.js must not import modules'); });
|
||||
await module.evaluate();
|
||||
|
||||
const { debug } = module.namespace;
|
||||
debug.enable({ persist: false });
|
||||
|
||||
assert.equal(debug.isEnabled(), true, 'session debug should enable diagnostics');
|
||||
assert.equal(
|
||||
localStorage.getItem('verstak-debug'),
|
||||
null,
|
||||
'a --debug session must not make diagnostics persist into ordinary launches',
|
||||
);
|
||||
|
||||
console.log('debug mode smoke passed');
|
||||
@@ -0,0 +1,112 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
createI18n,
|
||||
resolveLocale,
|
||||
} from '../src/lib/i18n/index.js';
|
||||
import englishShellCatalog from '../src/lib/i18n/catalogs/en.js';
|
||||
import russianShellCatalog from '../src/lib/i18n/catalogs/ru.js';
|
||||
|
||||
assert.deepEqual(
|
||||
Object.keys(russianShellCatalog).sort(),
|
||||
Object.keys(englishShellCatalog).sort(),
|
||||
'English and Russian shell catalogs must have identical keys',
|
||||
);
|
||||
|
||||
assert.equal(resolveLocale('system', ['ru-RU']), 'ru');
|
||||
assert.equal(resolveLocale('system', ['uk-UA', 'en-US']), 'en');
|
||||
assert.equal(resolveLocale('ru', ['en-US']), 'ru');
|
||||
assert.equal(resolveLocale('en', ['ru-RU']), 'en');
|
||||
assert.throws(() => resolveLocale('de', ['de-DE']), /unsupported language/);
|
||||
|
||||
const catalogs = {
|
||||
'localized.plugin': {
|
||||
en: { 'manifest.name': 'Localized Plugin', greeting: 'Hello, {name}!' },
|
||||
ru: {
|
||||
'manifest.name': 'Локализованный плагин',
|
||||
'contributions.views.localized.view.title': 'Локализованный экран',
|
||||
greeting: 'Привет, {name}!',
|
||||
},
|
||||
},
|
||||
};
|
||||
const loads = [];
|
||||
const service = createI18n({
|
||||
shellCatalogs: {
|
||||
en: { loading: 'Loading {name}...', fallbackOnly: 'English fallback' },
|
||||
ru: { loading: 'Загрузка {name}...' },
|
||||
},
|
||||
systemLanguages: () => ['ru-RU'],
|
||||
loadPluginCatalog: async (pluginId, locale) => {
|
||||
loads.push(`${pluginId}:${locale}`);
|
||||
return catalogs[pluginId]?.[locale] || {};
|
||||
},
|
||||
});
|
||||
|
||||
await service.initialize('system');
|
||||
assert.equal(service.getLanguagePreference(), 'system');
|
||||
assert.equal(service.getLocale(), 'ru');
|
||||
assert.equal(service.t('loading', { name: 'Верстак' }), 'Загрузка Верстак...');
|
||||
assert.equal(service.t('fallbackOnly'), 'English fallback');
|
||||
assert.equal(service.t('missing', undefined, 'Explicit fallback'), 'Explicit fallback');
|
||||
assert.equal(service.t('unknown'), 'unknown');
|
||||
|
||||
await service.loadPlugin('localized.plugin', {
|
||||
defaultLocale: 'en',
|
||||
locales: { en: 'locales/en.json', ru: 'locales/ru.json' },
|
||||
});
|
||||
assert.deepEqual(loads.sort(), ['localized.plugin:en', 'localized.plugin:ru']);
|
||||
assert.equal(service.translatePlugin('localized.plugin', 'greeting', { name: 'Мир' }), 'Привет, Мир!');
|
||||
|
||||
const plugin = {
|
||||
manifest: {
|
||||
id: 'localized.plugin',
|
||||
name: 'Localized Plugin',
|
||||
description: 'Literal description',
|
||||
contributes: {
|
||||
views: [{ id: 'localized.view', title: 'Literal View', component: 'View' }],
|
||||
},
|
||||
},
|
||||
};
|
||||
const localized = service.localizePlugin(plugin);
|
||||
assert.notEqual(localized, plugin);
|
||||
assert.equal(localized.manifest.name, 'Локализованный плагин');
|
||||
assert.equal(localized.manifest.description, 'Literal description');
|
||||
assert.equal(localized.manifest.contributes.views[0].title, 'Локализованный экран');
|
||||
assert.equal(plugin.manifest.name, 'Localized Plugin');
|
||||
const summary = service.localizeContributionSummary({
|
||||
views: [{ pluginId: 'localized.plugin', id: 'localized.view', title: 'Literal View', component: 'View' }],
|
||||
});
|
||||
assert.equal(summary.views[0].title, 'Локализованный экран');
|
||||
|
||||
let notifications = 0;
|
||||
const unsubscribe = service.subscribe(() => { notifications += 1; });
|
||||
assert.equal(notifications, 1);
|
||||
await service.setLanguagePreference('en');
|
||||
assert.equal(service.getLocale(), 'en');
|
||||
assert.equal(service.translatePlugin('localized.plugin', 'greeting', { name: 'World' }), 'Hello, World!');
|
||||
assert.equal(notifications, 2);
|
||||
unsubscribe();
|
||||
await service.setLanguagePreference('ru');
|
||||
assert.equal(notifications, 2);
|
||||
|
||||
const resilientService = createI18n({
|
||||
shellCatalogs: { en: { title: 'Title' }, ru: { title: 'Заголовок' } },
|
||||
systemLanguages: () => ['en-US'],
|
||||
loadPluginCatalog: async () => { throw new Error('broken catalog'); },
|
||||
});
|
||||
await resilientService.initialize('en');
|
||||
await assert.rejects(
|
||||
resilientService.loadPlugin('broken.plugin', {
|
||||
defaultLocale: 'en',
|
||||
locales: { en: 'locales/en.json', ru: 'locales/ru.json' },
|
||||
}),
|
||||
/broken catalog/,
|
||||
);
|
||||
let resilientNotification = '';
|
||||
resilientService.subscribe((nextLocale) => { resilientNotification = nextLocale; });
|
||||
await resilientService.setLanguagePreference('ru');
|
||||
assert.equal(resilientService.getLanguagePreference(), 'ru');
|
||||
assert.equal(resilientService.getLocale(), 'ru');
|
||||
assert.equal(resilientNotification, 'ru');
|
||||
assert.equal(resilientService.t('title'), 'Заголовок');
|
||||
|
||||
console.log('i18n service tests passed');
|
||||
@@ -0,0 +1,36 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const files = [
|
||||
'src/lib/shell/CommandPalette.svelte',
|
||||
'src/lib/plugin-manager/PluginManager.svelte',
|
||||
'src/lib/shell/VaultSelection.svelte',
|
||||
'src/lib/shell/WorkspaceTree.svelte',
|
||||
'src/lib/plugin-host/PluginBundleHost.svelte',
|
||||
];
|
||||
const patterns = [
|
||||
/(?:^|\n)\s*(?:error|localError|createError)\s*=\s*(?:err|String\()/,
|
||||
/(?:^|\n)\s*error\s*=\s*['"].*['"]\s*\+\s*(?:err|String\()/,
|
||||
/tr\([^\n]*\{\s*error\s*:/,
|
||||
];
|
||||
const violations = [];
|
||||
|
||||
for (const relativePath of files) {
|
||||
const source = fs.readFileSync(path.join(root, relativePath), 'utf8');
|
||||
for (const pattern of patterns) {
|
||||
if (pattern.test(source)) violations.push(relativePath);
|
||||
}
|
||||
}
|
||||
|
||||
if (violations.length) {
|
||||
throw new Error(`Technical backend errors reach desktop UI in: ${[...new Set(violations)].join(', ')}`);
|
||||
}
|
||||
|
||||
const bundleHost = fs.readFileSync(path.join(root, 'src/lib/plugin-host/PluginBundleHost.svelte'), 'utf8');
|
||||
if (!/<p class="error-message">\{errorText \|\| tr\('bundle\.unknownError'\)\}<\/p>\s*<details class="error-details">/.test(bundleHost)) {
|
||||
throw new Error('Plugin bundle errors must keep the user-facing message outside expandable technical details');
|
||||
}
|
||||
|
||||
console.log('desktop UI does not interpolate raw backend errors');
|
||||
@@ -3,6 +3,7 @@ import path from 'node:path';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
|
||||
const pluginData = {};
|
||||
const scheduledNotifications = [];
|
||||
|
||||
globalThis.window = {
|
||||
__VERSTAK_PLUGIN_REGISTRY__: {},
|
||||
@@ -38,15 +39,40 @@ globalThis.window = {
|
||||
pluginData[pluginId][name] = Object.assign({}, data || {});
|
||||
return Promise.resolve('');
|
||||
},
|
||||
ReplacePluginNotifications: (pluginId, items) => {
|
||||
scheduledNotifications.push({ pluginId, items });
|
||||
return Promise.resolve(items[0]?.id === 'rejected' ? 'notification permission denied' : '');
|
||||
},
|
||||
ClearPluginNotifications: (pluginId) => {
|
||||
scheduledNotifications.push({ pluginId, clear: true });
|
||||
return Promise.resolve('');
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
globalThis.__mockApp = window.go.api.App;
|
||||
const localeListeners = new Set();
|
||||
globalThis.__mockI18n = {
|
||||
getLocale: () => 'ru',
|
||||
translatePlugin: (_pluginId, key, params, fallback) => {
|
||||
const messages = { greeting: 'Привет, {name}!' };
|
||||
const message = messages[key] || fallback || key;
|
||||
return message.replace(/\{([^}]+)\}/g, (placeholder, name) => (
|
||||
Object.prototype.hasOwnProperty.call(params || {}, name) ? String(params[name]) : placeholder
|
||||
));
|
||||
},
|
||||
subscribe: (listener) => {
|
||||
localeListeners.add(listener);
|
||||
listener('ru');
|
||||
return () => localeListeners.delete(listener);
|
||||
},
|
||||
};
|
||||
|
||||
const sourcePath = path.resolve('frontend/src/lib/plugin-host/VerstakPluginAPI.js');
|
||||
const source = fs.readFileSync(sourcePath, 'utf8')
|
||||
.replace("import * as App from '../../../wailsjs/go/api/App';", 'const App = globalThis.__mockApp;');
|
||||
.replace("import * as App from '../../../wailsjs/go/api/App';", 'const App = globalThis.__mockApp;')
|
||||
.replace("import { i18n } from '../i18n/index.js';", 'const i18n = globalThis.__mockI18n;');
|
||||
const tempPath = path.resolve('/tmp/verstak-plugin-api-contributions-test.mjs');
|
||||
fs.writeFileSync(tempPath, source);
|
||||
|
||||
@@ -59,6 +85,17 @@ if (!api.contributions || typeof api.contributions.list !== 'function') {
|
||||
if (!api.commands || typeof api.commands.executeFor !== 'function') {
|
||||
throw new Error('api.commands.executeFor is missing');
|
||||
}
|
||||
if (!api.i18n || typeof api.i18n.getLocale !== 'function' || typeof api.i18n.t !== 'function' || typeof api.i18n.onDidChangeLocale !== 'function') {
|
||||
throw new Error('api.i18n contract is missing');
|
||||
}
|
||||
if (api.i18n.getLocale() !== 'ru' || api.i18n.t('greeting', { name: 'Мир' }) !== 'Привет, Мир!') {
|
||||
throw new Error('api.i18n locale or translation is incorrect');
|
||||
}
|
||||
let localeNotifications = 0;
|
||||
api.i18n.onDidChangeLocale(() => { localeNotifications += 1; });
|
||||
if (localeNotifications !== 1 || localeListeners.size !== 1) {
|
||||
throw new Error('api.i18n locale subscription was not registered');
|
||||
}
|
||||
|
||||
const fileActions = await api.contributions.list('fileActions');
|
||||
if (fileActions.length !== 1 || fileActions[0].id !== 'provider.file.action') {
|
||||
@@ -88,4 +125,31 @@ if (stored.version !== 1 || stored.workspaceRootPath !== 'Project') {
|
||||
throw new Error(`unexpected storage data: ${JSON.stringify(stored)}`);
|
||||
}
|
||||
|
||||
if (!api.notifications || typeof api.notifications.replace !== 'function' || typeof api.notifications.clear !== 'function') {
|
||||
throw new Error('api.notifications replace/clear contract is missing');
|
||||
}
|
||||
await api.notifications.replace([{ id: 'reminder-1', dueAt: '2026-07-14T10:00:00Z', title: 'Reminder' }]);
|
||||
await api.notifications.clear();
|
||||
if (scheduledNotifications.length !== 2
|
||||
|| scheduledNotifications[0].pluginId !== 'verstak.files'
|
||||
|| scheduledNotifications[0].items[0].id !== 'reminder-1'
|
||||
|| scheduledNotifications[1].pluginId !== 'verstak.files'
|
||||
|| !scheduledNotifications[1].clear) {
|
||||
throw new Error(`unexpected notification calls: ${JSON.stringify(scheduledNotifications)}`);
|
||||
}
|
||||
let rejected = false;
|
||||
try {
|
||||
await api.notifications.replace([{ id: 'rejected', dueAt: '2026-07-14T10:00:00Z', title: 'Reminder' }]);
|
||||
} catch (err) {
|
||||
rejected = String(err.message || err).includes('[plugin:verstak.files] notifications.replace failed: notification permission denied');
|
||||
}
|
||||
if (!rejected) {
|
||||
throw new Error('notification backend errors must be plugin-scoped rejections');
|
||||
}
|
||||
|
||||
api.dispose();
|
||||
if (localeListeners.size !== 0) {
|
||||
throw new Error('api.i18n locale subscription was not disposed');
|
||||
}
|
||||
|
||||
console.log('plugin api contributions smoke passed');
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
|
||||
const source = await readFile(new URL('../src/lib/shell/WorkspaceTree.svelte', import.meta.url), 'utf8');
|
||||
|
||||
assert.match(source, /\.workspace-create-field select\s*\{[^}]*appearance:\s*none/, 'workspace template select must hide the native arrow');
|
||||
assert.match(source, /\.workspace-create-field select option\s*\{[^}]*background/, 'workspace template options must use the application surface');
|
||||
|
||||
console.log('workspace select style contract passed');
|
||||
@@ -0,0 +1,28 @@
|
||||
import en from '../src/lib/i18n/catalogs/en.js';
|
||||
import ru from '../src/lib/i18n/catalogs/ru.js';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const forbidden = [
|
||||
['English catalog', /\bworkspace(?:s)?\b/i],
|
||||
['Russian catalog', /рабоч(?:ее|ие|ем|его|их)\s+пространств(?:о|а|е)?/i],
|
||||
];
|
||||
|
||||
for (const [name, pattern] of forbidden) {
|
||||
const violations = Object.entries(name === 'English catalog' ? en : ru)
|
||||
.filter(([, value]) => pattern.test(value));
|
||||
if (violations.length) {
|
||||
throw new Error(`${name} still exposes workspace terminology: ${violations.map(([key]) => key).join(', ')}`);
|
||||
}
|
||||
}
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const overview = fs.readFileSync(path.join(root, 'src/lib/shell/TodaySurface.svelte'), 'utf8');
|
||||
for (const phrase of ['Workspace opened', 'Workspace activity', 'Workspace overview note']) {
|
||||
if (overview.includes(phrase)) {
|
||||
throw new Error(`Overview exposes workspace terminology: ${phrase}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('desktop user terminology uses Deal/Дело');
|
||||
@@ -0,0 +1,13 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const bindingsPath = path.resolve('frontend/wailsjs/go/api/App.js');
|
||||
const bindings = fs.readFileSync(bindingsPath, 'utf8');
|
||||
|
||||
for (const method of ['ReplacePluginNotifications', 'ClearPluginNotifications']) {
|
||||
if (!bindings.includes(`export function ${method}(`)) {
|
||||
throw new Error(`Wails binding does not export ${method}`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Wails notification bindings are present');
|
||||
@@ -1,3 +1,4 @@
|
||||
import { resolve } from 'node:path';
|
||||
import { defineConfig } from 'vite';
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
||||
|
||||
@@ -13,6 +14,9 @@ export default defineConfig(({ mode }) => {
|
||||
server: {
|
||||
port: isTest ? 5174 : 5173,
|
||||
strictPort: true,
|
||||
fs: {
|
||||
allow: [resolve(__dirname, '..', '..')],
|
||||
},
|
||||
},
|
||||
optimizeDeps: {
|
||||
include: [
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
import {workspace} from '../models';
|
||||
import {context} from '../models';
|
||||
import {workbench} from '../models';
|
||||
import {capability} from '../models';
|
||||
import {api} from '../models';
|
||||
import {permissions} from '../models';
|
||||
import {plugin} from '../models';
|
||||
import {files} from '../models';
|
||||
import {notifications} from '../models';
|
||||
|
||||
export function ArchiveWorkspaceNode(arg1:string):Promise<string>;
|
||||
|
||||
export function ClearPluginNotifications(arg1:string):Promise<string>;
|
||||
|
||||
export function CloseVault():Promise<void>;
|
||||
|
||||
export function CreateVault(arg1:string):Promise<void>;
|
||||
@@ -24,6 +28,8 @@ export function DeleteVaultTrash(arg1:string,arg2:string):Promise<string>;
|
||||
|
||||
export function DisablePlugin(arg1:string):Promise<string>;
|
||||
|
||||
export function DomReady(arg1:context.Context):Promise<void>;
|
||||
|
||||
export function EditWorkbenchResource(arg1:string,arg2:Record<string, any>):Promise<workbench.OpenResourceResult|string>;
|
||||
|
||||
export function EnablePlugin(arg1:string):Promise<string>;
|
||||
@@ -48,6 +54,8 @@ export function GetPluginCapability(arg1:string,arg2:string):Promise<Record<stri
|
||||
|
||||
export function GetPluginFrontendInfo(arg1:string):Promise<Record<string, any>>;
|
||||
|
||||
export function GetPluginLocalization(arg1:string,arg2:string):Promise<Record<string, string>|string>;
|
||||
|
||||
export function GetPlugins():Promise<Array<plugin.Plugin>>;
|
||||
|
||||
export function GetVaultFileMetadata(arg1:string,arg2:string):Promise<files.FileMetadata|string>;
|
||||
@@ -70,14 +78,18 @@ export function ListVaultFiles(arg1:string,arg2:string):Promise<Array<files.File
|
||||
|
||||
export function ListVaultTrash(arg1:string):Promise<Array<files.TrashEntry>|string>;
|
||||
|
||||
export function ListWorkspaces():Promise<Array<workspace.Workspace>|string>;
|
||||
export function ListWorkspaceIdentities():Promise<Array<workspace.WorkspaceIdentity>|string>;
|
||||
|
||||
export function ListWorkspaceTemplates():Promise<Array<workspace.WorkspaceTemplate>|string>;
|
||||
|
||||
export function ListWorkspaces():Promise<Array<workspace.Workspace>|string>;
|
||||
|
||||
export function MoveVaultPath(arg1:string,arg2:string,arg3:string,arg4:files.MoveOptions):Promise<string>;
|
||||
|
||||
export function MoveWorkspaceNode(arg1:string,arg2:string):Promise<string>;
|
||||
|
||||
export function OpenExternalURL(arg1:string,arg2:string):Promise<string>;
|
||||
|
||||
export function OpenVault(arg1:string):Promise<void>;
|
||||
|
||||
export function OpenVaultPathExternal(arg1:string,arg2:string):Promise<string>;
|
||||
@@ -118,8 +130,14 @@ export function PluginSyncTestConnection(arg1:string,arg2:string,arg3:string,arg
|
||||
|
||||
export function PublishPluginEvent(arg1:string,arg2:string,arg3:Record<string, any>):Promise<string>;
|
||||
|
||||
export function PurgeWorkspaceTrash(arg1:string):Promise<string>;
|
||||
|
||||
export function Quit():Promise<void>;
|
||||
|
||||
export function ReadPluginDataJSON(arg1:string,arg2:string):Promise<Record<string, any>>;
|
||||
|
||||
export function ReadPluginDataNDJSON(arg1:string,arg2:string):Promise<Array<Record<string, any>>>;
|
||||
|
||||
export function ReadPluginSetting(arg1:string,arg2:string):Promise<any>;
|
||||
|
||||
export function ReadPluginSettings(arg1:string):Promise<Record<string, any>|string>;
|
||||
@@ -136,8 +154,14 @@ export function RenameWorkspace(arg1:string,arg2:string):Promise<string>;
|
||||
|
||||
export function RenameWorkspaceNode(arg1:string,arg2:string):Promise<string>;
|
||||
|
||||
export function RepairWorkspaceIdentity(arg1:string,arg2:string):Promise<string>;
|
||||
|
||||
export function ReplacePluginNotifications(arg1:string,arg2:Array<notifications.Request>):Promise<string>;
|
||||
|
||||
export function RestoreVaultTrash(arg1:string,arg2:string,arg3:files.RestoreOptions):Promise<string|string>;
|
||||
|
||||
export function RestoreWorkspaceTrash(arg1:string,arg2:string):Promise<workspace.Workspace|string>;
|
||||
|
||||
export function SelectDirectory():Promise<string>;
|
||||
|
||||
export function SelectVaultForOpen():Promise<string>;
|
||||
@@ -148,8 +172,14 @@ export function SetCurrentWorkspace(arg1:string):Promise<string>;
|
||||
|
||||
export function SetCurrentWorkspaceNode(arg1:string):Promise<string>;
|
||||
|
||||
export function SetNotificationService(arg1:api.notificationService):Promise<void>;
|
||||
|
||||
export function ShowVaultPathInFolder(arg1:string,arg2:string):Promise<string>;
|
||||
|
||||
export function ShowWindow():Promise<void>;
|
||||
|
||||
export function Shutdown(arg1:context.Context):Promise<void>;
|
||||
|
||||
export function SubscribePluginEvent(arg1:string,arg2:string):Promise<string>;
|
||||
|
||||
export function TrashVaultPath(arg1:string,arg2:string):Promise<files.TrashResult|string>;
|
||||
@@ -166,6 +196,8 @@ export function WriteFrontendLog(arg1:string,arg2:string):Promise<void>;
|
||||
|
||||
export function WritePluginDataJSON(arg1:string,arg2:string,arg3:Record<string, any>):Promise<string>;
|
||||
|
||||
export function WritePluginDataNDJSON(arg1:string,arg2:string,arg3:Array<Record<string, any>>):Promise<string>;
|
||||
|
||||
export function WritePluginSetting(arg1:string,arg2:string,arg3:any):Promise<string>;
|
||||
|
||||
export function WritePluginSettings(arg1:string,arg2:Record<string, any>):Promise<string>;
|
||||
|
||||
@@ -6,6 +6,10 @@ export function ArchiveWorkspaceNode(arg1) {
|
||||
return window['go']['api']['App']['ArchiveWorkspaceNode'](arg1);
|
||||
}
|
||||
|
||||
export function ClearPluginNotifications(arg1) {
|
||||
return window['go']['api']['App']['ClearPluginNotifications'](arg1);
|
||||
}
|
||||
|
||||
export function CloseVault() {
|
||||
return window['go']['api']['App']['CloseVault']();
|
||||
}
|
||||
@@ -34,6 +38,10 @@ export function DisablePlugin(arg1) {
|
||||
return window['go']['api']['App']['DisablePlugin'](arg1);
|
||||
}
|
||||
|
||||
export function DomReady(arg1) {
|
||||
return window['go']['api']['App']['DomReady'](arg1);
|
||||
}
|
||||
|
||||
export function EditWorkbenchResource(arg1, arg2) {
|
||||
return window['go']['api']['App']['EditWorkbenchResource'](arg1, arg2);
|
||||
}
|
||||
@@ -82,6 +90,10 @@ export function GetPluginFrontendInfo(arg1) {
|
||||
return window['go']['api']['App']['GetPluginFrontendInfo'](arg1);
|
||||
}
|
||||
|
||||
export function GetPluginLocalization(arg1, arg2) {
|
||||
return window['go']['api']['App']['GetPluginLocalization'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function GetPlugins() {
|
||||
return window['go']['api']['App']['GetPlugins']();
|
||||
}
|
||||
@@ -126,14 +138,18 @@ export function ListVaultTrash(arg1) {
|
||||
return window['go']['api']['App']['ListVaultTrash'](arg1);
|
||||
}
|
||||
|
||||
export function ListWorkspaces() {
|
||||
return window['go']['api']['App']['ListWorkspaces']();
|
||||
export function ListWorkspaceIdentities() {
|
||||
return window['go']['api']['App']['ListWorkspaceIdentities']();
|
||||
}
|
||||
|
||||
export function ListWorkspaceTemplates() {
|
||||
return window['go']['api']['App']['ListWorkspaceTemplates']();
|
||||
}
|
||||
|
||||
export function ListWorkspaces() {
|
||||
return window['go']['api']['App']['ListWorkspaces']();
|
||||
}
|
||||
|
||||
export function MoveVaultPath(arg1, arg2, arg3, arg4) {
|
||||
return window['go']['api']['App']['MoveVaultPath'](arg1, arg2, arg3, arg4);
|
||||
}
|
||||
@@ -142,6 +158,10 @@ export function MoveWorkspaceNode(arg1, arg2) {
|
||||
return window['go']['api']['App']['MoveWorkspaceNode'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function OpenExternalURL(arg1, arg2) {
|
||||
return window['go']['api']['App']['OpenExternalURL'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function OpenVault(arg1) {
|
||||
return window['go']['api']['App']['OpenVault'](arg1);
|
||||
}
|
||||
@@ -222,10 +242,22 @@ export function PublishPluginEvent(arg1, arg2, arg3) {
|
||||
return window['go']['api']['App']['PublishPluginEvent'](arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
export function PurgeWorkspaceTrash(arg1) {
|
||||
return window['go']['api']['App']['PurgeWorkspaceTrash'](arg1);
|
||||
}
|
||||
|
||||
export function Quit() {
|
||||
return window['go']['api']['App']['Quit']();
|
||||
}
|
||||
|
||||
export function ReadPluginDataJSON(arg1, arg2) {
|
||||
return window['go']['api']['App']['ReadPluginDataJSON'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function ReadPluginDataNDJSON(arg1, arg2) {
|
||||
return window['go']['api']['App']['ReadPluginDataNDJSON'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function ReadPluginSetting(arg1, arg2) {
|
||||
return window['go']['api']['App']['ReadPluginSetting'](arg1, arg2);
|
||||
}
|
||||
@@ -258,10 +290,22 @@ export function RenameWorkspaceNode(arg1, arg2) {
|
||||
return window['go']['api']['App']['RenameWorkspaceNode'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function RepairWorkspaceIdentity(arg1, arg2) {
|
||||
return window['go']['api']['App']['RepairWorkspaceIdentity'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function ReplacePluginNotifications(arg1, arg2) {
|
||||
return window['go']['api']['App']['ReplacePluginNotifications'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function RestoreVaultTrash(arg1, arg2, arg3) {
|
||||
return window['go']['api']['App']['RestoreVaultTrash'](arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
export function RestoreWorkspaceTrash(arg1, arg2) {
|
||||
return window['go']['api']['App']['RestoreWorkspaceTrash'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function SelectDirectory() {
|
||||
return window['go']['api']['App']['SelectDirectory']();
|
||||
}
|
||||
@@ -282,10 +326,22 @@ export function SetCurrentWorkspaceNode(arg1) {
|
||||
return window['go']['api']['App']['SetCurrentWorkspaceNode'](arg1);
|
||||
}
|
||||
|
||||
export function SetNotificationService(arg1) {
|
||||
return window['go']['api']['App']['SetNotificationService'](arg1);
|
||||
}
|
||||
|
||||
export function ShowVaultPathInFolder(arg1, arg2) {
|
||||
return window['go']['api']['App']['ShowVaultPathInFolder'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function ShowWindow() {
|
||||
return window['go']['api']['App']['ShowWindow']();
|
||||
}
|
||||
|
||||
export function Shutdown(arg1) {
|
||||
return window['go']['api']['App']['Shutdown'](arg1);
|
||||
}
|
||||
|
||||
export function SubscribePluginEvent(arg1, arg2) {
|
||||
return window['go']['api']['App']['SubscribePluginEvent'](arg1, arg2);
|
||||
}
|
||||
@@ -318,6 +374,10 @@ export function WritePluginDataJSON(arg1, arg2, arg3) {
|
||||
return window['go']['api']['App']['WritePluginDataJSON'](arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
export function WritePluginDataNDJSON(arg1, arg2, arg3) {
|
||||
return window['go']['api']['App']['WritePluginDataNDJSON'](arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
export function WritePluginSetting(arg1, arg2, arg3) {
|
||||
return window['go']['api']['App']['WritePluginSetting'](arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ module github.com/verstak/verstak-desktop
|
||||
go 1.24.4
|
||||
|
||||
require (
|
||||
fyne.io/systray v1.12.2
|
||||
github.com/google/uuid v1.6.0
|
||||
github.com/wailsapp/wails/v2 v2.12.0
|
||||
golang.org/x/net v0.35.0
|
||||
)
|
||||
|
||||
require (
|
||||
@@ -32,7 +34,6 @@ require (
|
||||
github.com/wailsapp/go-webview2 v1.0.22 // indirect
|
||||
github.com/wailsapp/mimetype v1.4.1 // indirect
|
||||
golang.org/x/crypto v0.33.0 // indirect
|
||||
golang.org/x/net v0.35.0 // indirect
|
||||
golang.org/x/sys v0.30.0 // indirect
|
||||
golang.org/x/text v0.22.0 // indirect
|
||||
)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
fyne.io/systray v1.12.2 h1:Y8DZxgLHsVQt6rY9Zrkkg+j67S7vv/1F2viOWKPpVeA=
|
||||
fyne.io/systray v1.12.2/go.mod h1:RVwqP9nYMo7h5zViCBHri2FgjXF7H2cub7MAq4NSoLs=
|
||||
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3 h1:N3IGoHHp9pb6mj1cbXbuaSXV/UMKwmbKLf53nQmtqMA=
|
||||
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3/go.mod h1:QtOLZGz8olr4qH2vWK0QH0w0O4T9fEIjMuWpKUsH7nc=
|
||||
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
|
||||
|
||||
@@ -3,21 +3,26 @@ package api
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
|
||||
"github.com/verstak/verstak-desktop/internal/core/appsettings"
|
||||
"github.com/verstak/verstak-desktop/internal/core/browserreceiver"
|
||||
"github.com/verstak/verstak-desktop/internal/core/capability"
|
||||
"github.com/verstak/verstak-desktop/internal/core/contribution"
|
||||
"github.com/verstak/verstak-desktop/internal/core/events"
|
||||
corefiles "github.com/verstak/verstak-desktop/internal/core/files"
|
||||
"github.com/verstak/verstak-desktop/internal/core/notifications"
|
||||
"github.com/verstak/verstak-desktop/internal/core/plugin"
|
||||
"github.com/verstak/verstak-desktop/internal/core/storage"
|
||||
syncsvc "github.com/verstak/verstak-desktop/internal/core/sync"
|
||||
@@ -25,6 +30,44 @@ import (
|
||||
"github.com/verstak/verstak-desktop/internal/core/workspace"
|
||||
)
|
||||
|
||||
type fakeNotificationScheduler struct {
|
||||
replaceCalls int
|
||||
clearCalls int
|
||||
startCalls int
|
||||
stopCalls int
|
||||
pluginID string
|
||||
requests []notifications.Request
|
||||
onStart func()
|
||||
onStop func()
|
||||
}
|
||||
|
||||
func (s *fakeNotificationScheduler) Replace(pluginID string, requests []notifications.Request) error {
|
||||
s.replaceCalls++
|
||||
s.pluginID = pluginID
|
||||
s.requests = append([]notifications.Request(nil), requests...)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *fakeNotificationScheduler) Clear(pluginID string) error {
|
||||
s.clearCalls++
|
||||
s.pluginID = pluginID
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *fakeNotificationScheduler) Start(context.Context) {
|
||||
s.startCalls++
|
||||
if s.onStart != nil {
|
||||
s.onStart()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *fakeNotificationScheduler) Stop() {
|
||||
s.stopCalls++
|
||||
if s.onStop != nil {
|
||||
s.onStop()
|
||||
}
|
||||
}
|
||||
|
||||
func newLocalHTTPTestServer(t *testing.T, handler http.Handler) *httptest.Server {
|
||||
t.Helper()
|
||||
|
||||
@@ -75,6 +118,18 @@ func newTestApp(tmpRoot string) *App {
|
||||
}
|
||||
}
|
||||
|
||||
func newNotificationsTestApp(manifest plugin.Manifest) (*App, *fakeNotificationScheduler) {
|
||||
scheduler := &fakeNotificationScheduler{}
|
||||
return &App{
|
||||
plugins: []plugin.Plugin{{
|
||||
Manifest: manifest,
|
||||
Status: plugin.StatusLoaded,
|
||||
Enabled: true,
|
||||
}},
|
||||
notifications: scheduler,
|
||||
}, scheduler
|
||||
}
|
||||
|
||||
func newFilesTestApp(t *testing.T, perms []string) (*App, string) {
|
||||
t.Helper()
|
||||
v := vault.NewVault(nil)
|
||||
@@ -132,6 +187,220 @@ func newSyncFilesTestApp(t *testing.T, perms []string, deviceID string) (*App, s
|
||||
return app, root
|
||||
}
|
||||
|
||||
func TestReplacePluginNotificationsRequiresCapabilityAndPermission(t *testing.T) {
|
||||
requests := []notifications.Request{{ID: "reminder", DueAt: "2026-07-14T10:00:00Z", Title: "Reminder"}}
|
||||
for _, manifest := range []plugin.Manifest{
|
||||
{ID: "notifications.test", Permissions: []string{"notifications.schedule"}},
|
||||
{ID: "notifications.test", Requires: []string{"verstak/core/notifications/v1"}},
|
||||
} {
|
||||
app, scheduler := newNotificationsTestApp(manifest)
|
||||
if got := app.ReplacePluginNotifications(manifest.ID, requests); got == "" {
|
||||
t.Fatalf("manifest %#v unexpectedly scheduled notifications", manifest)
|
||||
}
|
||||
if scheduler.replaceCalls != 0 {
|
||||
t.Fatalf("rejected request called scheduler %d times", scheduler.replaceCalls)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplaceAndClearPluginNotificationsStayWithinPluginNamespace(t *testing.T) {
|
||||
manifest := plugin.Manifest{
|
||||
ID: "notifications.test",
|
||||
Permissions: []string{"notifications.schedule"},
|
||||
Requires: []string{"verstak/core/notifications/v1"},
|
||||
}
|
||||
app, scheduler := newNotificationsTestApp(manifest)
|
||||
requests := []notifications.Request{{ID: "reminder", DueAt: "2026-07-14T10:00:00Z", Title: "Reminder"}}
|
||||
if got := app.ReplacePluginNotifications(manifest.ID, requests); got != "" {
|
||||
t.Fatalf("ReplacePluginNotifications error = %q", got)
|
||||
}
|
||||
if scheduler.replaceCalls != 1 || scheduler.pluginID != manifest.ID || len(scheduler.requests) != 1 {
|
||||
t.Fatalf("scheduler state = %#v", scheduler)
|
||||
}
|
||||
if got := app.ClearPluginNotifications(manifest.ID); got != "" {
|
||||
t.Fatalf("ClearPluginNotifications error = %q", got)
|
||||
}
|
||||
if scheduler.clearCalls != 1 || scheduler.pluginID != manifest.ID {
|
||||
t.Fatalf("clear state = %#v", scheduler)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReloadPluginsRestoresNotificationCoreCapability(t *testing.T) {
|
||||
app := &App{
|
||||
capRegistry: capability.NewRegistry(),
|
||||
contribRegistry: contribution.NewRegistry(),
|
||||
}
|
||||
|
||||
app.ReloadPlugins()
|
||||
|
||||
if !app.capRegistry.Has("verstak/core/notifications/v1") {
|
||||
t.Fatal("ReloadPlugins did not restore verstak/core/notifications/v1")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDomReadyInitializesNotificationsBeforeScheduler(t *testing.T) {
|
||||
oldInitialize := initializeNativeNotifications
|
||||
defer func() { initializeNativeNotifications = oldInitialize }()
|
||||
|
||||
order := []string{}
|
||||
initializeNativeNotifications = func(context.Context) error {
|
||||
order = append(order, "initialize")
|
||||
return nil
|
||||
}
|
||||
app, scheduler := newNotificationsTestApp(plugin.Manifest{ID: "notifications.test"})
|
||||
scheduler.onStart = func() { order = append(order, "start") }
|
||||
|
||||
app.DomReady(context.Background())
|
||||
|
||||
if got, want := strings.Join(order, ","), "initialize,start"; got != want {
|
||||
t.Fatalf("notification startup order = %q, want %q", got, want)
|
||||
}
|
||||
if scheduler.startCalls != 1 {
|
||||
t.Fatalf("scheduler start calls = %d, want 1", scheduler.startCalls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDomReadyDoesNotStartSchedulerWhenNotificationInitializationFails(t *testing.T) {
|
||||
oldInitialize := initializeNativeNotifications
|
||||
defer func() { initializeNativeNotifications = oldInitialize }()
|
||||
|
||||
initializeNativeNotifications = func(context.Context) error { return fmt.Errorf("unavailable") }
|
||||
app, scheduler := newNotificationsTestApp(plugin.Manifest{ID: "notifications.test"})
|
||||
|
||||
app.DomReady(context.Background())
|
||||
|
||||
if scheduler.startCalls != 0 {
|
||||
t.Fatalf("scheduler start calls = %d, want 0 when native notifications are unavailable", scheduler.startCalls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShutdownStopsSchedulerBeforeCleaningUpNotifications(t *testing.T) {
|
||||
oldCleanup := cleanupNativeNotifications
|
||||
defer func() { cleanupNativeNotifications = oldCleanup }()
|
||||
|
||||
order := []string{}
|
||||
cleanupNativeNotifications = func(context.Context) { order = append(order, "cleanup") }
|
||||
app, scheduler := newNotificationsTestApp(plugin.Manifest{ID: "notifications.test"})
|
||||
scheduler.onStop = func() { order = append(order, "stop") }
|
||||
|
||||
app.Shutdown(context.Background())
|
||||
|
||||
if got, want := strings.Join(order, ","), "stop,cleanup"; got != want {
|
||||
t.Fatalf("notification shutdown order = %q, want %q", got, want)
|
||||
}
|
||||
if scheduler.stopCalls != 1 {
|
||||
t.Fatalf("scheduler stop calls = %d, want 1", scheduler.stopCalls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNativeNotificationSenderUsesStablePluginScopedID(t *testing.T) {
|
||||
oldSend := sendNativeNotification
|
||||
defer func() { sendNativeNotification = oldSend }()
|
||||
|
||||
var gotTitle, gotBody, gotID string
|
||||
sendNativeNotification = func(_ context.Context, options runtime.NotificationOptions) error {
|
||||
gotID = options.ID
|
||||
gotTitle = options.Title
|
||||
gotBody = options.Body
|
||||
return nil
|
||||
}
|
||||
|
||||
err := NewNativeNotificationSender().Send(context.Background(), notifications.Item{
|
||||
PluginID: "verstak.todo",
|
||||
ID: "task-42",
|
||||
Title: "Todo reminder",
|
||||
Body: "Prepare alpha release",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Send() error = %v", err)
|
||||
}
|
||||
if gotID != "verstak:verstak.todo:task-42" || gotTitle != "Todo reminder" || gotBody != "Prepare alpha release" {
|
||||
t.Fatalf("native notification = id=%q title=%q body=%q", gotID, gotTitle, gotBody)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBeforeCloseAllowsExitUntilTrayIsReady(t *testing.T) {
|
||||
oldHide := hideNativeWindow
|
||||
defer func() { hideNativeWindow = oldHide }()
|
||||
|
||||
hideCalls := 0
|
||||
hideNativeWindow = func(context.Context) { hideCalls++ }
|
||||
app := &App{}
|
||||
|
||||
if prevent := app.BeforeClose(context.Background()); prevent {
|
||||
t.Fatal("BeforeClose() = true, want false while tray is unavailable")
|
||||
}
|
||||
if hideCalls != 0 {
|
||||
t.Fatalf("hide calls = %d, want 0", hideCalls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBeforeCloseHidesWindowAfterTrayIsReady(t *testing.T) {
|
||||
oldHide := hideNativeWindow
|
||||
defer func() { hideNativeWindow = oldHide }()
|
||||
|
||||
hideCalls := 0
|
||||
hideNativeWindow = func(context.Context) { hideCalls++ }
|
||||
app := &App{}
|
||||
app.SetTrayReady(true)
|
||||
|
||||
if prevent := app.BeforeClose(context.Background()); !prevent {
|
||||
t.Fatal("BeforeClose() = false, want true while tray is ready")
|
||||
}
|
||||
if hideCalls != 1 {
|
||||
t.Fatalf("hide calls = %d, want 1", hideCalls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrayQuitAllowsWindowCloseAndQuitsApplication(t *testing.T) {
|
||||
oldQuit := quitNativeApplication
|
||||
defer func() { quitNativeApplication = oldQuit }()
|
||||
|
||||
quitCalls := 0
|
||||
quitNativeApplication = func(context.Context) { quitCalls++ }
|
||||
app := &App{ctx: context.Background()}
|
||||
|
||||
app.Quit()
|
||||
|
||||
if quitCalls != 1 {
|
||||
t.Fatalf("quit calls = %d, want 1", quitCalls)
|
||||
}
|
||||
if prevent := app.BeforeClose(context.Background()); prevent {
|
||||
t.Fatal("BeforeClose() = true after Quit(), want false")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrayQuitRequestsNativeShutdownOnlyOnce(t *testing.T) {
|
||||
oldQuit := quitNativeApplication
|
||||
defer func() { quitNativeApplication = oldQuit }()
|
||||
|
||||
quitCalls := 0
|
||||
quitNativeApplication = func(context.Context) { quitCalls++ }
|
||||
app := &App{ctx: context.Background()}
|
||||
|
||||
app.Quit()
|
||||
app.Quit()
|
||||
|
||||
if quitCalls != 1 {
|
||||
t.Fatalf("native quit calls = %d, want 1", quitCalls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShowWindowUsesWailsContext(t *testing.T) {
|
||||
oldShow := showNativeWindow
|
||||
defer func() { showNativeWindow = oldShow }()
|
||||
|
||||
showCalls := 0
|
||||
showNativeWindow = func(context.Context) { showCalls++ }
|
||||
app := &App{ctx: context.Background()}
|
||||
|
||||
app.ShowWindow()
|
||||
|
||||
if showCalls != 1 {
|
||||
t.Fatalf("show calls = %d, want 1", showCalls)
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetPluginFrontendInfo_KnownPluginWithFrontend verifies that
|
||||
// GetPluginFrontendInfo returns correct metadata for a plugin with a frontend.
|
||||
func TestGetPluginFrontendInfo_KnownPluginWithFrontend(t *testing.T) {
|
||||
@@ -343,6 +612,65 @@ func TestGetPluginAssetContent_NonexistentFile(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPluginLocalizationReadsDeclaredCatalog(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if err := os.MkdirAll(filepath.Join(root, "locales"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(root, "locales", "ru.json"), []byte(`{"greeting":"Привет","count":"Всего: {count}"}`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
app := newTestApp(root)
|
||||
app.plugins[0].Manifest.Localization = &plugin.LocalizationConfig{
|
||||
DefaultLocale: "en",
|
||||
Locales: map[string]string{
|
||||
"en": "locales/en.json",
|
||||
"ru": "locales/ru.json",
|
||||
},
|
||||
}
|
||||
|
||||
catalog, errStr := app.GetPluginLocalization("test.plugin", "ru")
|
||||
if errStr != "" {
|
||||
t.Fatalf("GetPluginLocalization: %s", errStr)
|
||||
}
|
||||
if catalog["greeting"] != "Привет" || catalog["count"] != "Всего: {count}" {
|
||||
t.Fatalf("catalog = %#v", catalog)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetPluginLocalizationRejectsInvalidCatalogs(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if err := os.MkdirAll(filepath.Join(root, "locales"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(root, "locales", "bad.json"), []byte(`{"valid":"text","invalid":42}`), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
app := newTestApp(root)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
config *plugin.LocalizationConfig
|
||||
locale string
|
||||
want string
|
||||
}{
|
||||
{"missing declaration", nil, "ru", "does not declare"},
|
||||
{"unknown locale", &plugin.LocalizationConfig{DefaultLocale: "en", Locales: map[string]string{"en": "locales/en.json"}}, "ru", "not declared"},
|
||||
{"traversal", &plugin.LocalizationConfig{DefaultLocale: "en", Locales: map[string]string{"en": "../outside.json"}}, "en", "traversal"},
|
||||
{"backslash", &plugin.LocalizationConfig{DefaultLocale: "en", Locales: map[string]string{"en": `locales\bad.json`}}, "en", "backslash"},
|
||||
{"non string value", &plugin.LocalizationConfig{DefaultLocale: "en", Locales: map[string]string{"en": "locales/bad.json"}}, "en", "parse"},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
app.plugins[0].Manifest.Localization = tc.config
|
||||
_, errStr := app.GetPluginLocalization("test.plugin", tc.locale)
|
||||
if !strings.Contains(errStr, tc.want) {
|
||||
t.Fatalf("error = %q, want substring %q", errStr, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilesBridgeReadWriteListMoveTrash(t *testing.T) {
|
||||
app, root := newFilesTestApp(t, []string{"files.read", "files.write", "files.delete"})
|
||||
|
||||
@@ -532,21 +860,14 @@ func TestActivityProviderRecordsFileChangedWithoutMountedView(t *testing.T) {
|
||||
t.Fatalf("WriteVaultTextFile: %s", errStr)
|
||||
}
|
||||
|
||||
settings, err := app.storage.ReadPluginSettings("verstak.activity")
|
||||
stored, err := app.storage.ReadPluginDataNDJSON("verstak.activity", activityRawDataName)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadPluginSettings: %v", err)
|
||||
}
|
||||
stored, ok := settings["events:workspace:Project"].([]interface{})
|
||||
if !ok {
|
||||
t.Fatalf("events:workspace:Project = %#v, want []interface{}", settings["events:workspace:Project"])
|
||||
t.Fatalf("ReadPluginDataNDJSON: %v", err)
|
||||
}
|
||||
if len(stored) != 1 {
|
||||
t.Fatalf("stored %d activity events, want 1", len(stored))
|
||||
}
|
||||
activity, ok := stored[0].(map[string]interface{})
|
||||
if !ok {
|
||||
t.Fatalf("activity = %#v, want map[string]interface{}", stored[0])
|
||||
}
|
||||
activity := stored[0]
|
||||
if activity["type"] != "file.changed" {
|
||||
t.Fatalf("activity type = %#v, want file.changed", activity["type"])
|
||||
}
|
||||
@@ -558,6 +879,441 @@ func TestActivityProviderRecordsFileChangedWithoutMountedView(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrowserActivityBatchPersistsWithoutMountedViewAndDeduplicates(t *testing.T) {
|
||||
v := vault.NewVault(nil)
|
||||
if err := v.CreateVault(t.TempDir()); err != nil {
|
||||
t.Fatalf("CreateVault: %v", err)
|
||||
}
|
||||
app := &App{
|
||||
storage: storage.New(v),
|
||||
vault: v,
|
||||
plugins: []plugin.Plugin{{
|
||||
Manifest: plugin.Manifest{ID: activityPluginID, Permissions: []string{"storage.namespace"}},
|
||||
Status: plugin.StatusLoaded,
|
||||
Enabled: true,
|
||||
}},
|
||||
}
|
||||
event := events.Event{
|
||||
Name: "browser.activity.batch",
|
||||
Timestamp: "2026-07-12T10:05:01Z",
|
||||
Payload: map[string]interface{}{
|
||||
"batchId": "batch-activity-1",
|
||||
"entries": []map[string]interface{}{{
|
||||
"hostname": "example.com", "startedAt": "2026-07-12T10:00:00Z", "endedAt": "2026-07-12T10:05:00Z", "durationSeconds": int64(300),
|
||||
}},
|
||||
},
|
||||
}
|
||||
if err := app.recordBrowserActivityBatch(event); err != nil {
|
||||
t.Fatalf("recordBrowserActivityBatch: %v", err)
|
||||
}
|
||||
if err := app.recordBrowserActivityBatch(event); err != nil {
|
||||
t.Fatalf("recordBrowserActivityBatch retry: %v", err)
|
||||
}
|
||||
records, err := app.storage.ReadPluginDataNDJSON(activityPluginID, activityRawDataName)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadPluginDataNDJSON: %v", err)
|
||||
}
|
||||
if len(records) != 1 {
|
||||
t.Fatalf("records = %+v, want one idempotent domain activity", records)
|
||||
}
|
||||
if records[0]["type"] != "browser.activity.domain" || records[0]["hostname"] != "example.com" {
|
||||
t.Fatalf("record = %+v, want domain-only activity", records[0])
|
||||
}
|
||||
if _, ok := records[0]["url"]; ok {
|
||||
t.Fatalf("record must not contain URL: %+v", records[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrowserInboxRecordsCaptureWithoutMountedView(t *testing.T) {
|
||||
v := vault.NewVault(nil)
|
||||
if err := v.CreateVault(t.TempDir()); err != nil {
|
||||
t.Fatalf("CreateVault: %v", err)
|
||||
}
|
||||
bus := events.NewBus()
|
||||
app := &App{
|
||||
eventBus: bus,
|
||||
storage: storage.New(v),
|
||||
vault: v,
|
||||
plugins: []plugin.Plugin{{
|
||||
Manifest: plugin.Manifest{
|
||||
ID: "verstak.browser-inbox",
|
||||
Name: "Browser Inbox",
|
||||
Permissions: []string{"storage.namespace"},
|
||||
},
|
||||
Status: plugin.StatusLoaded,
|
||||
Enabled: true,
|
||||
}},
|
||||
}
|
||||
app.ensureBrowserInboxSubscriptions()
|
||||
|
||||
if err := app.recordBrowserCapture(events.Event{
|
||||
Name: "browser.capture.page",
|
||||
Timestamp: "2026-07-11T12:00:00Z",
|
||||
Payload: map[string]interface{}{
|
||||
"captureId": "capture-background",
|
||||
"capturedAt": "2026-07-11T11:59:00Z",
|
||||
"kind": "page",
|
||||
"url": "https://example.com/article",
|
||||
"title": "Background capture",
|
||||
"domain": "example.com",
|
||||
},
|
||||
}); err != nil {
|
||||
t.Fatalf("RecordBrowserCapture: %v", err)
|
||||
}
|
||||
bus.Publish(events.Event{Name: browserInboxMutationEvent, Payload: map[string]interface{}{
|
||||
"pluginId": browserInboxPluginID, "action": "assign", "captureId": "capture-background", "workspaceRootPath": "Project",
|
||||
}})
|
||||
bus.Publish(events.Event{Name: browserInboxMutationEvent, Payload: map[string]interface{}{
|
||||
"pluginId": browserInboxPluginID, "action": "processed", "captureId": "capture-background", "processed": true,
|
||||
}})
|
||||
bus.Publish(events.Event{Name: browserInboxMutationEvent, Payload: map[string]interface{}{
|
||||
"pluginId": browserInboxPluginID, "action": "archive", "captureId": "capture-background",
|
||||
}})
|
||||
if err := app.recordBrowserCapture(events.Event{
|
||||
Name: "browser.capture.page",
|
||||
Payload: map[string]interface{}{
|
||||
"captureId": "capture-background",
|
||||
"title": "Retried payload",
|
||||
},
|
||||
}); err != nil {
|
||||
t.Fatalf("RecordBrowserCapture retry: %v", err)
|
||||
}
|
||||
|
||||
settings, err := app.storage.ReadPluginSettings("verstak.browser-inbox")
|
||||
if err != nil {
|
||||
t.Fatalf("ReadPluginSettings: %v", err)
|
||||
}
|
||||
stored, ok := settings["captures:global"].([]interface{})
|
||||
if !ok || len(stored) != 1 {
|
||||
t.Fatalf("captures:global = %#v, want one capture", settings["captures:global"])
|
||||
}
|
||||
capture, ok := stored[0].(map[string]interface{})
|
||||
if !ok {
|
||||
t.Fatalf("capture = %#v, want map[string]interface{}", stored[0])
|
||||
}
|
||||
if capture["captureId"] != "capture-background" || capture["title"] != "Background capture" || capture["workspaceRootPath"] != "Project" || capture["processed"] != true || capture["globalState"] != "archived" {
|
||||
t.Fatalf("stored capture = %#v", capture)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrowserInboxArchiveKeepsAssignmentUntilExplicitPermanentDelete(t *testing.T) {
|
||||
v := vault.NewVault(nil)
|
||||
if err := v.CreateVault(t.TempDir()); err != nil {
|
||||
t.Fatalf("CreateVault: %v", err)
|
||||
}
|
||||
bus := events.NewBus()
|
||||
app := &App{
|
||||
eventBus: bus,
|
||||
storage: storage.New(v),
|
||||
vault: v,
|
||||
plugins: []plugin.Plugin{{
|
||||
Manifest: plugin.Manifest{ID: browserInboxPluginID, Permissions: []string{"storage.namespace"}},
|
||||
Status: plugin.StatusLoaded,
|
||||
Enabled: true,
|
||||
}},
|
||||
}
|
||||
app.ensureBrowserInboxSubscriptions()
|
||||
if err := app.recordBrowserCapture(events.Event{Name: "browser.capture.page", Payload: map[string]interface{}{
|
||||
"captureId": "archive-1", "capturedAt": "2026-07-12T10:00:00Z", "url": "https://example.com", "workspaceRootPath": "Project",
|
||||
}}); err != nil {
|
||||
t.Fatalf("recordBrowserCapture: %v", err)
|
||||
}
|
||||
bus.Publish(events.Event{Name: browserInboxMutationEvent, Payload: map[string]interface{}{
|
||||
"pluginId": browserInboxPluginID, "action": "archive", "captureId": "archive-1",
|
||||
}})
|
||||
settings, err := app.storage.ReadPluginSettings(browserInboxPluginID)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadPluginSettings: %v", err)
|
||||
}
|
||||
captures, _ := settings[browserInboxGlobalKey].([]interface{})
|
||||
if len(captures) != 1 {
|
||||
t.Fatalf("captures after archive = %#v, want retained capture", captures)
|
||||
}
|
||||
archived := captures[0].(map[string]interface{})
|
||||
if archived["workspaceRootPath"] != "Project" || archived["globalState"] != "archived" {
|
||||
t.Fatalf("archived capture = %#v, want preserved assignment", archived)
|
||||
}
|
||||
bus.Publish(events.Event{Name: browserInboxMutationEvent, Payload: map[string]interface{}{
|
||||
"pluginId": browserInboxPluginID, "action": "delete", "captureId": "archive-1", "permanent": true,
|
||||
}})
|
||||
settings, err = app.storage.ReadPluginSettings(browserInboxPluginID)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadPluginSettings after delete: %v", err)
|
||||
}
|
||||
captures, _ = settings[browserInboxGlobalKey].([]interface{})
|
||||
if len(captures) != 0 {
|
||||
t.Fatalf("captures after permanent delete = %#v, want none", captures)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrowserInboxWorkspaceReferenceSurvivesRenameAndTrash(t *testing.T) {
|
||||
v := vault.NewVault(nil)
|
||||
if err := v.CreateVault(t.TempDir()); err != nil {
|
||||
t.Fatalf("CreateVault: %v", err)
|
||||
}
|
||||
manager := workspace.NewManager(v.GetVaultPath())
|
||||
created, err := manager.CreateWorkspace("Project", "minimal")
|
||||
if err != nil {
|
||||
t.Fatalf("CreateWorkspace: %v", err)
|
||||
}
|
||||
bus := events.NewBus()
|
||||
app := &App{
|
||||
eventBus: bus,
|
||||
storage: storage.New(v),
|
||||
vault: v,
|
||||
workspace: manager,
|
||||
plugins: []plugin.Plugin{{
|
||||
Manifest: plugin.Manifest{ID: browserInboxPluginID, Permissions: []string{"storage.namespace"}},
|
||||
Status: plugin.StatusLoaded,
|
||||
Enabled: true,
|
||||
}},
|
||||
}
|
||||
app.ensureBrowserInboxSubscriptions()
|
||||
if err := app.recordBrowserCapture(events.Event{Name: "browser.capture.page", Payload: map[string]interface{}{
|
||||
"captureId": "workspace-ref", "capturedAt": "2026-07-12T10:00:00Z", "url": "https://example.com", "workspaceRootPath": "Project",
|
||||
}}); err != nil {
|
||||
t.Fatalf("recordBrowserCapture: %v", err)
|
||||
}
|
||||
if errStr := app.RenameWorkspace("Project", "Client"); errStr != "" {
|
||||
t.Fatalf("RenameWorkspace: %s", errStr)
|
||||
}
|
||||
if _, errStr := app.TrashWorkspace("Client"); errStr != "" {
|
||||
t.Fatalf("TrashWorkspace: %s", errStr)
|
||||
}
|
||||
settings, err := app.storage.ReadPluginSettings(browserInboxPluginID)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadPluginSettings: %v", err)
|
||||
}
|
||||
capture := settings[browserInboxGlobalKey].([]interface{})[0].(map[string]interface{})
|
||||
if capture["workspaceId"] != created.ID || capture["workspaceRootPath"] != "Client" || capture["workspaceState"] != "trashed" || capture["workspaceTrashId"] == "" {
|
||||
t.Fatalf("workspace reference = %#v", capture)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenExternalURLUsesBrowserOpenService(t *testing.T) {
|
||||
app, _ := newFilesTestApp(t, []string{"files.openExternal"})
|
||||
opened := ""
|
||||
app.externalOpen = newTestExternalOpenService(func(path string) error {
|
||||
opened = path
|
||||
return nil
|
||||
})
|
||||
if errStr := app.OpenExternalURL("files.plugin", "https://example.com/path"); errStr != "" {
|
||||
t.Fatalf("OpenExternalURL: %s", errStr)
|
||||
}
|
||||
if opened != "https://example.com/path" {
|
||||
t.Fatalf("opened = %q, want URL", opened)
|
||||
}
|
||||
if errStr := app.OpenExternalURL("files.plugin", "ftp://example.com"); errStr == "" {
|
||||
t.Fatal("OpenExternalURL accepted unsupported URL scheme")
|
||||
}
|
||||
}
|
||||
|
||||
func TestJournalHandledSessionPersistsActivityWatermark(t *testing.T) {
|
||||
v := vault.NewVault(nil)
|
||||
if err := v.CreateVault(t.TempDir()); err != nil {
|
||||
t.Fatalf("CreateVault: %v", err)
|
||||
}
|
||||
bus := events.NewBus()
|
||||
app := &App{
|
||||
eventBus: bus,
|
||||
storage: storage.New(v),
|
||||
vault: v,
|
||||
contribRegistry: contribution.NewRegistry(),
|
||||
plugins: []plugin.Plugin{
|
||||
{Manifest: plugin.Manifest{ID: activityPluginID, Permissions: []string{"storage.namespace"}}, Status: plugin.StatusLoaded, Enabled: true},
|
||||
{Manifest: plugin.Manifest{ID: "verstak.journal", Permissions: []string{"events.publish"}}, Status: plugin.StatusLoaded, Enabled: true},
|
||||
},
|
||||
}
|
||||
app.ensureActivityProviderSubscriptions()
|
||||
bus.Publish(events.Event{Name: activitySessionHandledEvent, Payload: map[string]interface{}{
|
||||
"pluginId": "verstak.journal", "sessionId": "session-1", "handledThrough": "2026-07-12T10:30:00Z", "status": "accepted",
|
||||
}})
|
||||
settings, err := app.storage.ReadPluginSettings(activityPluginID)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadPluginSettings: %v", err)
|
||||
}
|
||||
handled := settings[activitySessionHandlingKey].(map[string]interface{})
|
||||
record := handled["session-1"].(map[string]interface{})
|
||||
if record["status"] != "accepted" || record["handledThrough"] != "2026-07-12T10:30:00Z" {
|
||||
t.Fatalf("handled record = %#v", record)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrowserInboxRejectsCaptureWithoutOpenVault(t *testing.T) {
|
||||
v := vault.NewVault(nil)
|
||||
app := &App{
|
||||
storage: storage.New(v),
|
||||
vault: v,
|
||||
plugins: []plugin.Plugin{{
|
||||
Manifest: plugin.Manifest{
|
||||
ID: browserInboxPluginID,
|
||||
Permissions: []string{"storage.namespace"},
|
||||
},
|
||||
Status: plugin.StatusLoaded,
|
||||
Enabled: true,
|
||||
}},
|
||||
}
|
||||
app.ensureBrowserInboxSubscriptions()
|
||||
|
||||
err := app.recordBrowserCapture(events.Event{
|
||||
Name: "browser.capture.page",
|
||||
Payload: map[string]interface{}{"captureId": "capture-no-vault"},
|
||||
})
|
||||
|
||||
if err == nil || !strings.Contains(err.Error(), "unavailable") {
|
||||
t.Fatalf("RecordBrowserCapture error = %v, want unavailable", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrowserInboxSerializesConcurrentCapturesAndMutations(t *testing.T) {
|
||||
v := vault.NewVault(nil)
|
||||
if err := v.CreateVault(t.TempDir()); err != nil {
|
||||
t.Fatalf("CreateVault: %v", err)
|
||||
}
|
||||
bus := events.NewBus()
|
||||
app := &App{
|
||||
eventBus: bus,
|
||||
storage: storage.New(v),
|
||||
vault: v,
|
||||
plugins: []plugin.Plugin{{
|
||||
Manifest: plugin.Manifest{
|
||||
ID: browserInboxPluginID,
|
||||
Permissions: []string{"storage.namespace"},
|
||||
},
|
||||
Status: plugin.StatusLoaded,
|
||||
Enabled: true,
|
||||
}},
|
||||
}
|
||||
app.ensureBrowserInboxSubscriptions()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if err := app.storage.WritePluginSetting(browserInboxPluginID, "domainBindings", map[string]interface{}{
|
||||
"example.com": "Project",
|
||||
}); err != nil {
|
||||
t.Errorf("WritePluginSetting(domainBindings): %v", err)
|
||||
}
|
||||
}()
|
||||
for i := 0; i < 50; i++ {
|
||||
wg.Add(1)
|
||||
go func(index int) {
|
||||
defer wg.Done()
|
||||
if err := app.recordBrowserCapture(events.Event{
|
||||
Name: "browser.capture.page",
|
||||
Timestamp: "2026-07-11T12:00:00Z",
|
||||
Payload: map[string]interface{}{
|
||||
"captureId": fmt.Sprintf("capture-%02d", index),
|
||||
"kind": "page",
|
||||
"url": fmt.Sprintf("https://example.com/%d", index),
|
||||
},
|
||||
}); err != nil {
|
||||
t.Errorf("RecordBrowserCapture(%d): %v", index, err)
|
||||
}
|
||||
}(i)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
bus.Publish(events.Event{
|
||||
Name: browserInboxMutationEvent,
|
||||
Payload: map[string]interface{}{
|
||||
"pluginId": browserInboxPluginID,
|
||||
"action": "assign",
|
||||
"captureId": "capture-00",
|
||||
"workspaceRootPath": "Project",
|
||||
},
|
||||
})
|
||||
bus.Publish(events.Event{
|
||||
Name: browserInboxMutationEvent,
|
||||
Payload: map[string]interface{}{
|
||||
"pluginId": browserInboxPluginID,
|
||||
"action": "delete",
|
||||
"captureId": "capture-01",
|
||||
},
|
||||
})
|
||||
|
||||
settings, err := app.storage.ReadPluginSettings(browserInboxPluginID)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadPluginSettings: %v", err)
|
||||
}
|
||||
stored, ok := settings[browserInboxGlobalKey].([]interface{})
|
||||
if !ok || len(stored) != 49 {
|
||||
t.Fatalf("captures:global contains %d captures, want 49", len(stored))
|
||||
}
|
||||
var assigned map[string]interface{}
|
||||
for _, item := range stored {
|
||||
capture := item.(map[string]interface{})
|
||||
if capture["captureId"] == "capture-00" {
|
||||
assigned = capture
|
||||
}
|
||||
if capture["captureId"] == "capture-01" {
|
||||
t.Fatal("deleted capture remained in storage")
|
||||
}
|
||||
}
|
||||
if assigned == nil || assigned["workspaceRootPath"] != "Project" {
|
||||
t.Fatalf("assigned capture = %#v", assigned)
|
||||
}
|
||||
if settings["domainBindings"] == nil {
|
||||
t.Fatal("concurrent domainBindings update was lost")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBrowserInboxMutationMigratesAndClearsLegacyCaptures(t *testing.T) {
|
||||
v := vault.NewVault(nil)
|
||||
if err := v.CreateVault(t.TempDir()); err != nil {
|
||||
t.Fatalf("CreateVault: %v", err)
|
||||
}
|
||||
bus := events.NewBus()
|
||||
app := &App{
|
||||
eventBus: bus,
|
||||
storage: storage.New(v),
|
||||
vault: v,
|
||||
plugins: []plugin.Plugin{{
|
||||
Manifest: plugin.Manifest{ID: browserInboxPluginID, Permissions: []string{"storage.namespace"}},
|
||||
Status: plugin.StatusLoaded,
|
||||
Enabled: true,
|
||||
}},
|
||||
}
|
||||
if err := app.storage.WritePluginSettings(browserInboxPluginID, map[string]interface{}{
|
||||
browserInboxLegacyKey: []interface{}{map[string]interface{}{
|
||||
"captureId": "legacy-duplicate",
|
||||
"title": "Stale legacy copy",
|
||||
}},
|
||||
browserInboxGlobalKey: []interface{}{map[string]interface{}{
|
||||
"captureId": "legacy-duplicate",
|
||||
"title": "Canonical copy",
|
||||
"workspaceRootPath": "Project",
|
||||
"processed": true,
|
||||
}},
|
||||
}); err != nil {
|
||||
t.Fatalf("WritePluginSettings: %v", err)
|
||||
}
|
||||
app.ensureBrowserInboxSubscriptions()
|
||||
|
||||
bus.Publish(events.Event{Name: browserInboxMutationEvent, Payload: map[string]interface{}{
|
||||
"pluginId": browserInboxPluginID,
|
||||
"action": "migrate",
|
||||
}})
|
||||
|
||||
settings, err := app.storage.ReadPluginSettings(browserInboxPluginID)
|
||||
if err != nil {
|
||||
t.Fatalf("ReadPluginSettings: %v", err)
|
||||
}
|
||||
legacy := settings[browserInboxLegacyKey].([]interface{})
|
||||
if len(legacy) != 0 {
|
||||
t.Fatalf("legacy captures = %#v, want empty", legacy)
|
||||
}
|
||||
stored := settings[browserInboxGlobalKey].([]interface{})
|
||||
if len(stored) != 1 {
|
||||
t.Fatalf("canonical captures = %#v, want one", stored)
|
||||
}
|
||||
capture := stored[0].(map[string]interface{})
|
||||
if capture["title"] != "Canonical copy" || capture["workspaceRootPath"] != "Project" || capture["processed"] != true {
|
||||
t.Fatalf("canonical capture = %#v", capture)
|
||||
}
|
||||
}
|
||||
|
||||
func TestActivityFromEventRedactsBinaryPayload(t *testing.T) {
|
||||
activity := activityFromEvent(events.Event{
|
||||
Name: "browser.capture.file",
|
||||
@@ -1294,6 +2050,37 @@ func assertSyncState(t *testing.T, service *syncsvc.Service, wantDeviceID, wantS
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppSettingsLanguageAPI(t *testing.T) {
|
||||
settings := appsettings.NewManager(filepath.Join(t.TempDir(), "config.json"))
|
||||
if err := settings.Load(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := settings.Update(&appsettings.Config{Theme: "light", DevMode: true}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
app := &App{appSettings: settings, debug: true}
|
||||
|
||||
if got := app.GetAppSettings()["language"]; got != "system" {
|
||||
t.Fatalf("initial language = %#v, want system", got)
|
||||
}
|
||||
if got := app.GetAppSettings()["debug"]; got != true {
|
||||
t.Fatalf("debug = %#v, want true", got)
|
||||
}
|
||||
if errStr := app.UpdateAppSettings(map[string]interface{}{"language": "ru"}); errStr != "" {
|
||||
t.Fatalf("UpdateAppSettings language: %s", errStr)
|
||||
}
|
||||
got := app.GetAppSettings()
|
||||
if got["language"] != "ru" || got["theme"] != "light" || got["devMode"] != true {
|
||||
t.Fatalf("settings after language update = %#v", got)
|
||||
}
|
||||
if errStr := app.UpdateAppSettings(map[string]interface{}{"language": "de"}); errStr == "" {
|
||||
t.Fatal("UpdateAppSettings accepted unsupported language")
|
||||
}
|
||||
if got := app.GetAppSettings()["language"]; got != "ru" {
|
||||
t.Fatalf("language after rejected update = %#v, want ru", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetCurrentVaultInitializesWorkspaceWhenMissingAtStartup(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
vaultParent := filepath.Join(tmpDir, "vault-parent")
|
||||
@@ -1493,6 +2280,10 @@ func TestWorkspaceAPIPublishesLifecycleEvents(t *testing.T) {
|
||||
if errStr := app.SetCurrentWorkspace("Project"); errStr != "" {
|
||||
t.Fatalf("SetCurrentWorkspace: %s", errStr)
|
||||
}
|
||||
currentID, ok := app.GetCurrentWorkspace()["workspaceId"].(string)
|
||||
if !ok || currentID == "" {
|
||||
t.Fatalf("GetCurrentWorkspace workspaceId = %#v", app.GetCurrentWorkspace()["workspaceId"])
|
||||
}
|
||||
if errStr := app.RenameWorkspace("Project", "Renamed"); errStr != "" {
|
||||
t.Fatalf("RenameWorkspace: %s", errStr)
|
||||
}
|
||||
@@ -1503,6 +2294,10 @@ func TestWorkspaceAPIPublishesLifecycleEvents(t *testing.T) {
|
||||
if got := received["workspace.created"]["workspaceRootPath"]; got != "Project" {
|
||||
t.Fatalf("workspace.created workspaceRootPath = %#v, want Project", got)
|
||||
}
|
||||
createdID, _ := received["workspace.created"]["workspaceId"].(string)
|
||||
if createdID == "" {
|
||||
t.Fatal("workspace.created workspaceId is empty")
|
||||
}
|
||||
if got := received["workspace.created"]["templateId"]; got != "client-project" {
|
||||
t.Fatalf("workspace.created templateId = %#v, want client-project", got)
|
||||
}
|
||||
@@ -1512,17 +2307,88 @@ func TestWorkspaceAPIPublishesLifecycleEvents(t *testing.T) {
|
||||
if got := received["workspace.renamed"]["workspaceRootPath"]; got != "Renamed" {
|
||||
t.Fatalf("workspace.renamed workspaceRootPath = %#v, want Renamed", got)
|
||||
}
|
||||
if got := received["workspace.renamed"]["workspaceId"]; got != createdID {
|
||||
t.Fatalf("workspace.renamed workspaceId = %#v, want %q", got, createdID)
|
||||
}
|
||||
if got := received["workspace.renamed"]["previousWorkspaceRootPath"]; got != "Project" {
|
||||
t.Fatalf("workspace.renamed previousWorkspaceRootPath = %#v, want Project", got)
|
||||
}
|
||||
if got := received["workspace.trashed"]["workspaceRootPath"]; got != "Renamed" {
|
||||
t.Fatalf("workspace.trashed workspaceRootPath = %#v, want Renamed", got)
|
||||
}
|
||||
if got := received["workspace.trashed"]["workspaceId"]; got != createdID {
|
||||
t.Fatalf("workspace.trashed workspaceId = %#v, want %q", got, createdID)
|
||||
}
|
||||
if got := received["workspace.trashed"]["trashPath"]; got == "" {
|
||||
t.Fatalf("workspace.trashed trashPath = %#v, want non-empty", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkspaceIdentityAPIListsAndRepairsDuplicates(t *testing.T) {
|
||||
app, vaultDir := newFilesTestApp(t, []string{"files.read"})
|
||||
app.workspace = workspace.NewManager(vaultDir)
|
||||
if err := app.workspace.Load(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, errStr := app.CreateWorkspace("Original", "default"); errStr != "" {
|
||||
t.Fatalf("CreateWorkspace: %s", errStr)
|
||||
}
|
||||
identities, errStr := app.ListWorkspaceIdentities()
|
||||
if errStr != "" {
|
||||
t.Fatalf("ListWorkspaceIdentities: %s", errStr)
|
||||
}
|
||||
var original workspace.WorkspaceIdentity
|
||||
for _, identity := range identities {
|
||||
if identity.RootPath == "Original" {
|
||||
original = identity
|
||||
break
|
||||
}
|
||||
}
|
||||
if original.WorkspaceID == "" || original.State != "active" {
|
||||
t.Fatalf("identities = %+v", identities)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkspaceTrashRestoreAndPurgePublishIdentityLifecycle(t *testing.T) {
|
||||
app, vaultDir := newFilesTestApp(t, []string{"files.read"})
|
||||
app.workspace = workspace.NewManager(vaultDir)
|
||||
app.eventBus = events.NewBus()
|
||||
if err := app.workspace.Load(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
received := map[string]map[string]interface{}{}
|
||||
for _, eventName := range []string{"workspace.restored", "workspace.purged"} {
|
||||
name := eventName
|
||||
app.eventBus.Subscribe(name, func(event events.Event) {
|
||||
received[name], _ = event.Payload.(map[string]interface{})
|
||||
})
|
||||
}
|
||||
if _, errStr := app.CreateWorkspace("Client", "default"); errStr != "" {
|
||||
t.Fatalf("CreateWorkspace: %s", errStr)
|
||||
}
|
||||
trashed, errStr := app.TrashWorkspace("Client")
|
||||
if errStr != "" {
|
||||
t.Fatalf("TrashWorkspace: %s", errStr)
|
||||
}
|
||||
restored, errStr := app.RestoreWorkspaceTrash(trashed.TrashID, "Client-Restored")
|
||||
if errStr != "" {
|
||||
t.Fatalf("RestoreWorkspaceTrash: %s", errStr)
|
||||
}
|
||||
if got := received["workspace.restored"]["workspaceId"]; got != restored.ID {
|
||||
t.Fatalf("restored workspaceId = %#v, want %q", got, restored.ID)
|
||||
}
|
||||
trashed, errStr = app.TrashWorkspace("Client-Restored")
|
||||
if errStr != "" {
|
||||
t.Fatalf("TrashWorkspace restored: %s", errStr)
|
||||
}
|
||||
if errStr := app.PurgeWorkspaceTrash(trashed.TrashID); errStr != "" {
|
||||
t.Fatalf("PurgeWorkspaceTrash: %s", errStr)
|
||||
}
|
||||
if got := received["workspace.purged"]["workspaceId"]; got != restored.ID {
|
||||
t.Fatalf("purged workspaceId = %#v, want %q", got, restored.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMoveWorkspaceNodeCompatibilityIsUnsupported(t *testing.T) {
|
||||
app, vaultDir := newFilesTestApp(t, []string{"files.read"})
|
||||
app.workspace = workspace.NewManager(vaultDir)
|
||||
|
||||
@@ -21,6 +21,7 @@ type Config struct {
|
||||
CurrentVaultPath string `json:"currentVaultPath"`
|
||||
RecentVaults []string `json:"recentVaults"`
|
||||
Theme string `json:"theme"`
|
||||
Language string `json:"language"`
|
||||
DevMode bool `json:"devMode"`
|
||||
UserPluginsDir string `json:"userPluginsDir"`
|
||||
Workbench WorkbenchPreferences `json:"workbench,omitempty"`
|
||||
@@ -30,6 +31,21 @@ type Config struct {
|
||||
LastOpenedAt string `json:"lastOpenedAt"`
|
||||
}
|
||||
|
||||
const (
|
||||
LanguageSystem = "system"
|
||||
LanguageEnglish = "en"
|
||||
LanguageRussian = "ru"
|
||||
)
|
||||
|
||||
func validLanguage(language string) bool {
|
||||
switch language {
|
||||
case LanguageSystem, LanguageEnglish, LanguageRussian:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type WorkbenchPreferences struct {
|
||||
DefaultTextEditorProvider string `json:"defaultTextEditorProvider,omitempty"`
|
||||
DefaultMarkdownEditorProvider string `json:"defaultMarkdownEditorProvider,omitempty"`
|
||||
@@ -62,9 +78,10 @@ type WindowState struct {
|
||||
|
||||
// Manager provides thread-safe access to app settings.
|
||||
type Manager struct {
|
||||
mu sync.RWMutex
|
||||
config *Config
|
||||
configPath string
|
||||
mu sync.RWMutex
|
||||
config *Config
|
||||
configPath string
|
||||
onLanguageChanged func(string)
|
||||
}
|
||||
|
||||
// DefaultConfigPath returns the default path for app settings.
|
||||
@@ -121,6 +138,9 @@ func (m *Manager) Load() error {
|
||||
if cfg.Theme == "" {
|
||||
cfg.Theme = "dark"
|
||||
}
|
||||
if !validLanguage(cfg.Language) {
|
||||
cfg.Language = LanguageSystem
|
||||
}
|
||||
if cfg.RecentVaults == nil {
|
||||
cfg.RecentVaults = []string{}
|
||||
}
|
||||
@@ -179,6 +199,9 @@ func (m *Manager) Update(patch *Config) error {
|
||||
if patch.Theme != "" {
|
||||
m.config.Theme = patch.Theme
|
||||
}
|
||||
if patch.Language != "" && validLanguage(patch.Language) {
|
||||
m.config.Language = patch.Language
|
||||
}
|
||||
if patch.UserPluginsDir != "" {
|
||||
m.config.UserPluginsDir = patch.UserPluginsDir
|
||||
}
|
||||
@@ -200,6 +223,42 @@ func (m *Manager) Update(patch *Config) error {
|
||||
return m.saveLocked()
|
||||
}
|
||||
|
||||
// UpdateLanguage validates and persists the installation-local UI language.
|
||||
func (m *Manager) UpdateLanguage(language string) error {
|
||||
language = strings.TrimSpace(language)
|
||||
if !validLanguage(language) {
|
||||
return fmt.Errorf("unsupported language %q", language)
|
||||
}
|
||||
|
||||
m.mu.Lock()
|
||||
if m.config == nil {
|
||||
m.config = defaultConfig()
|
||||
}
|
||||
m.config.Language = language
|
||||
m.config.LastOpenedAt = time.Now().UTC().Format(time.RFC3339)
|
||||
err := m.saveLocked()
|
||||
handler := m.onLanguageChanged
|
||||
m.mu.Unlock()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if handler != nil {
|
||||
handler(language)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetLanguageChangedHandler registers the shell callback invoked after a
|
||||
// language preference has been durably updated.
|
||||
func (m *Manager) SetLanguageChangedHandler(handler func(string)) {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
m.mu.Lock()
|
||||
m.onLanguageChanged = handler
|
||||
m.mu.Unlock()
|
||||
}
|
||||
|
||||
// UpdateSync replaces sync settings without changing unrelated app settings.
|
||||
func (m *Manager) UpdateSync(syncSettings SyncSettings) error {
|
||||
m.mu.Lock()
|
||||
@@ -287,6 +346,7 @@ func defaultConfig() *Config {
|
||||
CurrentVaultPath: "",
|
||||
RecentVaults: []string{},
|
||||
Theme: "dark",
|
||||
Language: LanguageSystem,
|
||||
DevMode: false,
|
||||
UserPluginsDir: filepath.Join(os.Getenv("HOME"), ".config", "verstak", "plugins"),
|
||||
Workbench: WorkbenchPreferences{},
|
||||
@@ -303,6 +363,7 @@ func copyConfig(c *Config) *Config {
|
||||
CurrentVaultPath: c.CurrentVaultPath,
|
||||
RecentVaults: recent,
|
||||
Theme: c.Theme,
|
||||
Language: c.Language,
|
||||
DevMode: c.DevMode,
|
||||
UserPluginsDir: c.UserPluginsDir,
|
||||
Workbench: c.Workbench,
|
||||
|
||||
@@ -3,6 +3,7 @@ package appsettings
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -25,6 +26,81 @@ func TestLoad_DefaultCreation(t *testing.T) {
|
||||
if cfg.CurrentVaultPath != "" {
|
||||
t.Errorf("CurrentVaultPath: got %q, want empty", cfg.CurrentVaultPath)
|
||||
}
|
||||
if cfg.Language != "system" {
|
||||
t.Errorf("Language: got %q, want %q", cfg.Language, "system")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoad_MissingLanguageDefaultsToSystem(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "config.json")
|
||||
if err := os.WriteFile(path, []byte(`{"schemaVersion":1,"theme":"dark","devMode":true}`), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
m := NewManager(path)
|
||||
if err := m.Load(); err != nil {
|
||||
t.Fatalf("Load: %v", err)
|
||||
}
|
||||
if got := m.Get().Language; got != "system" {
|
||||
t.Fatalf("Language = %q, want system", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateLanguagePersistsAndPreservesUnrelatedSettings(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "config.json")
|
||||
m := NewManager(path)
|
||||
if err := m.Load(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := m.Update(&Config{Theme: "light", DevMode: true}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := m.UpdateLanguage("ru"); err != nil {
|
||||
t.Fatalf("UpdateLanguage: %v", err)
|
||||
}
|
||||
|
||||
reloaded := NewManager(path)
|
||||
if err := reloaded.Load(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg := reloaded.Get()
|
||||
if cfg.Language != "ru" || cfg.Theme != "light" || !cfg.DevMode {
|
||||
t.Fatalf("settings after language update = %+v", cfg)
|
||||
}
|
||||
if err := reloaded.UpdateLanguage("de"); err == nil {
|
||||
t.Fatal("UpdateLanguage(de) succeeded, want validation error")
|
||||
}
|
||||
if got := reloaded.Get().Language; got != "ru" {
|
||||
t.Fatalf("Language after rejected update = %q, want ru", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateLanguageNotifiesTheDesktopShellAfterPersisting(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "config.json")
|
||||
manager := NewManager(path)
|
||||
if err := manager.Load(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var received []string
|
||||
manager.SetLanguageChangedHandler(func(language string) {
|
||||
received = append(received, language)
|
||||
})
|
||||
if err := manager.UpdateLanguage(LanguageRussian); err != nil {
|
||||
t.Fatalf("UpdateLanguage: %v", err)
|
||||
}
|
||||
if got := manager.Get().Language; got != LanguageRussian {
|
||||
t.Fatalf("persisted language = %q, want %q", got, LanguageRussian)
|
||||
}
|
||||
if !reflect.DeepEqual(received, []string{LanguageRussian}) {
|
||||
t.Fatalf("language notifications = %#v, want [%q]", received, LanguageRussian)
|
||||
}
|
||||
if err := manager.UpdateLanguage("de"); err == nil {
|
||||
t.Fatal("UpdateLanguage(de) succeeded, want validation failure")
|
||||
}
|
||||
if !reflect.DeepEqual(received, []string{LanguageRussian}) {
|
||||
t.Fatalf("language notification fired after rejected update: %#v", received)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoad_CorruptConfig(t *testing.T) {
|
||||
|
||||
@@ -12,18 +12,20 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/verstak/verstak-desktop/internal/core/events"
|
||||
"github.com/verstak/verstak-desktop/internal/core/hostname"
|
||||
)
|
||||
|
||||
const (
|
||||
capturePath = "/api/browser-inbox/v1/captures"
|
||||
activityBatchPath = "/api/browser-activity/v1/batches"
|
||||
DefaultAddr = "127.0.0.1:47731"
|
||||
DefaultCaptureURL = "http://" + DefaultAddr + capturePath
|
||||
DefaultActivityURL = "http://" + DefaultAddr + activityBatchPath
|
||||
receiverTokenHeader = "X-Verstak-Receiver-Token"
|
||||
)
|
||||
|
||||
@@ -43,6 +45,9 @@ const (
|
||||
maxFileTextBytes = 2 * 1024 * 1024
|
||||
maxFileBytes = 8 * 1024 * 1024
|
||||
maxFileDataBase64Bytes = 4 * ((maxFileBytes + 2) / 3)
|
||||
maxActivityBodyBytes = 256 * 1024
|
||||
maxActivityEntries = 100
|
||||
maxActivityDuration = 10 * time.Minute
|
||||
)
|
||||
|
||||
type Receiver struct {
|
||||
@@ -55,8 +60,12 @@ type Receiver struct {
|
||||
type WorkspaceProvider func() string
|
||||
|
||||
type Options struct {
|
||||
RequireToken bool
|
||||
ReceiverToken string
|
||||
RequireToken bool
|
||||
ReceiverToken string
|
||||
Available func() bool
|
||||
Persist func(events.Event) error
|
||||
ActivityAvailable func() bool
|
||||
PersistActivity func(events.Event) error
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
@@ -105,6 +114,23 @@ type CaptureBrowser struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// ActivityBatchPayload contains only domain-level time accounting. It never
|
||||
// accepts or emits page URLs, titles, content, or navigation history.
|
||||
type ActivityBatchPayload struct {
|
||||
SchemaVersion int `json:"schemaVersion"`
|
||||
BatchID string `json:"batchId"`
|
||||
CreatedAt string `json:"createdAt"`
|
||||
Source string `json:"source"`
|
||||
Entries []ActivityEntry `json:"entries"`
|
||||
}
|
||||
|
||||
type ActivityEntry struct {
|
||||
Hostname string `json:"hostname"`
|
||||
StartedAt string `json:"startedAt"`
|
||||
EndedAt string `json:"endedAt"`
|
||||
DurationSeconds int64 `json:"durationSeconds"`
|
||||
}
|
||||
|
||||
func New(bus *events.Bus, providers ...WorkspaceProvider) *Receiver {
|
||||
return NewWithOptions(bus, Options{}, providers...)
|
||||
}
|
||||
@@ -128,6 +154,29 @@ func (r *Receiver) SetReceiverToken(token string) {
|
||||
r.options.ReceiverToken = strings.TrimSpace(token)
|
||||
}
|
||||
|
||||
// SetPersistence configures durable capture storage and its availability gate.
|
||||
func (r *Receiver) SetPersistence(available func() bool, persist func(events.Event) error) {
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
r.optionsMu.Lock()
|
||||
defer r.optionsMu.Unlock()
|
||||
r.options.Available = available
|
||||
r.options.Persist = persist
|
||||
}
|
||||
|
||||
// SetActivityPersistence configures durable passive browser activity storage.
|
||||
// An acknowledgement is sent only after persist returns successfully.
|
||||
func (r *Receiver) SetActivityPersistence(available func() bool, persist func(events.Event) error) {
|
||||
if r == nil {
|
||||
return
|
||||
}
|
||||
r.optionsMu.Lock()
|
||||
defer r.optionsMu.Unlock()
|
||||
r.options.ActivityAvailable = available
|
||||
r.options.PersistActivity = persist
|
||||
}
|
||||
|
||||
func Start(addr string, receiver *Receiver) (*Server, error) {
|
||||
if receiver == nil {
|
||||
return nil, fmt.Errorf("receiver is required")
|
||||
@@ -168,6 +217,10 @@ func (s *Server) Close() error {
|
||||
func (r *Receiver) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
||||
if req.URL.Path == activityBatchPath {
|
||||
r.serveActivityBatch(w, req)
|
||||
return
|
||||
}
|
||||
if req.URL.Path != capturePath {
|
||||
http.NotFound(w, req)
|
||||
return
|
||||
@@ -181,6 +234,11 @@ func (r *Receiver) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
writeError(w, http.StatusUnauthorized, err.Error())
|
||||
return
|
||||
}
|
||||
options := r.currentOptions()
|
||||
if options.Available != nil && !options.Available() {
|
||||
writeError(w, http.StatusServiceUnavailable, "browser inbox unavailable")
|
||||
return
|
||||
}
|
||||
|
||||
defer req.Body.Close()
|
||||
decoder := json.NewDecoder(http.MaxBytesReader(w, req.Body, maxCaptureBodyBytes))
|
||||
@@ -209,17 +267,27 @@ func (r *Receiver) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
}
|
||||
|
||||
eventName := "browser.capture." + payload.Kind
|
||||
if r.bus == nil || !r.bus.HasSubscribers(eventName) {
|
||||
if options.Persist == nil && (r.bus == nil || !r.bus.HasSubscribers(eventName)) {
|
||||
writeError(w, http.StatusServiceUnavailable, "browser inbox unavailable")
|
||||
return
|
||||
}
|
||||
eventPayload := payload.EventPayload()
|
||||
r.annotateWorkspace(eventPayload)
|
||||
r.bus.Publish(events.Event{
|
||||
event := events.Event{
|
||||
Name: eventName,
|
||||
Timestamp: time.Now().UTC().Format(time.RFC3339Nano),
|
||||
Payload: eventPayload,
|
||||
})
|
||||
}
|
||||
if options.Persist != nil {
|
||||
if err := options.Persist(event); err != nil {
|
||||
log.Printf("[browserreceiver] persist %s: %v", payload.CaptureID, err)
|
||||
writeError(w, http.StatusServiceUnavailable, "browser inbox unavailable")
|
||||
return
|
||||
}
|
||||
}
|
||||
if r.bus != nil {
|
||||
r.bus.Publish(event)
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{
|
||||
@@ -228,6 +296,68 @@ func (r *Receiver) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
func (r *Receiver) serveActivityBatch(w http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != http.MethodPost {
|
||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"error": "method not allowed"})
|
||||
return
|
||||
}
|
||||
if err := r.validateReceiverToken(req); err != nil {
|
||||
writeError(w, http.StatusUnauthorized, err.Error())
|
||||
return
|
||||
}
|
||||
options := r.currentOptions()
|
||||
if options.ActivityAvailable == nil || !options.ActivityAvailable() || options.PersistActivity == nil {
|
||||
writeError(w, http.StatusServiceUnavailable, "activity storage unavailable")
|
||||
return
|
||||
}
|
||||
|
||||
defer req.Body.Close()
|
||||
decoder := json.NewDecoder(http.MaxBytesReader(w, req.Body, maxActivityBodyBytes))
|
||||
var batch ActivityBatchPayload
|
||||
if err := decoder.Decode(&batch); err != nil {
|
||||
writeActivityDecodeError(w, err)
|
||||
return
|
||||
}
|
||||
if err := decoder.Decode(&struct{}{}); err != io.EOF {
|
||||
writeActivityDecodeError(w, err)
|
||||
return
|
||||
}
|
||||
if err := batch.NormalizeAndValidate(); err != nil {
|
||||
writeError(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
event := events.Event{
|
||||
Name: "browser.activity.batch",
|
||||
Timestamp: time.Now().UTC().Format(time.RFC3339Nano),
|
||||
Payload: batch.EventPayload(),
|
||||
}
|
||||
if err := options.PersistActivity(event); err != nil {
|
||||
log.Printf("[browserreceiver] persist activity %s: %v", batch.BatchID, err)
|
||||
writeError(w, http.StatusServiceUnavailable, "activity storage unavailable")
|
||||
return
|
||||
}
|
||||
if r.bus != nil {
|
||||
r.bus.Publish(event)
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{
|
||||
"status": "accepted",
|
||||
"batchId": batch.BatchID,
|
||||
})
|
||||
}
|
||||
|
||||
func (r *Receiver) currentOptions() Options {
|
||||
if r == nil {
|
||||
return Options{}
|
||||
}
|
||||
r.optionsMu.RLock()
|
||||
defer r.optionsMu.RUnlock()
|
||||
return r.options
|
||||
}
|
||||
|
||||
func (r *Receiver) validateReceiverToken(req *http.Request) error {
|
||||
if r == nil {
|
||||
return nil
|
||||
@@ -333,6 +463,80 @@ func (p CapturePayload) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// NormalizeAndValidate validates a batch before it is made durable and replaces
|
||||
// each submitted hostname with the shared canonical A-label form.
|
||||
func (p *ActivityBatchPayload) NormalizeAndValidate() error {
|
||||
if p == nil || p.SchemaVersion != 1 {
|
||||
return fmt.Errorf("unsupported schemaVersion")
|
||||
}
|
||||
if strings.TrimSpace(p.BatchID) == "" {
|
||||
return fmt.Errorf("batchId is required")
|
||||
}
|
||||
if err := validateCaptureText(p.BatchID, "batchId", maxCaptureIDBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.TrimSpace(p.CreatedAt) == "" {
|
||||
return fmt.Errorf("createdAt is required")
|
||||
}
|
||||
if _, err := time.Parse(time.RFC3339, p.CreatedAt); err != nil {
|
||||
return fmt.Errorf("createdAt is invalid")
|
||||
}
|
||||
if err := validateCaptureText(p.CreatedAt, "createdAt", maxCapturedAtBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.TrimSpace(p.Source) == "" {
|
||||
return fmt.Errorf("source is required")
|
||||
}
|
||||
if err := validateCaptureText(p.Source, "source", maxCaptureSourceBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(p.Entries) == 0 || len(p.Entries) > maxActivityEntries {
|
||||
return fmt.Errorf("entries must contain between 1 and %d items", maxActivityEntries)
|
||||
}
|
||||
for index := range p.Entries {
|
||||
entry := &p.Entries[index]
|
||||
canonical := hostname.NormalizeHostnameV1(entry.Hostname)
|
||||
if canonical == "" {
|
||||
return fmt.Errorf("entries[%d].hostname is invalid", index)
|
||||
}
|
||||
startedAt, err := time.Parse(time.RFC3339, entry.StartedAt)
|
||||
if err != nil {
|
||||
return fmt.Errorf("entries[%d].startedAt is invalid", index)
|
||||
}
|
||||
endedAt, err := time.Parse(time.RFC3339, entry.EndedAt)
|
||||
if err != nil {
|
||||
return fmt.Errorf("entries[%d].endedAt is invalid", index)
|
||||
}
|
||||
interval := endedAt.Sub(startedAt)
|
||||
if interval <= 0 || interval > maxActivityDuration {
|
||||
return fmt.Errorf("entries[%d] interval must be between 1 second and %s", index, maxActivityDuration)
|
||||
}
|
||||
if entry.DurationSeconds <= 0 || entry.DurationSeconds > int64(maxActivityDuration/time.Second) || time.Duration(entry.DurationSeconds)*time.Second > interval {
|
||||
return fmt.Errorf("entries[%d].durationSeconds is invalid", index)
|
||||
}
|
||||
entry.Hostname = canonical
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p ActivityBatchPayload) EventPayload() map[string]interface{} {
|
||||
entries := make([]map[string]interface{}, 0, len(p.Entries))
|
||||
for _, entry := range p.Entries {
|
||||
entries = append(entries, map[string]interface{}{
|
||||
"hostname": entry.Hostname,
|
||||
"startedAt": entry.StartedAt,
|
||||
"endedAt": entry.EndedAt,
|
||||
"durationSeconds": entry.DurationSeconds,
|
||||
})
|
||||
}
|
||||
return map[string]interface{}{
|
||||
"batchId": strings.TrimSpace(p.BatchID),
|
||||
"createdAt": strings.TrimSpace(p.CreatedAt),
|
||||
"source": strings.TrimSpace(p.Source),
|
||||
"entries": entries,
|
||||
}
|
||||
}
|
||||
|
||||
func (p CapturePayload) validateFile() error {
|
||||
if p.File == nil || strings.TrimSpace(p.File.Name) == "" {
|
||||
return fmt.Errorf("file.name is required")
|
||||
@@ -413,10 +617,19 @@ func (p CapturePayload) EventPayload() map[string]interface{} {
|
||||
}
|
||||
|
||||
func captureDomain(rawURL, fallback string) string {
|
||||
if u, err := url.Parse(strings.TrimSpace(rawURL)); err == nil && u.Hostname() != "" {
|
||||
return u.Hostname()
|
||||
if normalized := hostname.NormalizeURLHostnameV1(rawURL); normalized != "" {
|
||||
return normalized
|
||||
}
|
||||
return strings.TrimSpace(fallback)
|
||||
return hostname.NormalizeHostnameV1(fallback)
|
||||
}
|
||||
|
||||
func writeActivityDecodeError(w http.ResponseWriter, err error) {
|
||||
var maxBytesErr *http.MaxBytesError
|
||||
if errors.As(err, &maxBytesErr) {
|
||||
writeError(w, http.StatusRequestEntityTooLarge, "activity payload exceeds limit")
|
||||
return
|
||||
}
|
||||
writeError(w, http.StatusBadRequest, "invalid JSON")
|
||||
}
|
||||
|
||||
func writeError(w http.ResponseWriter, status int, message string) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -237,6 +238,101 @@ func TestReceiverLeavesCaptureUnassignedWithoutCurrentWorkspace(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReceiverAcceptsDomainActivityBatchAfterDurablePersistence(t *testing.T) {
|
||||
bus := events.NewBus()
|
||||
received := make(chan events.Event, 1)
|
||||
bus.Subscribe("browser.activity.batch", func(event events.Event) {
|
||||
received <- event
|
||||
})
|
||||
persisted := 0
|
||||
receiver := NewWithOptions(bus, Options{
|
||||
ActivityAvailable: func() bool { return true },
|
||||
PersistActivity: func(event events.Event) error {
|
||||
persisted++
|
||||
return nil
|
||||
},
|
||||
})
|
||||
body := `{
|
||||
"schemaVersion": 1,
|
||||
"batchId": "batch-123",
|
||||
"createdAt": "2026-07-12T10:05:00.000Z",
|
||||
"source": "verstak-browser-extension",
|
||||
"entries": [{
|
||||
"hostname": "пример.рф",
|
||||
"startedAt": "2026-07-12T10:00:00.000Z",
|
||||
"endedAt": "2026-07-12T10:05:00.000Z",
|
||||
"durationSeconds": 300
|
||||
}]
|
||||
}`
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/browser-activity/v1/batches", bytes.NewBufferString(body))
|
||||
rec := httptest.NewRecorder()
|
||||
|
||||
receiver.ServeHTTP(rec, req)
|
||||
|
||||
if rec.Code != http.StatusAccepted {
|
||||
t.Fatalf("status = %d, want %d; body=%s", rec.Code, http.StatusAccepted, rec.Body.String())
|
||||
}
|
||||
if persisted != 1 {
|
||||
t.Fatalf("persisted = %d, want 1 before acknowledgement", persisted)
|
||||
}
|
||||
var response map[string]string
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &response); err != nil {
|
||||
t.Fatalf("response json: %v", err)
|
||||
}
|
||||
if response["batchId"] != "batch-123" || response["status"] != "accepted" {
|
||||
t.Fatalf("response = %+v, want accepted batch-123", response)
|
||||
}
|
||||
event := <-received
|
||||
payload, ok := event.Payload.(map[string]interface{})
|
||||
if !ok {
|
||||
t.Fatalf("event payload type = %T, want map[string]interface{}", event.Payload)
|
||||
}
|
||||
if payload["batchId"] != "batch-123" {
|
||||
t.Fatalf("event payload = %+v, want batch id", payload)
|
||||
}
|
||||
entries, ok := payload["entries"].([]map[string]interface{})
|
||||
if !ok || len(entries) != 1 || entries[0]["hostname"] != "xn--e1afmkfd.xn--p1ai" {
|
||||
t.Fatalf("event entries = %+v, want one canonical hostname", payload["entries"])
|
||||
}
|
||||
if _, ok := payload["url"]; ok {
|
||||
t.Fatalf("activity payload must not contain URL: %+v", payload)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReceiverRejectsDomainActivityWithoutConsumerOrValidInterval(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
receiver *Receiver
|
||||
body string
|
||||
wantCode int
|
||||
}{
|
||||
{
|
||||
name: "consumer unavailable",
|
||||
receiver: New(events.NewBus()),
|
||||
body: `{"schemaVersion":1,"batchId":"batch-a","createdAt":"2026-07-12T10:05:00Z","source":"verstak-browser-extension","entries":[{"hostname":"example.com","startedAt":"2026-07-12T10:00:00Z","endedAt":"2026-07-12T10:05:00Z","durationSeconds":300}]}`,
|
||||
wantCode: http.StatusServiceUnavailable,
|
||||
},
|
||||
{
|
||||
name: "duration too long",
|
||||
receiver: NewWithOptions(events.NewBus(), Options{
|
||||
ActivityAvailable: func() bool { return true },
|
||||
PersistActivity: func(events.Event) error { return nil },
|
||||
}),
|
||||
body: `{"schemaVersion":1,"batchId":"batch-b","createdAt":"2026-07-12T10:05:00Z","source":"verstak-browser-extension","entries":[{"hostname":"example.com","startedAt":"2026-07-12T10:00:00Z","endedAt":"2026-07-12T10:20:01Z","durationSeconds":1201}]}`,
|
||||
wantCode: http.StatusBadRequest,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
req := httptest.NewRequest(http.MethodPost, "/api/browser-activity/v1/batches", strings.NewReader(tc.body))
|
||||
rec := httptest.NewRecorder()
|
||||
tc.receiver.ServeHTTP(rec, req)
|
||||
if rec.Code != tc.wantCode {
|
||||
t.Fatalf("status = %d, want %d; body=%s", rec.Code, tc.wantCode, rec.Body.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestReceiverRequiresTokenWhenPaired(t *testing.T) {
|
||||
bus := events.NewBus()
|
||||
received := make(chan events.Event, 1)
|
||||
@@ -321,6 +417,61 @@ func TestReceiverAcceptsPairedToken(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReceiverRejectsCaptureWhenInboxIsUnavailable(t *testing.T) {
|
||||
bus := events.NewBus()
|
||||
bus.Subscribe("browser.capture.page", func(event events.Event) {
|
||||
t.Fatalf("unexpected event while inbox is unavailable: %#v", event)
|
||||
})
|
||||
receiver := NewWithOptions(bus, Options{
|
||||
Available: func() bool { return false },
|
||||
})
|
||||
req := httptest.NewRequest(http.MethodPost, capturePath, strings.NewReader(`{
|
||||
"schemaVersion": 1,
|
||||
"captureId": "capture-no-vault",
|
||||
"capturedAt": "2026-07-11T12:00:00Z",
|
||||
"kind": "page",
|
||||
"page": {"url": "https://example.com"}
|
||||
}`))
|
||||
res := httptest.NewRecorder()
|
||||
|
||||
receiver.ServeHTTP(res, req)
|
||||
|
||||
if res.Code != http.StatusServiceUnavailable {
|
||||
t.Fatalf("status = %d, want %d; body=%s", res.Code, http.StatusServiceUnavailable, res.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestReceiverDoesNotAcknowledgeFailedPersistence(t *testing.T) {
|
||||
bus := events.NewBus()
|
||||
published := false
|
||||
bus.Subscribe("browser.capture.page", func(event events.Event) {
|
||||
published = true
|
||||
})
|
||||
receiver := NewWithOptions(bus, Options{
|
||||
Available: func() bool { return true },
|
||||
Persist: func(event events.Event) error {
|
||||
return errors.New("disk full")
|
||||
},
|
||||
})
|
||||
req := httptest.NewRequest(http.MethodPost, capturePath, strings.NewReader(`{
|
||||
"schemaVersion": 1,
|
||||
"captureId": "capture-disk-full",
|
||||
"capturedAt": "2026-07-11T12:00:00Z",
|
||||
"kind": "page",
|
||||
"page": {"url": "https://example.com"}
|
||||
}`))
|
||||
res := httptest.NewRecorder()
|
||||
|
||||
receiver.ServeHTTP(res, req)
|
||||
|
||||
if res.Code != http.StatusServiceUnavailable {
|
||||
t.Fatalf("status = %d, want %d; body=%s", res.Code, http.StatusServiceUnavailable, res.Body.String())
|
||||
}
|
||||
if published {
|
||||
t.Fatal("capture event was published after persistence failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestReceiverRotatesPairedToken(t *testing.T) {
|
||||
bus := events.NewBus()
|
||||
bus.Subscribe("browser.capture.page", func(event events.Event) {})
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package capability
|
||||
|
||||
const CorePluginID = "verstak-desktop"
|
||||
|
||||
var platformCapabilities = []string{
|
||||
"verstak/core/plugin-manager/v1",
|
||||
"verstak/core/capability-registry/v1",
|
||||
"verstak/core/contribution-registry/v1",
|
||||
"verstak/core/permissions/v1",
|
||||
"verstak/core/events/v1",
|
||||
"verstak/core/files/v1",
|
||||
"verstak/core/workbench/v1",
|
||||
"verstak/core/notifications/v1",
|
||||
}
|
||||
|
||||
// CorePlatformCapabilities returns a copy of the capabilities registered by
|
||||
// the desktop before dynamic plugins are resolved.
|
||||
func CorePlatformCapabilities() []string {
|
||||
return append([]string(nil), platformCapabilities...)
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package hostname
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"net/url"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"golang.org/x/net/idna"
|
||||
)
|
||||
|
||||
const (
|
||||
maxDNSHostnameLength = 253
|
||||
maxDNSLabelLength = 63
|
||||
)
|
||||
|
||||
// NormalizeHostnameV1 returns the canonical A-label hostname used by domain
|
||||
// bindings. It accepts a bare DNS name, IPv4 address, bracketed IPv6 literal,
|
||||
// localhost, or a single-label internal hostname. Invalid input returns "".
|
||||
func NormalizeHostnameV1(input string) string {
|
||||
value := strings.TrimSpace(input)
|
||||
if value == "" || strings.IndexFunc(value, unicode.IsSpace) >= 0 || strings.ContainsAny(value, "\\/?#@") {
|
||||
return ""
|
||||
}
|
||||
|
||||
if strings.HasPrefix(value, "[") || strings.HasSuffix(value, "]") {
|
||||
if !strings.HasPrefix(value, "[") || !strings.HasSuffix(value, "]") {
|
||||
return ""
|
||||
}
|
||||
return normalizeIPv6(value[1 : len(value)-1])
|
||||
}
|
||||
if strings.Contains(value, ":") {
|
||||
return ""
|
||||
}
|
||||
|
||||
value = strings.TrimSuffix(value, ".")
|
||||
if value == "" || strings.HasSuffix(value, ".") {
|
||||
return ""
|
||||
}
|
||||
if isNumericHostname(value) {
|
||||
return normalizeIPv4(value)
|
||||
}
|
||||
return normalizeDNS(value)
|
||||
}
|
||||
|
||||
// NormalizeURLHostnameV1 returns the canonical hostname from an HTTP(S) URL.
|
||||
// Ports, paths, credentials, and fragments are intentionally not preserved.
|
||||
func NormalizeURLHostnameV1(input string) string {
|
||||
value := strings.TrimSpace(input)
|
||||
if value == "" {
|
||||
return ""
|
||||
}
|
||||
parsed, err := url.ParseRequestURI(value)
|
||||
if err != nil || (parsed.Scheme != "http" && parsed.Scheme != "https") {
|
||||
return ""
|
||||
}
|
||||
host := parsed.Hostname()
|
||||
if host == "" {
|
||||
return ""
|
||||
}
|
||||
if address, err := netip.ParseAddr(host); err == nil && address.Is6() {
|
||||
return address.String()
|
||||
}
|
||||
return NormalizeHostnameV1(host)
|
||||
}
|
||||
|
||||
func normalizeIPv4(value string) string {
|
||||
address, err := netip.ParseAddr(value)
|
||||
if err != nil || !address.Is4() || address.String() != value {
|
||||
return ""
|
||||
}
|
||||
return address.String()
|
||||
}
|
||||
|
||||
func normalizeIPv6(value string) string {
|
||||
address, err := netip.ParseAddr(value)
|
||||
if err != nil || !address.Is6() {
|
||||
return ""
|
||||
}
|
||||
return address.String()
|
||||
}
|
||||
|
||||
func normalizeDNS(value string) string {
|
||||
ascii, err := idna.Lookup.ToASCII(value)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
ascii = strings.ToLower(strings.TrimSuffix(ascii, "."))
|
||||
if ascii == "" || strings.HasSuffix(ascii, ".") || len(ascii) > maxDNSHostnameLength {
|
||||
return ""
|
||||
}
|
||||
for _, label := range strings.Split(ascii, ".") {
|
||||
if len(label) == 0 || len(label) > maxDNSLabelLength || !isDNSLabel(label) {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return ascii
|
||||
}
|
||||
|
||||
func isNumericHostname(value string) bool {
|
||||
for _, char := range value {
|
||||
if (char < '0' || char > '9') && char != '.' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func isDNSLabel(label string) bool {
|
||||
if !isASCIIAlphaNum(label[0]) || !isASCIIAlphaNum(label[len(label)-1]) {
|
||||
return false
|
||||
}
|
||||
for _, char := range label {
|
||||
if !isASCIIAlphaNum(byte(char)) && char != '-' {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func isASCIIAlphaNum(char byte) bool {
|
||||
return char >= 'a' && char <= 'z' || char >= '0' && char <= '9'
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package hostname
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type normalizationVector struct {
|
||||
Input string `json:"input"`
|
||||
Output string `json:"output"`
|
||||
}
|
||||
|
||||
type normalizationVectors struct {
|
||||
Bare []normalizationVector `json:"bare"`
|
||||
URL []normalizationVector `json:"url"`
|
||||
}
|
||||
|
||||
func TestNormalizeHostnameV1Vectors(t *testing.T) {
|
||||
vectors := loadVectors(t)
|
||||
for _, vector := range vectors.Bare {
|
||||
if got := NormalizeHostnameV1(vector.Input); got != vector.Output {
|
||||
t.Errorf("NormalizeHostnameV1(%q) = %q, want %q", vector.Input, got, vector.Output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeURLHostnameV1Vectors(t *testing.T) {
|
||||
vectors := loadVectors(t)
|
||||
for _, vector := range vectors.URL {
|
||||
if got := NormalizeURLHostnameV1(vector.Input); got != vector.Output {
|
||||
t.Errorf("NormalizeURLHostnameV1(%q) = %q, want %q", vector.Input, got, vector.Output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func loadVectors(t *testing.T) normalizationVectors {
|
||||
t.Helper()
|
||||
path := filepath.Join("testdata", "hostname-normalization-v1.json")
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
t.Fatalf("read %s: %v", path, err)
|
||||
}
|
||||
var vectors normalizationVectors
|
||||
if err := json.Unmarshal(data, &vectors); err != nil {
|
||||
t.Fatalf("decode %s: %v", path, err)
|
||||
}
|
||||
return vectors
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://raw.githubusercontent.com/mirivlad/verstak-sdk/main/schemas/hostname-normalization-v1.json",
|
||||
"title": "Verstak canonical hostname normalization v1 test vectors",
|
||||
"description": "Canonical hostnames are lowercase ASCII A-labels without a port or trailing DNS dot. Bare hostnames accept DNS names, IPv4, bracketed IPv6, localhost, and internal single-label names. URL inputs accept only HTTP(S). Invalid or excessively long input normalizes to an empty string.",
|
||||
"version": 1,
|
||||
"bare": [
|
||||
{ "input": "example.com", "output": "example.com" },
|
||||
{ "input": " Example.COM. ", "output": "example.com" },
|
||||
{ "input": "пример.рф", "output": "xn--e1afmkfd.xn--p1ai" },
|
||||
{ "input": "bücher.example", "output": "xn--bcher-kva.example" },
|
||||
{ "input": "127.0.0.1", "output": "127.0.0.1" },
|
||||
{ "input": "[2001:db8::1]", "output": "2001:db8::1" },
|
||||
{ "input": "localhost", "output": "localhost" },
|
||||
{ "input": "intranet", "output": "intranet" },
|
||||
{ "input": "", "output": "" },
|
||||
{ "input": "https://example.com", "output": "" },
|
||||
{ "input": "example.com:443", "output": "" },
|
||||
{ "input": "user@example.com", "output": "" },
|
||||
{ "input": "bad host", "output": "" },
|
||||
{ "input": "example..com", "output": "" },
|
||||
{ "input": "example.com..", "output": "" },
|
||||
{ "input": "127.000.000.001", "output": "" },
|
||||
{ "input": "[2001:db8::1]:443", "output": "" },
|
||||
{ "input": "a...............................................................example", "output": "" }
|
||||
],
|
||||
"url": [
|
||||
{ "input": "https://пример.рф/path", "output": "xn--e1afmkfd.xn--p1ai" },
|
||||
{ "input": "http://Example.COM.:8080/path", "output": "example.com" },
|
||||
{ "input": "https://[2001:db8::1]/", "output": "2001:db8::1" },
|
||||
{ "input": "ftp://example.com/path", "output": "" },
|
||||
{ "input": "not a URL", "output": "" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
// Package notifications persists plugin-owned reminder schedules and delivers
|
||||
// due entries through a desktop-native sender.
|
||||
package notifications
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
maxRequestsPerPlugin = 500
|
||||
maxIDLength = 256
|
||||
maxTitleLength = 512
|
||||
maxBodyLength = 4096
|
||||
)
|
||||
|
||||
// VaultPath provides a stable operation while a vault is open.
|
||||
type VaultPath interface {
|
||||
WithOpenPath(func(string) error) error
|
||||
}
|
||||
|
||||
// Request is a desired scheduled notification in a plugin's own namespace.
|
||||
type Request struct {
|
||||
ID string `json:"id"`
|
||||
DueAt string `json:"dueAt"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body,omitempty"`
|
||||
}
|
||||
|
||||
// Item is the persisted form of a plugin notification schedule.
|
||||
type Item struct {
|
||||
PluginID string `json:"pluginId"`
|
||||
ID string `json:"id"`
|
||||
DueAt string `json:"dueAt"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body,omitempty"`
|
||||
SentForDueAt string `json:"sentForDueAt,omitempty"`
|
||||
}
|
||||
|
||||
// Sender delivers one native desktop notification.
|
||||
type Sender interface {
|
||||
Send(context.Context, Item) error
|
||||
}
|
||||
|
||||
// Manager owns canonical schedules for every authorized plugin.
|
||||
type Manager struct {
|
||||
mu sync.Mutex
|
||||
vault VaultPath
|
||||
sender Sender
|
||||
now func() time.Time
|
||||
|
||||
items []Item
|
||||
loaded bool
|
||||
stop chan struct{}
|
||||
}
|
||||
|
||||
// New creates a notification manager. The supplied clock is used by tests; a
|
||||
// nil clock uses the current time.
|
||||
func New(vault VaultPath, sender Sender, now func() time.Time) *Manager {
|
||||
if now == nil {
|
||||
now = time.Now
|
||||
}
|
||||
return &Manager{vault: vault, sender: sender, now: now}
|
||||
}
|
||||
|
||||
// Replace atomically replaces one plugin's desired schedules.
|
||||
func (m *Manager) Replace(pluginID string, requests []Request) error {
|
||||
if err := validateRequests(pluginID, requests); err != nil {
|
||||
return err
|
||||
}
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if err := m.loadLocked(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
previous := make(map[string]Item)
|
||||
kept := make([]Item, 0, len(m.items)+len(requests))
|
||||
for _, item := range m.items {
|
||||
if item.PluginID == pluginID {
|
||||
previous[item.ID] = item
|
||||
continue
|
||||
}
|
||||
kept = append(kept, item)
|
||||
}
|
||||
for _, request := range requests {
|
||||
item := Item{
|
||||
PluginID: pluginID,
|
||||
ID: request.ID,
|
||||
DueAt: request.DueAt,
|
||||
Title: request.Title,
|
||||
Body: request.Body,
|
||||
}
|
||||
if old, ok := previous[request.ID]; ok && old.DueAt == request.DueAt {
|
||||
item.SentForDueAt = old.SentForDueAt
|
||||
}
|
||||
kept = append(kept, item)
|
||||
}
|
||||
sortItems(kept)
|
||||
if err := m.writeLocked(kept); err != nil {
|
||||
return err
|
||||
}
|
||||
m.items = kept
|
||||
return nil
|
||||
}
|
||||
|
||||
// Clear removes every schedule owned by a plugin.
|
||||
func (m *Manager) Clear(pluginID string) error {
|
||||
return m.Replace(pluginID, nil)
|
||||
}
|
||||
|
||||
// Items returns a snapshot of the current schedule state.
|
||||
func (m *Manager) Items() []Item {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if err := m.loadLocked(); err != nil {
|
||||
return nil
|
||||
}
|
||||
return append([]Item(nil), m.items...)
|
||||
}
|
||||
|
||||
// Path reports the canonical schedule path while the vault is open.
|
||||
func (m *Manager) Path() string {
|
||||
if m == nil || m.vault == nil {
|
||||
return ""
|
||||
}
|
||||
var path string
|
||||
if err := m.vault.WithOpenPath(func(vaultPath string) error {
|
||||
path = schedulePath(vaultPath)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return ""
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
// Start immediately checks due schedules, then repeats every 30 seconds.
|
||||
func (m *Manager) Start(ctx context.Context) {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
m.mu.Lock()
|
||||
if m.stop != nil {
|
||||
m.mu.Unlock()
|
||||
return
|
||||
}
|
||||
stop := make(chan struct{})
|
||||
m.stop = stop
|
||||
m.mu.Unlock()
|
||||
|
||||
go func() {
|
||||
m.Tick(ctx)
|
||||
ticker := time.NewTicker(30 * time.Second)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
m.Tick(ctx)
|
||||
case <-stop:
|
||||
return
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// Stop stops a running scheduler. It is safe to call repeatedly.
|
||||
func (m *Manager) Stop() {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if m.stop == nil {
|
||||
return
|
||||
}
|
||||
close(m.stop)
|
||||
m.stop = nil
|
||||
}
|
||||
|
||||
// Tick delivers each overdue schedule once. A sender failure leaves the item
|
||||
// pending for a later tick.
|
||||
func (m *Manager) Tick(ctx context.Context) {
|
||||
if m == nil || m.sender == nil {
|
||||
return
|
||||
}
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if err := m.loadLocked(); err != nil {
|
||||
return
|
||||
}
|
||||
now := m.now().UTC()
|
||||
for index, item := range m.items {
|
||||
dueAt, err := time.Parse(time.RFC3339, item.DueAt)
|
||||
if err != nil || dueAt.After(now) || item.SentForDueAt == item.DueAt {
|
||||
continue
|
||||
}
|
||||
if err := m.sender.Send(ctx, item); err != nil {
|
||||
continue
|
||||
}
|
||||
updated := append([]Item(nil), m.items...)
|
||||
updated[index].SentForDueAt = item.DueAt
|
||||
if err := m.writeLocked(updated); err != nil {
|
||||
continue
|
||||
}
|
||||
m.items = updated
|
||||
}
|
||||
}
|
||||
|
||||
func validateRequests(pluginID string, requests []Request) error {
|
||||
if strings.TrimSpace(pluginID) == "" || strings.ContainsAny(pluginID, "/\\") {
|
||||
return fmt.Errorf("invalid plugin ID %q", pluginID)
|
||||
}
|
||||
if len(requests) > maxRequestsPerPlugin {
|
||||
return fmt.Errorf("plugin %q has more than %d notification schedules", pluginID, maxRequestsPerPlugin)
|
||||
}
|
||||
seen := make(map[string]bool, len(requests))
|
||||
for _, request := range requests {
|
||||
if request.ID == "" || len(request.ID) > maxIDLength {
|
||||
return fmt.Errorf("notification ID is empty or too long")
|
||||
}
|
||||
if seen[request.ID] {
|
||||
return fmt.Errorf("duplicate notification ID %q", request.ID)
|
||||
}
|
||||
seen[request.ID] = true
|
||||
if !strings.HasSuffix(request.DueAt, "Z") {
|
||||
return fmt.Errorf("notification %q dueAt must be UTC RFC3339", request.ID)
|
||||
}
|
||||
if _, err := time.Parse(time.RFC3339, request.DueAt); err != nil {
|
||||
return fmt.Errorf("notification %q has invalid dueAt: %w", request.ID, err)
|
||||
}
|
||||
if strings.TrimSpace(request.Title) == "" || len(request.Title) > maxTitleLength {
|
||||
return fmt.Errorf("notification %q title is empty or too long", request.ID)
|
||||
}
|
||||
if len(request.Body) > maxBodyLength {
|
||||
return fmt.Errorf("notification %q body is too long", request.ID)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func sortItems(items []Item) {
|
||||
sort.Slice(items, func(left, right int) bool {
|
||||
if items[left].PluginID != items[right].PluginID {
|
||||
return items[left].PluginID < items[right].PluginID
|
||||
}
|
||||
return items[left].ID < items[right].ID
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package notifications
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type testVault struct {
|
||||
path string
|
||||
}
|
||||
|
||||
func (v testVault) WithOpenPath(operation func(string) error) error {
|
||||
return operation(v.path)
|
||||
}
|
||||
|
||||
type fakeSender struct {
|
||||
err error
|
||||
items []Item
|
||||
}
|
||||
|
||||
func (s *fakeSender) Send(_ context.Context, item Item) error {
|
||||
s.items = append(s.items, item)
|
||||
return s.err
|
||||
}
|
||||
|
||||
func testManager(t *testing.T, sender *fakeSender, now time.Time) *Manager {
|
||||
t.Helper()
|
||||
return New(testVault{path: t.TempDir()}, sender, func() time.Time { return now })
|
||||
}
|
||||
|
||||
func request(id, dueAt string) Request {
|
||||
return Request{ID: id, DueAt: dueAt, Title: "Reminder " + id, Body: "Todo " + id}
|
||||
}
|
||||
|
||||
func TestReplaceRemovesStalePluginSchedules(t *testing.T) {
|
||||
manager := testManager(t, &fakeSender{}, time.Date(2026, 7, 14, 9, 0, 0, 0, time.UTC))
|
||||
if err := manager.Replace("verstak.todo", []Request{
|
||||
request("first", "2026-07-14T10:00:00Z"),
|
||||
request("second", "2026-07-14T11:00:00Z"),
|
||||
}); err != nil {
|
||||
t.Fatalf("initial replace: %v", err)
|
||||
}
|
||||
if err := manager.Replace("verstak.todo", []Request{request("second", "2026-07-14T11:00:00Z")}); err != nil {
|
||||
t.Fatalf("stale-item replace: %v", err)
|
||||
}
|
||||
|
||||
items := manager.Items()
|
||||
if len(items) != 1 || items[0].PluginID != "verstak.todo" || items[0].ID != "second" {
|
||||
t.Fatalf("items = %#v, want only second Todo reminder", items)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplaceReschedulesDeliveredItem(t *testing.T) {
|
||||
now := time.Date(2026, 7, 14, 12, 0, 0, 0, time.UTC)
|
||||
sender := &fakeSender{}
|
||||
manager := testManager(t, sender, now)
|
||||
if err := manager.Replace("verstak.todo", []Request{request("todo-1", "2026-07-14T11:00:00Z")}); err != nil {
|
||||
t.Fatalf("initial replace: %v", err)
|
||||
}
|
||||
manager.Tick(context.Background())
|
||||
if len(sender.items) != 1 || manager.Items()[0].SentForDueAt == "" {
|
||||
t.Fatalf("first delivery = %#v, state = %#v", sender.items, manager.Items())
|
||||
}
|
||||
|
||||
if err := manager.Replace("verstak.todo", []Request{request("todo-1", "2026-07-14T13:00:00Z")}); err != nil {
|
||||
t.Fatalf("reschedule: %v", err)
|
||||
}
|
||||
if got := manager.Items()[0].SentForDueAt; got != "" {
|
||||
t.Fatalf("rescheduled item kept old acknowledgment %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTickRetriesFailedSendAndAcknowledgesOneDelivery(t *testing.T) {
|
||||
now := time.Date(2026, 7, 14, 12, 0, 0, 0, time.UTC)
|
||||
sender := &fakeSender{err: errors.New("notification unavailable")}
|
||||
manager := testManager(t, sender, now)
|
||||
if err := manager.Replace("verstak.todo", []Request{request("todo-1", "2026-07-14T11:00:00Z")}); err != nil {
|
||||
t.Fatalf("replace: %v", err)
|
||||
}
|
||||
|
||||
manager.Tick(context.Background())
|
||||
if len(sender.items) != 1 || manager.Items()[0].SentForDueAt != "" {
|
||||
t.Fatalf("failed send was acknowledged: sent=%d items=%#v", len(sender.items), manager.Items())
|
||||
}
|
||||
|
||||
sender.err = nil
|
||||
manager.Tick(context.Background())
|
||||
manager.Tick(context.Background())
|
||||
if len(sender.items) != 2 {
|
||||
t.Fatalf("send attempts = %d, want 2", len(sender.items))
|
||||
}
|
||||
if got := manager.Items()[0].SentForDueAt; got != "2026-07-14T11:00:00Z" {
|
||||
t.Fatalf("sent acknowledgment = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPersistentSchedulesReloadAndDeliverOverdueOnlyOnce(t *testing.T) {
|
||||
path := t.TempDir()
|
||||
now := time.Date(2026, 7, 14, 12, 0, 0, 0, time.UTC)
|
||||
first := New(testVault{path: path}, &fakeSender{}, func() time.Time { return now })
|
||||
if err := first.Replace("verstak.todo", []Request{request("todo-1", "2026-07-14T11:00:00Z")}); err != nil {
|
||||
t.Fatalf("replace: %v", err)
|
||||
}
|
||||
if got, want := filepath.Join(path, ".verstak", "notifications", "schedules.json"), first.Path(); got != want {
|
||||
t.Fatalf("schedule path = %q, want %q", got, want)
|
||||
}
|
||||
|
||||
sender := &fakeSender{}
|
||||
restarted := New(testVault{path: path}, sender, func() time.Time { return now })
|
||||
restarted.Tick(context.Background())
|
||||
restarted.Tick(context.Background())
|
||||
if len(sender.items) != 1 || sender.items[0].ID != "todo-1" {
|
||||
t.Fatalf("overdue delivery = %#v", sender.items)
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplaceRejectsInvalidRequests(t *testing.T) {
|
||||
manager := testManager(t, &fakeSender{}, time.Now().UTC())
|
||||
for _, requests := range [][]Request{
|
||||
{{ID: "", DueAt: "2026-07-14T10:00:00Z", Title: "title"}},
|
||||
{{ID: "same", DueAt: "2026-07-14T10:00:00Z", Title: "title"}, {ID: "same", DueAt: "2026-07-14T11:00:00Z", Title: "title"}},
|
||||
{{ID: "bad-date", DueAt: "not-a-date", Title: "title"}},
|
||||
} {
|
||||
if err := manager.Replace("verstak.todo", requests); err == nil {
|
||||
t.Fatalf("Replace(%#v) succeeded", requests)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package notifications
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
type storedSchedules struct {
|
||||
Items []Item `json:"items"`
|
||||
}
|
||||
|
||||
func schedulePath(vaultPath string) string {
|
||||
return filepath.Join(vaultPath, ".verstak", "notifications", "schedules.json")
|
||||
}
|
||||
|
||||
func (m *Manager) loadLocked() error {
|
||||
if m.loaded {
|
||||
return nil
|
||||
}
|
||||
if m.vault == nil {
|
||||
return fmt.Errorf("notification vault is not initialized")
|
||||
}
|
||||
var loaded []Item
|
||||
if err := m.vault.WithOpenPath(func(vaultPath string) error {
|
||||
path := schedulePath(vaultPath)
|
||||
data, err := os.ReadFile(path)
|
||||
if os.IsNotExist(err) {
|
||||
loaded = []Item{}
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("read notification schedules: %w", err)
|
||||
}
|
||||
var stored storedSchedules
|
||||
if err := json.Unmarshal(data, &stored); err != nil {
|
||||
return fmt.Errorf("decode notification schedules: %w", err)
|
||||
}
|
||||
for _, item := range stored.Items {
|
||||
if err := validateRequests(item.PluginID, []Request{{ID: item.ID, DueAt: item.DueAt, Title: item.Title, Body: item.Body}}); err != nil {
|
||||
return fmt.Errorf("invalid stored notification schedule: %w", err)
|
||||
}
|
||||
loaded = append(loaded, item)
|
||||
}
|
||||
sortItems(loaded)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
m.items = loaded
|
||||
m.loaded = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Manager) writeLocked(items []Item) error {
|
||||
if m.vault == nil {
|
||||
return fmt.Errorf("notification vault is not initialized")
|
||||
}
|
||||
return m.vault.WithOpenPath(func(vaultPath string) error {
|
||||
data, err := json.MarshalIndent(storedSchedules{Items: items}, "", " ")
|
||||
if err != nil {
|
||||
return fmt.Errorf("encode notification schedules: %w", err)
|
||||
}
|
||||
path := schedulePath(vaultPath)
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
return fmt.Errorf("create notification schedule directory: %w", err)
|
||||
}
|
||||
temporary := filepath.Join(filepath.Dir(path), fmt.Sprintf(".schedules.%d.tmp", time.Now().UnixNano()))
|
||||
if err := os.WriteFile(temporary, data, 0o644); err != nil {
|
||||
return fmt.Errorf("write notification schedules: %w", err)
|
||||
}
|
||||
if err := os.Rename(temporary, path); err != nil {
|
||||
_ = os.Remove(temporary)
|
||||
return fmt.Errorf("replace notification schedules: %w", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -39,6 +39,7 @@ func (r *Registry) registerDefaults() {
|
||||
{Name: "files.openExternal", Description: "Open vault files and folders in external OS applications", Dangerous: true},
|
||||
{Name: "storage.namespace", Description: "Read/write plugin's own storage namespace", Dangerous: false},
|
||||
{Name: "storage.migrations", Description: "Run database migrations in plugin namespace", Dangerous: false},
|
||||
{Name: "notifications.schedule", Description: "Schedule native notifications in the plugin's own namespace", Dangerous: false},
|
||||
{Name: "events.publish", Description: "Publish events to the event bus", Dangerous: false},
|
||||
{Name: "events.subscribe", Description: "Subscribe to events on the event bus", Dangerous: false},
|
||||
{Name: "ui.register", Description: "Register UI components and contributions", Dangerous: false},
|
||||
|
||||
@@ -3,25 +3,16 @@ package plugin
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/verstak/verstak-desktop/internal/core/capability"
|
||||
)
|
||||
|
||||
// coreCapabilities lists the 5 core capabilities that the platform registers
|
||||
// before any plugins are loaded.
|
||||
var coreCapabilities = []string{
|
||||
"verstak/core/plugin-manager/v1",
|
||||
"verstak/core/capability-registry/v1",
|
||||
"verstak/core/contribution-registry/v1",
|
||||
"verstak/core/permissions/v1",
|
||||
"verstak/core/events/v1",
|
||||
}
|
||||
|
||||
// registerCoreCapabilities registers the 5 core capabilities on a registry.
|
||||
// registerCoreCapabilities registers the desktop's core capabilities on a registry.
|
||||
func registerCoreCapabilities(t *testing.T, reg *capability.Registry) {
|
||||
t.Helper()
|
||||
if err := reg.Register("verstak-core", coreCapabilities); err != nil {
|
||||
if err := reg.Register(capability.CorePluginID, capability.CorePlatformCapabilities()); err != nil {
|
||||
t.Fatalf("failed to register core capabilities: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -76,6 +67,43 @@ func TestLifecycle_CoreCapabilitiesRegisteredBeforePlugins(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBundledOfficialPluginRequirementsResolve(t *testing.T) {
|
||||
plugins, errs := DiscoverPlugins([]string{bundledPluginDir(t)})
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("discover bundled plugins: %v", errs)
|
||||
}
|
||||
|
||||
reg := capability.NewRegistry()
|
||||
registerCoreCapabilities(t, reg)
|
||||
ResolveLifecycle(plugins, reg, nil)
|
||||
|
||||
foundTodo := false
|
||||
for _, loaded := range plugins {
|
||||
if loaded.Manifest.ID == "verstak.todo" {
|
||||
foundTodo = true
|
||||
}
|
||||
if loaded.Status == StatusMissingRequiredCapability {
|
||||
t.Fatalf("bundled plugin %q is missing required capabilities: %s", loaded.Manifest.ID, loaded.Error)
|
||||
}
|
||||
}
|
||||
|
||||
if !foundTodo {
|
||||
t.Fatal("bundled Todo manifest was not discovered")
|
||||
}
|
||||
}
|
||||
|
||||
func bundledPluginDir(t *testing.T) string {
|
||||
t.Helper()
|
||||
if configured := os.Getenv("VERSTAK_RELEASE_PLUGIN_DIR"); configured != "" {
|
||||
return configured
|
||||
}
|
||||
_, sourceFile, _, ok := runtime.Caller(0)
|
||||
if !ok {
|
||||
t.Fatal("could not resolve lifecycle test path")
|
||||
}
|
||||
return filepath.Join(filepath.Dir(sourceFile), "../../../plugins")
|
||||
}
|
||||
|
||||
// TestLifecycle_MissingRequiredCapability verifies that when the required
|
||||
// capability is NOT registered, CheckRequired reports it as missing and the
|
||||
// plugin status should be set to StatusMissingRequiredCapability.
|
||||
|
||||
@@ -7,28 +7,36 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Manifest represents a Verstak plugin.json manifest.
|
||||
type Manifest struct {
|
||||
SchemaVersion int `json:"schemaVersion"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
APIVersion string `json:"apiVersion"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Source string `json:"source,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
Provides []string `json:"provides"`
|
||||
Requires []string `json:"requires,omitempty"`
|
||||
OptionalRequires []string `json:"optionalRequires,omitempty"`
|
||||
Permissions []string `json:"permissions"`
|
||||
Frontend *FrontendConfig `json:"frontend,omitempty"`
|
||||
Backend *BackendConfig `json:"backend,omitempty"`
|
||||
Migrations *MigrationConfig `json:"migrations,omitempty"`
|
||||
Contributes *Contributions `json:"contributes,omitempty"`
|
||||
Sync *SyncConfig `json:"sync,omitempty"`
|
||||
SchemaVersion int `json:"schemaVersion"`
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
APIVersion string `json:"apiVersion"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Source string `json:"source,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
Localization *LocalizationConfig `json:"localization,omitempty"`
|
||||
Provides []string `json:"provides"`
|
||||
Requires []string `json:"requires,omitempty"`
|
||||
OptionalRequires []string `json:"optionalRequires,omitempty"`
|
||||
Permissions []string `json:"permissions"`
|
||||
Frontend *FrontendConfig `json:"frontend,omitempty"`
|
||||
Backend *BackendConfig `json:"backend,omitempty"`
|
||||
Migrations *MigrationConfig `json:"migrations,omitempty"`
|
||||
Contributes *Contributions `json:"contributes,omitempty"`
|
||||
Sync *SyncConfig `json:"sync,omitempty"`
|
||||
}
|
||||
|
||||
// LocalizationConfig declares plugin-owned UI message catalogs.
|
||||
type LocalizationConfig struct {
|
||||
DefaultLocale string `json:"defaultLocale"`
|
||||
Locales map[string]string `json:"locales"`
|
||||
}
|
||||
|
||||
// FrontendConfig describes the plugin's frontend bundle.
|
||||
@@ -237,6 +245,25 @@ func ValidateManifest(m *Manifest) []string {
|
||||
if len(m.Permissions) == 0 {
|
||||
errs.add("permissions must have at least one permission")
|
||||
}
|
||||
if m.Localization != nil {
|
||||
if !isValidLocaleTag(m.Localization.DefaultLocale) {
|
||||
errs.add("localization.defaultLocale %q is not a valid lower-case locale", m.Localization.DefaultLocale)
|
||||
}
|
||||
if len(m.Localization.Locales) == 0 {
|
||||
errs.add("localization.locales must contain at least one catalog")
|
||||
}
|
||||
if _, ok := m.Localization.Locales[m.Localization.DefaultLocale]; !ok {
|
||||
errs.add("localization.defaultLocale %q must have a declared catalog", m.Localization.DefaultLocale)
|
||||
}
|
||||
for locale, catalogPath := range m.Localization.Locales {
|
||||
if !isValidLocaleTag(locale) {
|
||||
errs.add("localization locale %q is not a valid lower-case locale", locale)
|
||||
}
|
||||
if err := ValidateLocalizationPath(catalogPath); err != nil {
|
||||
errs.add("localization locale %q: %v", locale, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if m.Contributes != nil {
|
||||
for i, provider := range m.Contributes.OpenProviders {
|
||||
if provider.ID == "" {
|
||||
@@ -262,6 +289,31 @@ func ValidateManifest(m *Manifest) []string {
|
||||
return errs.errors
|
||||
}
|
||||
|
||||
var localeTagPattern = regexp.MustCompile(`^[a-z]{2}(?:-[a-z0-9]+)*$`)
|
||||
|
||||
func isValidLocaleTag(locale string) bool {
|
||||
return localeTagPattern.MatchString(locale)
|
||||
}
|
||||
|
||||
// ValidateLocalizationPath accepts only slash-separated plugin-relative paths.
|
||||
func ValidateLocalizationPath(catalogPath string) error {
|
||||
if strings.TrimSpace(catalogPath) == "" {
|
||||
return fmt.Errorf("catalog path is required")
|
||||
}
|
||||
if filepath.IsAbs(catalogPath) || filepath.VolumeName(catalogPath) != "" || strings.HasPrefix(catalogPath, "/") {
|
||||
return fmt.Errorf("catalog path must be relative")
|
||||
}
|
||||
if strings.Contains(catalogPath, `\`) {
|
||||
return fmt.Errorf("catalog path must not contain backslash")
|
||||
}
|
||||
for _, part := range strings.Split(catalogPath, "/") {
|
||||
if part == ".." {
|
||||
return fmt.Errorf("catalog path traversal is not allowed")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func isValidPluginID(id string) bool {
|
||||
if id == "" {
|
||||
return false
|
||||
|
||||
@@ -233,6 +233,50 @@ func TestValidateManifest_OpenProviders(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateManifest_Localization(t *testing.T) {
|
||||
base := &Manifest{
|
||||
SchemaVersion: 1,
|
||||
ID: "localized.plugin",
|
||||
Name: "Localized",
|
||||
Version: "1.0.0",
|
||||
APIVersion: "1.0",
|
||||
Provides: []string{"localized.capability"},
|
||||
Permissions: []string{"ui.register"},
|
||||
Localization: &LocalizationConfig{
|
||||
DefaultLocale: "en",
|
||||
Locales: map[string]string{
|
||||
"en": "locales/en.json",
|
||||
"ru": "locales/ru.json",
|
||||
},
|
||||
},
|
||||
}
|
||||
if errs := ValidateManifest(base); len(errs) != 0 {
|
||||
t.Fatalf("valid localization errors = %v", errs)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
localization *LocalizationConfig
|
||||
want string
|
||||
}{
|
||||
{"missing default catalog", &LocalizationConfig{DefaultLocale: "en", Locales: map[string]string{"ru": "locales/ru.json"}}, "defaultLocale"},
|
||||
{"invalid locale", &LocalizationConfig{DefaultLocale: "EN", Locales: map[string]string{"EN": "locales/en.json"}}, "locale"},
|
||||
{"absolute path", &LocalizationConfig{DefaultLocale: "en", Locales: map[string]string{"en": "/tmp/en.json"}}, "relative"},
|
||||
{"traversal", &LocalizationConfig{DefaultLocale: "en", Locales: map[string]string{"en": "../en.json"}}, "traversal"},
|
||||
{"backslash", &LocalizationConfig{DefaultLocale: "en", Locales: map[string]string{"en": `locales\en.json`}}, "backslash"},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
manifest := *base
|
||||
manifest.Localization = tc.localization
|
||||
combined := strings.Join(ValidateManifest(&manifest), "\n")
|
||||
if !strings.Contains(combined, tc.want) {
|
||||
t.Fatalf("errors = %q, want %q", combined, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestDiscoverPlugins_MultipleDirs ensures discovery scans multiple directories.
|
||||
func TestDiscoverPlugins_MultipleDirs(t *testing.T) {
|
||||
dir1 := t.TempDir()
|
||||
|
||||
@@ -20,6 +20,17 @@ type Storage struct {
|
||||
vault *vault.Vault
|
||||
}
|
||||
|
||||
// NDJSONRetention bounds append-only plugin data. Records are compacted after
|
||||
// a successful append so settings.json never becomes an event log.
|
||||
type NDJSONRetention struct {
|
||||
TimestampField string
|
||||
MaxAge time.Duration
|
||||
MaxEntries int
|
||||
MaxBytes int64
|
||||
DeduplicateField string
|
||||
DeduplicateValue string
|
||||
}
|
||||
|
||||
// New creates a new Storage instance backed by the given vault.
|
||||
func New(v *vault.Vault) *Storage {
|
||||
return &Storage{vault: v}
|
||||
@@ -84,13 +95,22 @@ func atomicWrite(path string, data []byte) error {
|
||||
// ReadPluginSettings reads all settings for a plugin.
|
||||
// Returns empty map if settings.json does not exist.
|
||||
func (s *Storage) ReadPluginSettings(pluginID string) (map[string]interface{}, error) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
if err := validatePluginID(pluginID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result map[string]interface{}
|
||||
err := s.withOpenVault(func(vaultPath string) error {
|
||||
var err error
|
||||
result, err = readPluginSettingsAt(vaultPath, pluginID)
|
||||
return err
|
||||
})
|
||||
return result, err
|
||||
}
|
||||
|
||||
dir := s.vault.GetPluginSettingsPath(pluginID)
|
||||
path := filepath.Join(dir, "settings.json")
|
||||
|
||||
func readPluginSettingsAt(vaultPath, pluginID string) (map[string]interface{}, error) {
|
||||
path := filepath.Join(vaultPath, ".verstak", "plugin-settings", pluginID, "settings.json")
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
@@ -108,13 +128,18 @@ func (s *Storage) ReadPluginSettings(pluginID string) (map[string]interface{}, e
|
||||
|
||||
// WritePluginSettings writes all settings for a plugin atomically.
|
||||
func (s *Storage) WritePluginSettings(pluginID string, data map[string]interface{}) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if err := validatePluginID(pluginID); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.withOpenVault(func(vaultPath string) error {
|
||||
return writePluginSettingsAt(vaultPath, pluginID, data)
|
||||
})
|
||||
}
|
||||
|
||||
dir := s.vault.GetPluginSettingsPath(pluginID)
|
||||
path := filepath.Join(dir, "settings.json")
|
||||
|
||||
func writePluginSettingsAt(vaultPath, pluginID string, data map[string]interface{}) error {
|
||||
path := filepath.Join(vaultPath, ".verstak", "plugin-settings", pluginID, "settings.json")
|
||||
encoded, err := json.MarshalIndent(data, "", " ")
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal settings for plugin %s: %w", pluginID, err)
|
||||
@@ -137,12 +162,39 @@ func (s *Storage) ReadPluginSetting(pluginID, key string) (interface{}, error) {
|
||||
|
||||
// WritePluginSetting writes a single setting key.
|
||||
func (s *Storage) WritePluginSetting(pluginID, key string, value interface{}) error {
|
||||
settings, err := s.ReadPluginSettings(pluginID)
|
||||
if err != nil {
|
||||
return s.UpdatePluginSettings(pluginID, func(settings map[string]interface{}) error {
|
||||
settings[key] = value
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// UpdatePluginSettings atomically reads, mutates, and writes a plugin's settings.
|
||||
func (s *Storage) UpdatePluginSettings(pluginID string, update func(map[string]interface{}) error) error {
|
||||
if update == nil {
|
||||
return fmt.Errorf("settings update is nil")
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if err := validatePluginID(pluginID); err != nil {
|
||||
return err
|
||||
}
|
||||
settings[key] = value
|
||||
return s.WritePluginSettings(pluginID, settings)
|
||||
return s.withOpenVault(func(vaultPath string) error {
|
||||
settings, err := readPluginSettingsAt(vaultPath, pluginID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := update(settings); err != nil {
|
||||
return err
|
||||
}
|
||||
return writePluginSettingsAt(vaultPath, pluginID, settings)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Storage) withOpenVault(operation func(string) error) error {
|
||||
if s == nil || s.vault == nil {
|
||||
return fmt.Errorf("vault is not initialized")
|
||||
}
|
||||
return s.vault.WithOpenPath(operation)
|
||||
}
|
||||
|
||||
// ─── Data JSON API ────────────────────────────────────────
|
||||
@@ -193,6 +245,204 @@ func (s *Storage) WritePluginDataJSON(pluginID, name string, data map[string]int
|
||||
return atomicWrite(path, encoded)
|
||||
}
|
||||
|
||||
// ReadPluginDataNDJSON reads an append-only named data file. A missing file is
|
||||
// represented by an empty slice.
|
||||
func (s *Storage) ReadPluginDataNDJSON(pluginID, name string) ([]map[string]interface{}, error) {
|
||||
if err := validatePluginID(pluginID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := validateStorageName("data", name); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
var records []map[string]interface{}
|
||||
err := s.withOpenVault(func(vaultPath string) error {
|
||||
var err error
|
||||
records, err = readPluginDataNDJSONAt(vaultPath, pluginID, name)
|
||||
return err
|
||||
})
|
||||
return records, err
|
||||
}
|
||||
|
||||
// AppendPluginDataNDJSON appends records durably and then applies bounded
|
||||
// retention. It returns false without writing when the supplied idempotency
|
||||
// value is already present in the retained log.
|
||||
func (s *Storage) AppendPluginDataNDJSON(pluginID, name string, records []map[string]interface{}, retention NDJSONRetention) (bool, error) {
|
||||
if err := validatePluginID(pluginID); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if err := validateStorageName("data", name); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(records) == 0 {
|
||||
return false, fmt.Errorf("NDJSON records are empty")
|
||||
}
|
||||
if retention.MaxEntries < 0 || retention.MaxBytes < 0 || retention.MaxAge < 0 {
|
||||
return false, fmt.Errorf("NDJSON retention values must not be negative")
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
stored := false
|
||||
err := s.withOpenVault(func(vaultPath string) error {
|
||||
existing, err := readPluginDataNDJSONAt(vaultPath, pluginID, name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if retention.DeduplicateField != "" && retention.DeduplicateValue != "" {
|
||||
for _, record := range existing {
|
||||
if fmt.Sprint(record[retention.DeduplicateField]) == retention.DeduplicateValue {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
path := pluginDataNDJSONPath(vaultPath, pluginID, name)
|
||||
if err := appendNDJSON(path, records); err != nil {
|
||||
return err
|
||||
}
|
||||
stored = true
|
||||
compacted := compactNDJSONRecords(append(existing, records...), retention, time.Now().UTC())
|
||||
if !sameNDJSONRecords(append(existing, records...), compacted) {
|
||||
return writeNDJSON(path, compacted)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return stored, err
|
||||
}
|
||||
|
||||
// WritePluginDataNDJSON replaces a named append-only data file. It is reserved
|
||||
// for explicit user actions such as clearing Activity, never normal event
|
||||
// ingestion.
|
||||
func (s *Storage) WritePluginDataNDJSON(pluginID, name string, records []map[string]interface{}) error {
|
||||
if err := validatePluginID(pluginID); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateStorageName("data", name); err != nil {
|
||||
return err
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.withOpenVault(func(vaultPath string) error {
|
||||
return writeNDJSON(pluginDataNDJSONPath(vaultPath, pluginID, name), records)
|
||||
})
|
||||
}
|
||||
|
||||
func pluginDataNDJSONPath(vaultPath, pluginID, name string) string {
|
||||
return filepath.Join(vaultPath, ".verstak", "plugin-data", pluginID, name+".ndjson")
|
||||
}
|
||||
|
||||
func readPluginDataNDJSONAt(vaultPath, pluginID, name string) ([]map[string]interface{}, error) {
|
||||
data, err := os.ReadFile(pluginDataNDJSONPath(vaultPath, pluginID, name))
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return []map[string]interface{}{}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("failed to read NDJSON data %s for plugin %s: %w", name, pluginID, err)
|
||||
}
|
||||
if len(data) == 0 {
|
||||
return []map[string]interface{}{}, nil
|
||||
}
|
||||
lines := strings.Split(strings.TrimSuffix(string(data), "\n"), "\n")
|
||||
records := make([]map[string]interface{}, 0, len(lines))
|
||||
for index, line := range lines {
|
||||
if strings.TrimSpace(line) == "" {
|
||||
continue
|
||||
}
|
||||
var record map[string]interface{}
|
||||
if err := json.Unmarshal([]byte(line), &record); err != nil {
|
||||
return nil, fmt.Errorf("corrupt NDJSON data %s line %d for plugin %s: %w", name, index+1, pluginID, err)
|
||||
}
|
||||
records = append(records, record)
|
||||
}
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func appendNDJSON(path string, records []map[string]interface{}) error {
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
return fmt.Errorf("failed to create NDJSON data directory: %w", err)
|
||||
}
|
||||
file, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open NDJSON data file: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
for _, record := range records {
|
||||
encoded, err := json.Marshal(record)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal NDJSON record: %w", err)
|
||||
}
|
||||
if _, err := file.Write(append(encoded, '\n')); err != nil {
|
||||
return fmt.Errorf("failed to append NDJSON record: %w", err)
|
||||
}
|
||||
}
|
||||
if err := file.Sync(); err != nil {
|
||||
return fmt.Errorf("failed to sync NDJSON data: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeNDJSON(path string, records []map[string]interface{}) error {
|
||||
data := make([]byte, 0)
|
||||
for _, record := range records {
|
||||
encoded, err := json.Marshal(record)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal NDJSON record: %w", err)
|
||||
}
|
||||
data = append(data, encoded...)
|
||||
data = append(data, '\n')
|
||||
}
|
||||
return atomicWrite(path, data)
|
||||
}
|
||||
|
||||
func compactNDJSONRecords(records []map[string]interface{}, retention NDJSONRetention, now time.Time) []map[string]interface{} {
|
||||
kept := make([]map[string]interface{}, 0, len(records))
|
||||
cutoff := now.Add(-retention.MaxAge)
|
||||
for _, record := range records {
|
||||
if retention.MaxAge > 0 && retention.TimestampField != "" {
|
||||
if raw, ok := record[retention.TimestampField].(string); ok {
|
||||
if timestamp, err := time.Parse(time.RFC3339, raw); err == nil && timestamp.Before(cutoff) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
kept = append(kept, record)
|
||||
}
|
||||
if retention.MaxEntries > 0 && len(kept) > retention.MaxEntries {
|
||||
kept = kept[len(kept)-retention.MaxEntries:]
|
||||
}
|
||||
if retention.MaxBytes > 0 {
|
||||
for len(kept) > 0 && ndjsonSize(kept) > retention.MaxBytes {
|
||||
kept = kept[1:]
|
||||
}
|
||||
}
|
||||
return kept
|
||||
}
|
||||
|
||||
func ndjsonSize(records []map[string]interface{}) int64 {
|
||||
var total int64
|
||||
for _, record := range records {
|
||||
encoded, err := json.Marshal(record)
|
||||
if err == nil {
|
||||
total += int64(len(encoded) + 1)
|
||||
}
|
||||
}
|
||||
return total
|
||||
}
|
||||
|
||||
func sameNDJSONRecords(left, right []map[string]interface{}) bool {
|
||||
if len(left) != len(right) {
|
||||
return false
|
||||
}
|
||||
for index := range left {
|
||||
leftJSON, leftErr := json.Marshal(left[index])
|
||||
rightJSON, rightErr := json.Marshal(right[index])
|
||||
if leftErr != nil || rightErr != nil || string(leftJSON) != string(rightJSON) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ─── Cache JSON API ───────────────────────────────────────
|
||||
|
||||
// ReadPluginCacheJSON reads a named JSON cache file for a plugin.
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestAppendPluginDataNDJSONCompactsAndDeduplicates(t *testing.T) {
|
||||
s, vaultDir := newTestStorage(t)
|
||||
retention := NDJSONRetention{
|
||||
TimestampField: "occurredAt",
|
||||
MaxAge: 60 * 24 * time.Hour,
|
||||
MaxEntries: 2,
|
||||
MaxBytes: 16 * 1024,
|
||||
DeduplicateField: "sourceBatchId",
|
||||
DeduplicateValue: "batch-1",
|
||||
}
|
||||
old := time.Now().UTC().Add(-61 * 24 * time.Hour).Format(time.RFC3339)
|
||||
now := time.Now().UTC().Format(time.RFC3339)
|
||||
|
||||
stored, err := s.AppendPluginDataNDJSON("verstak.activity", "activity-events", []map[string]interface{}{
|
||||
{"activityId": "old", "sourceBatchId": "old-batch", "occurredAt": old},
|
||||
}, retention)
|
||||
if err != nil || !stored {
|
||||
t.Fatalf("old append = (%v, %v), want (true, nil)", stored, err)
|
||||
}
|
||||
|
||||
stored, err = s.AppendPluginDataNDJSON("verstak.activity", "activity-events", []map[string]interface{}{
|
||||
{"activityId": "current-1", "sourceBatchId": "batch-1", "occurredAt": now},
|
||||
}, retention)
|
||||
if err != nil || !stored {
|
||||
t.Fatalf("first current append = (%v, %v), want (true, nil)", stored, err)
|
||||
}
|
||||
|
||||
stored, err = s.AppendPluginDataNDJSON("verstak.activity", "activity-events", []map[string]interface{}{
|
||||
{"activityId": "duplicate", "sourceBatchId": "batch-1", "occurredAt": now},
|
||||
}, retention)
|
||||
if err != nil || stored {
|
||||
t.Fatalf("duplicate append = (%v, %v), want (false, nil)", stored, err)
|
||||
}
|
||||
|
||||
for _, item := range []struct {
|
||||
id string
|
||||
batch string
|
||||
}{
|
||||
{id: "current-2", batch: "batch-3"},
|
||||
{id: "current-3", batch: "batch-4"},
|
||||
} {
|
||||
retention.DeduplicateValue = item.batch
|
||||
if stored, err := s.AppendPluginDataNDJSON("verstak.activity", "activity-events", []map[string]interface{}{
|
||||
{"activityId": item.id, "sourceBatchId": item.batch, "occurredAt": now},
|
||||
}, retention); err != nil || !stored {
|
||||
t.Fatalf("append %s = (%v, %v), want (true, nil)", item.id, stored, err)
|
||||
}
|
||||
}
|
||||
|
||||
records, err := s.ReadPluginDataNDJSON("verstak.activity", "activity-events")
|
||||
if err != nil {
|
||||
t.Fatalf("ReadPluginDataNDJSON: %v", err)
|
||||
}
|
||||
if len(records) != 2 || records[0]["activityId"] != "current-2" || records[1]["activityId"] != "current-3" {
|
||||
t.Fatalf("records = %+v, want current-2 and current-3", records)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(vaultDir, "VerstakVault", ".verstak", "plugin-data", "verstak.activity", "activity-events.ndjson")); err != nil {
|
||||
t.Fatalf("activity data file missing: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWritePluginDataNDJSONReplacesRecordsForExplicitUserClear(t *testing.T) {
|
||||
s, _ := newTestStorage(t)
|
||||
if _, err := s.AppendPluginDataNDJSON("verstak.activity", "activity-events", []map[string]interface{}{
|
||||
{"activityId": "one", "occurredAt": time.Now().UTC().Format(time.RFC3339)},
|
||||
{"activityId": "two", "occurredAt": time.Now().UTC().Format(time.RFC3339)},
|
||||
}, NDJSONRetention{}); err != nil {
|
||||
t.Fatalf("AppendPluginDataNDJSON: %v", err)
|
||||
}
|
||||
if err := s.WritePluginDataNDJSON("verstak.activity", "activity-events", []map[string]interface{}{
|
||||
{"activityId": "two", "occurredAt": time.Now().UTC().Format(time.RFC3339)},
|
||||
}); err != nil {
|
||||
t.Fatalf("WritePluginDataNDJSON: %v", err)
|
||||
}
|
||||
records, err := s.ReadPluginDataNDJSON("verstak.activity", "activity-events")
|
||||
if err != nil {
|
||||
t.Fatalf("ReadPluginDataNDJSON: %v", err)
|
||||
}
|
||||
if len(records) != 1 || records[0]["activityId"] != "two" {
|
||||
t.Fatalf("records = %+v, want only two", records)
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,23 @@ func (v *Vault) GetVaultPath() string {
|
||||
return v.path
|
||||
}
|
||||
|
||||
// WithOpenPath runs fn while holding a read lease on the currently open vault.
|
||||
// CloseVault and OpenVault wait until the operation completes.
|
||||
func (v *Vault) WithOpenPath(fn func(string) error) error {
|
||||
if v == nil {
|
||||
return fmt.Errorf("vault is not initialized")
|
||||
}
|
||||
if fn == nil {
|
||||
return fmt.Errorf("vault path operation is nil")
|
||||
}
|
||||
v.mu.RLock()
|
||||
defer v.mu.RUnlock()
|
||||
if v.status != StatusOpen || strings.TrimSpace(v.path) == "" {
|
||||
return fmt.Errorf("vault is not open")
|
||||
}
|
||||
return fn(v.path)
|
||||
}
|
||||
|
||||
// GetVaultMeta returns the current vault metadata.
|
||||
func (v *Vault) GetVaultMeta() *VaultMeta {
|
||||
v.mu.RLock()
|
||||
|
||||
@@ -40,6 +40,7 @@ const (
|
||||
|
||||
// Workspace is a physical top-level workspace folder.
|
||||
type Workspace struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
RootPath string `json:"rootPath"`
|
||||
}
|
||||
@@ -66,6 +67,7 @@ type WorkspaceTemplate struct {
|
||||
// Metadata stores semantic workspace metadata that is not the source of truth
|
||||
// for whether the workspace exists.
|
||||
type Metadata struct {
|
||||
WorkspaceID string `json:"workspaceId,omitempty"`
|
||||
WorkspaceName string `json:"workspaceName"`
|
||||
CreatedFromTemplate *TemplateSnapshot `json:"createdFromTemplate,omitempty"`
|
||||
Features map[string]bool `json:"features,omitempty"`
|
||||
@@ -74,6 +76,12 @@ type Metadata struct {
|
||||
UpdatedAt string `json:"updatedAt,omitempty"`
|
||||
}
|
||||
|
||||
const workspaceIdentityRelativePath = ".verstak/workspace.json"
|
||||
|
||||
type workspaceIdentityMarker struct {
|
||||
WorkspaceID string `json:"workspaceId"`
|
||||
}
|
||||
|
||||
// MetadataPatch updates metadata fields without replacing unspecified fields.
|
||||
type MetadataPatch struct {
|
||||
Features map[string]bool `json:"features,omitempty"`
|
||||
@@ -82,12 +90,20 @@ type MetadataPatch struct {
|
||||
|
||||
// TrashResult describes a workspace moved into the internal trash area.
|
||||
type TrashResult struct {
|
||||
WorkspaceID string `json:"workspaceId"`
|
||||
OriginalPath string `json:"originalPath"`
|
||||
TrashPath string `json:"trashPath"`
|
||||
TrashID string `json:"trashId"`
|
||||
DeletedAt string `json:"deletedAt"`
|
||||
}
|
||||
|
||||
// WorkspaceIdentity identifies an existing top-level workspace independently of its path.
|
||||
type WorkspaceIdentity struct {
|
||||
WorkspaceID string `json:"workspaceId"`
|
||||
RootPath string `json:"rootPath"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
// WorkspaceNode is a compatibility shell view of a top-level workspace.
|
||||
// Path is deliberately not serialized; workspaceRootPath is derived from Name/ID.
|
||||
type WorkspaceNode struct {
|
||||
@@ -301,7 +317,11 @@ func (m *Manager) ListWorkspaces() ([]Workspace, error) {
|
||||
if !entry.IsDir() {
|
||||
continue
|
||||
}
|
||||
workspaces = append(workspaces, Workspace{Name: name, RootPath: name})
|
||||
workspaceID, err := ensureWorkspaceIdentity(filepath.Join(m.vaultDir, name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
workspaces = append(workspaces, Workspace{ID: workspaceID, Name: name, RootPath: name})
|
||||
}
|
||||
sort.Slice(workspaces, func(i, j int) bool {
|
||||
return strings.ToLower(workspaces[i].Name) < strings.ToLower(workspaces[j].Name)
|
||||
@@ -309,6 +329,84 @@ func (m *Manager) ListWorkspaces() ([]Workspace, error) {
|
||||
return workspaces, nil
|
||||
}
|
||||
|
||||
// GetWorkspaceIdentity resolves the durable identity for an existing workspace.
|
||||
func (m *Manager) GetWorkspaceIdentity(name string) (WorkspaceIdentity, error) {
|
||||
name = strings.TrimSpace(name)
|
||||
if err := validateWorkspaceName(name); err != nil {
|
||||
return WorkspaceIdentity{}, err
|
||||
}
|
||||
full := filepath.Join(m.vaultDir, name)
|
||||
if err := ensureExistingWorkspaceDir(full, name); err != nil {
|
||||
return WorkspaceIdentity{}, err
|
||||
}
|
||||
workspaceID, err := ensureWorkspaceIdentity(full)
|
||||
if err != nil {
|
||||
return WorkspaceIdentity{}, err
|
||||
}
|
||||
return WorkspaceIdentity{WorkspaceID: workspaceID, RootPath: name, State: "active"}, nil
|
||||
}
|
||||
|
||||
// ListWorkspaceIdentities returns durable identities and flags copied markers.
|
||||
func (m *Manager) ListWorkspaceIdentities() ([]WorkspaceIdentity, error) {
|
||||
workspaces, err := m.ListWorkspaces()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
counts := make(map[string]int, len(workspaces))
|
||||
for _, workspace := range workspaces {
|
||||
counts[workspace.ID]++
|
||||
}
|
||||
identities := make([]WorkspaceIdentity, 0, len(workspaces))
|
||||
for _, workspace := range workspaces {
|
||||
state := "active"
|
||||
if counts[workspace.ID] > 1 {
|
||||
state = "duplicate"
|
||||
}
|
||||
identities = append(identities, WorkspaceIdentity{
|
||||
WorkspaceID: workspace.ID,
|
||||
RootPath: workspace.RootPath,
|
||||
State: state,
|
||||
})
|
||||
}
|
||||
return identities, nil
|
||||
}
|
||||
|
||||
// RepairWorkspaceIdentity keeps the identity on one copied workspace and regenerates the other.
|
||||
func (m *Manager) RepairWorkspaceIdentity(keepName, regenerateName string) error {
|
||||
keepName = strings.TrimSpace(keepName)
|
||||
regenerateName = strings.TrimSpace(regenerateName)
|
||||
if err := validateWorkspaceName(keepName); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateWorkspaceName(regenerateName); err != nil {
|
||||
return err
|
||||
}
|
||||
if keepName == regenerateName {
|
||||
return fmt.Errorf("workspace identity repair requires two workspaces")
|
||||
}
|
||||
keepPath := filepath.Join(m.vaultDir, keepName)
|
||||
regeneratePath := filepath.Join(m.vaultDir, regenerateName)
|
||||
if err := ensureExistingWorkspaceDir(keepPath, keepName); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ensureExistingWorkspaceDir(regeneratePath, regenerateName); err != nil {
|
||||
return err
|
||||
}
|
||||
keepID, err := ensureWorkspaceIdentity(keepPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
regenerateID, err := ensureWorkspaceIdentity(regeneratePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if keepID != regenerateID {
|
||||
return fmt.Errorf("workspaces do not share an identity")
|
||||
}
|
||||
_, err = writeWorkspaceIdentity(regeneratePath)
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateWorkspace creates a top-level workspace folder and applies a template once.
|
||||
func (m *Manager) CreateWorkspace(name, templateID string) (Workspace, error) {
|
||||
name = strings.TrimSpace(name)
|
||||
@@ -339,11 +437,16 @@ func (m *Manager) CreateWorkspace(name, templateID string) (Workspace, error) {
|
||||
}
|
||||
}()
|
||||
|
||||
workspaceID, err := ensureWorkspaceIdentity(full)
|
||||
if err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
if err := applyTemplate(full, template); err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
now := time.Now().UTC().Format(time.RFC3339Nano)
|
||||
meta := Metadata{
|
||||
WorkspaceID: workspaceID,
|
||||
WorkspaceName: name,
|
||||
CreatedFromTemplate: &TemplateSnapshot{
|
||||
TemplateID: template.ID,
|
||||
@@ -362,7 +465,82 @@ func (m *Manager) CreateWorkspace(name, templateID string) (Workspace, error) {
|
||||
}
|
||||
|
||||
created = false
|
||||
return Workspace{Name: name, RootPath: name}, nil
|
||||
return Workspace{ID: workspaceID, Name: name, RootPath: name}, nil
|
||||
}
|
||||
|
||||
func writeWorkspaceIdentity(workspacePath string) (string, error) {
|
||||
workspaceID := uuid.NewString()
|
||||
data, err := json.Marshal(workspaceIdentityMarker{WorkspaceID: workspaceID})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
markerPath := filepath.Join(workspacePath, filepath.FromSlash(workspaceIdentityRelativePath))
|
||||
if err := os.MkdirAll(filepath.Dir(markerPath), 0o755); err != nil {
|
||||
return "", err
|
||||
}
|
||||
tmpPath := markerPath + ".tmp"
|
||||
if err := os.WriteFile(tmpPath, data, 0o644); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := os.Rename(tmpPath, markerPath); err != nil {
|
||||
_ = os.Remove(tmpPath)
|
||||
return "", err
|
||||
}
|
||||
return workspaceID, nil
|
||||
}
|
||||
|
||||
func ensureWorkspaceIdentity(workspacePath string) (string, error) {
|
||||
workspaceID, err := readWorkspaceIdentity(workspacePath)
|
||||
if os.IsNotExist(err) {
|
||||
return writeWorkspaceIdentity(workspacePath)
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return workspaceID, nil
|
||||
}
|
||||
|
||||
func readWorkspaceIdentity(workspacePath string) (string, error) {
|
||||
markerPath := filepath.Join(workspacePath, filepath.FromSlash(workspaceIdentityRelativePath))
|
||||
data, err := os.ReadFile(markerPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var marker workspaceIdentityMarker
|
||||
if err := json.Unmarshal(data, &marker); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if _, err := uuid.Parse(marker.WorkspaceID); err != nil {
|
||||
return "", fmt.Errorf("invalid workspace identity: %w", err)
|
||||
}
|
||||
return marker.WorkspaceID, nil
|
||||
}
|
||||
|
||||
// GetWorkspaceTrashIdentity reads a trashed workspace identity without restoring it.
|
||||
func (m *Manager) GetWorkspaceTrashIdentity(trashID string) (WorkspaceIdentity, error) {
|
||||
trashID = strings.TrimSpace(trashID)
|
||||
if err := validateWorkspaceTrashID(trashID); err != nil {
|
||||
return WorkspaceIdentity{}, err
|
||||
}
|
||||
trashDir := filepath.Join(m.vaultDir, ".verstak", "trash", "workspaces", trashID)
|
||||
data, err := os.ReadFile(filepath.Join(trashDir, "metadata.json"))
|
||||
if err != nil {
|
||||
return WorkspaceIdentity{}, err
|
||||
}
|
||||
var trashMeta struct {
|
||||
OriginalPath string `json:"originalPath"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &trashMeta); err != nil {
|
||||
return WorkspaceIdentity{}, err
|
||||
}
|
||||
if err := validateWorkspaceName(trashMeta.OriginalPath); err != nil {
|
||||
return WorkspaceIdentity{}, err
|
||||
}
|
||||
workspaceID, err := readWorkspaceIdentity(filepath.Join(trashDir, trashMeta.OriginalPath))
|
||||
if err != nil {
|
||||
return WorkspaceIdentity{}, err
|
||||
}
|
||||
return WorkspaceIdentity{WorkspaceID: workspaceID, RootPath: trashMeta.OriginalPath, State: "trashed"}, nil
|
||||
}
|
||||
|
||||
// ListWorkspaceTemplates returns selectable built-ins in their presentation order.
|
||||
@@ -456,6 +634,10 @@ func (m *Manager) TrashWorkspace(name string) (TrashResult, error) {
|
||||
if err := ensureExistingWorkspaceDir(full, name); err != nil {
|
||||
return TrashResult{}, err
|
||||
}
|
||||
workspaceID, err := ensureWorkspaceIdentity(full)
|
||||
if err != nil {
|
||||
return TrashResult{}, err
|
||||
}
|
||||
|
||||
deletedAt := time.Now().UTC().Format(time.RFC3339Nano)
|
||||
trashID := time.Now().UTC().Format("20060102T150405.000000000Z") + "-" + uuid.NewString()
|
||||
@@ -468,7 +650,7 @@ func (m *Manager) TrashWorkspace(name string) (TrashResult, error) {
|
||||
return TrashResult{}, err
|
||||
}
|
||||
|
||||
result := TrashResult{OriginalPath: name, TrashPath: trashRel, TrashID: trashID, DeletedAt: deletedAt}
|
||||
result := TrashResult{WorkspaceID: workspaceID, OriginalPath: name, TrashPath: trashRel, TrashID: trashID, DeletedAt: deletedAt}
|
||||
trashMeta := map[string]string{
|
||||
"originalPath": name,
|
||||
"trashPath": trashRel,
|
||||
@@ -500,6 +682,83 @@ func (m *Manager) TrashWorkspace(name string) (TrashResult, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// RestoreWorkspaceTrash restores a trashed workspace under targetName without changing its identity.
|
||||
func (m *Manager) RestoreWorkspaceTrash(trashID, targetName string) (Workspace, error) {
|
||||
trashID = strings.TrimSpace(trashID)
|
||||
targetName = strings.TrimSpace(targetName)
|
||||
if err := validateWorkspaceTrashID(trashID); err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
if err := validateWorkspaceName(targetName); err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
trashDir := filepath.Join(m.vaultDir, ".verstak", "trash", "workspaces", trashID)
|
||||
data, err := os.ReadFile(filepath.Join(trashDir, "metadata.json"))
|
||||
if err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
var trashMeta struct {
|
||||
OriginalPath string `json:"originalPath"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &trashMeta); err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
if err := validateWorkspaceName(trashMeta.OriginalPath); err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
payloadPath := filepath.Join(trashDir, trashMeta.OriginalPath)
|
||||
if err := ensureExistingWorkspaceDir(payloadPath, trashMeta.OriginalPath); err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
targetPath := filepath.Join(m.vaultDir, targetName)
|
||||
if _, err := os.Lstat(targetPath); err == nil {
|
||||
return Workspace{}, fmt.Errorf("conflict: %s", targetName)
|
||||
} else if !os.IsNotExist(err) {
|
||||
return Workspace{}, err
|
||||
}
|
||||
if err := os.Rename(payloadPath, targetPath); err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
restored := true
|
||||
defer func() {
|
||||
if restored {
|
||||
_ = os.Rename(targetPath, payloadPath)
|
||||
}
|
||||
}()
|
||||
if err := moveIfExists(filepath.Join(trashDir, "workspace.metadata.json"), m.metadataPath(targetName)); err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
workspaceID, err := ensureWorkspaceIdentity(targetPath)
|
||||
if err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
if err := os.RemoveAll(trashDir); err != nil {
|
||||
return Workspace{}, err
|
||||
}
|
||||
restored = false
|
||||
return Workspace{ID: workspaceID, Name: targetName, RootPath: targetName}, nil
|
||||
}
|
||||
|
||||
func validateWorkspaceTrashID(trashID string) error {
|
||||
if trashID == "" || strings.ContainsAny(trashID, `/\\`) || filepath.Clean(trashID) != trashID {
|
||||
return fmt.Errorf("invalid workspace trash ID")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PurgeWorkspaceTrash permanently removes a workspace trash entry.
|
||||
func (m *Manager) PurgeWorkspaceTrash(trashID string) error {
|
||||
trashID = strings.TrimSpace(trashID)
|
||||
if err := validateWorkspaceTrashID(trashID); err != nil {
|
||||
return err
|
||||
}
|
||||
trashDir := filepath.Join(m.vaultDir, ".verstak", "trash", "workspaces", trashID)
|
||||
if _, err := os.Stat(filepath.Join(trashDir, "metadata.json")); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.RemoveAll(trashDir)
|
||||
}
|
||||
|
||||
// GetWorkspaceMetadata returns stored metadata or safe generic metadata.
|
||||
func (m *Manager) GetWorkspaceMetadata(name string) (Metadata, error) {
|
||||
name = strings.TrimSpace(name)
|
||||
|
||||
@@ -292,6 +292,167 @@ func TestTrashWorkspaceMovesFolderToTrashAndRemovesFromList(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateWorkspaceWritesDurableIdentityMarker(t *testing.T) {
|
||||
vaultDir := newVaultDir(t)
|
||||
m := NewManager(vaultDir)
|
||||
if _, err := m.CreateWorkspace("Client", "default"); err != nil {
|
||||
t.Fatalf("CreateWorkspace: %v", err)
|
||||
}
|
||||
|
||||
markerPath := filepath.Join(vaultDir, "Client", ".verstak", "workspace.json")
|
||||
data, err := os.ReadFile(markerPath)
|
||||
if err != nil {
|
||||
t.Fatalf("read identity marker: %v", err)
|
||||
}
|
||||
var marker map[string]string
|
||||
if err := json.Unmarshal(data, &marker); err != nil {
|
||||
t.Fatalf("decode identity marker: %v", err)
|
||||
}
|
||||
if marker["workspaceId"] == "" {
|
||||
t.Fatalf("workspaceId = %q, want UUID", marker["workspaceId"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestListWorkspacesKeepsIdentityAfterRename(t *testing.T) {
|
||||
vaultDir := newVaultDir(t)
|
||||
m := NewManager(vaultDir)
|
||||
created, err := m.CreateWorkspace("Client", "default")
|
||||
if err != nil {
|
||||
t.Fatalf("CreateWorkspace: %v", err)
|
||||
}
|
||||
if err := m.RenameWorkspace("Client", "Client-2026"); err != nil {
|
||||
t.Fatalf("RenameWorkspace: %v", err)
|
||||
}
|
||||
|
||||
workspaces, err := m.ListWorkspaces()
|
||||
if err != nil {
|
||||
t.Fatalf("ListWorkspaces: %v", err)
|
||||
}
|
||||
if len(workspaces) != 1 {
|
||||
t.Fatalf("workspaces = %+v, want one", workspaces)
|
||||
}
|
||||
if workspaces[0].Name != "Client-2026" {
|
||||
t.Fatalf("workspace name = %q, want Client-2026", workspaces[0].Name)
|
||||
}
|
||||
if workspaces[0].ID != created.ID {
|
||||
t.Fatalf("workspace ID = %q, want %q", workspaces[0].ID, created.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListWorkspaceIdentitiesMarksCopiedMarkerAsDuplicate(t *testing.T) {
|
||||
vaultDir := newVaultDir(t)
|
||||
m := NewManager(vaultDir)
|
||||
if _, err := m.CreateWorkspace("Original", "default"); err != nil {
|
||||
t.Fatalf("CreateWorkspace: %v", err)
|
||||
}
|
||||
if err := os.Mkdir(filepath.Join(vaultDir, "Copied"), 0o755); err != nil {
|
||||
t.Fatalf("mkdir copied: %v", err)
|
||||
}
|
||||
originalMarker := filepath.Join(vaultDir, "Original", ".verstak", "workspace.json")
|
||||
copiedMarker := filepath.Join(vaultDir, "Copied", ".verstak", "workspace.json")
|
||||
if err := os.MkdirAll(filepath.Dir(copiedMarker), 0o755); err != nil {
|
||||
t.Fatalf("mkdir copied marker: %v", err)
|
||||
}
|
||||
data, err := os.ReadFile(originalMarker)
|
||||
if err != nil {
|
||||
t.Fatalf("read original marker: %v", err)
|
||||
}
|
||||
if err := os.WriteFile(copiedMarker, data, 0o644); err != nil {
|
||||
t.Fatalf("write copied marker: %v", err)
|
||||
}
|
||||
|
||||
identities, err := m.ListWorkspaceIdentities()
|
||||
if err != nil {
|
||||
t.Fatalf("ListWorkspaceIdentities: %v", err)
|
||||
}
|
||||
if len(identities) != 2 {
|
||||
t.Fatalf("identities = %+v, want two", identities)
|
||||
}
|
||||
for _, identity := range identities {
|
||||
if identity.State != "duplicate" {
|
||||
t.Fatalf("identity %+v state = %q, want duplicate", identity, identity.State)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepairWorkspaceIdentityRegeneratesCopiedMarker(t *testing.T) {
|
||||
vaultDir := newVaultDir(t)
|
||||
m := NewManager(vaultDir)
|
||||
if _, err := m.CreateWorkspace("Original", "default"); err != nil {
|
||||
t.Fatalf("CreateWorkspace: %v", err)
|
||||
}
|
||||
if err := os.Mkdir(filepath.Join(vaultDir, "Copied"), 0o755); err != nil {
|
||||
t.Fatalf("mkdir copied: %v", err)
|
||||
}
|
||||
originalMarker := filepath.Join(vaultDir, "Original", ".verstak", "workspace.json")
|
||||
copiedMarker := filepath.Join(vaultDir, "Copied", ".verstak", "workspace.json")
|
||||
if err := os.MkdirAll(filepath.Dir(copiedMarker), 0o755); err != nil {
|
||||
t.Fatalf("mkdir copied marker: %v", err)
|
||||
}
|
||||
data, err := os.ReadFile(originalMarker)
|
||||
if err != nil {
|
||||
t.Fatalf("read original marker: %v", err)
|
||||
}
|
||||
if err := os.WriteFile(copiedMarker, data, 0o644); err != nil {
|
||||
t.Fatalf("write copied marker: %v", err)
|
||||
}
|
||||
|
||||
if err := m.RepairWorkspaceIdentity("Original", "Copied"); err != nil {
|
||||
t.Fatalf("RepairWorkspaceIdentity: %v", err)
|
||||
}
|
||||
identities, err := m.ListWorkspaceIdentities()
|
||||
if err != nil {
|
||||
t.Fatalf("ListWorkspaceIdentities: %v", err)
|
||||
}
|
||||
if len(identities) != 2 || identities[0].State != "active" || identities[1].State != "active" {
|
||||
t.Fatalf("identities after repair = %+v", identities)
|
||||
}
|
||||
if identities[0].WorkspaceID == identities[1].WorkspaceID {
|
||||
t.Fatalf("repair kept duplicate ID %q", identities[0].WorkspaceID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRestoreWorkspaceTrashPreservesIdentity(t *testing.T) {
|
||||
vaultDir := newVaultDir(t)
|
||||
m := NewManager(vaultDir)
|
||||
created, err := m.CreateWorkspace("Client", "default")
|
||||
if err != nil {
|
||||
t.Fatalf("CreateWorkspace: %v", err)
|
||||
}
|
||||
trashed, err := m.TrashWorkspace("Client")
|
||||
if err != nil {
|
||||
t.Fatalf("TrashWorkspace: %v", err)
|
||||
}
|
||||
restored, err := m.RestoreWorkspaceTrash(trashed.TrashID, "Client-Restored")
|
||||
if err != nil {
|
||||
t.Fatalf("RestoreWorkspaceTrash: %v", err)
|
||||
}
|
||||
if restored.Name != "Client-Restored" || restored.ID != created.ID {
|
||||
t.Fatalf("restored = %+v, want name Client-Restored and ID %q", restored, created.ID)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(vaultDir, "Client-Restored", ".verstak", "workspace.json")); err != nil {
|
||||
t.Fatalf("restored marker: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPurgeWorkspaceTrashRemovesPayload(t *testing.T) {
|
||||
vaultDir := newVaultDir(t)
|
||||
m := NewManager(vaultDir)
|
||||
if _, err := m.CreateWorkspace("Client", "default"); err != nil {
|
||||
t.Fatalf("CreateWorkspace: %v", err)
|
||||
}
|
||||
trashed, err := m.TrashWorkspace("Client")
|
||||
if err != nil {
|
||||
t.Fatalf("TrashWorkspace: %v", err)
|
||||
}
|
||||
if err := m.PurgeWorkspaceTrash(trashed.TrashID); err != nil {
|
||||
t.Fatalf("PurgeWorkspaceTrash: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(vaultDir, ".verstak", "trash", "workspaces", trashed.TrashID)); !os.IsNotExist(err) {
|
||||
t.Fatalf("workspace trash remains, stat err=%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateAndRenameConflictsAreExplicit(t *testing.T) {
|
||||
vaultDir := newVaultDir(t)
|
||||
mustMkdir(t, filepath.Join(vaultDir, "Existing"))
|
||||
|
||||
@@ -0,0 +1,314 @@
|
||||
// Package tray owns the native tray menu wiring for the desktop shell.
|
||||
package tray
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
var errBackendUnavailable = errors.New("tray backend is unavailable")
|
||||
|
||||
// MenuItem exposes click events from a native tray menu item.
|
||||
type MenuItem interface {
|
||||
Clicked() <-chan struct{}
|
||||
SetTitle(title string)
|
||||
SetTooltip(tooltip string)
|
||||
}
|
||||
|
||||
// BackendCallbacks are invoked by the native tray implementation.
|
||||
// A backend keeps the platform-native secondary-click handler enabled so the
|
||||
// operating system opens the menu on a right click.
|
||||
type BackendCallbacks struct {
|
||||
Ready func()
|
||||
Exit func()
|
||||
LeftClick func()
|
||||
}
|
||||
|
||||
// Backend is the platform tray implementation.
|
||||
type Backend interface {
|
||||
Start(callbacks BackendCallbacks) error
|
||||
SetIcon(icon []byte) error
|
||||
SetTooltip(tooltip string) error
|
||||
AddMenuItem(title, tooltip string) (MenuItem, error)
|
||||
Stop()
|
||||
}
|
||||
|
||||
// Actions are executed from the native tray menu.
|
||||
type Actions struct {
|
||||
Show func()
|
||||
Quit func()
|
||||
}
|
||||
|
||||
// Labels contains the user-visible text for one tray menu locale.
|
||||
type Labels struct {
|
||||
ShowTitle string
|
||||
ShowTooltip string
|
||||
QuitTitle string
|
||||
QuitTooltip string
|
||||
}
|
||||
|
||||
func englishLabels() Labels {
|
||||
return Labels{
|
||||
ShowTitle: "Show Verstak",
|
||||
ShowTooltip: "Show the Verstak window",
|
||||
QuitTitle: "Quit",
|
||||
QuitTooltip: "Quit Verstak",
|
||||
}
|
||||
}
|
||||
|
||||
func russianLabels() Labels {
|
||||
return Labels{
|
||||
ShowTitle: "Показать Верстак",
|
||||
ShowTooltip: "Показать окно Верстака",
|
||||
QuitTitle: "Выйти",
|
||||
QuitTooltip: "Завершить Верстак",
|
||||
}
|
||||
}
|
||||
|
||||
// LabelsForPreference resolves the saved language preference for native tray UI.
|
||||
// System locale values are intentionally passed in by the shell so this package
|
||||
// stays independent of process environment and is deterministic in tests.
|
||||
func LabelsForPreference(preference string, systemLocales ...string) Labels {
|
||||
if strings.EqualFold(strings.TrimSpace(preference), "ru") {
|
||||
return russianLabels()
|
||||
}
|
||||
if strings.EqualFold(strings.TrimSpace(preference), "system") {
|
||||
for _, locale := range systemLocales {
|
||||
locale = strings.ToLower(strings.TrimSpace(locale))
|
||||
if locale == "" {
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(locale, "ru") {
|
||||
return russianLabels()
|
||||
}
|
||||
return englishLabels()
|
||||
}
|
||||
}
|
||||
return englishLabels()
|
||||
}
|
||||
|
||||
// Controller initializes one native tray and routes its menu actions.
|
||||
type Controller struct {
|
||||
backend Backend
|
||||
icon []byte
|
||||
|
||||
startOnce sync.Once
|
||||
readyOnce sync.Once
|
||||
stopOnce sync.Once
|
||||
started atomic.Bool
|
||||
ready atomic.Bool
|
||||
|
||||
mu sync.RWMutex
|
||||
labels Labels
|
||||
actions Actions
|
||||
show MenuItem
|
||||
quit MenuItem
|
||||
startErr error
|
||||
readyChanged func(bool)
|
||||
}
|
||||
|
||||
// New creates a tray controller for one application process.
|
||||
func New(backend Backend, icon []byte) *Controller {
|
||||
return &Controller{
|
||||
backend: backend,
|
||||
icon: append([]byte(nil), icon...),
|
||||
labels: englishLabels(),
|
||||
}
|
||||
}
|
||||
|
||||
// SetReadyChangedHandler receives readiness changes after native initialization
|
||||
// has either completed or ended. It lets the Wails close policy avoid hiding a
|
||||
// window before the tray can bring it back.
|
||||
func (c *Controller) SetReadyChangedHandler(handler func(bool)) {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
c.mu.Lock()
|
||||
c.readyChanged = handler
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
// Ready reports whether the tray has completed icon and menu initialization.
|
||||
func (c *Controller) Ready() bool {
|
||||
return c != nil && c.ready.Load()
|
||||
}
|
||||
|
||||
// SetLabels updates the current and future native tray menu labels.
|
||||
func (c *Controller) SetLabels(labels Labels) {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
c.mu.Lock()
|
||||
c.labels = labels
|
||||
show, quit := c.show, c.quit
|
||||
c.mu.Unlock()
|
||||
applyLabels(show, quit, labels)
|
||||
}
|
||||
|
||||
// Start connects the tray to Wails without taking over Wails' GUI event loop.
|
||||
// Ready remains false until the backend callback and all required menu setup
|
||||
// finish successfully.
|
||||
func (c *Controller) Start(actions Actions) error {
|
||||
if c == nil || c.backend == nil {
|
||||
return errBackendUnavailable
|
||||
}
|
||||
c.startOnce.Do(func() {
|
||||
c.mu.Lock()
|
||||
c.actions = actions
|
||||
c.mu.Unlock()
|
||||
c.started.Store(true)
|
||||
log.Printf("[tray] starting native backend")
|
||||
err := c.backend.Start(BackendCallbacks{
|
||||
Ready: c.onReady,
|
||||
Exit: c.onExit,
|
||||
LeftClick: c.onLeftClick,
|
||||
})
|
||||
if err != nil {
|
||||
c.mu.Lock()
|
||||
c.startErr = err
|
||||
c.mu.Unlock()
|
||||
c.started.Store(false)
|
||||
c.setReady(false)
|
||||
log.Printf("[tray] backend start failed: %v; falling back to normal window close", err)
|
||||
}
|
||||
})
|
||||
c.mu.RLock()
|
||||
err := c.startErr
|
||||
c.mu.RUnlock()
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Controller) onReady() {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
if !c.started.Load() {
|
||||
log.Printf("[tray] ready callback ignored after backend startup failed")
|
||||
return
|
||||
}
|
||||
c.readyOnce.Do(func() {
|
||||
log.Printf("[tray] native backend reported ready")
|
||||
if err := c.backend.SetIcon(c.icon); err != nil {
|
||||
c.fail("icon setup", err)
|
||||
return
|
||||
}
|
||||
if err := c.backend.SetTooltip("Verstak"); err != nil {
|
||||
c.fail("tooltip setup", err)
|
||||
return
|
||||
}
|
||||
c.mu.RLock()
|
||||
labels := c.labels
|
||||
actions := c.actions
|
||||
c.mu.RUnlock()
|
||||
show, err := c.backend.AddMenuItem(labels.ShowTitle, labels.ShowTooltip)
|
||||
if err != nil || show == nil {
|
||||
if err == nil {
|
||||
err = errors.New("show menu item is nil")
|
||||
}
|
||||
c.fail("show menu creation", err)
|
||||
return
|
||||
}
|
||||
quit, err := c.backend.AddMenuItem(labels.QuitTitle, labels.QuitTooltip)
|
||||
if err != nil || quit == nil {
|
||||
if err == nil {
|
||||
err = errors.New("quit menu item is nil")
|
||||
}
|
||||
c.fail("quit menu creation", err)
|
||||
return
|
||||
}
|
||||
c.mu.Lock()
|
||||
c.show, c.quit = show, quit
|
||||
labels = c.labels
|
||||
c.mu.Unlock()
|
||||
applyLabels(show, quit, labels)
|
||||
if actions.Show != nil {
|
||||
go routeClicks(show.Clicked(), func() {
|
||||
log.Printf("[tray] Show command")
|
||||
actions.Show()
|
||||
})
|
||||
}
|
||||
if actions.Quit != nil {
|
||||
go routeClicks(quit.Clicked(), func() {
|
||||
log.Printf("[tray] Quit command")
|
||||
actions.Quit()
|
||||
})
|
||||
}
|
||||
c.setReady(true)
|
||||
log.Printf("[tray] native tray is ready")
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Controller) onLeftClick() {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
log.Printf("[tray] left click")
|
||||
if !c.Ready() {
|
||||
log.Printf("[tray] left click ignored while tray is not ready")
|
||||
return
|
||||
}
|
||||
c.mu.RLock()
|
||||
show := c.actions.Show
|
||||
c.mu.RUnlock()
|
||||
if show != nil {
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Controller) onExit() {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
c.setReady(false)
|
||||
log.Printf("[tray] native message loop ended; falling back to normal window close")
|
||||
}
|
||||
|
||||
func (c *Controller) fail(stage string, err error) {
|
||||
c.setReady(false)
|
||||
log.Printf("[tray] %s failed: %v; falling back to normal window close", stage, err)
|
||||
c.Stop()
|
||||
}
|
||||
|
||||
func (c *Controller) setReady(ready bool) {
|
||||
if c == nil || c.ready.Swap(ready) == ready {
|
||||
return
|
||||
}
|
||||
c.mu.RLock()
|
||||
handler := c.readyChanged
|
||||
c.mu.RUnlock()
|
||||
if handler != nil {
|
||||
handler(ready)
|
||||
}
|
||||
}
|
||||
|
||||
func applyLabels(show, quit MenuItem, labels Labels) {
|
||||
if show != nil {
|
||||
show.SetTitle(labels.ShowTitle)
|
||||
show.SetTooltip(labels.ShowTooltip)
|
||||
}
|
||||
if quit != nil {
|
||||
quit.SetTitle(labels.QuitTitle)
|
||||
quit.SetTooltip(labels.QuitTooltip)
|
||||
}
|
||||
}
|
||||
|
||||
// Stop releases the native tray after Wails has begun application shutdown.
|
||||
func (c *Controller) Stop() {
|
||||
if c == nil || c.backend == nil || !c.started.Load() {
|
||||
return
|
||||
}
|
||||
c.stopOnce.Do(func() {
|
||||
c.setReady(false)
|
||||
log.Printf("[tray] stopping native backend")
|
||||
c.backend.Stop()
|
||||
})
|
||||
}
|
||||
|
||||
func routeClicks(clicked <-chan struct{}, action func()) {
|
||||
for range clicked {
|
||||
action()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
package tray
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type fakeMenuItem struct {
|
||||
clicked chan struct{}
|
||||
title string
|
||||
tooltip string
|
||||
}
|
||||
|
||||
func (i *fakeMenuItem) Clicked() <-chan struct{} { return i.clicked }
|
||||
func (i *fakeMenuItem) SetTitle(title string) { i.title = title }
|
||||
func (i *fakeMenuItem) SetTooltip(tooltip string) { i.tooltip = tooltip }
|
||||
|
||||
type fakeBackend struct {
|
||||
callbacks BackendCallbacks
|
||||
icon []byte
|
||||
tooltip string
|
||||
items map[string]*fakeMenuItem
|
||||
startErr error
|
||||
iconErr error
|
||||
menuErr error
|
||||
starts int
|
||||
stops int
|
||||
}
|
||||
|
||||
func (b *fakeBackend) Start(callbacks BackendCallbacks) error {
|
||||
b.starts++
|
||||
b.callbacks = callbacks
|
||||
return b.startErr
|
||||
}
|
||||
|
||||
func (b *fakeBackend) SetIcon(icon []byte) error {
|
||||
b.icon = append([]byte(nil), icon...)
|
||||
return b.iconErr
|
||||
}
|
||||
|
||||
func (b *fakeBackend) SetTooltip(tooltip string) error {
|
||||
b.tooltip = tooltip
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *fakeBackend) AddMenuItem(title, tooltip string) (MenuItem, error) {
|
||||
if b.menuErr != nil {
|
||||
return nil, b.menuErr
|
||||
}
|
||||
item := &fakeMenuItem{clicked: make(chan struct{}, 1), title: title, tooltip: tooltip}
|
||||
b.items[title] = item
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func (b *fakeBackend) Stop() { b.stops++ }
|
||||
|
||||
func (b *fakeBackend) ready() {
|
||||
if b.callbacks.Ready != nil {
|
||||
b.callbacks.Ready()
|
||||
}
|
||||
}
|
||||
|
||||
func (b *fakeBackend) exited() {
|
||||
if b.callbacks.Exit != nil {
|
||||
b.callbacks.Exit()
|
||||
}
|
||||
}
|
||||
|
||||
func (b *fakeBackend) leftClick() {
|
||||
if b.callbacks.LeftClick != nil {
|
||||
b.callbacks.LeftClick()
|
||||
}
|
||||
}
|
||||
|
||||
func waitFor(t *testing.T, signal <-chan struct{}) {
|
||||
t.Helper()
|
||||
select {
|
||||
case <-signal:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("timed out waiting for tray action")
|
||||
}
|
||||
}
|
||||
|
||||
func TestControllerBecomesReadyOnlyAfterBackendCallback(t *testing.T) {
|
||||
backend := &fakeBackend{items: make(map[string]*fakeMenuItem)}
|
||||
controller := New(backend, []byte{1, 2, 3})
|
||||
|
||||
if err := controller.Start(Actions{}); err != nil {
|
||||
t.Fatalf("Start() error = %v", err)
|
||||
}
|
||||
if controller.Ready() {
|
||||
t.Fatal("tray became ready before backend callback")
|
||||
}
|
||||
|
||||
backend.ready()
|
||||
if !controller.Ready() {
|
||||
t.Fatal("tray did not become ready after backend callback")
|
||||
}
|
||||
if string(backend.icon) != string([]byte{1, 2, 3}) || backend.tooltip != "Verstak" {
|
||||
t.Fatalf("tray initialization = icon:%v tooltip:%q", backend.icon, backend.tooltip)
|
||||
}
|
||||
}
|
||||
|
||||
func TestControllerRoutesLeftClickAndMenuActionsToShowAndQuit(t *testing.T) {
|
||||
backend := &fakeBackend{items: make(map[string]*fakeMenuItem)}
|
||||
showCalls := make(chan struct{}, 2)
|
||||
quitCalls := make(chan struct{}, 1)
|
||||
controller := New(backend, []byte{1})
|
||||
|
||||
if err := controller.Start(Actions{
|
||||
Show: func() { showCalls <- struct{}{} },
|
||||
Quit: func() { quitCalls <- struct{}{} },
|
||||
}); err != nil {
|
||||
t.Fatalf("Start() error = %v", err)
|
||||
}
|
||||
backend.ready()
|
||||
|
||||
backend.leftClick()
|
||||
waitFor(t, showCalls)
|
||||
showItem := backend.items["Show Verstak"]
|
||||
quitItem := backend.items["Quit"]
|
||||
if showItem == nil || quitItem == nil {
|
||||
t.Fatalf("tray menu = %#v, want Show Verstak and Quit", backend.items)
|
||||
}
|
||||
showItem.clicked <- struct{}{}
|
||||
waitFor(t, showCalls)
|
||||
quitItem.clicked <- struct{}{}
|
||||
waitFor(t, quitCalls)
|
||||
}
|
||||
|
||||
func TestControllerStopCallsBackendOnce(t *testing.T) {
|
||||
backend := &fakeBackend{items: make(map[string]*fakeMenuItem)}
|
||||
controller := New(backend, []byte{1})
|
||||
if err := controller.Start(Actions{}); err != nil {
|
||||
t.Fatalf("Start() error = %v", err)
|
||||
}
|
||||
|
||||
controller.Stop()
|
||||
controller.Stop()
|
||||
|
||||
if backend.stops != 1 {
|
||||
t.Fatalf("backend stop calls = %d, want 1", backend.stops)
|
||||
}
|
||||
}
|
||||
|
||||
func TestControllerStartupAndSetupFailuresNeverBecomeReady(t *testing.T) {
|
||||
for name, backend := range map[string]*fakeBackend{
|
||||
"start": {items: make(map[string]*fakeMenuItem), startErr: errors.New("start failed")},
|
||||
"icon": {items: make(map[string]*fakeMenuItem), iconErr: errors.New("icon failed")},
|
||||
"menu": {items: make(map[string]*fakeMenuItem), menuErr: errors.New("menu failed")},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
controller := New(backend, []byte{1})
|
||||
err := controller.Start(Actions{})
|
||||
if name == "start" && err == nil {
|
||||
t.Fatal("Start() error = nil, want startup failure")
|
||||
}
|
||||
if name != "start" && err != nil {
|
||||
t.Fatalf("Start() error = %v, want nil before ready callback", err)
|
||||
}
|
||||
backend.ready()
|
||||
if controller.Ready() {
|
||||
t.Fatal("failed tray became ready")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestControllerExitRevokesReadinessAndKeepsLocalizedMenuItems(t *testing.T) {
|
||||
backend := &fakeBackend{items: make(map[string]*fakeMenuItem)}
|
||||
controller := New(backend, []byte{1})
|
||||
controller.SetLabels(LabelsForPreference("ru"))
|
||||
if err := controller.Start(Actions{}); err != nil {
|
||||
t.Fatalf("Start() error = %v", err)
|
||||
}
|
||||
backend.ready()
|
||||
|
||||
show := backend.items["Показать Верстак"]
|
||||
quit := backend.items["Выйти"]
|
||||
if show == nil || quit == nil {
|
||||
t.Fatalf("Russian tray menu = %#v", backend.items)
|
||||
}
|
||||
controller.SetLabels(LabelsForPreference("en"))
|
||||
if show.title != "Show Verstak" || quit.title != "Quit" {
|
||||
t.Fatalf("English tray menu after update = show:%q quit:%q", show.title, quit.title)
|
||||
}
|
||||
backend.exited()
|
||||
if controller.Ready() {
|
||||
t.Fatal("tray stayed ready after backend exit")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLabelsForSystemRussianLocale(t *testing.T) {
|
||||
labels := LabelsForPreference("system", "", "ru_RU.UTF-8", "en_US.UTF-8")
|
||||
if labels.ShowTitle != "Показать Верстак" || labels.QuitTitle != "Выйти" {
|
||||
t.Fatalf("system Russian labels = %#v", labels)
|
||||
}
|
||||
labels = LabelsForPreference("system", "C.UTF-8", "", "ru_RU.UTF-8")
|
||||
if labels.ShowTitle != "Show Verstak" || labels.QuitTitle != "Quit" {
|
||||
t.Fatalf("higher-priority system locale must win, got %#v", labels)
|
||||
}
|
||||
}
|
||||
|
||||
func TestControllerReadyNotificationIsSafeAcrossCallbacks(t *testing.T) {
|
||||
backend := &fakeBackend{items: make(map[string]*fakeMenuItem)}
|
||||
controller := New(backend, []byte{1})
|
||||
var changes []bool
|
||||
var mu sync.Mutex
|
||||
controller.SetReadyChangedHandler(func(ready bool) {
|
||||
mu.Lock()
|
||||
changes = append(changes, ready)
|
||||
mu.Unlock()
|
||||
})
|
||||
if err := controller.Start(Actions{}); err != nil {
|
||||
t.Fatalf("Start() error = %v", err)
|
||||
}
|
||||
backend.ready()
|
||||
backend.exited()
|
||||
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
if len(changes) != 2 || !changes[0] || changes[1] {
|
||||
t.Fatalf("ready changes = %#v, want [true false]", changes)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
//go:build linux
|
||||
|
||||
package tray
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed verstak.png
|
||||
var defaultIcon []byte
|
||||
|
||||
// DefaultIcon returns the Linux PNG tray icon embedded in the binary.
|
||||
func DefaultIcon() []byte {
|
||||
return append([]byte(nil), defaultIcon...)
|
||||
}
|
||||
|
||||
// IconFileExtension is used when the backend materializes the embedded icon.
|
||||
func IconFileExtension() string { return ".png" }
|
||||
@@ -0,0 +1,18 @@
|
||||
//go:build linux
|
||||
|
||||
package tray
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDefaultIconUsesPlatformResource(t *testing.T) {
|
||||
icon := DefaultIcon()
|
||||
if len(icon) == 0 {
|
||||
t.Fatal("DefaultIcon() returned no data")
|
||||
}
|
||||
if IconFileExtension() != ".png" {
|
||||
t.Fatalf("IconFileExtension() = %q, want .png on Linux", IconFileExtension())
|
||||
}
|
||||
if string(icon[:8]) != "\x89PNG\r\n\x1a\n" {
|
||||
t.Fatal("DefaultIcon() is not PNG data on Linux")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
//go:build windows
|
||||
|
||||
package tray
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed verstak.ico
|
||||
var defaultIcon []byte
|
||||
|
||||
// DefaultIcon returns the multi-resolution Windows ICO embedded in the binary.
|
||||
func DefaultIcon() []byte {
|
||||
return append([]byte(nil), defaultIcon...)
|
||||
}
|
||||
|
||||
// IconFileExtension is used when the backend materializes the embedded icon.
|
||||
func IconFileExtension() string { return ".ico" }
|
||||
@@ -0,0 +1,37 @@
|
||||
//go:build windows
|
||||
|
||||
package tray
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDefaultIconIsMultiResolutionICO(t *testing.T) {
|
||||
icon := DefaultIcon()
|
||||
if IconFileExtension() != ".ico" || len(icon) < 6 {
|
||||
t.Fatalf("Windows tray icon is not ICO data")
|
||||
}
|
||||
if binary.LittleEndian.Uint16(icon[0:2]) != 0 || binary.LittleEndian.Uint16(icon[2:4]) != 1 {
|
||||
t.Fatal("Windows tray icon has an invalid ICO header")
|
||||
}
|
||||
count := int(binary.LittleEndian.Uint16(icon[4:6]))
|
||||
if count < 6 {
|
||||
t.Fatalf("ICO image count = %d, want at least 6", count)
|
||||
}
|
||||
want := map[int]bool{16: false, 20: false, 24: false, 32: false, 48: false, 256: false}
|
||||
for offset := 6; offset+16 <= len(icon) && offset < 6+count*16; offset += 16 {
|
||||
size := int(icon[offset])
|
||||
if size == 0 {
|
||||
size = 256
|
||||
}
|
||||
if _, ok := want[size]; ok {
|
||||
want[size] = true
|
||||
}
|
||||
}
|
||||
for size, found := range want {
|
||||
if !found {
|
||||
t.Errorf("ICO is missing %dx%d image", size, size)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package tray
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"fyne.io/systray"
|
||||
)
|
||||
|
||||
var (
|
||||
runWithExternalLoop = systray.RunWithExternalLoop
|
||||
setOnTapped = systray.SetOnTapped
|
||||
)
|
||||
|
||||
type systrayBackend struct {
|
||||
mu sync.Mutex
|
||||
end func()
|
||||
iconPath string
|
||||
started bool
|
||||
stopRequested bool
|
||||
}
|
||||
|
||||
type systrayMenuItem struct {
|
||||
item *systray.MenuItem
|
||||
}
|
||||
|
||||
// NewNativeBackend creates the cross-platform tray backend. It uses
|
||||
// RunWithExternalLoop so the native tray message loop runs alongside Wails.
|
||||
func NewNativeBackend() Backend {
|
||||
return &systrayBackend{}
|
||||
}
|
||||
|
||||
func (b *systrayBackend) Start(callbacks BackendCallbacks) (err error) {
|
||||
if b == nil {
|
||||
return errBackendUnavailable
|
||||
}
|
||||
b.mu.Lock()
|
||||
if b.started {
|
||||
b.mu.Unlock()
|
||||
return errors.New("native tray backend was already started")
|
||||
}
|
||||
b.started = true
|
||||
b.mu.Unlock()
|
||||
defer func() {
|
||||
if recovered := recover(); recovered != nil {
|
||||
err = fmt.Errorf("native tray startup panic: %v", recovered)
|
||||
}
|
||||
}()
|
||||
start, end := runWithExternalLoop(callbacks.Ready, callbacks.Exit)
|
||||
if callbacks.LeftClick != nil {
|
||||
setOnTapped(callbacks.LeftClick)
|
||||
}
|
||||
// The Ready callback is asynchronous on Windows and can synchronously
|
||||
// decide that startup failed. Start the native loop before publishing the
|
||||
// end function so a concurrent Stop is never left with a half-started loop.
|
||||
start()
|
||||
b.mu.Lock()
|
||||
stopRequested := b.stopRequested
|
||||
if !stopRequested {
|
||||
b.end = end
|
||||
}
|
||||
b.mu.Unlock()
|
||||
if stopRequested {
|
||||
end()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *systrayBackend) SetIcon(icon []byte) error {
|
||||
if b == nil || len(icon) == 0 {
|
||||
return errors.New("tray icon is empty")
|
||||
}
|
||||
file, err := os.CreateTemp("", "verstak-tray-*"+IconFileExtension())
|
||||
if err != nil {
|
||||
return fmt.Errorf("create tray icon file: %w", err)
|
||||
}
|
||||
path := file.Name()
|
||||
if _, err := file.Write(icon); err != nil {
|
||||
file.Close()
|
||||
os.Remove(path)
|
||||
return fmt.Errorf("write tray icon file: %w", err)
|
||||
}
|
||||
if err := file.Close(); err != nil {
|
||||
os.Remove(path)
|
||||
return fmt.Errorf("close tray icon file: %w", err)
|
||||
}
|
||||
if err := systray.SetIconFromFilePath(path); err != nil {
|
||||
os.Remove(path)
|
||||
return fmt.Errorf("set native tray icon: %w", err)
|
||||
}
|
||||
b.mu.Lock()
|
||||
previous := b.iconPath
|
||||
b.iconPath = path
|
||||
b.mu.Unlock()
|
||||
if previous != "" && previous != path {
|
||||
_ = os.Remove(previous)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *systrayBackend) SetTooltip(tooltip string) error {
|
||||
if strings.TrimSpace(tooltip) == "" {
|
||||
return errors.New("tray tooltip is empty")
|
||||
}
|
||||
systray.SetTooltip(tooltip)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *systrayBackend) AddMenuItem(title, tooltip string) (MenuItem, error) {
|
||||
if strings.TrimSpace(title) == "" {
|
||||
return nil, errors.New("tray menu title is empty")
|
||||
}
|
||||
item := systray.AddMenuItem(title, tooltip)
|
||||
if item == nil {
|
||||
return nil, errors.New("native tray menu item is nil")
|
||||
}
|
||||
return systrayMenuItem{item: item}, nil
|
||||
}
|
||||
|
||||
func (b *systrayBackend) Stop() {
|
||||
if b == nil {
|
||||
return
|
||||
}
|
||||
b.mu.Lock()
|
||||
end, iconPath := b.end, b.iconPath
|
||||
b.end = nil
|
||||
b.iconPath = ""
|
||||
b.stopRequested = true
|
||||
b.mu.Unlock()
|
||||
if end != nil {
|
||||
end()
|
||||
}
|
||||
if iconPath != "" {
|
||||
_ = os.Remove(iconPath)
|
||||
}
|
||||
}
|
||||
|
||||
func (item systrayMenuItem) Clicked() <-chan struct{} {
|
||||
if item.item == nil {
|
||||
return nil
|
||||
}
|
||||
return item.item.ClickedCh
|
||||
}
|
||||
|
||||
func (item systrayMenuItem) SetTitle(title string) {
|
||||
if item.item != nil {
|
||||
item.item.SetTitle(title)
|
||||
}
|
||||
}
|
||||
|
||||
func (item systrayMenuItem) SetTooltip(tooltip string) {
|
||||
if item.item != nil {
|
||||
item.item.SetTooltip(tooltip)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package tray
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBackendStopsWhenReadyCallbackStopsDuringStartup(t *testing.T) {
|
||||
originalRun := runWithExternalLoop
|
||||
originalSetOnTapped := setOnTapped
|
||||
defer func() {
|
||||
runWithExternalLoop = originalRun
|
||||
setOnTapped = originalSetOnTapped
|
||||
}()
|
||||
|
||||
var startCalls, endCalls int
|
||||
runWithExternalLoop = func(onReady, _ func()) (func(), func()) {
|
||||
onReady()
|
||||
return func() { startCalls++ }, func() { endCalls++ }
|
||||
}
|
||||
setOnTapped = func(func()) {}
|
||||
|
||||
backend := &systrayBackend{}
|
||||
if err := backend.Start(BackendCallbacks{Ready: backend.Stop}); err != nil {
|
||||
t.Fatalf("Start: %v", err)
|
||||
}
|
||||
if startCalls != 1 {
|
||||
t.Fatalf("start calls = %d, want 1", startCalls)
|
||||
}
|
||||
if endCalls != 1 {
|
||||
t.Fatalf("end calls = %d, want 1", endCalls)
|
||||
}
|
||||
}
|
||||