mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
chore: bootstrap repository tooling and release automation
This commit is contained in:
74
.github/workflows/ci.yml
vendored
Normal file
74
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-test-audit:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
|
||||||
|
- name: Setup Bun
|
||||||
|
uses: oven-sh/setup-bun@v2
|
||||||
|
with:
|
||||||
|
bun-version: 1.3.5
|
||||||
|
|
||||||
|
- name: Cache dependencies
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.bun/install/cache
|
||||||
|
node_modules
|
||||||
|
key: ${{ runner.os }}-bun-${{ hashFiles('bun.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-bun-
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: bun install --frozen-lockfile
|
||||||
|
|
||||||
|
- name: Build (TypeScript check)
|
||||||
|
# Keep explicit typecheck for fast fail before full build/bundle.
|
||||||
|
run: bun run tsc --noEmit
|
||||||
|
|
||||||
|
- name: Test suite (source)
|
||||||
|
run: bun run test:fast
|
||||||
|
|
||||||
|
- name: Launcher smoke suite (source)
|
||||||
|
run: bun run test:launcher:smoke:src
|
||||||
|
|
||||||
|
- name: Upload launcher smoke artifacts (on failure)
|
||||||
|
if: failure()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: launcher-smoke
|
||||||
|
path: .tmp/launcher-smoke/**
|
||||||
|
if-no-files-found: ignore
|
||||||
|
|
||||||
|
- name: Build (bundle)
|
||||||
|
run: bun run build
|
||||||
|
|
||||||
|
- name: Dist smoke suite
|
||||||
|
run: bun run test:smoke:dist
|
||||||
|
|
||||||
|
- name: Build docs
|
||||||
|
run: bun run docs:build
|
||||||
|
|
||||||
|
- name: Security audit
|
||||||
|
run: bun audit --audit-level high
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Build Bun subminer wrapper
|
||||||
|
run: make build-launcher
|
||||||
|
|
||||||
|
- name: Verify Bun subminer wrapper
|
||||||
|
run: dist/launcher/subminer --help >/dev/null
|
||||||
|
|
||||||
|
- name: Enforce generated launcher workflow
|
||||||
|
run: bash scripts/verify-generated-launcher.sh
|
||||||
49
.github/workflows/claude.yml
vendored
Normal file
49
.github/workflows/claude.yml
vendored
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
name: Claude Code
|
||||||
|
|
||||||
|
on:
|
||||||
|
issue_comment:
|
||||||
|
types: [created]
|
||||||
|
pull_request_review_comment:
|
||||||
|
types: [created]
|
||||||
|
issues:
|
||||||
|
types: [opened, assigned]
|
||||||
|
pull_request_review:
|
||||||
|
types: [submitted]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
claude:
|
||||||
|
if: |
|
||||||
|
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
|
||||||
|
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
|
||||||
|
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
|
||||||
|
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: read
|
||||||
|
issues: read
|
||||||
|
id-token: write
|
||||||
|
actions: read # Required for Claude to read CI results on PRs
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 1
|
||||||
|
|
||||||
|
- name: Run Claude Code
|
||||||
|
id: claude
|
||||||
|
uses: anthropics/claude-code-action@v1
|
||||||
|
with:
|
||||||
|
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
|
||||||
|
|
||||||
|
# This is an optional setting that allows Claude to read CI results on PRs
|
||||||
|
additional_permissions: |
|
||||||
|
actions: read
|
||||||
|
|
||||||
|
# Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it.
|
||||||
|
# prompt: 'Update the pull request description to include a summary of changes.'
|
||||||
|
|
||||||
|
# Optional: Add claude_args to customize behavior and configuration
|
||||||
|
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
|
||||||
|
# or https://code.claude.com/docs/en/cli-reference for available options
|
||||||
|
# claude_args: '--allowed-tools Bash(gh pr:*)'
|
||||||
296
.github/workflows/release.yml
vendored
Normal file
296
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,296 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: release-${{ github.ref }}
|
||||||
|
cancel-in-progress: false
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
quality-gate:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
|
||||||
|
- name: Setup Bun
|
||||||
|
uses: oven-sh/setup-bun@v2
|
||||||
|
with:
|
||||||
|
bun-version: 1.3.5
|
||||||
|
|
||||||
|
- name: Cache dependencies
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.bun/install/cache
|
||||||
|
node_modules
|
||||||
|
key: ${{ runner.os }}-bun-${{ hashFiles('bun.lock') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-bun-
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: bun install --frozen-lockfile
|
||||||
|
|
||||||
|
- name: Test suite (source)
|
||||||
|
run: bun run test:fast
|
||||||
|
|
||||||
|
- name: Launcher smoke suite (source)
|
||||||
|
run: bun run test:launcher:smoke:src
|
||||||
|
|
||||||
|
- name: Upload launcher smoke artifacts (on failure)
|
||||||
|
if: failure()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: launcher-smoke
|
||||||
|
path: .tmp/launcher-smoke/**
|
||||||
|
if-no-files-found: ignore
|
||||||
|
|
||||||
|
- name: Build (bundle)
|
||||||
|
run: bun run build
|
||||||
|
|
||||||
|
- name: Dist smoke suite
|
||||||
|
run: bun run test:smoke:dist
|
||||||
|
|
||||||
|
build-linux:
|
||||||
|
needs: [quality-gate]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
|
||||||
|
- name: Setup Bun
|
||||||
|
uses: oven-sh/setup-bun@v2
|
||||||
|
with:
|
||||||
|
bun-version: 1.3.5
|
||||||
|
|
||||||
|
- name: Cache dependencies
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.bun/install/cache
|
||||||
|
node_modules
|
||||||
|
vendor/texthooker-ui/node_modules
|
||||||
|
key: ${{ runner.os }}-bun-${{ hashFiles('bun.lock', 'vendor/texthooker-ui/package.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-bun-
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: bun install --frozen-lockfile
|
||||||
|
|
||||||
|
- name: Build texthooker-ui
|
||||||
|
run: |
|
||||||
|
cd vendor/texthooker-ui
|
||||||
|
bun install
|
||||||
|
bun run build
|
||||||
|
|
||||||
|
- name: Build AppImage
|
||||||
|
run: bun run build:appimage
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Upload AppImage artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: appimage
|
||||||
|
path: release/*.AppImage
|
||||||
|
|
||||||
|
build-macos:
|
||||||
|
needs: [quality-gate]
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
|
||||||
|
- name: Setup Bun
|
||||||
|
uses: oven-sh/setup-bun@v2
|
||||||
|
with:
|
||||||
|
bun-version: 1.3.5
|
||||||
|
|
||||||
|
- name: Cache dependencies
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.bun/install/cache
|
||||||
|
node_modules
|
||||||
|
vendor/texthooker-ui/node_modules
|
||||||
|
key: ${{ runner.os }}-bun-${{ hashFiles('bun.lock', 'vendor/texthooker-ui/package.json') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-bun-
|
||||||
|
|
||||||
|
- name: Validate macOS signing/notarization secrets
|
||||||
|
run: |
|
||||||
|
missing=0
|
||||||
|
for name in CSC_LINK CSC_KEY_PASSWORD APPLE_ID APPLE_APP_SPECIFIC_PASSWORD APPLE_TEAM_ID; do
|
||||||
|
if [ -z "${!name}" ]; then
|
||||||
|
echo "Missing required secret: $name"
|
||||||
|
missing=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ "$missing" -ne 0 ]; then
|
||||||
|
echo "Set all required macOS signing/notarization secrets and rerun."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
CSC_LINK: ${{ secrets.CSC_LINK }}
|
||||||
|
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
|
||||||
|
APPLE_ID: ${{ secrets.APPLE_ID }}
|
||||||
|
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
|
||||||
|
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: bun install --frozen-lockfile
|
||||||
|
|
||||||
|
- name: Build texthooker-ui
|
||||||
|
run: |
|
||||||
|
cd vendor/texthooker-ui
|
||||||
|
bun install
|
||||||
|
bun run build
|
||||||
|
|
||||||
|
- name: Build signed + notarized macOS artifacts
|
||||||
|
run: bun run build:mac
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
CSC_LINK: ${{ secrets.CSC_LINK }}
|
||||||
|
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
|
||||||
|
APPLE_ID: ${{ secrets.APPLE_ID }}
|
||||||
|
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
|
||||||
|
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
|
||||||
|
|
||||||
|
- name: Upload macOS artifacts
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: macos
|
||||||
|
path: |
|
||||||
|
release/*.dmg
|
||||||
|
release/*.zip
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: [build-linux, build-macos]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Download AppImage
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: appimage
|
||||||
|
path: release
|
||||||
|
|
||||||
|
- name: Download macOS artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: macos
|
||||||
|
path: release
|
||||||
|
|
||||||
|
- name: Setup Bun
|
||||||
|
uses: oven-sh/setup-bun@v2
|
||||||
|
with:
|
||||||
|
bun-version: 1.3.5
|
||||||
|
|
||||||
|
- name: Build Bun subminer wrapper
|
||||||
|
run: make build-launcher
|
||||||
|
|
||||||
|
- name: Verify Bun subminer wrapper
|
||||||
|
run: dist/launcher/subminer --help >/dev/null
|
||||||
|
|
||||||
|
- name: Enforce generated launcher workflow
|
||||||
|
run: bash scripts/verify-generated-launcher.sh
|
||||||
|
|
||||||
|
- name: Package optional assets bundle
|
||||||
|
run: |
|
||||||
|
VERSION="${GITHUB_REF#refs/tags/}"
|
||||||
|
tar -czf "release/subminer-assets-${VERSION}.tar.gz" \
|
||||||
|
config.example.jsonc \
|
||||||
|
plugin/subminer.lua \
|
||||||
|
plugin/subminer.conf \
|
||||||
|
assets/themes/subminer.rasi
|
||||||
|
|
||||||
|
- name: Generate checksums
|
||||||
|
run: |
|
||||||
|
shopt -s nullglob
|
||||||
|
files=(release/*.AppImage release/*.dmg release/*.zip release/*.tar.gz dist/launcher/subminer)
|
||||||
|
if [ "${#files[@]}" -eq 0 ]; then
|
||||||
|
echo "No release artifacts found for checksum generation."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
sha256sum "${files[@]}" > release/SHA256SUMS.txt
|
||||||
|
|
||||||
|
- name: Get version from tag
|
||||||
|
id: version
|
||||||
|
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Generate changelog
|
||||||
|
id: changelog
|
||||||
|
run: |
|
||||||
|
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
|
||||||
|
if [ -n "$PREV_TAG" ]; then
|
||||||
|
CHANGES=$(git log --pretty=format:"- %s" ${PREV_TAG}..HEAD)
|
||||||
|
else
|
||||||
|
COMMIT_COUNT=$(git rev-list --count HEAD)
|
||||||
|
if [ "$COMMIT_COUNT" -gt 10 ]; then
|
||||||
|
CHANGES=$(git log --pretty=format:"- %s" HEAD~10..HEAD)
|
||||||
|
else
|
||||||
|
CHANGES=$(git log --pretty=format:"- %s")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "CHANGES<<EOF" >> $GITHUB_OUTPUT
|
||||||
|
echo "$CHANGES" >> $GITHUB_OUTPUT
|
||||||
|
echo "EOF" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
name: ${{ steps.version.outputs.VERSION }}
|
||||||
|
body: |
|
||||||
|
## Changes
|
||||||
|
${{ steps.changelog.outputs.CHANGES }}
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
### AppImage (Recommended)
|
||||||
|
1. Download the AppImage below
|
||||||
|
2. Make it executable: `chmod +x SubMiner-*.AppImage`
|
||||||
|
3. Run: `./SubMiner-*.AppImage`
|
||||||
|
|
||||||
|
### macOS
|
||||||
|
1. Download `subminer-*.dmg`
|
||||||
|
2. Open the DMG and drag `SubMiner.app` into `/Applications`
|
||||||
|
3. If needed, use the ZIP artifact as an alternative
|
||||||
|
|
||||||
|
### Manual Installation
|
||||||
|
See the [README](https://github.com/${{ github.repository }}#installation) for manual installation instructions.
|
||||||
|
|
||||||
|
### Optional Assets (config example + mpv plugin + rofi theme)
|
||||||
|
1. Download `subminer-assets-*.tar.gz`
|
||||||
|
2. Extract and copy `config.example.jsonc` to `~/.config/SubMiner/config.jsonc`
|
||||||
|
3. Copy `plugin/subminer.lua` to `~/.config/mpv/scripts/`
|
||||||
|
4. Copy `plugin/subminer.conf` to `~/.config/mpv/script-opts/`
|
||||||
|
5. Copy `assets/themes/subminer.rasi` to:
|
||||||
|
- Linux: `~/.local/share/SubMiner/themes/subminer.rasi`
|
||||||
|
- macOS: `~/Library/Application Support/SubMiner/themes/subminer.rasi`
|
||||||
|
|
||||||
|
Note: the `subminer` wrapper script uses Bun (`#!/usr/bin/env bun`), so `bun` must be installed and on `PATH`.
|
||||||
|
files: |
|
||||||
|
release/*.AppImage
|
||||||
|
release/*.dmg
|
||||||
|
release/*.zip
|
||||||
|
release/*.tar.gz
|
||||||
|
release/SHA256SUMS.txt
|
||||||
|
dist/launcher/subminer
|
||||||
|
draft: false
|
||||||
|
prerelease: false
|
||||||
38
.gitignore
vendored
Normal file
38
.gitignore
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Electron build output
|
||||||
|
out/
|
||||||
|
dist/
|
||||||
|
release/
|
||||||
|
|
||||||
|
# Launcher build artifact (produced by make build-launcher)
|
||||||
|
subminer
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
|
||||||
|
# OS files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.idea/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
**/CLAUDE.md
|
||||||
|
environment.toml
|
||||||
|
**/CLAUDE.md
|
||||||
|
.env
|
||||||
|
.vscode/*
|
||||||
|
|
||||||
|
# VitePress
|
||||||
|
.vitepress/cache/
|
||||||
|
.vitepress/dist/
|
||||||
|
docs/.vitepress/cache/
|
||||||
|
docs/.vitepress/dist/
|
||||||
|
tests/*
|
||||||
|
.worktrees/
|
||||||
|
.codex/*
|
||||||
|
.agents/*
|
||||||
7
.gitmodules
vendored
Normal file
7
.gitmodules
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[submodule "vendor/texthooker-ui"]
|
||||||
|
path = vendor/texthooker-ui
|
||||||
|
url = https://github.com/ksyasuda/texthooker-ui.git
|
||||||
|
branch = subminer
|
||||||
|
[submodule "vendor/yomitan-jlpt-vocab"]
|
||||||
|
path = vendor/yomitan-jlpt-vocab
|
||||||
|
url = https://github.com/stephenmk/yomitan-jlpt-vocab
|
||||||
6
.prettierignore
Normal file
6
.prettierignore
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
release
|
||||||
|
coverage
|
||||||
|
vendor
|
||||||
|
*.log
|
||||||
5
.prettierrc.json
Normal file
5
.prettierrc.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 100,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "all"
|
||||||
|
}
|
||||||
29
AGENTS.md
Normal file
29
AGENTS.md
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
<!-- BACKLOG.MD MCP GUIDELINES START -->
|
||||||
|
|
||||||
|
<CRITICAL_INSTRUCTION>
|
||||||
|
|
||||||
|
## BACKLOG WORKFLOW INSTRUCTIONS
|
||||||
|
|
||||||
|
This project uses Backlog.md MCP for all task and project management activities.
|
||||||
|
|
||||||
|
**CRITICAL GUIDANCE**
|
||||||
|
|
||||||
|
- If your client supports MCP resources, read `backlog://workflow/overview` to understand when and how to use Backlog for this project.
|
||||||
|
- If your client only supports tools or the above request fails, call `backlog.get_workflow_overview()` tool to load the tool-oriented overview (it lists the matching guide tools).
|
||||||
|
|
||||||
|
- **First time working here?** Read the overview resource IMMEDIATELY to learn the workflow
|
||||||
|
- **Already familiar?** You should have the overview cached ("## Backlog.md Overview (MCP)")
|
||||||
|
- **When to read it**: BEFORE creating tasks, or when you're unsure whether to track work
|
||||||
|
|
||||||
|
These guides cover:
|
||||||
|
- Decision framework for when to create tasks
|
||||||
|
- Search-first workflow to avoid duplicates
|
||||||
|
- Links to detailed guides for task creation, execution, and finalization
|
||||||
|
- MCP tools reference
|
||||||
|
|
||||||
|
You MUST read the overview resource to understand the complete workflow. The information is NOT summarized here.
|
||||||
|
|
||||||
|
</CRITICAL_INSTRUCTION>
|
||||||
|
|
||||||
|
<!-- BACKLOG.MD MCP GUIDELINES END -->
|
||||||
674
LICENSE
Normal file
674
LICENSE
Normal file
@@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||||
238
Makefile
Normal file
238
Makefile
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
.PHONY: help deps build build-launcher install build-linux build-macos build-macos-unsigned clean install-linux install-macos install-plugin uninstall uninstall-linux uninstall-macos print-dirs pretty ensure-bun generate-config generate-example-config docs-dev docs docs-preview dev-start dev-start-macos dev-toggle dev-stop
|
||||||
|
|
||||||
|
APP_NAME := subminer
|
||||||
|
THEME_SOURCE := assets/themes/subminer.rasi
|
||||||
|
LAUNCHER_OUT := dist/launcher/$(APP_NAME)
|
||||||
|
THEME_FILE := subminer.rasi
|
||||||
|
PLUGIN_LUA := plugin/subminer.lua
|
||||||
|
PLUGIN_CONF := plugin/subminer.conf
|
||||||
|
|
||||||
|
# Default install prefix for the wrapper script.
|
||||||
|
PREFIX ?= $(HOME)/.local
|
||||||
|
BINDIR ?= $(PREFIX)/bin
|
||||||
|
|
||||||
|
# Linux data dir defaults to XDG_DATA_HOME/SubMiner.
|
||||||
|
XDG_DATA_HOME ?= $(HOME)/.local/share
|
||||||
|
LINUX_DATA_DIR ?= $(XDG_DATA_HOME)/SubMiner
|
||||||
|
|
||||||
|
# macOS data dir uses the standard Application Support location.
|
||||||
|
# Note: contains spaces; recipes must quote it.
|
||||||
|
MACOS_DATA_DIR ?= $(HOME)/Library/Application Support/SubMiner
|
||||||
|
MACOS_APP_DIR ?= $(HOME)/Applications
|
||||||
|
MACOS_APP_DEST ?= $(MACOS_APP_DIR)/SubMiner.app
|
||||||
|
|
||||||
|
# mpv plugin install directories.
|
||||||
|
MPV_CONFIG_DIR ?= $(HOME)/.config/mpv
|
||||||
|
MPV_SCRIPTS_DIR ?= $(MPV_CONFIG_DIR)/scripts
|
||||||
|
MPV_SCRIPT_OPTS_DIR ?= $(MPV_CONFIG_DIR)/script-opts
|
||||||
|
|
||||||
|
# If building from source, the AppImage will typically land in release/.
|
||||||
|
APPIMAGE_SRC := $(firstword $(wildcard release/SubMiner-*.AppImage))
|
||||||
|
MACOS_APP_SRC := $(firstword $(wildcard release/*.app release/*/*.app))
|
||||||
|
MACOS_ZIP_SRC := $(firstword $(wildcard release/SubMiner-*.zip))
|
||||||
|
|
||||||
|
UNAME_S := $(shell uname -s 2>/dev/null || echo Unknown)
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
PLATFORM := windows
|
||||||
|
else ifeq ($(UNAME_S),Linux)
|
||||||
|
PLATFORM := linux
|
||||||
|
else ifeq ($(UNAME_S),Darwin)
|
||||||
|
PLATFORM := macos
|
||||||
|
else
|
||||||
|
PLATFORM := unknown
|
||||||
|
endif
|
||||||
|
|
||||||
|
help:
|
||||||
|
@printf '%s\n' \
|
||||||
|
"Targets:" \
|
||||||
|
" build Build platform package for detected OS ($(PLATFORM))" \
|
||||||
|
" install Install platform artifacts for detected OS ($(PLATFORM))" \
|
||||||
|
" build-linux Build Linux AppImage" \
|
||||||
|
" build-macos Build macOS DMG/ZIP (signed if configured)" \
|
||||||
|
" build-macos-unsigned Build macOS DMG/ZIP without signing/notarization" \
|
||||||
|
" clean Remove build artifacts (dist/, release/, AppImage, binary)" \
|
||||||
|
" dev-start Build and launch local Electron app" \
|
||||||
|
" dev-start-macos Build and launch local Electron app with macOS tracker backend" \
|
||||||
|
" dev-toggle Toggle overlay in a running local Electron app" \
|
||||||
|
" dev-stop Stop a running local Electron app" \
|
||||||
|
" docs-dev Run VitePress docs dev server" \
|
||||||
|
" docs Build VitePress static docs" \
|
||||||
|
" docs-preview Preview built VitePress docs" \
|
||||||
|
" install-linux Install Linux wrapper/theme/app artifacts" \
|
||||||
|
" install-macos Install macOS wrapper/theme/app artifacts" \
|
||||||
|
" install-plugin Install mpv Lua plugin and plugin config" \
|
||||||
|
" generate-config Generate ~/.config/SubMiner/config.jsonc from centralized defaults" \
|
||||||
|
"" \
|
||||||
|
"Other targets:" \
|
||||||
|
" deps Install JS dependencies (root + texthooker-ui)" \
|
||||||
|
" uninstall-linux Remove Linux install artifacts" \
|
||||||
|
" uninstall-macos Remove macOS install artifacts" \
|
||||||
|
" print-dirs Show resolved install locations" \
|
||||||
|
"" \
|
||||||
|
"Variables:" \
|
||||||
|
" PREFIX=... Override wrapper install prefix (default: $$HOME/.local)" \
|
||||||
|
" BINDIR=... Override wrapper install bin dir" \
|
||||||
|
" XDG_DATA_HOME=... Override Linux data dir base (default: $$HOME/.local/share)" \
|
||||||
|
" LINUX_DATA_DIR=... Override Linux app data dir" \
|
||||||
|
" MACOS_DATA_DIR=... Override macOS app data dir" \
|
||||||
|
" MACOS_APP_DIR=... Override macOS app install dir (default: $$HOME/Applications)" \
|
||||||
|
" MPV_CONFIG_DIR=... Override mpv config dir (default: $$HOME/.config/mpv)"
|
||||||
|
|
||||||
|
print-dirs:
|
||||||
|
@printf '%s\n' \
|
||||||
|
"PLATFORM=$(PLATFORM)" \
|
||||||
|
"UNAME_S=$(UNAME_S)" \
|
||||||
|
"BINDIR=$(BINDIR)" \
|
||||||
|
"LINUX_DATA_DIR=$(LINUX_DATA_DIR)" \
|
||||||
|
"MACOS_DATA_DIR=$(MACOS_DATA_DIR)" \
|
||||||
|
"MACOS_APP_DIR=$(MACOS_APP_DIR)" \
|
||||||
|
"MACOS_APP_DEST=$(MACOS_APP_DEST)" \
|
||||||
|
"APPIMAGE_SRC=$(APPIMAGE_SRC)" \
|
||||||
|
"MACOS_APP_SRC=$(MACOS_APP_SRC)" \
|
||||||
|
"MACOS_ZIP_SRC=$(MACOS_ZIP_SRC)"
|
||||||
|
|
||||||
|
deps:
|
||||||
|
@$(MAKE) --no-print-directory ensure-bun
|
||||||
|
@bun install
|
||||||
|
@cd vendor/texthooker-ui && bun install --frozen-lockfile
|
||||||
|
|
||||||
|
ensure-bun:
|
||||||
|
@command -v bun >/dev/null 2>&1 || { printf '%s\n' "[ERROR] bun not found"; exit 1; }
|
||||||
|
|
||||||
|
pretty: ensure-bun
|
||||||
|
@bun run format
|
||||||
|
|
||||||
|
build:
|
||||||
|
@printf '%s\n' "[INFO] Detected platform: $(PLATFORM)"
|
||||||
|
@case "$(PLATFORM)" in \
|
||||||
|
linux) $(MAKE) --no-print-directory build-linux ;; \
|
||||||
|
macos) $(MAKE) --no-print-directory build-macos ;; \
|
||||||
|
*) printf '%s\n' "[ERROR] Unsupported OS for this Makefile target: $(PLATFORM)"; exit 1 ;; \
|
||||||
|
esac
|
||||||
|
|
||||||
|
install:
|
||||||
|
@printf '%s\n' "[INFO] Detected platform: $(PLATFORM)"
|
||||||
|
@case "$(PLATFORM)" in \
|
||||||
|
linux) $(MAKE) --no-print-directory install-linux ;; \
|
||||||
|
macos) $(MAKE) --no-print-directory install-macos ;; \
|
||||||
|
*) printf '%s\n' "[ERROR] Unsupported OS for this Makefile target: $(PLATFORM)"; exit 1 ;; \
|
||||||
|
esac
|
||||||
|
|
||||||
|
build-linux: deps
|
||||||
|
@printf '%s\n' "[INFO] Building Linux package (AppImage)"
|
||||||
|
@cd vendor/texthooker-ui && bun run build
|
||||||
|
@bun run build:appimage
|
||||||
|
|
||||||
|
build-macos: deps
|
||||||
|
@printf '%s\n' "[INFO] Building macOS package (DMG + ZIP)"
|
||||||
|
@cd vendor/texthooker-ui && bun run build
|
||||||
|
@bun run build:mac
|
||||||
|
|
||||||
|
build-macos-unsigned: deps
|
||||||
|
@printf '%s\n' "[INFO] Building macOS package (DMG + ZIP, unsigned)"
|
||||||
|
@cd vendor/texthooker-ui && bun run build
|
||||||
|
@bun run build:mac:unsigned
|
||||||
|
|
||||||
|
build-launcher:
|
||||||
|
@printf '%s\n' "[INFO] Bundling launcher script"
|
||||||
|
@install -d "$(dir $(LAUNCHER_OUT))"
|
||||||
|
@bun build ./launcher/main.ts --target=bun --packages=bundle --outfile="$(LAUNCHER_OUT)"
|
||||||
|
@if ! head -1 "$(LAUNCHER_OUT)" | grep -q '^#!/usr/bin/env bun'; then \
|
||||||
|
{ printf '#!/usr/bin/env bun\n'; cat "$(LAUNCHER_OUT)"; } > "$(LAUNCHER_OUT).tmp" && mv "$(LAUNCHER_OUT).tmp" "$(LAUNCHER_OUT)"; \
|
||||||
|
fi
|
||||||
|
@chmod +x "$(LAUNCHER_OUT)"
|
||||||
|
@printf '%s\n' "[INFO] Launcher artifact: $(LAUNCHER_OUT)"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@printf '%s\n' "[INFO] Removing build artifacts"
|
||||||
|
@rm -rf dist release
|
||||||
|
@rm -f "$(BINDIR)/subminer" "$(BINDIR)/SubMiner.AppImage"
|
||||||
|
|
||||||
|
generate-config: ensure-bun
|
||||||
|
@bun run build
|
||||||
|
@bun run electron . --generate-config
|
||||||
|
|
||||||
|
generate-example-config: ensure-bun
|
||||||
|
@bun run build
|
||||||
|
@bun run generate:config-example
|
||||||
|
|
||||||
|
docs-dev: ensure-bun
|
||||||
|
@bun run docs:dev
|
||||||
|
|
||||||
|
docs: ensure-bun
|
||||||
|
@bun run docs:build
|
||||||
|
|
||||||
|
docs-preview: ensure-bun
|
||||||
|
@bun run docs:preview
|
||||||
|
|
||||||
|
dev-start: ensure-bun
|
||||||
|
@bun run build
|
||||||
|
@bun run electron . --start
|
||||||
|
|
||||||
|
dev-start-macos: ensure-bun
|
||||||
|
@bun run build
|
||||||
|
@bun run electron . --start --backend macos
|
||||||
|
|
||||||
|
dev-toggle: ensure-bun
|
||||||
|
@bun run electron . --toggle
|
||||||
|
|
||||||
|
dev-stop: ensure-bun
|
||||||
|
@bun run electron . --stop
|
||||||
|
|
||||||
|
|
||||||
|
install-linux: build-launcher
|
||||||
|
@printf '%s\n' "[INFO] Installing Linux wrapper/theme artifacts"
|
||||||
|
@install -d "$(BINDIR)"
|
||||||
|
@install -m 0755 "$(LAUNCHER_OUT)" "$(BINDIR)/$(APP_NAME)"
|
||||||
|
@install -d "$(LINUX_DATA_DIR)/themes"
|
||||||
|
@install -m 0644 "./$(THEME_SOURCE)" "$(LINUX_DATA_DIR)/themes/$(THEME_FILE)"
|
||||||
|
@if [ -n "$(APPIMAGE_SRC)" ]; then \
|
||||||
|
install -m 0755 "$(APPIMAGE_SRC)" "$(BINDIR)/SubMiner.AppImage"; \
|
||||||
|
else \
|
||||||
|
printf '%s\n' "[WARN] No release/SubMiner-*.AppImage found; skipping AppImage install"; \
|
||||||
|
printf '%s\n' " Build one with: make build"; \
|
||||||
|
fi
|
||||||
|
@printf '%s\n' "Installed to:" " $(BINDIR)/subminer" " $(LINUX_DATA_DIR)/themes/$(THEME_FILE)"
|
||||||
|
|
||||||
|
install-macos: build-launcher
|
||||||
|
@printf '%s\n' "[INFO] Installing macOS wrapper/theme/app artifacts"
|
||||||
|
@install -d "$(BINDIR)"
|
||||||
|
@install -m 0755 "$(LAUNCHER_OUT)" "$(BINDIR)/$(APP_NAME)"
|
||||||
|
@install -d "$(MACOS_DATA_DIR)/themes"
|
||||||
|
@install -m 0644 "./$(THEME_SOURCE)" "$(MACOS_DATA_DIR)/themes/$(THEME_FILE)"
|
||||||
|
@install -d "$(MACOS_APP_DIR)"
|
||||||
|
@if [ -n "$(MACOS_APP_SRC)" ]; then \
|
||||||
|
rm -rf "$(MACOS_APP_DEST)"; \
|
||||||
|
cp -R "$(MACOS_APP_SRC)" "$(MACOS_APP_DEST)"; \
|
||||||
|
printf '%s\n' "[INFO] Installed app bundle from $(MACOS_APP_SRC)"; \
|
||||||
|
elif [ -n "$(MACOS_ZIP_SRC)" ]; then \
|
||||||
|
rm -rf "$(MACOS_APP_DEST)"; \
|
||||||
|
ditto -x -k "$(MACOS_ZIP_SRC)" "$(MACOS_APP_DIR)"; \
|
||||||
|
printf '%s\n' "[INFO] Installed app bundle from $(MACOS_ZIP_SRC)"; \
|
||||||
|
else \
|
||||||
|
printf '%s\n' "[WARN] No macOS app bundle or zip found in release/; skipping app install"; \
|
||||||
|
printf '%s\n' " Build one with: make build"; \
|
||||||
|
fi
|
||||||
|
@printf '%s\n' "Installed to:" " $(BINDIR)/subminer" " $(MACOS_DATA_DIR)/themes/$(THEME_FILE)" " $(MACOS_APP_DEST)"
|
||||||
|
|
||||||
|
install-plugin:
|
||||||
|
@printf '%s\n' "[INFO] Installing mpv plugin artifacts"
|
||||||
|
@install -d "$(MPV_SCRIPTS_DIR)"
|
||||||
|
@install -d "$(MPV_SCRIPT_OPTS_DIR)"
|
||||||
|
@install -m 0644 "./$(PLUGIN_LUA)" "$(MPV_SCRIPTS_DIR)/subminer.lua"
|
||||||
|
@install -m 0644 "./$(PLUGIN_CONF)" "$(MPV_SCRIPT_OPTS_DIR)/subminer.conf"
|
||||||
|
@printf '%s\n' "Installed to:" " $(MPV_SCRIPTS_DIR)/subminer.lua" " $(MPV_SCRIPT_OPTS_DIR)/subminer.conf"
|
||||||
|
|
||||||
|
# Uninstall behavior kept unchanged by default.
|
||||||
|
uninstall: uninstall-linux
|
||||||
|
|
||||||
|
uninstall-linux:
|
||||||
|
@rm -f "$(BINDIR)/subminer" "$(BINDIR)/SubMiner.AppImage"
|
||||||
|
@rm -f "$(LINUX_DATA_DIR)/themes/$(THEME_FILE)"
|
||||||
|
@printf '%s\n' "Removed:" " $(BINDIR)/subminer" " $(BINDIR)/SubMiner.AppImage" " $(LINUX_DATA_DIR)/themes/$(THEME_FILE)"
|
||||||
|
|
||||||
|
uninstall-macos:
|
||||||
|
@rm -f "$(BINDIR)/subminer"
|
||||||
|
@rm -f "$(MACOS_DATA_DIR)/themes/$(THEME_FILE)"
|
||||||
|
@rm -rf "$(MACOS_APP_DEST)"
|
||||||
|
@printf '%s\n' "Removed:" " $(BINDIR)/subminer" " $(MACOS_DATA_DIR)/themes/$(THEME_FILE)" " $(MACOS_APP_DEST)"
|
||||||
14
build/entitlements.mac.plist
Normal file
14
build/entitlements.mac.plist
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>com.apple.security.cs.allow-jit</key>
|
||||||
|
<true/>
|
||||||
|
<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
|
||||||
|
<true/>
|
||||||
|
<key>com.apple.security.cs.disable-library-validation</key>
|
||||||
|
<true/>
|
||||||
|
<key>com.apple.security.automation.apple-events</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
135
package.json
Normal file
135
package.json
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
{
|
||||||
|
"name": "subminer",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "All-in-one sentence mining overlay with AnkiConnect and dictionary integration",
|
||||||
|
"packageManager": "bun@1.3.5",
|
||||||
|
"main": "dist/main-entry.js",
|
||||||
|
"scripts": {
|
||||||
|
"get-frequency": "bun run scripts/get_frequency.ts --pretty --color-top-x 10000 --yomitan-user-data ~/.config/SubMiner --colorized-line",
|
||||||
|
"get-frequency:electron": "bun build scripts/get_frequency.ts --format=cjs --target=node --outfile dist/scripts/get_frequency.js --external electron && electron dist/scripts/get_frequency.js --pretty --color-top-x 10000 --yomitan-user-data ~/.config/SubMiner --colorized-line",
|
||||||
|
"test-yomitan-parser": "bun run scripts/test-yomitan-parser.ts",
|
||||||
|
"test-yomitan-parser:electron": "bun build scripts/test-yomitan-parser.ts --format=cjs --target=node --outfile dist/scripts/test-yomitan-parser.js --external electron && electron dist/scripts/test-yomitan-parser.js",
|
||||||
|
"build": "tsc && bun run build:renderer && cp src/renderer/index.html src/renderer/style.css dist/renderer/ && cp -r src/renderer/fonts dist/renderer/ && bash scripts/build-macos-helper.sh",
|
||||||
|
"build:renderer": "esbuild src/renderer/renderer.ts --bundle --platform=browser --format=esm --target=es2022 --outfile=dist/renderer/renderer.js --sourcemap",
|
||||||
|
"docs:dev": "VITE_EXTRA_EXTENSIONS=jsonc vitepress dev docs --host 0.0.0.0 --port 5173 --strictPort",
|
||||||
|
"docs:build": "VITE_EXTRA_EXTENSIONS=jsonc vitepress build docs",
|
||||||
|
"docs:preview": "VITE_EXTRA_EXTENSIONS=jsonc vitepress preview docs --host 0.0.0.0 --port 4173 --strictPort",
|
||||||
|
"format": "prettier --write .",
|
||||||
|
"format:check": "prettier --check .",
|
||||||
|
"test:config:src": "bun test src/config/config.test.ts src/config/path-resolution.test.ts src/config/resolve/anki-connect.test.ts src/config/resolve/subtitle-style.test.ts src/config/resolve/jellyfin.test.ts src/config/definitions/domain-registry.test.ts",
|
||||||
|
"test:config:dist": "bun test dist/config/config.test.js dist/config/path-resolution.test.js dist/config/resolve/anki-connect.test.js dist/config/resolve/subtitle-style.test.js dist/config/resolve/jellyfin.test.js dist/config/definitions/domain-registry.test.js",
|
||||||
|
"test:config:smoke:dist": "bun test dist/config/path-resolution.test.js",
|
||||||
|
"test:launcher:smoke:src": "bun test launcher/smoke.e2e.test.ts",
|
||||||
|
"test:launcher:src": "bun test launcher/config.test.ts launcher/config-domain-parsers.test.ts launcher/parse-args.test.ts launcher/main.test.ts launcher/commands/command-modules.test.ts launcher/smoke.e2e.test.ts",
|
||||||
|
"test:core:src": "bun test src/cli/args.test.ts src/cli/help.test.ts src/core/services/cli-command.test.ts src/core/services/field-grouping-overlay.test.ts src/core/services/numeric-shortcut-session.test.ts src/core/services/secondary-subtitle.test.ts src/core/services/mpv-render-metrics.test.ts src/core/services/overlay-content-measurement.test.ts src/core/services/mpv-control.test.ts src/core/services/mpv.test.ts src/core/services/runtime-options-ipc.test.ts src/core/services/runtime-config.test.ts src/core/services/config-hot-reload.test.ts src/core/services/discord-presence.test.ts src/core/services/tokenizer.test.ts src/core/services/tokenizer/annotation-stage.test.ts src/core/services/tokenizer/parser-selection-stage.test.ts src/core/services/tokenizer/parser-enrichment-stage.test.ts src/core/services/subsync.test.ts src/core/services/overlay-bridge.test.ts src/core/services/overlay-shortcut-handler.test.ts src/core/services/mining.test.ts src/core/services/anki-jimaku.test.ts src/core/services/jellyfin.test.ts src/core/services/jellyfin-remote.test.ts src/core/services/immersion-tracker-service.test.ts src/core/services/app-ready.test.ts src/core/services/startup-bootstrap.test.ts src/core/services/subtitle-processing-controller.test.ts src/core/services/anilist/anilist-update-queue.test.ts src/core/utils/shortcut-config.test.ts src/renderer/error-recovery.test.ts src/subsync/utils.test.ts src/main/anilist-url-guard.test.ts src/window-trackers/x11-tracker.test.ts launcher/config.test.ts launcher/config-domain-parsers.test.ts launcher/parse-args.test.ts launcher/main.test.ts launcher/commands/command-modules.test.ts",
|
||||||
|
"test:core:dist": "bun test dist/cli/args.test.js dist/cli/help.test.js dist/core/services/cli-command.test.js dist/core/services/ipc.test.js dist/core/services/anki-jimaku-ipc.test.js dist/core/services/field-grouping-overlay.test.js dist/core/services/numeric-shortcut-session.test.js dist/core/services/secondary-subtitle.test.js dist/core/services/mpv-render-metrics.test.js dist/core/services/overlay-content-measurement.test.js dist/core/services/mpv-control.test.js dist/core/services/mpv.test.js dist/core/services/runtime-options-ipc.test.js dist/core/services/runtime-config.test.js dist/core/services/config-hot-reload.test.js dist/core/services/discord-presence.test.js dist/core/services/tokenizer.test.js dist/core/services/tokenizer/annotation-stage.test.js dist/core/services/tokenizer/parser-selection-stage.test.js dist/core/services/tokenizer/parser-enrichment-stage.test.js dist/core/services/subsync.test.js dist/core/services/overlay-bridge.test.js dist/core/services/overlay-manager.test.js dist/core/services/overlay-shortcut-handler.test.js dist/core/services/mining.test.js dist/core/services/anki-jimaku.test.js dist/core/services/jellyfin.test.js dist/core/services/jellyfin-remote.test.js dist/core/services/immersion-tracker-service.test.js dist/core/services/app-ready.test.js dist/core/services/startup-bootstrap.test.js dist/core/services/subtitle-processing-controller.test.js dist/core/services/anilist/anilist-token-store.test.js dist/core/services/anilist/anilist-update-queue.test.js dist/renderer/error-recovery.test.js dist/subsync/utils.test.js dist/main/anilist-url-guard.test.js dist/window-trackers/x11-tracker.test.js",
|
||||||
|
"test:core:smoke:dist": "bun test dist/cli/help.test.js dist/core/services/runtime-config.test.js dist/core/services/ipc.test.js dist/core/services/overlay-manager.test.js dist/core/services/anilist/anilist-token-store.test.js dist/core/services/startup-bootstrap.test.js dist/renderer/error-recovery.test.js dist/main/anilist-url-guard.test.js dist/window-trackers/x11-tracker.test.js",
|
||||||
|
"test:smoke:dist": "bun run test:config:smoke:dist && bun run test:core:smoke:dist",
|
||||||
|
"test:subtitle:dist": "echo \"Subtitle tests are currently not configured\"",
|
||||||
|
"test": "bun run test:config && bun run test:core",
|
||||||
|
"test:config": "bun run test:config:src",
|
||||||
|
"test:launcher": "bun run test:launcher:src",
|
||||||
|
"test:core": "bun run test:core:src",
|
||||||
|
"test:subtitle": "bun run build && bun run test:subtitle:dist",
|
||||||
|
"test:fast": "bun run test:config:src && bun run test:core:src",
|
||||||
|
"generate:config-example": "bun run build && bun dist/generate-config-example.js",
|
||||||
|
"start": "bun run build && electron . --start",
|
||||||
|
"dev": "bun run build && electron . --start --dev",
|
||||||
|
"stop": "electron . --stop",
|
||||||
|
"toggle": "electron . --toggle",
|
||||||
|
"build:appimage": "bun run build && electron-builder --linux AppImage",
|
||||||
|
"build:mac": "bun run build && electron-builder --mac dmg zip",
|
||||||
|
"build:mac:unsigned": "bun run build && env -u APPLE_ID -u APPLE_APP_SPECIFIC_PASSWORD -u APPLE_TEAM_ID -u CSC_LINK -u CSC_KEY_PASSWORD CSC_IDENTITY_AUTO_DISCOVERY=false electron-builder --mac dmg zip",
|
||||||
|
"build:mac:zip": "bun run build && electron-builder --mac zip"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"anki",
|
||||||
|
"ankiconnect",
|
||||||
|
"sentence-mining",
|
||||||
|
"japanese",
|
||||||
|
"subtitles",
|
||||||
|
"overlay",
|
||||||
|
"mpv",
|
||||||
|
"yomitan"
|
||||||
|
],
|
||||||
|
"author": "",
|
||||||
|
"license": "GPL-3.0-or-later",
|
||||||
|
"dependencies": {
|
||||||
|
"@catppuccin/vitepress": "^0.1.2",
|
||||||
|
"axios": "^1.13.5",
|
||||||
|
"commander": "^14.0.3",
|
||||||
|
"discord-rpc": "^4.0.1",
|
||||||
|
"jsonc-parser": "^3.3.1",
|
||||||
|
"mermaid": "^11.12.3",
|
||||||
|
"ws": "^8.19.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^25.3.0",
|
||||||
|
"@types/ws": "^8.18.1",
|
||||||
|
"electron": "^37.10.3",
|
||||||
|
"electron-builder": "^26.8.1",
|
||||||
|
"esbuild": "^0.25.12",
|
||||||
|
"prettier": "^3.8.1",
|
||||||
|
"typescript": "^5.9.3",
|
||||||
|
"vitepress": "^1.6.4"
|
||||||
|
},
|
||||||
|
"build": {
|
||||||
|
"appId": "com.sudacode.SubMiner",
|
||||||
|
"productName": "SubMiner",
|
||||||
|
"executableName": "SubMiner",
|
||||||
|
"artifactName": "SubMiner-${version}.${ext}",
|
||||||
|
"icon": "assets/SubMiner.png",
|
||||||
|
"directories": {
|
||||||
|
"output": "release"
|
||||||
|
},
|
||||||
|
"linux": {
|
||||||
|
"target": [
|
||||||
|
"AppImage"
|
||||||
|
],
|
||||||
|
"category": "AudioVideo",
|
||||||
|
"executableArgs": [
|
||||||
|
"--background"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"mac": {
|
||||||
|
"target": [
|
||||||
|
"dmg",
|
||||||
|
"zip"
|
||||||
|
],
|
||||||
|
"category": "public.app-category.video",
|
||||||
|
"icon": "assets/SubMiner.png",
|
||||||
|
"hardenedRuntime": true,
|
||||||
|
"entitlements": "build/entitlements.mac.plist",
|
||||||
|
"entitlementsInherit": "build/entitlements.mac.plist"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist/**/*",
|
||||||
|
"vendor/texthooker-ui/docs/**/*",
|
||||||
|
"vendor/texthooker-ui/package.json",
|
||||||
|
"package.json",
|
||||||
|
"scripts/get-mpv-window-macos.swift"
|
||||||
|
],
|
||||||
|
"extraResources": [
|
||||||
|
{
|
||||||
|
"from": "vendor/yomitan",
|
||||||
|
"to": "yomitan"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": "vendor/yomitan-jlpt-vocab",
|
||||||
|
"to": "yomitan-jlpt-vocab"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": "vendor/jiten_freq_global",
|
||||||
|
"to": "jiten_freq_global"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": "assets",
|
||||||
|
"to": "assets"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"from": "dist/scripts/get-mpv-window-macos",
|
||||||
|
"to": "scripts/get-mpv-window-macos"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
54
scripts/build-macos-helper.sh
Executable file
54
scripts/build-macos-helper.sh
Executable file
@@ -0,0 +1,54 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Build macOS window tracking helper binary
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
SWIFT_SOURCE="$SCRIPT_DIR/get-mpv-window-macos.swift"
|
||||||
|
OUTPUT_DIR="$SCRIPT_DIR/../dist/scripts"
|
||||||
|
OUTPUT_BINARY="$OUTPUT_DIR/get-mpv-window-macos"
|
||||||
|
OUTPUT_SOURCE_COPY="$OUTPUT_DIR/get-mpv-window-macos.swift"
|
||||||
|
|
||||||
|
fallback_to_source() {
|
||||||
|
echo "Falling back to source fallback: $OUTPUT_SOURCE_COPY"
|
||||||
|
mkdir -p "$OUTPUT_DIR"
|
||||||
|
cp "$SWIFT_SOURCE" "$OUTPUT_SOURCE_COPY"
|
||||||
|
}
|
||||||
|
|
||||||
|
build_swift_helper() {
|
||||||
|
echo "Compiling macOS window tracking helper..."
|
||||||
|
if ! command -v swiftc >/dev/null 2>&1; then
|
||||||
|
echo "swiftc not found in PATH; skipping compilation."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! swiftc -O "$SWIFT_SOURCE" -o "$OUTPUT_BINARY"; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
chmod +x "$OUTPUT_BINARY"
|
||||||
|
echo "✓ Built $OUTPUT_BINARY"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Optional skip flag for non-macOS CI/dev environments
|
||||||
|
if [[ "${SUBMINER_SKIP_MACOS_HELPER_BUILD:-}" == "1" ]]; then
|
||||||
|
echo "Skipping macOS helper build (SUBMINER_SKIP_MACOS_HELPER_BUILD=1)"
|
||||||
|
fallback_to_source
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Only build on macOS
|
||||||
|
if [[ "$(uname)" != "Darwin" ]]; then
|
||||||
|
echo "Skipping macOS helper build (not on macOS)"
|
||||||
|
fallback_to_source
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create output directory
|
||||||
|
mkdir -p "$OUTPUT_DIR"
|
||||||
|
|
||||||
|
# Compile Swift script to binary, fallback to source if unavailable or compilation fails
|
||||||
|
if ! build_swift_helper; then
|
||||||
|
fallback_to_source
|
||||||
|
fi
|
||||||
165
scripts/docs-sweep-once.sh
Executable file
165
scripts/docs-sweep-once.sh
Executable file
@@ -0,0 +1,165 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
REPO="${REPO:-$HOME/projects/japanese/SubMiner}"
|
||||||
|
LOCK_FILE="${LOCK_FILE:-/tmp/subminer-doc-sweep.lock}"
|
||||||
|
STATE_FILE="${STATE_FILE:-/tmp/subminer-doc-sweep.state}"
|
||||||
|
LOG_FILE="${LOG_FILE:-$REPO/.codex-doc-sweep.log}"
|
||||||
|
TIMEOUT_SECONDS="${TIMEOUT_SECONDS:-240}"
|
||||||
|
SUBAGENT_ROOT="${SUBAGENT_ROOT:-$REPO/docs/subagents}"
|
||||||
|
SUBAGENT_INDEX_FILE="${SUBAGENT_INDEX_FILE:-$SUBAGENT_ROOT/INDEX.md}"
|
||||||
|
SUBAGENT_COLLAB_FILE="${SUBAGENT_COLLAB_FILE:-$SUBAGENT_ROOT/collaboration.md}"
|
||||||
|
SUBAGENT_AGENTS_DIR="${SUBAGENT_AGENTS_DIR:-$SUBAGENT_ROOT/agents}"
|
||||||
|
LEGACY_SUBAGENT_FILE="${LEGACY_SUBAGENT_FILE:-$REPO/docs/subagent.md}"
|
||||||
|
AGENT_ID="${AGENT_ID:-docs-sweep}"
|
||||||
|
AGENT_ALIAS="${AGENT_ALIAS:-Docs Sweep}"
|
||||||
|
AGENT_MISSION="${AGENT_MISSION:-Docs drift cleanup and coordination updates}"
|
||||||
|
|
||||||
|
# Non-interactive agent command used to run the prompt.
|
||||||
|
# Example:
|
||||||
|
# AGENT_CMD='codex exec'
|
||||||
|
# AGENT_CMD='opencode run'
|
||||||
|
AGENT_CMD="${AGENT_CMD:-codex exec}"
|
||||||
|
AGENT_ID_SAFE="$(printf '%s' "$AGENT_ID" | tr -c 'A-Za-z0-9._-' '_')"
|
||||||
|
AGENT_FILE="${SUBAGENT_AGENTS_DIR}/${AGENT_ID_SAFE}.md"
|
||||||
|
|
||||||
|
mkdir -p "$(dirname "$LOCK_FILE")"
|
||||||
|
mkdir -p "$(dirname "$STATE_FILE")"
|
||||||
|
mkdir -p "$SUBAGENT_ROOT" "$SUBAGENT_AGENTS_DIR" "$SUBAGENT_ROOT/archive"
|
||||||
|
|
||||||
|
exec 9> "$LOCK_FILE"
|
||||||
|
if ! flock -n 9; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "$REPO"
|
||||||
|
|
||||||
|
current_state="$({
|
||||||
|
git status --porcelain=v1
|
||||||
|
git ls-files --others --exclude-standard
|
||||||
|
} | sha256sum | cut -d' ' -f1)"
|
||||||
|
|
||||||
|
previous_state="$(cat "$STATE_FILE" 2> /dev/null || true)"
|
||||||
|
if [[ "$current_state" == "$previous_state" ]]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf '%s' "$current_state" > "$STATE_FILE"
|
||||||
|
|
||||||
|
run_started_at="$(date -Is)"
|
||||||
|
run_started_utc="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||||
|
echo "[RUN] [$run_started_at] docs sweep running (agent_id=$AGENT_ID alias=$AGENT_ALIAS)"
|
||||||
|
echo "[$run_started_at] state changed; starting docs sweep (agent_id=$AGENT_ID alias=$AGENT_ALIAS)" >> "$LOG_FILE"
|
||||||
|
|
||||||
|
if [[ ! -f "$SUBAGENT_INDEX_FILE" ]]; then
|
||||||
|
cat > "$SUBAGENT_INDEX_FILE" << 'EOF'
|
||||||
|
# Subagents Index
|
||||||
|
|
||||||
|
Read first. Keep concise.
|
||||||
|
|
||||||
|
| agent_id | alias | mission | status | file | last_update_utc |
|
||||||
|
| --- | --- | --- | --- | --- | --- |
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -f "$SUBAGENT_COLLAB_FILE" ]]; then
|
||||||
|
cat > "$SUBAGENT_COLLAB_FILE" << 'EOF'
|
||||||
|
# Subagents Collaboration
|
||||||
|
|
||||||
|
Shared notes. Append-only.
|
||||||
|
|
||||||
|
- [YYYY-MM-DDTHH:MM:SSZ] [agent_id|alias] note, question, dependency, conflict, decision.
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -f "$AGENT_FILE" ]]; then
|
||||||
|
cat > "$AGENT_FILE" << EOF
|
||||||
|
# Agent: $AGENT_ID
|
||||||
|
|
||||||
|
- alias: $AGENT_ALIAS
|
||||||
|
- mission: $AGENT_MISSION
|
||||||
|
- status: planning
|
||||||
|
- branch: unknown
|
||||||
|
- started_at: $run_started_utc
|
||||||
|
- heartbeat_minutes: 20
|
||||||
|
|
||||||
|
## Current Work (newest first)
|
||||||
|
- [$run_started_utc] intent: initialize section
|
||||||
|
|
||||||
|
## Files Touched
|
||||||
|
- none yet
|
||||||
|
|
||||||
|
## Assumptions
|
||||||
|
- none yet
|
||||||
|
|
||||||
|
## Open Questions / Blockers
|
||||||
|
- none
|
||||||
|
|
||||||
|
## Next Step
|
||||||
|
- continue run
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -f "$LEGACY_SUBAGENT_FILE" ]]; then
|
||||||
|
echo "[WARN] [$run_started_at] legacy file exists; prefer sharded layout: $LEGACY_SUBAGENT_FILE" | tee -a "$LOG_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
read -r -d '' PROMPT << EOF || true
|
||||||
|
Watch for in-flight refactors. If repo changes introduced drift, update only:
|
||||||
|
- README.md
|
||||||
|
- AGENTS.md
|
||||||
|
- docs/**/*.md
|
||||||
|
- config.example.jsonc
|
||||||
|
- docs/public/config.example.jsonc <-- generated automatically with make generate-example-config / bun run generate:config-example
|
||||||
|
- package.json scripts/config references (only if needed)
|
||||||
|
|
||||||
|
Coordination protocol:
|
||||||
|
- Read in order before edits:
|
||||||
|
1) \`$SUBAGENT_INDEX_FILE\`
|
||||||
|
2) \`$SUBAGENT_COLLAB_FILE\`
|
||||||
|
3) \`$AGENT_FILE\`
|
||||||
|
- Edit scope:
|
||||||
|
- MAY edit own file: \`$AGENT_FILE\`
|
||||||
|
- MAY append to collaboration: \`$SUBAGENT_COLLAB_FILE\`
|
||||||
|
- MAY update own row in index: \`$SUBAGENT_INDEX_FILE\`
|
||||||
|
- MUST NOT edit other agent files in \`$SUBAGENT_AGENTS_DIR\`
|
||||||
|
- Ensure own file has updated: alias, mission, status, branch, started_at, heartbeat_minutes.
|
||||||
|
- Add UTC ISO entries in "Current Work (newest first)" for intent/progress/handoff for this run.
|
||||||
|
- Keep own file sections current: Files Touched, assumptions, blockers, next step.
|
||||||
|
- Ensure index row for \`$AGENT_ID\` reflects alias/mission/status/file/last_update_utc.
|
||||||
|
- If file conflict/dependency seen, append note in collaboration.
|
||||||
|
|
||||||
|
Run metadata:
|
||||||
|
- run_started_at_utc: $run_started_utc
|
||||||
|
- repo: $REPO
|
||||||
|
- agent_id: $AGENT_ID
|
||||||
|
- agent_alias: $AGENT_ALIAS
|
||||||
|
- agent_file: $AGENT_FILE
|
||||||
|
|
||||||
|
Rules:
|
||||||
|
- Keep edits minimal and accurate to current code.
|
||||||
|
- Do not commit.
|
||||||
|
- Do not push.
|
||||||
|
- If ambiguous, do not guess; skip and report uncertainty.
|
||||||
|
- Print concise summary with:
|
||||||
|
1) files changed + why
|
||||||
|
2) coordination updates made (\`$SUBAGENT_INDEX_FILE\`, \`$SUBAGENT_COLLAB_FILE\`, \`$AGENT_FILE\`)
|
||||||
|
3) open questions/blockers
|
||||||
|
EOF
|
||||||
|
|
||||||
|
quoted_prompt="$(printf '%q' "$PROMPT")"
|
||||||
|
|
||||||
|
job_status=0
|
||||||
|
if timeout "${TIMEOUT_SECONDS}s" bash -lc "$AGENT_CMD $quoted_prompt" >> "$LOG_FILE" 2>&1; then
|
||||||
|
run_finished_at="$(date -Is)"
|
||||||
|
echo "[OK] [$run_finished_at] docs sweep complete (agent_id=$AGENT_ID)"
|
||||||
|
echo "[$run_finished_at] docs sweep complete (agent_id=$AGENT_ID)" >> "$LOG_FILE"
|
||||||
|
else
|
||||||
|
run_failed_at="$(date -Is)"
|
||||||
|
exit_code=$?
|
||||||
|
job_status=$exit_code
|
||||||
|
echo "[FAIL] [$run_failed_at] docs sweep failed (exit $exit_code, agent_id=$AGENT_ID)"
|
||||||
|
echo "[$run_failed_at] docs sweep failed (exit $exit_code, agent_id=$AGENT_ID)" >> "$LOG_FILE"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit "$job_status"
|
||||||
192
scripts/docs-sweep-watch.sh
Executable file
192
scripts/docs-sweep-watch.sh
Executable file
@@ -0,0 +1,192 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
RUN_ONCE_SCRIPT="$SCRIPT_DIR/docs-sweep-once.sh"
|
||||||
|
INTERVAL_SECONDS="${INTERVAL_SECONDS:-300}"
|
||||||
|
REPO="${REPO:-$HOME/projects/japanese/SubMiner}"
|
||||||
|
LOG_FILE="${LOG_FILE:-$REPO/.codex-doc-sweep.log}"
|
||||||
|
SUBAGENT_ROOT="${SUBAGENT_ROOT:-$REPO/docs/subagents}"
|
||||||
|
SUBAGENT_INDEX_FILE="${SUBAGENT_INDEX_FILE:-$SUBAGENT_ROOT/INDEX.md}"
|
||||||
|
SUBAGENT_COLLAB_FILE="${SUBAGENT_COLLAB_FILE:-$SUBAGENT_ROOT/collaboration.md}"
|
||||||
|
SUBAGENT_AGENTS_DIR="${SUBAGENT_AGENTS_DIR:-$SUBAGENT_ROOT/agents}"
|
||||||
|
AGENT_ID="${AGENT_ID:-docs-sweep}"
|
||||||
|
AGENT_ID_SAFE="$(printf '%s' "$AGENT_ID" | tr -c 'A-Za-z0-9._-' '_')"
|
||||||
|
AGENT_FILE="${AGENT_FILE:-$SUBAGENT_AGENTS_DIR/${AGENT_ID_SAFE}.md}"
|
||||||
|
REPORT_WITH_CODEX=false
|
||||||
|
REPORT_TIMEOUT_SECONDS="${REPORT_TIMEOUT_SECONDS:-120}"
|
||||||
|
REPORT_AGENT_CMD="${REPORT_AGENT_CMD:-codex exec}"
|
||||||
|
|
||||||
|
if [[ ! -x "$RUN_ONCE_SCRIPT" ]]; then
|
||||||
|
echo "Missing executable: $RUN_ONCE_SCRIPT"
|
||||||
|
echo "Run: chmod +x scripts/docs-sweep-once.sh"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat << 'EOF'
|
||||||
|
Usage: scripts/docs-sweep-watch.sh [options]
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-r, --report One-off: summarize current log with Codex and exit.
|
||||||
|
-h, --help Show this help message.
|
||||||
|
|
||||||
|
Environment:
|
||||||
|
AGENT_ID Stable agent id (default: docs-sweep)
|
||||||
|
AGENT_ALIAS Human label shown in logs/coordination (default: Docs Sweep)
|
||||||
|
AGENT_MISSION One-line focus for this run
|
||||||
|
SUBAGENT_ROOT Coordination root (default: docs/subagents)
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
trim_log_runs() {
|
||||||
|
# Keep only the last 50 docs-sweep runs in the shared log file.
|
||||||
|
if [[ ! -f "$LOG_FILE" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local keep_runs=50
|
||||||
|
local start_line
|
||||||
|
start_line="$(
|
||||||
|
awk -v max="$keep_runs" '
|
||||||
|
/state changed; starting docs sweep/ { lines[++count] = NR }
|
||||||
|
END {
|
||||||
|
if (count > max) print lines[count - max + 1]
|
||||||
|
else print 0
|
||||||
|
}
|
||||||
|
' "$LOG_FILE"
|
||||||
|
)"
|
||||||
|
|
||||||
|
if [[ "$start_line" =~ ^[0-9]+$ ]] && (( start_line > 0 )); then
|
||||||
|
local tmp_file
|
||||||
|
tmp_file="$(mktemp "${LOG_FILE}.XXXXXX")"
|
||||||
|
tail -n +"$start_line" "$LOG_FILE" > "$tmp_file"
|
||||||
|
mv "$tmp_file" "$LOG_FILE"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
run_report() {
|
||||||
|
local has_log=false
|
||||||
|
local has_index=false
|
||||||
|
local has_collab=false
|
||||||
|
local has_agent_file=false
|
||||||
|
if [[ -s "$LOG_FILE" ]]; then
|
||||||
|
has_log=true
|
||||||
|
fi
|
||||||
|
if [[ -s "$SUBAGENT_INDEX_FILE" ]]; then
|
||||||
|
has_index=true
|
||||||
|
fi
|
||||||
|
if [[ -s "$SUBAGENT_COLLAB_FILE" ]]; then
|
||||||
|
has_collab=true
|
||||||
|
fi
|
||||||
|
if [[ -s "$AGENT_FILE" ]]; then
|
||||||
|
has_agent_file=true
|
||||||
|
fi
|
||||||
|
if [[ "$has_log" != "true" && "$has_index" != "true" && "$has_collab" != "true" && "$has_agent_file" != "true" ]]; then
|
||||||
|
echo "[REPORT] no inputs; missing/empty files:"
|
||||||
|
echo "[REPORT] - $LOG_FILE"
|
||||||
|
echo "[REPORT] - $SUBAGENT_INDEX_FILE"
|
||||||
|
echo "[REPORT] - $SUBAGENT_COLLAB_FILE"
|
||||||
|
echo "[REPORT] - $AGENT_FILE"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local report_prompt
|
||||||
|
read -r -d '' report_prompt << EOF || true
|
||||||
|
Summarize docs sweep state. Output:
|
||||||
|
- Changes made (short bullets; file-focused when possible)
|
||||||
|
- Agent coordination updates from sharded docs/subagents files
|
||||||
|
- Open questions / uncertainty
|
||||||
|
- Left undone / follow-up items
|
||||||
|
|
||||||
|
Constraints:
|
||||||
|
- Be concise.
|
||||||
|
- If uncertain, say uncertain.
|
||||||
|
Read these files directly if present:
|
||||||
|
$LOG_FILE
|
||||||
|
$SUBAGENT_INDEX_FILE
|
||||||
|
$SUBAGENT_COLLAB_FILE
|
||||||
|
$AGENT_FILE
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "[REPORT] codex summary start"
|
||||||
|
local report_file
|
||||||
|
local report_stderr
|
||||||
|
report_file="$(mktemp /tmp/docs-sweep-report.XXXXXX)"
|
||||||
|
report_stderr="$(mktemp /tmp/docs-sweep-report-stderr.XXXXXX)"
|
||||||
|
(
|
||||||
|
cd "$REPO"
|
||||||
|
timeout "${REPORT_TIMEOUT_SECONDS}s" bash -lc "$REPORT_AGENT_CMD -o $(printf '%q' "$report_file") $(printf '%q' "$report_prompt")" > /dev/null 2> "$report_stderr"
|
||||||
|
)
|
||||||
|
local report_exit=$?
|
||||||
|
if (( report_exit != 0 )); then
|
||||||
|
echo "[REPORT] codex summary failed (exit $report_exit)"
|
||||||
|
cat "$report_stderr"
|
||||||
|
echo
|
||||||
|
echo "[REPORT] codex summary end"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
if [[ -s "$report_file" ]]; then
|
||||||
|
cat "$report_file"
|
||||||
|
else
|
||||||
|
echo "[REPORT] codex produced no final message"
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
echo "[REPORT] codex summary end"
|
||||||
|
}
|
||||||
|
|
||||||
|
while (( $# > 0 )); do
|
||||||
|
case "$1" in
|
||||||
|
-r|--report)
|
||||||
|
REPORT_WITH_CODEX=true
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown option: $1"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ "$REPORT_WITH_CODEX" == "true" ]]; then
|
||||||
|
trim_log_runs
|
||||||
|
run_report
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
stop_requested=false
|
||||||
|
trap 'stop_requested=true' INT TERM
|
||||||
|
|
||||||
|
echo "Starting docs sweep watcher (interval: ${INTERVAL_SECONDS}s, subagent_root: ${SUBAGENT_ROOT}). Press Ctrl+C to stop."
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
run_started_at="$(date -Is)"
|
||||||
|
echo "[RUN] [$run_started_at] docs sweep cycle running"
|
||||||
|
if "$RUN_ONCE_SCRIPT"; then
|
||||||
|
run_finished_at="$(date -Is)"
|
||||||
|
echo "[OK] [$run_finished_at] docs sweep cycle complete"
|
||||||
|
else
|
||||||
|
run_failed_at="$(date -Is)"
|
||||||
|
exit_code=$?
|
||||||
|
echo "[FAIL] [$run_failed_at] docs sweep cycle failed (exit $exit_code)"
|
||||||
|
fi
|
||||||
|
trim_log_runs
|
||||||
|
|
||||||
|
if [[ "$stop_requested" == "true" ]]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep "$INTERVAL_SECONDS" &
|
||||||
|
wait $!
|
||||||
|
|
||||||
|
if [[ "$stop_requested" == "true" ]]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Docs sweep watcher stopped."
|
||||||
239
scripts/get-mpv-window-macos.swift
Normal file
239
scripts/get-mpv-window-macos.swift
Normal file
@@ -0,0 +1,239 @@
|
|||||||
|
#!/usr/bin/env swift
|
||||||
|
//
|
||||||
|
// get-mpv-window-macos.swift
|
||||||
|
// SubMiner - Get mpv window geometry on macOS
|
||||||
|
//
|
||||||
|
// This script uses Core Graphics APIs to find mpv windows system-wide.
|
||||||
|
// It works with both bundled and unbundled mpv installations.
|
||||||
|
//
|
||||||
|
// Usage: swift get-mpv-window-macos.swift
|
||||||
|
// Output: "x,y,width,height" or "not-found"
|
||||||
|
//
|
||||||
|
|
||||||
|
import Cocoa
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
private struct WindowGeometry {
|
||||||
|
let x: Int
|
||||||
|
let y: Int
|
||||||
|
let width: Int
|
||||||
|
let height: Int
|
||||||
|
}
|
||||||
|
|
||||||
|
private let targetMpvSocketPath: String? = {
|
||||||
|
guard CommandLine.arguments.count > 1 else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let value = CommandLine.arguments[1].trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
return value.isEmpty ? nil : value
|
||||||
|
}()
|
||||||
|
|
||||||
|
private func windowCommandLineForPid(_ pid: pid_t) -> String? {
|
||||||
|
let process = Process()
|
||||||
|
process.executableURL = URL(fileURLWithPath: "/bin/ps")
|
||||||
|
process.arguments = ["-p", "\(pid)", "-o", "args="]
|
||||||
|
|
||||||
|
let pipe = Pipe()
|
||||||
|
process.standardOutput = pipe
|
||||||
|
process.standardError = pipe
|
||||||
|
|
||||||
|
do {
|
||||||
|
try process.run()
|
||||||
|
process.waitUntilExit()
|
||||||
|
} catch {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if process.terminationStatus != 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||||
|
guard let commandLine = String(data: data, encoding: .utf8) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return commandLine
|
||||||
|
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
.replacingOccurrences(of: "\n", with: " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
private func windowHasTargetSocket(_ pid: pid_t) -> Bool {
|
||||||
|
guard let socketPath = targetMpvSocketPath else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let commandLine = windowCommandLineForPid(pid) else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return commandLine.contains("--input-ipc-server=\(socketPath)") ||
|
||||||
|
commandLine.contains("--input-ipc-server \(socketPath)")
|
||||||
|
}
|
||||||
|
|
||||||
|
private func geometryFromRect(x: CGFloat, y: CGFloat, width: CGFloat, height: CGFloat) -> WindowGeometry {
|
||||||
|
let minX = Int(floor(x))
|
||||||
|
let minY = Int(floor(y))
|
||||||
|
let maxX = Int(ceil(x + width))
|
||||||
|
let maxY = Int(ceil(y + height))
|
||||||
|
return WindowGeometry(
|
||||||
|
x: minX,
|
||||||
|
y: minY,
|
||||||
|
width: max(0, maxX - minX),
|
||||||
|
height: max(0, maxY - minY)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func normalizedMpvName(_ name: String) -> Bool {
|
||||||
|
let normalized = name.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
|
||||||
|
return normalized == "mpv"
|
||||||
|
}
|
||||||
|
|
||||||
|
private func geometryFromAXWindow(_ axWindow: AXUIElement) -> WindowGeometry? {
|
||||||
|
var positionRef: CFTypeRef?
|
||||||
|
var sizeRef: CFTypeRef?
|
||||||
|
|
||||||
|
let positionStatus = AXUIElementCopyAttributeValue(axWindow, kAXPositionAttribute as CFString, &positionRef)
|
||||||
|
let sizeStatus = AXUIElementCopyAttributeValue(axWindow, kAXSizeAttribute as CFString, &sizeRef)
|
||||||
|
|
||||||
|
guard positionStatus == .success,
|
||||||
|
sizeStatus == .success,
|
||||||
|
let positionRaw = positionRef,
|
||||||
|
let sizeRaw = sizeRef,
|
||||||
|
CFGetTypeID(positionRaw) == AXValueGetTypeID(),
|
||||||
|
CFGetTypeID(sizeRaw) == AXValueGetTypeID() else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let positionValue = positionRaw as! AXValue
|
||||||
|
let sizeValue = sizeRaw as! AXValue
|
||||||
|
|
||||||
|
guard AXValueGetType(positionValue) == .cgPoint,
|
||||||
|
AXValueGetType(sizeValue) == .cgSize else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var position = CGPoint.zero
|
||||||
|
var size = CGSize.zero
|
||||||
|
|
||||||
|
guard AXValueGetValue(positionValue, .cgPoint, &position),
|
||||||
|
AXValueGetValue(sizeValue, .cgSize, &size) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
let geometry = geometryFromRect(
|
||||||
|
x: position.x,
|
||||||
|
y: position.y,
|
||||||
|
width: size.width,
|
||||||
|
height: size.height
|
||||||
|
)
|
||||||
|
|
||||||
|
guard geometry.width >= 100, geometry.height >= 100 else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return geometry
|
||||||
|
}
|
||||||
|
|
||||||
|
private func geometryFromAccessibilityAPI() -> WindowGeometry? {
|
||||||
|
let runningApps = NSWorkspace.shared.runningApplications.filter { app in
|
||||||
|
guard let name = app.localizedName else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return normalizedMpvName(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
for app in runningApps {
|
||||||
|
let appElement = AXUIElementCreateApplication(app.processIdentifier)
|
||||||
|
if !windowHasTargetSocket(app.processIdentifier) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
var windowsRef: CFTypeRef?
|
||||||
|
let status = AXUIElementCopyAttributeValue(appElement, kAXWindowsAttribute as CFString, &windowsRef)
|
||||||
|
guard status == .success, let windows = windowsRef as? [AXUIElement], !windows.isEmpty else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for window in windows {
|
||||||
|
var minimizedRef: CFTypeRef?
|
||||||
|
let minimizedStatus = AXUIElementCopyAttributeValue(window, kAXMinimizedAttribute as CFString, &minimizedRef)
|
||||||
|
if minimizedStatus == .success, let minimized = minimizedRef as? Bool, minimized {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
var windowPid: pid_t = 0
|
||||||
|
if AXUIElementGetPid(window, &windowPid) != .success {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !windowHasTargetSocket(windowPid) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if let geometry = geometryFromAXWindow(window) {
|
||||||
|
return geometry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private func geometryFromCoreGraphics() -> WindowGeometry? {
|
||||||
|
// Keep the CG fallback for environments without Accessibility permissions.
|
||||||
|
// Use on-screen layer-0 windows to avoid off-screen helpers/shadows.
|
||||||
|
let options: CGWindowListOption = [.optionOnScreenOnly, .excludeDesktopElements]
|
||||||
|
let windowList = CGWindowListCopyWindowInfo(options, kCGNullWindowID) as? [[String: Any]] ?? []
|
||||||
|
|
||||||
|
for window in windowList {
|
||||||
|
guard let ownerName = window[kCGWindowOwnerName as String] as? String,
|
||||||
|
normalizedMpvName(ownerName) else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let ownerPid = window[kCGWindowOwnerPID as String] as? pid_t else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if !windowHasTargetSocket(ownerPid) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if let layer = window[kCGWindowLayer as String] as? Int, layer != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if let alpha = window[kCGWindowAlpha as String] as? Double, alpha <= 0.01 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if let onScreen = window[kCGWindowIsOnscreen as String] as? Int, onScreen == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let bounds = window[kCGWindowBounds as String] as? [String: CGFloat] else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
let geometry = geometryFromRect(
|
||||||
|
x: bounds["X"] ?? 0,
|
||||||
|
y: bounds["Y"] ?? 0,
|
||||||
|
width: bounds["Width"] ?? 0,
|
||||||
|
height: bounds["Height"] ?? 0
|
||||||
|
)
|
||||||
|
|
||||||
|
guard geometry.width >= 100, geometry.height >= 100 else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return geometry
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if let window = geometryFromAccessibilityAPI() ?? geometryFromCoreGraphics() {
|
||||||
|
print("\(window.x),\(window.y),\(window.width),\(window.height)")
|
||||||
|
} else {
|
||||||
|
print("not-found")
|
||||||
|
}
|
||||||
903
scripts/get_frequency.ts
Normal file
903
scripts/get_frequency.ts
Normal file
@@ -0,0 +1,903 @@
|
|||||||
|
import fs from 'node:fs';
|
||||||
|
import path from 'node:path';
|
||||||
|
import process from 'node:process';
|
||||||
|
|
||||||
|
import { createTokenizerDepsRuntime, tokenizeSubtitle } from '../src/core/services/tokenizer.js';
|
||||||
|
import { createFrequencyDictionaryLookup } from '../src/core/services/frequency-dictionary.js';
|
||||||
|
import { MecabTokenizer } from '../src/mecab-tokenizer.js';
|
||||||
|
import type { MergedToken, FrequencyDictionaryLookup } from '../src/types.js';
|
||||||
|
|
||||||
|
interface CliOptions {
|
||||||
|
input: string;
|
||||||
|
dictionaryPath: string;
|
||||||
|
emitPretty: boolean;
|
||||||
|
emitDiagnostics: boolean;
|
||||||
|
mecabCommand?: string;
|
||||||
|
mecabDictionaryPath?: string;
|
||||||
|
forceMecabOnly?: boolean;
|
||||||
|
yomitanExtensionPath?: string;
|
||||||
|
yomitanUserDataPath?: string;
|
||||||
|
emitColoredLine: boolean;
|
||||||
|
colorMode: 'single' | 'banded';
|
||||||
|
colorTopX: number;
|
||||||
|
colorSingle: string;
|
||||||
|
colorBand1: string;
|
||||||
|
colorBand2: string;
|
||||||
|
colorBand3: string;
|
||||||
|
colorBand4: string;
|
||||||
|
colorBand5: string;
|
||||||
|
colorKnown: string;
|
||||||
|
colorNPlusOne: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseCliArgs(argv: string[]): CliOptions {
|
||||||
|
const args = [...argv];
|
||||||
|
let inputParts: string[] = [];
|
||||||
|
let dictionaryPath = path.join(process.cwd(), 'vendor', 'jiten_freq_global');
|
||||||
|
let emitPretty = false;
|
||||||
|
let emitDiagnostics = false;
|
||||||
|
let mecabCommand: string | undefined;
|
||||||
|
let mecabDictionaryPath: string | undefined;
|
||||||
|
let forceMecabOnly = false;
|
||||||
|
let yomitanExtensionPath: string | undefined;
|
||||||
|
let yomitanUserDataPath: string | undefined;
|
||||||
|
let emitColoredLine = false;
|
||||||
|
let colorMode: 'single' | 'banded' = 'single';
|
||||||
|
let colorTopX = 1000;
|
||||||
|
let colorSingle = '#f5a97f';
|
||||||
|
let colorBand1 = '#ed8796';
|
||||||
|
let colorBand2 = '#f5a97f';
|
||||||
|
let colorBand3 = '#f9e2af';
|
||||||
|
let colorBand4 = '#a6e3a1';
|
||||||
|
let colorBand5 = '#8aadf4';
|
||||||
|
let colorKnown = '#a6da95';
|
||||||
|
let colorNPlusOne = '#c6a0f6';
|
||||||
|
|
||||||
|
while (args.length > 0) {
|
||||||
|
const arg = args.shift();
|
||||||
|
if (!arg) break;
|
||||||
|
|
||||||
|
if (arg === '--help' || arg === '-h') {
|
||||||
|
printUsage();
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--dictionary') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --dictionary');
|
||||||
|
}
|
||||||
|
dictionaryPath = path.resolve(next);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--mecab-command') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --mecab-command');
|
||||||
|
}
|
||||||
|
mecabCommand = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--mecab-dictionary') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --mecab-dictionary');
|
||||||
|
}
|
||||||
|
mecabDictionaryPath = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--yomitan-extension') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --yomitan-extension');
|
||||||
|
}
|
||||||
|
yomitanExtensionPath = path.resolve(next);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--yomitan-user-data') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --yomitan-user-data');
|
||||||
|
}
|
||||||
|
yomitanUserDataPath = path.resolve(next);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--colorized-line') {
|
||||||
|
emitColoredLine = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--color-mode') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --color-mode');
|
||||||
|
}
|
||||||
|
if (next !== 'single' && next !== 'banded') {
|
||||||
|
throw new Error("--color-mode must be 'single' or 'banded'");
|
||||||
|
}
|
||||||
|
colorMode = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--color-top-x') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --color-top-x');
|
||||||
|
}
|
||||||
|
const parsed = Number.parseInt(next, 10);
|
||||||
|
if (!Number.isFinite(parsed) || parsed <= 0) {
|
||||||
|
throw new Error('--color-top-x must be a positive integer');
|
||||||
|
}
|
||||||
|
colorTopX = parsed;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--color-single') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --color-single');
|
||||||
|
}
|
||||||
|
colorSingle = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--color-band-1') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --color-band-1');
|
||||||
|
}
|
||||||
|
colorBand1 = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--color-band-2') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --color-band-2');
|
||||||
|
}
|
||||||
|
colorBand2 = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--color-band-3') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --color-band-3');
|
||||||
|
}
|
||||||
|
colorBand3 = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--color-band-4') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --color-band-4');
|
||||||
|
}
|
||||||
|
colorBand4 = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--color-band-5') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --color-band-5');
|
||||||
|
}
|
||||||
|
colorBand5 = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--color-known') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --color-known');
|
||||||
|
}
|
||||||
|
colorKnown = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--color-n-plus-one') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --color-n-plus-one');
|
||||||
|
}
|
||||||
|
colorNPlusOne = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--dictionary=')) {
|
||||||
|
dictionaryPath = path.resolve(arg.slice('--dictionary='.length));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--mecab-command=')) {
|
||||||
|
mecabCommand = arg.slice('--mecab-command='.length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--mecab-dictionary=')) {
|
||||||
|
mecabDictionaryPath = arg.slice('--mecab-dictionary='.length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--yomitan-extension=')) {
|
||||||
|
yomitanExtensionPath = path.resolve(arg.slice('--yomitan-extension='.length));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--yomitan-user-data=')) {
|
||||||
|
yomitanUserDataPath = path.resolve(arg.slice('--yomitan-user-data='.length));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--colorized-line')) {
|
||||||
|
emitColoredLine = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--color-mode=')) {
|
||||||
|
const value = arg.slice('--color-mode='.length);
|
||||||
|
if (value !== 'single' && value !== 'banded') {
|
||||||
|
throw new Error("--color-mode must be 'single' or 'banded'");
|
||||||
|
}
|
||||||
|
colorMode = value;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--color-top-x=')) {
|
||||||
|
const value = arg.slice('--color-top-x='.length);
|
||||||
|
const parsed = Number.parseInt(value, 10);
|
||||||
|
if (!Number.isFinite(parsed) || parsed <= 0) {
|
||||||
|
throw new Error('--color-top-x must be a positive integer');
|
||||||
|
}
|
||||||
|
colorTopX = parsed;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--color-single=')) {
|
||||||
|
colorSingle = arg.slice('--color-single='.length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--color-band-1=')) {
|
||||||
|
colorBand1 = arg.slice('--color-band-1='.length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--color-band-2=')) {
|
||||||
|
colorBand2 = arg.slice('--color-band-2='.length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--color-band-3=')) {
|
||||||
|
colorBand3 = arg.slice('--color-band-3='.length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--color-band-4=')) {
|
||||||
|
colorBand4 = arg.slice('--color-band-4='.length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--color-band-5=')) {
|
||||||
|
colorBand5 = arg.slice('--color-band-5='.length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--color-known=')) {
|
||||||
|
colorKnown = arg.slice('--color-known='.length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--color-n-plus-one=')) {
|
||||||
|
colorNPlusOne = arg.slice('--color-n-plus-one='.length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--pretty') {
|
||||||
|
emitPretty = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--diagnostics') {
|
||||||
|
emitDiagnostics = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--force-mecab') {
|
||||||
|
forceMecabOnly = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('-')) {
|
||||||
|
throw new Error(`Unknown flag: ${arg}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
inputParts.push(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
const input = inputParts.join(' ').trim();
|
||||||
|
if (!input) {
|
||||||
|
const stdin = fs.readFileSync(0, 'utf8').trim();
|
||||||
|
if (!stdin) {
|
||||||
|
throw new Error('Please provide input text as arguments or via stdin.');
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
input: stdin,
|
||||||
|
dictionaryPath,
|
||||||
|
emitPretty,
|
||||||
|
emitDiagnostics,
|
||||||
|
forceMecabOnly,
|
||||||
|
yomitanExtensionPath,
|
||||||
|
yomitanUserDataPath,
|
||||||
|
emitColoredLine,
|
||||||
|
colorMode,
|
||||||
|
colorTopX,
|
||||||
|
colorSingle,
|
||||||
|
colorBand1,
|
||||||
|
colorBand2,
|
||||||
|
colorBand3,
|
||||||
|
colorBand4,
|
||||||
|
colorBand5,
|
||||||
|
colorKnown,
|
||||||
|
colorNPlusOne,
|
||||||
|
mecabCommand,
|
||||||
|
mecabDictionaryPath,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
input,
|
||||||
|
dictionaryPath,
|
||||||
|
emitPretty,
|
||||||
|
emitDiagnostics,
|
||||||
|
forceMecabOnly,
|
||||||
|
yomitanExtensionPath,
|
||||||
|
yomitanUserDataPath,
|
||||||
|
emitColoredLine,
|
||||||
|
colorMode,
|
||||||
|
colorTopX,
|
||||||
|
colorSingle,
|
||||||
|
colorBand1,
|
||||||
|
colorBand2,
|
||||||
|
colorBand3,
|
||||||
|
colorBand4,
|
||||||
|
colorBand5,
|
||||||
|
colorKnown,
|
||||||
|
colorNPlusOne,
|
||||||
|
mecabCommand,
|
||||||
|
mecabDictionaryPath,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function printUsage(): void {
|
||||||
|
process.stdout.write(`Usage:
|
||||||
|
bun run get-frequency [--pretty] [--diagnostics] [--dictionary <path>] [--mecab-command <path>] [--mecab-dictionary <path>] <text>
|
||||||
|
|
||||||
|
--pretty Pretty-print JSON output.
|
||||||
|
--diagnostics Include merged-frequency lookup-term details.
|
||||||
|
--force-mecab Skip Yomitan parser initialization and force MeCab fallback.
|
||||||
|
--yomitan-extension <path> Optional path to a Yomitan extension directory.
|
||||||
|
--yomitan-user-data <path> Optional Electron userData directory for Yomitan state.
|
||||||
|
--colorized-line Output a terminal-colorized line based on token classification.
|
||||||
|
--color-mode <single|banded> Frequency coloring mode (default: single).
|
||||||
|
--color-top-x <n> Frequency color applies when rank <= n (default: 1000).
|
||||||
|
--color-single <#hex> Frequency single-mode color (default: #f5a97f).
|
||||||
|
--color-band-1 <#hex> Frequency band-1 color.
|
||||||
|
--color-band-2 <#hex> Frequency band-2 color.
|
||||||
|
--color-band-3 <#hex> Frequency band-3 color.
|
||||||
|
--color-band-4 <#hex> Frequency band-4 color.
|
||||||
|
--color-band-5 <#hex> Frequency band-5 color.
|
||||||
|
--color-known <#hex> Known-word color (default: #a6da95).
|
||||||
|
--color-n-plus-one <#hex> N+1 target color (default: #c6a0f6).
|
||||||
|
--dictionary <path> Frequency dictionary root path (default: ./vendor/jiten_freq_global)
|
||||||
|
--mecab-command <path> Optional MeCab binary path (default: mecab)
|
||||||
|
--mecab-dictionary <path> Optional MeCab dictionary directory (default: system default)
|
||||||
|
-h, --help Show usage.
|
||||||
|
\n`);
|
||||||
|
}
|
||||||
|
|
||||||
|
type FrequencyCandidate = {
|
||||||
|
term: string;
|
||||||
|
rank: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
function getFrequencyLookupTextCandidates(token: MergedToken): string[] {
|
||||||
|
const lookupText = token.headword?.trim() || token.reading?.trim() || token.surface.trim();
|
||||||
|
return lookupText ? [lookupText] : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBestFrequencyLookupCandidate(
|
||||||
|
token: MergedToken,
|
||||||
|
getFrequencyRank: FrequencyDictionaryLookup,
|
||||||
|
): FrequencyCandidate | null {
|
||||||
|
const lookupTexts = getFrequencyLookupTextCandidates(token);
|
||||||
|
let best: FrequencyCandidate | null = null;
|
||||||
|
for (const term of lookupTexts) {
|
||||||
|
const rank = getFrequencyRank(term);
|
||||||
|
if (typeof rank !== 'number' || !Number.isFinite(rank) || rank <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!best || rank < best.rank) {
|
||||||
|
best = { term, rank };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
|
||||||
|
function simplifyToken(token: MergedToken): Record<string, unknown> {
|
||||||
|
return {
|
||||||
|
surface: token.surface,
|
||||||
|
reading: token.reading,
|
||||||
|
headword: token.headword,
|
||||||
|
startPos: token.startPos,
|
||||||
|
endPos: token.endPos,
|
||||||
|
partOfSpeech: token.partOfSpeech,
|
||||||
|
isMerged: token.isMerged,
|
||||||
|
isKnown: token.isKnown,
|
||||||
|
isNPlusOneTarget: token.isNPlusOneTarget,
|
||||||
|
frequencyRank: token.frequencyRank,
|
||||||
|
jlptLevel: token.jlptLevel,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function simplifyTokenWithVerbose(
|
||||||
|
token: MergedToken,
|
||||||
|
getFrequencyRank: FrequencyDictionaryLookup,
|
||||||
|
): Record<string, unknown> {
|
||||||
|
const candidates = getFrequencyLookupTextCandidates(token)
|
||||||
|
.map((term) => ({
|
||||||
|
term,
|
||||||
|
rank: getFrequencyRank(term),
|
||||||
|
}))
|
||||||
|
.filter(
|
||||||
|
(candidate) =>
|
||||||
|
typeof candidate.rank === 'number' && Number.isFinite(candidate.rank) && candidate.rank > 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
const bestCandidate = getBestFrequencyLookupCandidate(token, getFrequencyRank);
|
||||||
|
|
||||||
|
return {
|
||||||
|
surface: token.surface,
|
||||||
|
reading: token.reading,
|
||||||
|
headword: token.headword,
|
||||||
|
startPos: token.startPos,
|
||||||
|
endPos: token.endPos,
|
||||||
|
partOfSpeech: token.partOfSpeech,
|
||||||
|
isMerged: token.isMerged,
|
||||||
|
isKnown: token.isKnown,
|
||||||
|
isNPlusOneTarget: token.isNPlusOneTarget,
|
||||||
|
frequencyRank: token.frequencyRank,
|
||||||
|
jlptLevel: token.jlptLevel,
|
||||||
|
frequencyCandidates: candidates,
|
||||||
|
frequencyBestLookupTerm: bestCandidate?.term ?? null,
|
||||||
|
frequencyBestLookupRank: bestCandidate?.rank ?? null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
interface YomitanRuntimeState {
|
||||||
|
yomitanExt: unknown | null;
|
||||||
|
parserWindow: unknown | null;
|
||||||
|
parserReadyPromise: Promise<void> | null;
|
||||||
|
parserInitPromise: Promise<boolean> | null;
|
||||||
|
available: boolean;
|
||||||
|
note?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function withTimeout<T>(promise: Promise<T>, timeoutMs: number, label: string): Promise<T> {
|
||||||
|
return new Promise<T>((resolve, reject) => {
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
reject(new Error(`${label} timed out after ${timeoutMs}ms`));
|
||||||
|
}, timeoutMs);
|
||||||
|
promise
|
||||||
|
.then((value) => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
resolve(value);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function destroyUnknownParserWindow(window: unknown): void {
|
||||||
|
if (!window || typeof window !== 'object') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const candidate = window as {
|
||||||
|
isDestroyed?: () => boolean;
|
||||||
|
destroy?: () => void;
|
||||||
|
};
|
||||||
|
if (typeof candidate.isDestroyed !== 'function') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof candidate.destroy !== 'function') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!candidate.isDestroyed()) {
|
||||||
|
candidate.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createYomitanRuntimeState(userDataPath: string): Promise<YomitanRuntimeState> {
|
||||||
|
const state: YomitanRuntimeState = {
|
||||||
|
yomitanExt: null,
|
||||||
|
parserWindow: null,
|
||||||
|
parserReadyPromise: null,
|
||||||
|
parserInitPromise: null,
|
||||||
|
available: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
const electronImport = await import('electron').catch((error) => {
|
||||||
|
state.note = error instanceof Error ? error.message : 'unknown error';
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
if (!electronImport || !electronImport.app || !electronImport.app.whenReady) {
|
||||||
|
state.note = 'electron runtime not available in this process';
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await electronImport.app.whenReady();
|
||||||
|
const loadYomitanExtension = (await import('../src/core/services/yomitan-extension-loader.js'))
|
||||||
|
.loadYomitanExtension as (options: {
|
||||||
|
userDataPath: string;
|
||||||
|
getYomitanParserWindow: () => unknown;
|
||||||
|
setYomitanParserWindow: (window: unknown) => void;
|
||||||
|
setYomitanParserReadyPromise: (promise: Promise<void> | null) => void;
|
||||||
|
setYomitanParserInitPromise: (promise: Promise<boolean> | null) => void;
|
||||||
|
setYomitanExtension: (extension: unknown) => void;
|
||||||
|
}) => Promise<unknown>;
|
||||||
|
|
||||||
|
const extension = await loadYomitanExtension({
|
||||||
|
userDataPath,
|
||||||
|
getYomitanParserWindow: () => state.parserWindow,
|
||||||
|
setYomitanParserWindow: (window) => {
|
||||||
|
state.parserWindow = window;
|
||||||
|
},
|
||||||
|
setYomitanParserReadyPromise: (promise) => {
|
||||||
|
state.parserReadyPromise = promise;
|
||||||
|
},
|
||||||
|
setYomitanParserInitPromise: (promise) => {
|
||||||
|
state.parserInitPromise = promise;
|
||||||
|
},
|
||||||
|
setYomitanExtension: (extension) => {
|
||||||
|
state.yomitanExt = extension;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!extension) {
|
||||||
|
state.note = 'yomitan extension is not available';
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
state.yomitanExt = extension;
|
||||||
|
state.available = true;
|
||||||
|
return state;
|
||||||
|
} catch (error) {
|
||||||
|
state.note = error instanceof Error ? error.message : 'failed to initialize yomitan extension';
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createYomitanRuntimeStateWithSearch(
|
||||||
|
userDataPath: string,
|
||||||
|
extensionPath?: string,
|
||||||
|
): Promise<YomitanRuntimeState> {
|
||||||
|
const preferredPath = extensionPath ? path.resolve(extensionPath) : undefined;
|
||||||
|
const defaultVendorPath = path.resolve(process.cwd(), 'vendor', 'yomitan');
|
||||||
|
const candidates = [...(preferredPath ? [preferredPath] : []), defaultVendorPath];
|
||||||
|
|
||||||
|
for (const candidate of candidates) {
|
||||||
|
if (!candidate) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (fs.existsSync(path.join(candidate, 'manifest.json'))) {
|
||||||
|
const state = await createYomitanRuntimeState(userDataPath);
|
||||||
|
if (state.available) {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
if (!state.note) {
|
||||||
|
state.note = `Failed to load yomitan extension at ${candidate}`;
|
||||||
|
}
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return createYomitanRuntimeState(userDataPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getFrequencyLookup(dictionaryPath: string): Promise<FrequencyDictionaryLookup> {
|
||||||
|
return createFrequencyDictionaryLookup({
|
||||||
|
searchPaths: [dictionaryPath],
|
||||||
|
log: (message) => {
|
||||||
|
// Keep script output pure JSON by default
|
||||||
|
if (process.env.DEBUG_FREQUENCY === '1') {
|
||||||
|
console.error(message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const ANSI_RESET = '\u001b[0m';
|
||||||
|
const ANSI_FG_PREFIX = '\u001b[38;2';
|
||||||
|
const HEX_COLOR_PATTERN = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;
|
||||||
|
|
||||||
|
function parseHexRgb(input: string): [number, number, number] | null {
|
||||||
|
const normalized = input.trim().replace(/^#/, '');
|
||||||
|
if (!HEX_COLOR_PATTERN.test(`#${normalized}`)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const expanded =
|
||||||
|
normalized.length === 3
|
||||||
|
? normalized
|
||||||
|
.split('')
|
||||||
|
.map((char) => `${char}${char}`)
|
||||||
|
.join('')
|
||||||
|
: normalized;
|
||||||
|
const r = Number.parseInt(expanded.substring(0, 2), 16);
|
||||||
|
const g = Number.parseInt(expanded.substring(2, 4), 16);
|
||||||
|
const b = Number.parseInt(expanded.substring(4, 6), 16);
|
||||||
|
if (!Number.isFinite(r) || !Number.isFinite(g) || !Number.isFinite(b)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return [r, g, b];
|
||||||
|
}
|
||||||
|
|
||||||
|
function wrapWithForeground(text: string, color: string): string {
|
||||||
|
const rgb = parseHexRgb(color);
|
||||||
|
if (!rgb) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
return `${ANSI_FG_PREFIX};${rgb[0]};${rgb[1]};${rgb[2]}m${text}${ANSI_RESET}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBandColor(
|
||||||
|
rank: number,
|
||||||
|
colorTopX: number,
|
||||||
|
colorMode: 'single' | 'banded',
|
||||||
|
colorSingle: string,
|
||||||
|
bandedColors: [string, string, string, string, string],
|
||||||
|
): string {
|
||||||
|
const topX = Math.max(1, Math.floor(colorTopX));
|
||||||
|
const safeRank = Math.max(1, Math.floor(rank));
|
||||||
|
if (safeRank > topX) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
if (colorMode === 'single') {
|
||||||
|
return colorSingle;
|
||||||
|
}
|
||||||
|
const normalizedBand = Math.ceil((safeRank / topX) * bandedColors.length);
|
||||||
|
const band = Math.min(bandedColors.length, Math.max(1, normalizedBand));
|
||||||
|
return bandedColors[band - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTokenColor(token: MergedToken, args: CliOptions): string {
|
||||||
|
if (token.isNPlusOneTarget) {
|
||||||
|
return args.colorNPlusOne;
|
||||||
|
}
|
||||||
|
if (token.isKnown) {
|
||||||
|
return args.colorKnown;
|
||||||
|
}
|
||||||
|
if (typeof token.frequencyRank === 'number' && Number.isFinite(token.frequencyRank)) {
|
||||||
|
return getBandColor(token.frequencyRank, args.colorTopX, args.colorMode, args.colorSingle, [
|
||||||
|
args.colorBand1,
|
||||||
|
args.colorBand2,
|
||||||
|
args.colorBand3,
|
||||||
|
args.colorBand4,
|
||||||
|
args.colorBand5,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderColoredLine(text: string, tokens: MergedToken[], args: CliOptions): string {
|
||||||
|
if (!args.emitColoredLine) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
if (tokens.length === 0) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ordered = [...tokens].sort((a, b) => {
|
||||||
|
const aStart = a.startPos ?? 0;
|
||||||
|
const bStart = b.startPos ?? 0;
|
||||||
|
if (aStart !== bStart) {
|
||||||
|
return aStart - bStart;
|
||||||
|
}
|
||||||
|
return (a.endPos ?? a.surface.length) - (b.endPos ?? b.surface.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
let cursor = 0;
|
||||||
|
let output = '';
|
||||||
|
for (const token of ordered) {
|
||||||
|
const start = token.startPos ?? 0;
|
||||||
|
const end =
|
||||||
|
token.endPos ??
|
||||||
|
(token.startPos ? token.startPos + token.surface.length : token.surface.length);
|
||||||
|
if (start < 0 || end < 0 || end < start) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const safeStart = Math.min(Math.max(0, start), text.length);
|
||||||
|
const safeEnd = Math.min(Math.max(safeStart, end), text.length);
|
||||||
|
if (safeStart > cursor) {
|
||||||
|
output += text.slice(cursor, safeStart);
|
||||||
|
}
|
||||||
|
const tokenText = text.slice(safeStart, safeEnd);
|
||||||
|
const color = getTokenColor(token, args);
|
||||||
|
output += color ? wrapWithForeground(tokenText, color) : tokenText;
|
||||||
|
cursor = safeEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cursor < text.length) {
|
||||||
|
output += text.slice(cursor);
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main(): Promise<void> {
|
||||||
|
let electronModule: typeof import('electron') | null = null;
|
||||||
|
let yomitanState: YomitanRuntimeState | null = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const args = parseCliArgs(process.argv.slice(2));
|
||||||
|
const getFrequencyRank = await getFrequencyLookup(args.dictionaryPath);
|
||||||
|
|
||||||
|
const mecabTokenizer = new MecabTokenizer({
|
||||||
|
mecabCommand: args.mecabCommand,
|
||||||
|
dictionaryPath: args.mecabDictionaryPath,
|
||||||
|
});
|
||||||
|
const isMecabAvailable = await mecabTokenizer.checkAvailability();
|
||||||
|
if (!isMecabAvailable) {
|
||||||
|
throw new Error(
|
||||||
|
'MeCab is not available on this system. Install/run environment with MeCab to tokenize input.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
electronModule = await import('electron').catch(() => null);
|
||||||
|
if (electronModule && args.yomitanUserDataPath) {
|
||||||
|
electronModule.app.setPath('userData', args.yomitanUserDataPath);
|
||||||
|
}
|
||||||
|
yomitanState = !args.forceMecabOnly
|
||||||
|
? await createYomitanRuntimeStateWithSearch(
|
||||||
|
electronModule?.app?.getPath ? electronModule.app.getPath('userData') : process.cwd(),
|
||||||
|
args.yomitanExtensionPath,
|
||||||
|
)
|
||||||
|
: null;
|
||||||
|
const hasYomitan = Boolean(yomitanState?.available && yomitanState?.yomitanExt);
|
||||||
|
let useYomitan = hasYomitan;
|
||||||
|
|
||||||
|
const deps = createTokenizerDepsRuntime({
|
||||||
|
getYomitanExt: () => (useYomitan ? yomitanState!.yomitanExt : null) as never,
|
||||||
|
getYomitanParserWindow: () => (useYomitan ? yomitanState!.parserWindow : null) as never,
|
||||||
|
setYomitanParserWindow: (window) => {
|
||||||
|
if (!useYomitan) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
yomitanState!.parserWindow = window;
|
||||||
|
},
|
||||||
|
getYomitanParserReadyPromise: () =>
|
||||||
|
(useYomitan ? yomitanState!.parserReadyPromise : null) as never,
|
||||||
|
setYomitanParserReadyPromise: (promise) => {
|
||||||
|
if (!useYomitan) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
yomitanState!.parserReadyPromise = promise;
|
||||||
|
},
|
||||||
|
getYomitanParserInitPromise: () =>
|
||||||
|
(useYomitan ? yomitanState!.parserInitPromise : null) as never,
|
||||||
|
setYomitanParserInitPromise: (promise) => {
|
||||||
|
if (!useYomitan) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
yomitanState!.parserInitPromise = promise;
|
||||||
|
},
|
||||||
|
isKnownWord: () => false,
|
||||||
|
getKnownWordMatchMode: () => 'headword',
|
||||||
|
getJlptLevel: () => null,
|
||||||
|
getFrequencyDictionaryEnabled: () => true,
|
||||||
|
getFrequencyRank,
|
||||||
|
getMecabTokenizer: () => ({
|
||||||
|
tokenize: (text: string) => mecabTokenizer.tokenize(text),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
let subtitleData;
|
||||||
|
if (useYomitan) {
|
||||||
|
try {
|
||||||
|
subtitleData = await withTimeout(
|
||||||
|
tokenizeSubtitle(args.input, deps),
|
||||||
|
8000,
|
||||||
|
'Yomitan tokenizer',
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
useYomitan = false;
|
||||||
|
destroyUnknownParserWindow(yomitanState?.parserWindow ?? null);
|
||||||
|
if (yomitanState) {
|
||||||
|
yomitanState.parserWindow = null;
|
||||||
|
yomitanState.parserReadyPromise = null;
|
||||||
|
yomitanState.parserInitPromise = null;
|
||||||
|
const fallbackNote =
|
||||||
|
error instanceof Error ? error.message : 'Yomitan tokenizer timed out';
|
||||||
|
yomitanState.note = yomitanState.note
|
||||||
|
? `${yomitanState.note}; ${fallbackNote}`
|
||||||
|
: fallbackNote;
|
||||||
|
}
|
||||||
|
subtitleData = await tokenizeSubtitle(args.input, deps);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
subtitleData = await tokenizeSubtitle(args.input, deps);
|
||||||
|
}
|
||||||
|
const tokenCount = subtitleData.tokens?.length ?? 0;
|
||||||
|
const mergedCount = subtitleData.tokens?.filter((token) => token.isMerged).length ?? 0;
|
||||||
|
const tokens =
|
||||||
|
subtitleData.tokens?.map((token) =>
|
||||||
|
args.emitDiagnostics
|
||||||
|
? simplifyTokenWithVerbose(token, getFrequencyRank)
|
||||||
|
: simplifyToken(token),
|
||||||
|
) ?? null;
|
||||||
|
const diagnostics = {
|
||||||
|
yomitan: {
|
||||||
|
available: Boolean(yomitanState?.available),
|
||||||
|
loaded: useYomitan,
|
||||||
|
forceMecabOnly: args.forceMecabOnly,
|
||||||
|
note: yomitanState?.note ?? null,
|
||||||
|
},
|
||||||
|
mecab: {
|
||||||
|
command: args.mecabCommand ?? 'mecab',
|
||||||
|
dictionaryPath: args.mecabDictionaryPath ?? null,
|
||||||
|
available: isMecabAvailable,
|
||||||
|
},
|
||||||
|
tokenizer: {
|
||||||
|
sourceHint: tokenCount === 0 ? 'none' : useYomitan ? 'yomitan-merged' : 'mecab-merge',
|
||||||
|
mergedTokenCount: mergedCount,
|
||||||
|
totalTokenCount: tokenCount,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if (tokens === null) {
|
||||||
|
diagnostics.mecab['status'] = 'no-tokens';
|
||||||
|
diagnostics.mecab['note'] =
|
||||||
|
'MeCab returned no parseable tokens. This is often caused by a missing/invalid MeCab dictionary path.';
|
||||||
|
} else {
|
||||||
|
diagnostics.mecab['status'] = 'ok';
|
||||||
|
}
|
||||||
|
|
||||||
|
const output = {
|
||||||
|
input: args.input,
|
||||||
|
tokenizerText: subtitleData.text,
|
||||||
|
tokens,
|
||||||
|
diagnostics,
|
||||||
|
};
|
||||||
|
|
||||||
|
const json = JSON.stringify(output, null, args.emitPretty ? 2 : undefined);
|
||||||
|
process.stdout.write(`${json}\n`);
|
||||||
|
|
||||||
|
if (args.emitColoredLine && subtitleData.tokens) {
|
||||||
|
const coloredLine = renderColoredLine(subtitleData.text, subtitleData.tokens, args);
|
||||||
|
process.stdout.write(`${coloredLine}\n`);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
destroyUnknownParserWindow(yomitanState?.parserWindow ?? null);
|
||||||
|
if (electronModule?.app) {
|
||||||
|
electronModule.app.quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
.then(() => {
|
||||||
|
process.exit(0);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(`Error: ${(error as Error).message}`);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
168
scripts/mkv-to-readme-video.sh
Executable file
168
scripts/mkv-to-readme-video.sh
Executable file
@@ -0,0 +1,168 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat << 'USAGE'
|
||||||
|
Usage:
|
||||||
|
scripts/mkv-to-readme-video.sh [--force] <input.mkv>
|
||||||
|
|
||||||
|
Description:
|
||||||
|
Generates two browser-friendly files next to the input file:
|
||||||
|
- <name>.mp4 (H.264 + AAC, prefers NVIDIA GPU if available)
|
||||||
|
- <name>.webm (AV1/VP9 + Opus, prefers NVIDIA GPU if available)
|
||||||
|
- <name>.gif (palette-optimised, 15 fps)
|
||||||
|
|
||||||
|
Options:
|
||||||
|
-f, --force Overwrite existing output files
|
||||||
|
|
||||||
|
Encoding profile:
|
||||||
|
- Crop: 1920x1080 at x=760 y=180
|
||||||
|
- MP4: H.264 + AAC
|
||||||
|
- WebM: AV1/VP9 + Opus at 30 fps
|
||||||
|
USAGE
|
||||||
|
}
|
||||||
|
|
||||||
|
force=0
|
||||||
|
input=""
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
-f|--force)
|
||||||
|
force=1
|
||||||
|
;;
|
||||||
|
-*)
|
||||||
|
echo "Error: unknown option: $1" >&2
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [[ -n "$input" ]]; then
|
||||||
|
echo "Error: expected exactly one input file." >&2
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
input="$1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z "$input" ]]; then
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command -v ffmpeg > /dev/null 2>&1; then
|
||||||
|
echo "Error: ffmpeg is not installed or not in PATH." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -f "$input" ]]; then
|
||||||
|
echo "Error: input file not found: $input" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
dir="$(dirname "$input")"
|
||||||
|
filename="$(basename "$input")"
|
||||||
|
base="${filename%.*}"
|
||||||
|
|
||||||
|
mp4_out="$dir/$base.mp4"
|
||||||
|
webm_out="$dir/$base.webm"
|
||||||
|
gif_out="$dir/$base.gif"
|
||||||
|
|
||||||
|
overwrite_flag="-n"
|
||||||
|
if [[ "$force" -eq 1 ]]; then
|
||||||
|
overwrite_flag="-y"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$force" -eq 0 ]]; then
|
||||||
|
for output in "$mp4_out" "$webm_out" "$gif_out"; do
|
||||||
|
if [[ -e "$output" ]]; then
|
||||||
|
echo "Error: output exists: $output (use --force to overwrite)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
has_encoder() {
|
||||||
|
local encoder="$1"
|
||||||
|
ffmpeg -hide_banner -encoders 2> /dev/null | grep -qE "[[:space:]]${encoder}[[:space:]]"
|
||||||
|
}
|
||||||
|
|
||||||
|
crop_vf="crop=1920:1080:760:180"
|
||||||
|
webm_vf="${crop_vf},fps=30"
|
||||||
|
gif_vf="${crop_vf},fps=15,scale=960:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=128[p];[s1][p]paletteuse=dither=bayer:bayer_scale=3"
|
||||||
|
|
||||||
|
echo "Generating MP4: $mp4_out"
|
||||||
|
if has_encoder "h264_nvenc"; then
|
||||||
|
echo "Trying GPU encoder for MP4: h264_nvenc"
|
||||||
|
if ffmpeg "$overwrite_flag" -i "$input" \
|
||||||
|
-vf "$crop_vf" \
|
||||||
|
-c:v h264_nvenc -preset p6 -rc:v vbr -cq:v 20 -b:v 0 \
|
||||||
|
-pix_fmt yuv420p -movflags +faststart \
|
||||||
|
-c:a aac -b:a 160k \
|
||||||
|
"$mp4_out"; then
|
||||||
|
:
|
||||||
|
else
|
||||||
|
echo "GPU MP4 encode failed; retrying with CPU encoder: libx264"
|
||||||
|
ffmpeg "$overwrite_flag" -i "$input" \
|
||||||
|
-vf "$crop_vf" \
|
||||||
|
-c:v libx264 -preset slow -crf 20 \
|
||||||
|
-profile:v high -level 4.1 -pix_fmt yuv420p \
|
||||||
|
-movflags +faststart \
|
||||||
|
-c:a aac -b:a 160k \
|
||||||
|
"$mp4_out"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Using CPU encoder for MP4: libx264"
|
||||||
|
ffmpeg "$overwrite_flag" -i "$input" \
|
||||||
|
-vf "$crop_vf" \
|
||||||
|
-c:v libx264 -preset slow -crf 20 \
|
||||||
|
-profile:v high -level 4.1 -pix_fmt yuv420p \
|
||||||
|
-movflags +faststart \
|
||||||
|
-c:a aac -b:a 160k \
|
||||||
|
"$mp4_out"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Generating WebM: $webm_out"
|
||||||
|
if has_encoder "av1_nvenc"; then
|
||||||
|
echo "Trying GPU encoder for WebM: av1_nvenc"
|
||||||
|
if ffmpeg "$overwrite_flag" -i "$input" \
|
||||||
|
-vf "$webm_vf" \
|
||||||
|
-c:v av1_nvenc -preset p6 -cq:v 34 -b:v 0 \
|
||||||
|
-c:a libopus -b:a 96k \
|
||||||
|
"$webm_out"; then
|
||||||
|
:
|
||||||
|
else
|
||||||
|
echo "GPU WebM encode failed; retrying with CPU encoder: libvpx-vp9"
|
||||||
|
ffmpeg "$overwrite_flag" -i "$input" \
|
||||||
|
-vf "$webm_vf" \
|
||||||
|
-c:v libvpx-vp9 -crf 34 -b:v 0 \
|
||||||
|
-row-mt 1 -threads 8 \
|
||||||
|
-c:a libopus -b:a 96k \
|
||||||
|
"$webm_out"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Using CPU encoder for WebM: libvpx-vp9"
|
||||||
|
ffmpeg "$overwrite_flag" -i "$input" \
|
||||||
|
-vf "$webm_vf" \
|
||||||
|
-c:v libvpx-vp9 -crf 34 -b:v 0 \
|
||||||
|
-row-mt 1 -threads 8 \
|
||||||
|
-c:a libopus -b:a 96k \
|
||||||
|
"$webm_out"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Generating GIF: $gif_out"
|
||||||
|
ffmpeg "$overwrite_flag" -i "$input" \
|
||||||
|
-vf "$gif_vf" \
|
||||||
|
"$gif_out"
|
||||||
|
|
||||||
|
echo "Done."
|
||||||
|
echo "MP4: $mp4_out"
|
||||||
|
echo "WebM: $webm_out"
|
||||||
|
echo "GIF: $gif_out"
|
||||||
236
scripts/patch-texthooker.sh
Executable file
236
scripts/patch-texthooker.sh
Executable file
@@ -0,0 +1,236 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# SubMiner - All-in-one sentence mining overlay
|
||||||
|
# Copyright (C) 2024 sudacode
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# patch-texthooker.sh - Apply patches to texthooker-ui
|
||||||
|
#
|
||||||
|
# This script patches texthooker-ui to:
|
||||||
|
# 1) Handle empty sentences from mpv.
|
||||||
|
# 2) Apply SubMiner default texthooker styling.
|
||||||
|
#
|
||||||
|
# Usage: ./patch-texthooker.sh [texthooker_dir]
|
||||||
|
# texthooker_dir: Path to the texthooker-ui directory (default: vendor/texthooker-ui)
|
||||||
|
#
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
sed_in_place() {
|
||||||
|
local script="$1"
|
||||||
|
local file="$2"
|
||||||
|
|
||||||
|
if sed -i '' "$script" "$file" 2>/dev/null; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
sed -i "$script" "$file"
|
||||||
|
}
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
TEXTHOOKER_DIR="${1:-$SCRIPT_DIR/../vendor/texthooker-ui}"
|
||||||
|
|
||||||
|
if [ ! -d "$TEXTHOOKER_DIR" ]; then
|
||||||
|
echo "Error: texthooker-ui directory not found: $TEXTHOOKER_DIR"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Patching texthooker-ui in: $TEXTHOOKER_DIR"
|
||||||
|
|
||||||
|
SOCKET_TS="$TEXTHOOKER_DIR/src/socket.ts"
|
||||||
|
APP_CSS="$TEXTHOOKER_DIR/src/app.css"
|
||||||
|
STORES_TS="$TEXTHOOKER_DIR/src/stores/stores.ts"
|
||||||
|
|
||||||
|
if [ ! -f "$SOCKET_TS" ]; then
|
||||||
|
echo "Error: socket.ts not found at $SOCKET_TS"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$APP_CSS" ]; then
|
||||||
|
echo "Error: app.css not found at $APP_CSS"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$STORES_TS" ]; then
|
||||||
|
echo "Error: stores.ts not found at $STORES_TS"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Patching socket.ts..."
|
||||||
|
|
||||||
|
# Patch 1: Change || to ?? (nullish coalescing)
|
||||||
|
# This ensures empty string is kept instead of falling back to raw JSON
|
||||||
|
if grep -q '\.sentence ?? event\.data' "$SOCKET_TS"; then
|
||||||
|
echo " - Nullish coalescing already patched, skipping"
|
||||||
|
else
|
||||||
|
sed_in_place 's/\.sentence || event\.data/.sentence ?? event.data/' "$SOCKET_TS"
|
||||||
|
echo " - Changed || to ?? (nullish coalescing)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Patch 2: Skip emitting empty lines
|
||||||
|
# This prevents empty sentences from being added to the UI
|
||||||
|
if grep -q "if (line)" "$SOCKET_TS"; then
|
||||||
|
echo " - Empty line check already patched, skipping"
|
||||||
|
else
|
||||||
|
sed_in_place 's/\t\tnewLine\$\.next(\[line, LineType\.SOCKET\]);/\t\tif (line) {\n\t\t\tnewLine$.next([line, LineType.SOCKET]);\n\t\t}/' "$SOCKET_TS"
|
||||||
|
echo " - Added empty line check"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Patching app.css..."
|
||||||
|
|
||||||
|
# Patch 3: Apply SubMiner default texthooker-ui styling
|
||||||
|
if grep -q "SUBMINER_DEFAULT_STYLE_START" "$APP_CSS"; then
|
||||||
|
echo " - Default SubMiner CSS already patched, skipping"
|
||||||
|
else
|
||||||
|
cat >> "$APP_CSS" << 'EOF'
|
||||||
|
|
||||||
|
/* SUBMINER_DEFAULT_STYLE_START */
|
||||||
|
:root {
|
||||||
|
--sm-bg: #1a1b2e;
|
||||||
|
--sm-surface: #222436;
|
||||||
|
--sm-border: rgba(255, 255, 255, 0.05);
|
||||||
|
--sm-text: #c8d3f5;
|
||||||
|
--sm-text-muted: #636da6;
|
||||||
|
--sm-hover-bg: rgba(130, 170, 255, 0.06);
|
||||||
|
--sm-scrollbar: rgba(255, 255, 255, 0.08);
|
||||||
|
--sm-scrollbar-hover: rgba(255, 255, 255, 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
flex: 1;
|
||||||
|
min-height: 100%;
|
||||||
|
overflow: auto;
|
||||||
|
background: var(--sm-bg);
|
||||||
|
color: var(--sm-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
body[data-theme] {
|
||||||
|
background: var(--sm-bg);
|
||||||
|
color: var(--sm-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
main,
|
||||||
|
header,
|
||||||
|
#pip-container {
|
||||||
|
background: transparent;
|
||||||
|
color: var(--sm-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
header.bg-base-100,
|
||||||
|
header.bg-base-200 {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
main,
|
||||||
|
main.flex {
|
||||||
|
font-family: 'Noto Sans CJK JP', 'Hiragino Sans', system-ui, sans-serif;
|
||||||
|
padding: 0.5rem min(4vw, 2rem);
|
||||||
|
line-height: 1.7;
|
||||||
|
gap: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
p,
|
||||||
|
p.cursor-pointer {
|
||||||
|
font-family: 'Noto Sans CJK JP', 'Hiragino Sans', system-ui, sans-serif;
|
||||||
|
font-size: clamp(18px, 2vw, 26px);
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
line-height: 1.65;
|
||||||
|
white-space: normal;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0.65rem 1rem;
|
||||||
|
border: none;
|
||||||
|
border-bottom: 1px solid var(--sm-border);
|
||||||
|
border-radius: 0;
|
||||||
|
background: transparent;
|
||||||
|
transition: background 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
p:hover,
|
||||||
|
p.cursor-pointer:hover {
|
||||||
|
background: var(--sm-hover-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
p:last-child,
|
||||||
|
p.cursor-pointer:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.cursor-pointer.whitespace-pre-wrap {
|
||||||
|
white-space: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.cursor-pointer.my-2 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.cursor-pointer.py-4,
|
||||||
|
p.cursor-pointer.py-2,
|
||||||
|
p.cursor-pointer.px-2,
|
||||||
|
p.cursor-pointer.px-4 {
|
||||||
|
padding: 0.65rem 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
*::-webkit-scrollbar {
|
||||||
|
width: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
*::-webkit-scrollbar-track {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
*::-webkit-scrollbar-thumb {
|
||||||
|
background: var(--sm-scrollbar);
|
||||||
|
border-radius: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
*::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: var(--sm-scrollbar-hover);
|
||||||
|
}
|
||||||
|
/* SUBMINER_DEFAULT_STYLE_END */
|
||||||
|
EOF
|
||||||
|
echo " - Added default SubMiner CSS block"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Patching stores.ts defaults..."
|
||||||
|
|
||||||
|
# Patch 4: Change default settings for title/whitespace/animation/reconnect
|
||||||
|
if grep -q "preserveWhitespace\\$: false" "$STORES_TS" && \
|
||||||
|
grep -q "removeAllWhitespace\\$: true" "$STORES_TS" && \
|
||||||
|
grep -q "enableLineAnimation\\$: true" "$STORES_TS" && \
|
||||||
|
grep -q "continuousReconnect\\$: true" "$STORES_TS" && \
|
||||||
|
grep -q "windowTitle\\$: 'SubMiner Texthooker'" "$STORES_TS"; then
|
||||||
|
echo " - Default settings already patched, skipping"
|
||||||
|
else
|
||||||
|
sed_in_place "s/windowTitle\\$: '',/windowTitle\\$: 'SubMiner Texthooker',/" "$STORES_TS"
|
||||||
|
sed_in_place 's/preserveWhitespace\$: true,/preserveWhitespace\$: false,/' "$STORES_TS"
|
||||||
|
sed_in_place 's/removeAllWhitespace\$: false,/removeAllWhitespace\$: true,/' "$STORES_TS"
|
||||||
|
sed_in_place 's/enableLineAnimation\$: false,/enableLineAnimation\$: true,/' "$STORES_TS"
|
||||||
|
sed_in_place 's/continuousReconnect\$: false,/continuousReconnect\$: true,/' "$STORES_TS"
|
||||||
|
echo " - Updated default settings (title/whitespace/animation/reconnect)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "texthooker-ui patching complete!"
|
||||||
|
echo ""
|
||||||
|
echo "Changes applied:"
|
||||||
|
echo " 1. socket.ts: Use ?? instead of || to preserve empty strings"
|
||||||
|
echo " 2. socket.ts: Skip emitting empty sentences"
|
||||||
|
echo " 3. app.css: Apply SubMiner default styling (without !important)"
|
||||||
|
echo " 4. stores.ts: Update default settings for title/whitespace/animation/reconnect"
|
||||||
|
echo ""
|
||||||
|
echo "To rebuild: cd vendor/texthooker-ui && pnpm run build"
|
||||||
261
scripts/patch-yomitan.sh
Executable file
261
scripts/patch-yomitan.sh
Executable file
@@ -0,0 +1,261 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# SubMiner - All-in-one sentence mining overlay
|
||||||
|
# Copyright (C) 2024 sudacode
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# patch-yomitan.sh - Apply Electron compatibility patches to Yomitan
|
||||||
|
#
|
||||||
|
# This script applies the necessary patches to make Yomitan work in Electron
|
||||||
|
# after upgrading to a new version. Run this after extracting a fresh Yomitan release.
|
||||||
|
#
|
||||||
|
# Usage: ./patch-yomitan.sh [yomitan_dir]
|
||||||
|
# yomitan_dir: Path to the Yomitan directory (default: vendor/yomitan)
|
||||||
|
#
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
YOMITAN_DIR="${1:-$SCRIPT_DIR/../vendor/yomitan}"
|
||||||
|
|
||||||
|
if [ ! -d "$YOMITAN_DIR" ]; then
|
||||||
|
echo "Error: Yomitan directory not found: $YOMITAN_DIR"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Patching Yomitan in: $YOMITAN_DIR"
|
||||||
|
|
||||||
|
PERMISSIONS_UTIL="$YOMITAN_DIR/js/data/permissions-util.js"
|
||||||
|
|
||||||
|
if [ ! -f "$PERMISSIONS_UTIL" ]; then
|
||||||
|
echo "Error: permissions-util.js not found at $PERMISSIONS_UTIL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Patching permissions-util.js..."
|
||||||
|
|
||||||
|
if grep -q "Electron workaround" "$PERMISSIONS_UTIL"; then
|
||||||
|
echo " - Already patched, skipping"
|
||||||
|
else
|
||||||
|
cat > "$PERMISSIONS_UTIL.tmp" << 'PATCH_EOF'
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023-2025 Yomitan Authors
|
||||||
|
* Copyright (C) 2021-2022 Yomichan Authors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {getFieldMarkers} from './anki-util.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function returns whether an Anki field marker might require clipboard permissions.
|
||||||
|
* This is speculative and may not guarantee that the field marker actually does require the permission,
|
||||||
|
* as the custom handlebars template is not deeply inspected.
|
||||||
|
* @param {string} marker
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function ankiFieldMarkerMayUseClipboard(marker) {
|
||||||
|
switch (marker) {
|
||||||
|
case 'clipboard-image':
|
||||||
|
case 'clipboard-text':
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {chrome.permissions.Permissions} permissions
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
|
*/
|
||||||
|
export function hasPermissions(permissions) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
chrome.permissions.contains(permissions, (result) => {
|
||||||
|
const e = chrome.runtime.lastError;
|
||||||
|
if (e) {
|
||||||
|
reject(new Error(e.message));
|
||||||
|
} else {
|
||||||
|
resolve(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {chrome.permissions.Permissions} permissions
|
||||||
|
* @param {boolean} shouldHave
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
|
*/
|
||||||
|
export function setPermissionsGranted(permissions, shouldHave) {
|
||||||
|
return (
|
||||||
|
shouldHave ?
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
chrome.permissions.request(permissions, (result) => {
|
||||||
|
const e = chrome.runtime.lastError;
|
||||||
|
if (e) {
|
||||||
|
reject(new Error(e.message));
|
||||||
|
} else {
|
||||||
|
resolve(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}) :
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
chrome.permissions.remove(permissions, (result) => {
|
||||||
|
const e = chrome.runtime.lastError;
|
||||||
|
if (e) {
|
||||||
|
reject(new Error(e.message));
|
||||||
|
} else {
|
||||||
|
resolve(!result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Promise<chrome.permissions.Permissions>}
|
||||||
|
*/
|
||||||
|
export function getAllPermissions() {
|
||||||
|
// Electron workaround - chrome.permissions.getAll() not available
|
||||||
|
return Promise.resolve({
|
||||||
|
origins: ["<all_urls>"],
|
||||||
|
permissions: ["clipboardWrite", "storage", "unlimitedStorage", "scripting", "contextMenus"]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} fieldValue
|
||||||
|
* @returns {string[]}
|
||||||
|
*/
|
||||||
|
export function getRequiredPermissionsForAnkiFieldValue(fieldValue) {
|
||||||
|
const markers = getFieldMarkers(fieldValue);
|
||||||
|
for (const marker of markers) {
|
||||||
|
if (ankiFieldMarkerMayUseClipboard(marker)) {
|
||||||
|
return ['clipboardRead'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {chrome.permissions.Permissions} permissions
|
||||||
|
* @param {import('settings').ProfileOptions} options
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
export function hasRequiredPermissionsForOptions(permissions, options) {
|
||||||
|
const permissionsSet = new Set(permissions.permissions);
|
||||||
|
|
||||||
|
if (!permissionsSet.has('nativeMessaging') && (options.parsing.enableMecabParser || options.general.enableYomitanApi)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!permissionsSet.has('clipboardRead')) {
|
||||||
|
if (options.clipboard.enableBackgroundMonitor || options.clipboard.enableSearchPageMonitor) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const fieldsList = options.anki.cardFormats.map((cardFormat) => cardFormat.fields);
|
||||||
|
|
||||||
|
for (const fields of fieldsList) {
|
||||||
|
for (const {value: fieldValue} of Object.values(fields)) {
|
||||||
|
const markers = getFieldMarkers(fieldValue);
|
||||||
|
for (const marker of markers) {
|
||||||
|
if (ankiFieldMarkerMayUseClipboard(marker)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
PATCH_EOF
|
||||||
|
|
||||||
|
mv "$PERMISSIONS_UTIL.tmp" "$PERMISSIONS_UTIL"
|
||||||
|
echo " - Patched successfully"
|
||||||
|
fi
|
||||||
|
|
||||||
|
OPTIONS_SCHEMA="$YOMITAN_DIR/data/schemas/options-schema.json"
|
||||||
|
|
||||||
|
if [ ! -f "$OPTIONS_SCHEMA" ]; then
|
||||||
|
echo "Error: options-schema.json not found at $OPTIONS_SCHEMA"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Patching options-schema.json..."
|
||||||
|
|
||||||
|
if grep -q '"selectText".*"default": true' "$OPTIONS_SCHEMA"; then
|
||||||
|
sed -i '/"selectText": {/,/"default":/{s/"default": true/"default": false/}' "$OPTIONS_SCHEMA"
|
||||||
|
echo " - Changed selectText default to false"
|
||||||
|
elif grep -q '"selectText".*"default": false' "$OPTIONS_SCHEMA"; then
|
||||||
|
echo " - selectText already set to false, skipping"
|
||||||
|
else
|
||||||
|
echo " - Warning: Could not find selectText setting"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep -q '"layoutAwareScan".*"default": true' "$OPTIONS_SCHEMA"; then
|
||||||
|
sed -i '/"layoutAwareScan": {/,/"default":/{s/"default": true/"default": false/}' "$OPTIONS_SCHEMA"
|
||||||
|
echo " - Changed layoutAwareScan default to false"
|
||||||
|
elif grep -q '"layoutAwareScan".*"default": false' "$OPTIONS_SCHEMA"; then
|
||||||
|
echo " - layoutAwareScan already set to false, skipping"
|
||||||
|
else
|
||||||
|
echo " - Warning: Could not find layoutAwareScan setting"
|
||||||
|
fi
|
||||||
|
|
||||||
|
POPUP_JS="$YOMITAN_DIR/js/app/popup.js"
|
||||||
|
|
||||||
|
if [ ! -f "$POPUP_JS" ]; then
|
||||||
|
echo "Error: popup.js not found at $POPUP_JS"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Patching popup.js..."
|
||||||
|
|
||||||
|
if grep -q "yomitan-popup-shown" "$POPUP_JS"; then
|
||||||
|
echo " - Already patched, skipping"
|
||||||
|
else
|
||||||
|
# Add the visibility event dispatch after the existing _onVisibleChange code
|
||||||
|
# We need to add it after: void this._invokeSafe('displayVisibilityChanged', {value});
|
||||||
|
sed -i "/void this._invokeSafe('displayVisibilityChanged', {value});/a\\
|
||||||
|
\\
|
||||||
|
// Dispatch custom events for popup visibility (Electron integration)\\
|
||||||
|
if (value) {\\
|
||||||
|
window.dispatchEvent(new CustomEvent('yomitan-popup-shown'));\\
|
||||||
|
} else {\\
|
||||||
|
window.dispatchEvent(new CustomEvent('yomitan-popup-hidden'));\\
|
||||||
|
}" "$POPUP_JS"
|
||||||
|
echo " - Added visibility events"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Yomitan patching complete!"
|
||||||
|
echo ""
|
||||||
|
echo "Changes applied:"
|
||||||
|
echo " 1. permissions-util.js: Hardcoded permissions (Electron workaround)"
|
||||||
|
echo " 2. options-schema.json: selectText=false, layoutAwareScan=false"
|
||||||
|
echo " 3. popup.js: Added yomitan-popup-shown/hidden events"
|
||||||
|
echo ""
|
||||||
|
echo "To verify: Run 'bun run dev' and check for 'Yomitan extension loaded successfully'"
|
||||||
193
scripts/test-plugin-start-gate.lua
Normal file
193
scripts/test-plugin-start-gate.lua
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
local function run_plugin_scenario(config)
|
||||||
|
config = config or {}
|
||||||
|
|
||||||
|
local recorded = {
|
||||||
|
async_calls = {},
|
||||||
|
script_messages = {},
|
||||||
|
osd = {},
|
||||||
|
logs = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
local function make_mp_stub()
|
||||||
|
local mp = {}
|
||||||
|
|
||||||
|
function mp.get_property(name)
|
||||||
|
if name == "platform" then
|
||||||
|
return config.platform or "linux"
|
||||||
|
end
|
||||||
|
if name == "filename/no-ext" then
|
||||||
|
return config.filename_no_ext or ""
|
||||||
|
end
|
||||||
|
if name == "filename" then
|
||||||
|
return config.filename or ""
|
||||||
|
end
|
||||||
|
if name == "path" then
|
||||||
|
return config.path or ""
|
||||||
|
end
|
||||||
|
if name == "media-title" then
|
||||||
|
return config.media_title or ""
|
||||||
|
end
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
|
||||||
|
function mp.get_property_native(_name)
|
||||||
|
return config.chapter_list or {}
|
||||||
|
end
|
||||||
|
|
||||||
|
function mp.command_native(command)
|
||||||
|
local args = command.args or {}
|
||||||
|
if args[1] == "ps" then
|
||||||
|
return {
|
||||||
|
status = 0,
|
||||||
|
stdout = config.process_list or "",
|
||||||
|
stderr = "",
|
||||||
|
}
|
||||||
|
end
|
||||||
|
if args[1] == "curl" then
|
||||||
|
return { status = 0, stdout = "{}", stderr = "" }
|
||||||
|
end
|
||||||
|
return { status = 0, stdout = "", stderr = "" }
|
||||||
|
end
|
||||||
|
|
||||||
|
function mp.command_native_async(command, callback)
|
||||||
|
recorded.async_calls[#recorded.async_calls + 1] = command
|
||||||
|
if callback then
|
||||||
|
callback(true, { status = 0, stdout = "", stderr = "" }, nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function mp.add_timeout(_seconds, callback)
|
||||||
|
if callback then
|
||||||
|
callback()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function mp.register_script_message(name, fn)
|
||||||
|
recorded.script_messages[name] = fn
|
||||||
|
end
|
||||||
|
|
||||||
|
function mp.add_key_binding(_keys, _name, _fn) end
|
||||||
|
function mp.register_event(_name, _fn) end
|
||||||
|
function mp.add_hook(_name, _prio, _fn) end
|
||||||
|
function mp.observe_property(_name, _kind, _fn) end
|
||||||
|
function mp.osd_message(message, _duration)
|
||||||
|
recorded.osd[#recorded.osd + 1] = message
|
||||||
|
end
|
||||||
|
function mp.get_time()
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
function mp.commandv(...) end
|
||||||
|
function mp.set_property_native(...) end
|
||||||
|
function mp.get_script_name()
|
||||||
|
return "subminer"
|
||||||
|
end
|
||||||
|
|
||||||
|
return mp
|
||||||
|
end
|
||||||
|
|
||||||
|
local mp = make_mp_stub()
|
||||||
|
local options = {}
|
||||||
|
local utils = {}
|
||||||
|
|
||||||
|
function options.read_options(target, _name)
|
||||||
|
if config.socket_path then
|
||||||
|
target.socket_path = config.socket_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function utils.file_info(path)
|
||||||
|
local exists = config.files and config.files[path]
|
||||||
|
if exists then
|
||||||
|
return { is_dir = false }
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function utils.join_path(...)
|
||||||
|
local parts = { ... }
|
||||||
|
return table.concat(parts, "/")
|
||||||
|
end
|
||||||
|
|
||||||
|
function utils.parse_json(_json)
|
||||||
|
return {}, nil
|
||||||
|
end
|
||||||
|
|
||||||
|
package.loaded["mp"] = nil
|
||||||
|
package.loaded["mp.input"] = nil
|
||||||
|
package.loaded["mp.msg"] = nil
|
||||||
|
package.loaded["mp.options"] = nil
|
||||||
|
package.loaded["mp.utils"] = nil
|
||||||
|
|
||||||
|
package.preload["mp"] = function()
|
||||||
|
return mp
|
||||||
|
end
|
||||||
|
package.preload["mp.input"] = function()
|
||||||
|
return {
|
||||||
|
select = function(_) end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
package.preload["mp.msg"] = function()
|
||||||
|
return {
|
||||||
|
info = function(line)
|
||||||
|
recorded.logs[#recorded.logs + 1] = line
|
||||||
|
end,
|
||||||
|
warn = function(line)
|
||||||
|
recorded.logs[#recorded.logs + 1] = line
|
||||||
|
end,
|
||||||
|
error = function(line)
|
||||||
|
recorded.logs[#recorded.logs + 1] = line
|
||||||
|
end,
|
||||||
|
debug = function(line)
|
||||||
|
recorded.logs[#recorded.logs + 1] = line
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
package.preload["mp.options"] = function()
|
||||||
|
return options
|
||||||
|
end
|
||||||
|
package.preload["mp.utils"] = function()
|
||||||
|
return utils
|
||||||
|
end
|
||||||
|
|
||||||
|
local ok, err = pcall(dofile, "plugin/subminer.lua")
|
||||||
|
if not ok then
|
||||||
|
return nil, err, recorded
|
||||||
|
end
|
||||||
|
return recorded, nil, recorded
|
||||||
|
end
|
||||||
|
|
||||||
|
local function assert_true(condition, message)
|
||||||
|
if condition then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
error(message)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function find_start_call(async_calls)
|
||||||
|
for _, call in ipairs(async_calls) do
|
||||||
|
local args = call.args or {}
|
||||||
|
for i = 1, #args do
|
||||||
|
if args[i] == "--start" then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local binary_path = "/tmp/subminer-binary"
|
||||||
|
|
||||||
|
do
|
||||||
|
local recorded, err = run_plugin_scenario({
|
||||||
|
process_list = "",
|
||||||
|
files = {
|
||||||
|
[binary_path] = true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
assert_true(recorded ~= nil, "plugin failed to load for cold-start scenario: " .. tostring(err))
|
||||||
|
assert_true(recorded.script_messages["subminer-start"] ~= nil, "subminer-start script message not registered")
|
||||||
|
recorded.script_messages["subminer-start"]("texthooker=no")
|
||||||
|
assert_true(find_start_call(recorded.async_calls), "expected cold-start to invoke --start command when process is absent")
|
||||||
|
end
|
||||||
|
|
||||||
|
print("plugin start gate regression tests: OK")
|
||||||
638
scripts/test-yomitan-parser.ts
Normal file
638
scripts/test-yomitan-parser.ts
Normal file
@@ -0,0 +1,638 @@
|
|||||||
|
import fs from 'node:fs';
|
||||||
|
import os from 'node:os';
|
||||||
|
import path from 'node:path';
|
||||||
|
import process from 'node:process';
|
||||||
|
|
||||||
|
import { createTokenizerDepsRuntime, tokenizeSubtitle } from '../src/core/services/tokenizer.js';
|
||||||
|
import { MecabTokenizer } from '../src/mecab-tokenizer.js';
|
||||||
|
import type { MergedToken } from '../src/types.js';
|
||||||
|
|
||||||
|
interface CliOptions {
|
||||||
|
input: string;
|
||||||
|
emitPretty: boolean;
|
||||||
|
emitJson: boolean;
|
||||||
|
forceMecabOnly: boolean;
|
||||||
|
yomitanExtensionPath?: string;
|
||||||
|
yomitanUserDataPath?: string;
|
||||||
|
mecabCommand?: string;
|
||||||
|
mecabDictionaryPath?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface YomitanParseHeadword {
|
||||||
|
term?: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface YomitanParseSegment {
|
||||||
|
text?: unknown;
|
||||||
|
reading?: unknown;
|
||||||
|
headwords?: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface YomitanParseResultItem {
|
||||||
|
source?: unknown;
|
||||||
|
index?: unknown;
|
||||||
|
content?: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ParsedCandidate {
|
||||||
|
source: string;
|
||||||
|
index: number;
|
||||||
|
tokens: Array<{
|
||||||
|
surface: string;
|
||||||
|
reading: string;
|
||||||
|
headword: string;
|
||||||
|
startPos: number;
|
||||||
|
endPos: number;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface YomitanRuntimeState {
|
||||||
|
available: boolean;
|
||||||
|
note: string | null;
|
||||||
|
extension: Electron.Extension | null;
|
||||||
|
parserWindow: Electron.BrowserWindow | null;
|
||||||
|
parserReadyPromise: Promise<void> | null;
|
||||||
|
parserInitPromise: Promise<boolean> | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DEFAULT_YOMITAN_USER_DATA_PATH = path.join(os.homedir(), '.config', 'SubMiner');
|
||||||
|
|
||||||
|
function destroyParserWindow(window: Electron.BrowserWindow | null): void {
|
||||||
|
if (!window || window.isDestroyed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
window.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function shutdownYomitanRuntime(yomitan: YomitanRuntimeState): Promise<void> {
|
||||||
|
destroyParserWindow(yomitan.parserWindow);
|
||||||
|
const electronModule = await import('electron').catch(() => null);
|
||||||
|
if (electronModule?.app) {
|
||||||
|
electronModule.app.quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseCliArgs(argv: string[]): CliOptions {
|
||||||
|
const args = [...argv];
|
||||||
|
const inputParts: string[] = [];
|
||||||
|
let emitPretty = true;
|
||||||
|
let emitJson = false;
|
||||||
|
let forceMecabOnly = false;
|
||||||
|
let yomitanExtensionPath: string | undefined;
|
||||||
|
let yomitanUserDataPath: string | undefined = DEFAULT_YOMITAN_USER_DATA_PATH;
|
||||||
|
let mecabCommand: string | undefined;
|
||||||
|
let mecabDictionaryPath: string | undefined;
|
||||||
|
|
||||||
|
while (args.length > 0) {
|
||||||
|
const arg = args.shift();
|
||||||
|
if (!arg) break;
|
||||||
|
|
||||||
|
if (arg === '--help' || arg === '-h') {
|
||||||
|
printUsage();
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--pretty') {
|
||||||
|
emitPretty = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--json') {
|
||||||
|
emitJson = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--force-mecab') {
|
||||||
|
forceMecabOnly = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--yomitan-extension') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --yomitan-extension');
|
||||||
|
}
|
||||||
|
yomitanExtensionPath = path.resolve(next);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--yomitan-extension=')) {
|
||||||
|
yomitanExtensionPath = path.resolve(arg.slice('--yomitan-extension='.length));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--yomitan-user-data') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --yomitan-user-data');
|
||||||
|
}
|
||||||
|
yomitanUserDataPath = path.resolve(next);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--yomitan-user-data=')) {
|
||||||
|
yomitanUserDataPath = path.resolve(arg.slice('--yomitan-user-data='.length));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--mecab-command') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --mecab-command');
|
||||||
|
}
|
||||||
|
mecabCommand = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--mecab-command=')) {
|
||||||
|
mecabCommand = arg.slice('--mecab-command='.length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === '--mecab-dictionary') {
|
||||||
|
const next = args.shift();
|
||||||
|
if (!next) {
|
||||||
|
throw new Error('Missing value for --mecab-dictionary');
|
||||||
|
}
|
||||||
|
mecabDictionaryPath = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('--mecab-dictionary=')) {
|
||||||
|
mecabDictionaryPath = arg.slice('--mecab-dictionary='.length);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg.startsWith('-')) {
|
||||||
|
throw new Error(`Unknown flag: ${arg}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
inputParts.push(arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
const input = inputParts.join(' ').trim();
|
||||||
|
if (input.length > 0) {
|
||||||
|
return {
|
||||||
|
input,
|
||||||
|
emitPretty,
|
||||||
|
emitJson,
|
||||||
|
forceMecabOnly,
|
||||||
|
yomitanExtensionPath,
|
||||||
|
yomitanUserDataPath,
|
||||||
|
mecabCommand,
|
||||||
|
mecabDictionaryPath,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const stdin = fs.readFileSync(0, 'utf8').trim();
|
||||||
|
if (!stdin) {
|
||||||
|
throw new Error('Please provide input text as arguments or via stdin.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
input: stdin,
|
||||||
|
emitPretty,
|
||||||
|
emitJson,
|
||||||
|
forceMecabOnly,
|
||||||
|
yomitanExtensionPath,
|
||||||
|
yomitanUserDataPath,
|
||||||
|
mecabCommand,
|
||||||
|
mecabDictionaryPath,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function printUsage(): void {
|
||||||
|
process.stdout.write(`Usage:
|
||||||
|
bun run test-yomitan-parser:electron -- [--pretty] [--json] [--yomitan-extension <path>] [--yomitan-user-data <path>] [--mecab-command <path>] [--mecab-dictionary <path>] <text>
|
||||||
|
|
||||||
|
--pretty Pretty-print JSON output.
|
||||||
|
--json Emit machine-readable JSON output.
|
||||||
|
--force-mecab Skip Yomitan parser setup and test MeCab fallback only.
|
||||||
|
--yomitan-extension <path> Optional path to Yomitan extension directory.
|
||||||
|
--yomitan-user-data <path> Optional Electron userData directory (default: ~/.config/SubMiner).
|
||||||
|
--mecab-command <path> Optional MeCab binary path (default: mecab).
|
||||||
|
--mecab-dictionary <path> Optional MeCab dictionary directory.
|
||||||
|
-h, --help Show usage.
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeDisplayText(text: string): string {
|
||||||
|
return text.replace(/\r\n/g, '\n').replace(/\\N/g, '\n').replace(/\\n/g, '\n').trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeTokenizerText(text: string): string {
|
||||||
|
return normalizeDisplayText(text).replace(/\n/g, ' ').replace(/\s+/g, ' ').trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function isObject(value: unknown): value is Record<string, unknown> {
|
||||||
|
return Boolean(value && typeof value === 'object');
|
||||||
|
}
|
||||||
|
|
||||||
|
function isHeadwordRows(value: unknown): value is YomitanParseHeadword[][] {
|
||||||
|
return (
|
||||||
|
Array.isArray(value) &&
|
||||||
|
value.every(
|
||||||
|
(row) =>
|
||||||
|
Array.isArray(row) &&
|
||||||
|
row.every((entry) => isObject(entry) && typeof entry.term === 'string'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractHeadwordTerms(segment: YomitanParseSegment): string[] {
|
||||||
|
if (!isHeadwordRows(segment.headwords)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const terms: string[] = [];
|
||||||
|
const seen = new Set<string>();
|
||||||
|
for (const row of segment.headwords) {
|
||||||
|
for (const entry of row) {
|
||||||
|
const term = (entry.term as string).trim();
|
||||||
|
if (!term || seen.has(term)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
seen.add(term);
|
||||||
|
terms.push(term);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return terms;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mapParseResultsToCandidates(parseResults: unknown): ParsedCandidate[] {
|
||||||
|
if (!Array.isArray(parseResults)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const candidates: ParsedCandidate[] = [];
|
||||||
|
for (const item of parseResults) {
|
||||||
|
if (!isObject(item)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const parseItem = item as YomitanParseResultItem;
|
||||||
|
if (!Array.isArray(parseItem.content) || typeof parseItem.source !== 'string') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const candidateTokens: ParsedCandidate['tokens'] = [];
|
||||||
|
let charOffset = 0;
|
||||||
|
let validLineCount = 0;
|
||||||
|
|
||||||
|
for (const line of parseItem.content) {
|
||||||
|
if (!Array.isArray(line)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const lineSegments = line as YomitanParseSegment[];
|
||||||
|
if (lineSegments.some((segment) => typeof segment.text !== 'string')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
validLineCount += 1;
|
||||||
|
|
||||||
|
for (const segment of lineSegments) {
|
||||||
|
const surface = (segment.text as string) ?? '';
|
||||||
|
if (!surface) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const startPos = charOffset;
|
||||||
|
const endPos = startPos + surface.length;
|
||||||
|
charOffset = endPos;
|
||||||
|
const headwordTerms = extractHeadwordTerms(segment);
|
||||||
|
candidateTokens.push({
|
||||||
|
surface,
|
||||||
|
reading: typeof segment.reading === 'string' ? segment.reading : '',
|
||||||
|
headword: headwordTerms[0] ?? surface,
|
||||||
|
startPos,
|
||||||
|
endPos,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validLineCount === 0 || candidateTokens.length === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
candidates.push({
|
||||||
|
source: parseItem.source,
|
||||||
|
index:
|
||||||
|
typeof parseItem.index === 'number' && Number.isInteger(parseItem.index)
|
||||||
|
? parseItem.index
|
||||||
|
: 0,
|
||||||
|
tokens: candidateTokens,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return candidates;
|
||||||
|
}
|
||||||
|
|
||||||
|
function candidateTokenSignature(token: {
|
||||||
|
surface: string;
|
||||||
|
reading: string;
|
||||||
|
headword: string;
|
||||||
|
startPos: number;
|
||||||
|
endPos: number;
|
||||||
|
}): string {
|
||||||
|
return `${token.surface}\u001f${token.reading}\u001f${token.headword}\u001f${token.startPos}\u001f${token.endPos}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mergedTokenSignature(token: MergedToken): string {
|
||||||
|
return `${token.surface}\u001f${token.reading}\u001f${token.headword}\u001f${token.startPos}\u001f${token.endPos}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function findSelectedCandidateIndexes(
|
||||||
|
candidates: ParsedCandidate[],
|
||||||
|
mergedTokens: MergedToken[] | null,
|
||||||
|
): number[] {
|
||||||
|
if (!mergedTokens || mergedTokens.length === 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const mergedSignatures = mergedTokens.map(mergedTokenSignature);
|
||||||
|
const selected: number[] = [];
|
||||||
|
for (let i = 0; i < candidates.length; i += 1) {
|
||||||
|
const candidateSignatures = candidates[i].tokens.map(candidateTokenSignature);
|
||||||
|
if (candidateSignatures.length !== mergedSignatures.length) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let allMatch = true;
|
||||||
|
for (let j = 0; j < candidateSignatures.length; j += 1) {
|
||||||
|
if (candidateSignatures[j] !== mergedSignatures[j]) {
|
||||||
|
allMatch = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (allMatch) {
|
||||||
|
selected.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveYomitanExtensionPath(explicitPath?: string): string | null {
|
||||||
|
const candidates = [
|
||||||
|
explicitPath ? path.resolve(explicitPath) : null,
|
||||||
|
path.resolve(process.cwd(), 'vendor', 'yomitan'),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const candidate of candidates) {
|
||||||
|
if (!candidate) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (fs.existsSync(path.join(candidate, 'manifest.json'))) {
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setupYomitanRuntime(options: CliOptions): Promise<YomitanRuntimeState> {
|
||||||
|
const state: YomitanRuntimeState = {
|
||||||
|
available: false,
|
||||||
|
note: null,
|
||||||
|
extension: null,
|
||||||
|
parserWindow: null,
|
||||||
|
parserReadyPromise: null,
|
||||||
|
parserInitPromise: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (options.forceMecabOnly) {
|
||||||
|
state.note = 'force-mecab enabled';
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
const electronModule = await import('electron').catch((error) => {
|
||||||
|
state.note = error instanceof Error ? error.message : 'electron import failed';
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
if (!electronModule?.app || !electronModule?.session) {
|
||||||
|
state.note = 'electron runtime not available in this process';
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.yomitanUserDataPath) {
|
||||||
|
electronModule.app.setPath('userData', options.yomitanUserDataPath);
|
||||||
|
}
|
||||||
|
await electronModule.app.whenReady();
|
||||||
|
|
||||||
|
const extensionPath = resolveYomitanExtensionPath(options.yomitanExtensionPath);
|
||||||
|
if (!extensionPath) {
|
||||||
|
state.note = 'no Yomitan extension directory found';
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
state.extension = await electronModule.session.defaultSession.loadExtension(extensionPath, {
|
||||||
|
allowFileAccess: true,
|
||||||
|
});
|
||||||
|
state.available = true;
|
||||||
|
return state;
|
||||||
|
} catch (error) {
|
||||||
|
state.note = error instanceof Error ? error.message : 'failed to load Yomitan extension';
|
||||||
|
state.available = false;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchRawParseResults(
|
||||||
|
parserWindow: Electron.BrowserWindow,
|
||||||
|
text: string,
|
||||||
|
): Promise<unknown> {
|
||||||
|
const script = `
|
||||||
|
(async () => {
|
||||||
|
const invoke = (action, params) =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
chrome.runtime.sendMessage({ action, params }, (response) => {
|
||||||
|
if (chrome.runtime.lastError) {
|
||||||
|
reject(new Error(chrome.runtime.lastError.message));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!response || typeof response !== "object") {
|
||||||
|
reject(new Error("Invalid response from Yomitan backend"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (response.error) {
|
||||||
|
reject(new Error(response.error.message || "Yomitan backend error"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resolve(response.result);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const optionsFull = await invoke("optionsGetFull", undefined);
|
||||||
|
const profileIndex = optionsFull.profileCurrent;
|
||||||
|
const scanLength =
|
||||||
|
optionsFull.profiles?.[profileIndex]?.options?.scanning?.length ?? 40;
|
||||||
|
|
||||||
|
return await invoke("parseText", {
|
||||||
|
text: ${JSON.stringify(text)},
|
||||||
|
optionsContext: { index: profileIndex },
|
||||||
|
scanLength,
|
||||||
|
useInternalParser: true,
|
||||||
|
useMecabParser: true
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
`;
|
||||||
|
return parserWindow.webContents.executeJavaScript(script, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTextOutput(payload: Record<string, unknown>): void {
|
||||||
|
process.stdout.write(`Input: ${String(payload.input)}\n`);
|
||||||
|
process.stdout.write(`Tokenizer text: ${String(payload.tokenizerText)}\n`);
|
||||||
|
process.stdout.write(`Yomitan available: ${String(payload.yomitanAvailable)}\n`);
|
||||||
|
process.stdout.write(`Yomitan note: ${String(payload.yomitanNote ?? '')}\n`);
|
||||||
|
process.stdout.write(
|
||||||
|
`Selected candidate indexes: ${JSON.stringify(payload.selectedCandidateIndexes)}\n`,
|
||||||
|
);
|
||||||
|
process.stdout.write('\nFinal selected tokens:\n');
|
||||||
|
const finalTokens = payload.finalTokens as Array<Record<string, unknown>> | null;
|
||||||
|
if (!finalTokens || finalTokens.length === 0) {
|
||||||
|
process.stdout.write(' (none)\n');
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < finalTokens.length; i += 1) {
|
||||||
|
const token = finalTokens[i];
|
||||||
|
process.stdout.write(
|
||||||
|
` [${i}] ${token.surface} -> ${token.headword} (${token.reading}) [${token.startPos}, ${token.endPos})\n`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
process.stdout.write('\nYomitan parse candidates:\n');
|
||||||
|
const candidates = payload.candidates as Array<Record<string, unknown>>;
|
||||||
|
if (!candidates || candidates.length === 0) {
|
||||||
|
process.stdout.write(' (none)\n');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < candidates.length; i += 1) {
|
||||||
|
const candidate = candidates[i];
|
||||||
|
process.stdout.write(
|
||||||
|
` [${i}] source=${String(candidate.source)} index=${String(candidate.index)} selectedByTokenizer=${String(candidate.selectedByTokenizer)} tokenCount=${String(candidate.tokenCount)}\n`,
|
||||||
|
);
|
||||||
|
const tokens = candidate.tokens as Array<Record<string, unknown>> | undefined;
|
||||||
|
if (!tokens || tokens.length === 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (let j = 0; j < tokens.length; j += 1) {
|
||||||
|
const token = tokens[j];
|
||||||
|
process.stdout.write(
|
||||||
|
` - ${token.surface} -> ${token.headword} (${token.reading}) [${token.startPos}, ${token.endPos})\n`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function main(): Promise<void> {
|
||||||
|
const args = parseCliArgs(process.argv.slice(2));
|
||||||
|
const yomitan: YomitanRuntimeState = {
|
||||||
|
available: false,
|
||||||
|
note: null,
|
||||||
|
extension: null,
|
||||||
|
parserWindow: null,
|
||||||
|
parserReadyPromise: null,
|
||||||
|
parserInitPromise: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const mecabTokenizer = new MecabTokenizer({
|
||||||
|
mecabCommand: args.mecabCommand,
|
||||||
|
dictionaryPath: args.mecabDictionaryPath,
|
||||||
|
});
|
||||||
|
const isMecabAvailable = await mecabTokenizer.checkAvailability();
|
||||||
|
if (!isMecabAvailable) {
|
||||||
|
throw new Error('MeCab is not available on this system.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const runtime = await setupYomitanRuntime(args);
|
||||||
|
yomitan.available = runtime.available;
|
||||||
|
yomitan.note = runtime.note;
|
||||||
|
yomitan.extension = runtime.extension;
|
||||||
|
yomitan.parserWindow = runtime.parserWindow;
|
||||||
|
yomitan.parserReadyPromise = runtime.parserReadyPromise;
|
||||||
|
yomitan.parserInitPromise = runtime.parserInitPromise;
|
||||||
|
|
||||||
|
const deps = createTokenizerDepsRuntime({
|
||||||
|
getYomitanExt: () => yomitan.extension,
|
||||||
|
getYomitanParserWindow: () => yomitan.parserWindow,
|
||||||
|
setYomitanParserWindow: (window) => {
|
||||||
|
yomitan.parserWindow = window;
|
||||||
|
},
|
||||||
|
getYomitanParserReadyPromise: () => yomitan.parserReadyPromise,
|
||||||
|
setYomitanParserReadyPromise: (promise) => {
|
||||||
|
yomitan.parserReadyPromise = promise;
|
||||||
|
},
|
||||||
|
getYomitanParserInitPromise: () => yomitan.parserInitPromise,
|
||||||
|
setYomitanParserInitPromise: (promise) => {
|
||||||
|
yomitan.parserInitPromise = promise;
|
||||||
|
},
|
||||||
|
isKnownWord: () => false,
|
||||||
|
getKnownWordMatchMode: () => 'headword',
|
||||||
|
getJlptLevel: () => null,
|
||||||
|
getMecabTokenizer: () => ({
|
||||||
|
tokenize: (text: string) => mecabTokenizer.tokenize(text),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
const subtitleData = await tokenizeSubtitle(args.input, deps);
|
||||||
|
const tokenizeText = normalizeTokenizerText(args.input);
|
||||||
|
let rawParseResults: unknown = null;
|
||||||
|
if (
|
||||||
|
yomitan.available &&
|
||||||
|
yomitan.parserWindow &&
|
||||||
|
!yomitan.parserWindow.isDestroyed() &&
|
||||||
|
tokenizeText
|
||||||
|
) {
|
||||||
|
rawParseResults = await fetchRawParseResults(yomitan.parserWindow, tokenizeText);
|
||||||
|
}
|
||||||
|
|
||||||
|
const parsedCandidates = mapParseResultsToCandidates(rawParseResults);
|
||||||
|
const selectedCandidateIndexes = findSelectedCandidateIndexes(
|
||||||
|
parsedCandidates,
|
||||||
|
subtitleData.tokens,
|
||||||
|
);
|
||||||
|
const selectedIndexSet = new Set<number>(selectedCandidateIndexes);
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
input: args.input,
|
||||||
|
tokenizerText: subtitleData.text,
|
||||||
|
yomitanAvailable: yomitan.available,
|
||||||
|
yomitanNote: yomitan.note,
|
||||||
|
selectedCandidateIndexes,
|
||||||
|
finalTokens:
|
||||||
|
subtitleData.tokens?.map((token) => ({
|
||||||
|
surface: token.surface,
|
||||||
|
reading: token.reading,
|
||||||
|
headword: token.headword,
|
||||||
|
startPos: token.startPos,
|
||||||
|
endPos: token.endPos,
|
||||||
|
pos1: token.pos1,
|
||||||
|
partOfSpeech: token.partOfSpeech,
|
||||||
|
isKnown: token.isKnown,
|
||||||
|
isNPlusOneTarget: token.isNPlusOneTarget,
|
||||||
|
})) ?? null,
|
||||||
|
candidates: parsedCandidates.map((candidate, idx) => ({
|
||||||
|
source: candidate.source,
|
||||||
|
index: candidate.index,
|
||||||
|
selectedByTokenizer: selectedIndexSet.has(idx),
|
||||||
|
tokenCount: candidate.tokens.length,
|
||||||
|
tokens: candidate.tokens,
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (args.emitJson) {
|
||||||
|
process.stdout.write(`${JSON.stringify(payload, null, args.emitPretty ? 2 : undefined)}\n`);
|
||||||
|
} else {
|
||||||
|
renderTextOutput(payload);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
await shutdownYomitanRuntime(yomitan);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
.then(() => {
|
||||||
|
process.exit(0);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(`Error: ${(error as Error).message}`);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
42
scripts/verify-generated-launcher.sh
Executable file
42
scripts/verify-generated-launcher.sh
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
LAUNCHER_OUT="$REPO_ROOT/dist/launcher/subminer"
|
||||||
|
|
||||||
|
if [[ ! -f "$REPO_ROOT/launcher/main.ts" ]]; then
|
||||||
|
echo "[FAIL] launcher source missing: launcher/main.ts"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! grep -Fn -- "--outfile=\"\$(LAUNCHER_OUT)\"" "$REPO_ROOT/Makefile" >/dev/null; then
|
||||||
|
echo "[FAIL] Makefile build-launcher target is not writing to dist/launcher/subminer"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -f "$LAUNCHER_OUT" ]]; then
|
||||||
|
echo "[FAIL] generated launcher not found at dist/launcher/subminer"
|
||||||
|
echo " run: make build-launcher"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -x "$LAUNCHER_OUT" ]]; then
|
||||||
|
echo "[FAIL] generated launcher is not executable: dist/launcher/subminer"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -f "$REPO_ROOT/subminer" ]]; then
|
||||||
|
echo "[FAIL] stale repo-root launcher artifact found: ./subminer"
|
||||||
|
echo " expected generated location: dist/launcher/subminer"
|
||||||
|
echo " remove stale artifact and use: make build-launcher"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if git -C "$REPO_ROOT" ls-files --error-unmatch dist/launcher/subminer >/dev/null 2>&1; then
|
||||||
|
echo "[FAIL] dist/launcher/subminer is tracked by git; generated artifacts must remain untracked"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[OK] launcher workflow verified"
|
||||||
|
echo " source: launcher/*.ts"
|
||||||
|
echo " generated artifact: dist/launcher/subminer"
|
||||||
23
tsconfig.json
Normal file
23
tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "commonjs",
|
||||||
|
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
||||||
|
"outDir": "./dist",
|
||||||
|
"rootDir": "./src",
|
||||||
|
"strict": true,
|
||||||
|
"noUncheckedIndexedAccess": true,
|
||||||
|
"noImplicitOverride": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"isolatedModules": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"sourceMap": true
|
||||||
|
},
|
||||||
|
"include": ["src/**/*"],
|
||||||
|
"exclude": ["node_modules", "dist", "vendor"]
|
||||||
|
}
|
||||||
12
tsconfig.renderer.json
Normal file
12
tsconfig.renderer.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "es2022",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"rootDir": "./src",
|
||||||
|
"outDir": "./dist",
|
||||||
|
"declaration": false,
|
||||||
|
"declarationMap": false
|
||||||
|
},
|
||||||
|
"include": ["src/renderer/**/*"]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user