Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,27 @@ pnpm build:linux:arm64 # Linux (按 arm64 架构打包)
2. 输入应用名称或命令进行搜索
3. 按 `↑` `↓` `←` `→` 选择,`Enter` 确认,`Esc` 退出

### 命令行唤起

在终端执行 `ztools` 可以唤起已运行的 ZTools 实例并显示主窗口;如果应用尚未运行,则会先启动应用再显示窗口。命令会立即返回,不阻塞终端。

```bash
# Linux(deb 安装包)与 macOS 手动安装后可直接使用
ztools

# 开发环境中运行(先执行 pnpm build 构建主程序)
pnpm ztools

# 通过环境变量指定可执行文件
ZTOOLS_BIN=/path/to/ZTools ztools
```

不同安装方式下的可用性:

- **Linux deb**:安装包会自动创建 `/usr/bin/ztools` 命令,卸载时自动移除
- **macOS dmg**:首次使用需手动建立软链接:`sudo ln -s "/Applications/ZTools.app/Contents/Resources/ztools/ztools-launcher.sh" /usr/local/bin/ztools`
- **Windows**:仅覆盖开发环境(`pnpm ztools`)

## 🧩 插件开发

ZTools 是一个强大、可扩展的插件平台,使用自定义插件提升您的生产力。通过简单的配置、丰富的 API 以及跨平台支持,您可以轻松开发出功能强大的插件。
Expand Down Expand Up @@ -222,6 +243,9 @@ pnpm build:linux # 打包 Linux 应用 (当前主机架构)
pnpm build:linux:x64 # 打包 Linux 应用 (amd64/x64)
pnpm build:linux:arm64 # 打包 Linux 应用 (arm64)
pnpm build:unpack # 打包但不生成安装包(调试用)

# 命令行唤起
pnpm ztools # 唤起已运行的实例(或启动应用)
```

### 调试
Expand Down
24 changes: 24 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,27 @@ pnpm build:linux:arm64 # Linux (arm64)
2. Enter application name or command to search
3. Use `↑` `↓` `←` `→` to navigate, `Enter` to confirm, `Esc` to exit

### Wake Up from Command Line

Run `ztools` in a terminal to bring up an already running ZTools instance and show its main window; if the app is not running yet, it will be started first and then shown. The command returns immediately and does not block the terminal.

```bash
# Linux (deb package) and macOS (after manual install) can use it directly
ztools

# In the development environment (run pnpm build first)
pnpm ztools

# Point to a specific executable with an environment variable
ZTOOLS_BIN=/path/to/ZTools ztools
```

Availability by installation method:

- **Linux deb**: the package creates `/usr/bin/ztools` automatically and removes it on uninstall
- **macOS dmg**: create a symlink manually on first use: `sudo ln -s "/Applications/ZTools.app/Contents/Resources/ztools/ztools-launcher.sh" /usr/local/bin/ztools`
- **Windows**: development environment only (`pnpm ztools`)

## 🧩 Plugin Development

ZTools is a powerful and extensible plugin platform that enhances your productivity with custom plugins. With simple configuration, rich APIs, and cross-platform support, you can easily develop powerful plugins.
Expand Down Expand Up @@ -210,6 +231,9 @@ pnpm build:linux # Package Linux app (Default Arch)
pnpm build:linux:x64 # Package Linux app (amd64/x64)
pnpm build:linux:arm64 # Package Linux app (arm64)
pnpm build:unpack # Package without installer (for debugging)

# Command line wake-up
pnpm ztools # Wake up a running instance (or start the app)
```

### Debugging
Expand Down
57 changes: 57 additions & 0 deletions build/deb-after-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# ZTools deb 安装后脚本:在保留默认后置处理的基础上,
# 将 /usr/bin/ztools 符号链接指向命令行唤起启动器。

if type update-alternatives 2>/dev/null >&1; then
# Remove previous link if it doesn't use update-alternatives
if [ -L '/usr/bin/${executable}' -a -e '/usr/bin/${executable}' -a "`readlink '/usr/bin/${executable}'`" != '/etc/alternatives/${executable}' ]; then
rm -f '/usr/bin/${executable}'
fi
update-alternatives --install '/usr/bin/${executable}' '${executable}' '/opt/${sanitizedProductName}/${executable}' 100 || ln -sf '/opt/${sanitizedProductName}/${executable}' '/usr/bin/${executable}'
else
ln -sf '/opt/${sanitizedProductName}/${executable}' '/usr/bin/${executable}'
fi

# Check if user namespaces are supported by the kernel and working with a quick test:
if ! { [[ -L /proc/self/ns/user ]] && unshare --user true; }; then
# Use SUID chrome-sandbox only on systems without user namespaces:
chmod 4755 '/opt/${sanitizedProductName}/chrome-sandbox' || true
else
chmod 0755 '/opt/${sanitizedProductName}/chrome-sandbox' || true
fi

if hash update-mime-database 2>/dev/null; then
update-mime-database /usr/share/mime || true
fi

if hash update-desktop-database 2>/dev/null; then
update-desktop-database /usr/share/applications || true
fi

# 刷新 hicolor 图标缓存,缺失命令时静默跳过。
if hash gtk-update-icon-cache 2>/dev/null; then
gtk-update-icon-cache -f /usr/share/icons/hicolor || true
fi

# 安装 apparmor profile(Ubuntu 24+),与默认模板保持一致。
if apparmor_status --enabled > /dev/null 2>&1; then
APPARMOR_PROFILE_SOURCE='/opt/${sanitizedProductName}/resources/apparmor-profile'
APPARMOR_PROFILE_TARGET='/etc/apparmor.d/${executable}'
if apparmor_parser --skip-kernel-load --debug "$APPARMOR_PROFILE_SOURCE" > /dev/null 2>&1; then
cp -f "$APPARMOR_PROFILE_SOURCE" "$APPARMOR_PROFILE_TARGET"

if ! { [ -x '/usr/bin/ischroot' ] && /usr/bin/ischroot; } && hash apparmor_parser 2>/dev/null; then
apparmor_parser --replace --write-cache --skip-read-cache "$APPARMOR_PROFILE_TARGET"
fi
else
echo "Skipping the installation of the AppArmor profile as this version of AppArmor does not seem to support the bundled profile"
fi
fi

# 命令行唤起启动器:/usr/bin/ztools -> /opt/<product>/resources/ztools/ztools-launcher.sh
ztools_launcher='/opt/${sanitizedProductName}/resources/ztools/ztools-launcher.sh'
if [ -f "$ztools_launcher" ]; then
chmod +x "$ztools_launcher"
ln -sf "$ztools_launcher" '/usr/bin/ztools'
fi
28 changes: 28 additions & 0 deletions build/deb-after-remove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# ZTools deb 卸载后脚本:移除命令行唤起命令,并保留默认清理逻辑。

# 只移除指向 ZTools 启动器的 /usr/bin/ztools,避免误删用户自建的同名命令。
ztools_launcher='/opt/${sanitizedProductName}/resources/ztools/ztools-launcher.sh'
if [ -L '/usr/bin/ztools' ] && [ "$(readlink '/usr/bin/ztools')" = "$ztools_launcher" ]; then
rm -f '/usr/bin/ztools'
fi

# Delete the link to the binary
if type update-alternatives >/dev/null 2>&1; then
update-alternatives --remove '${executable}' '/usr/bin/${executable}'
else
rm -f '/usr/bin/${executable}'
fi

APPARMOR_PROFILE_DEST='/etc/apparmor.d/${executable}'

# Remove apparmor profile.
if [ -f "$APPARMOR_PROFILE_DEST" ]; then
rm -f "$APPARMOR_PROFILE_DEST"
fi

# 刷新 hicolor 图标缓存,缺失命令时静默跳过。
if hash gtk-update-icon-cache 2>/dev/null; then
gtk-update-icon-cache -f /usr/share/icons/hicolor || true
fi
Binary file added build/icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/icons/16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/icons/24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/icons/256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/icons/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/icons/48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/icons/512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/icons/64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions build/pacman-after-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# ZTools pacman 安装后脚本:创建命令行唤起启动器符号链接,
# 并刷新桌面数据库与图标缓存,确保应用菜单显示 ZTools 图标。

# 命令行唤起启动器:/usr/bin/ztools -> /opt/<product>/resources/ztools/ztools-launcher.sh
ztools_launcher='/opt/${sanitizedProductName}/resources/ztools/ztools-launcher.sh'
if [ -f "$ztools_launcher" ]; then
chmod +x "$ztools_launcher"
ln -sf "$ztools_launcher" '/usr/bin/ztools'
fi

# 刷新桌面入口数据库,缺失命令时静默跳过。
if hash update-desktop-database 2>/dev/null; then
update-desktop-database /usr/share/applications || true
fi

# 刷新 hicolor 图标缓存,缺失命令时静默跳过。
if hash gtk-update-icon-cache 2>/dev/null; then
gtk-update-icon-cache -f /usr/share/icons/hicolor || true
fi
20 changes: 20 additions & 0 deletions build/pacman-after-remove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# ZTools pacman 卸载后脚本:移除命令行唤起启动器符号链接,
# 并刷新桌面数据库与图标缓存。

# 只移除指向 ZTools 启动器的 /usr/bin/ztools,避免误删用户自建的同名命令。
ztools_launcher='/opt/${sanitizedProductName}/resources/ztools/ztools-launcher.sh'
if [ -L '/usr/bin/ztools' ] && [ "$(readlink '/usr/bin/ztools')" = "$ztools_launcher" ]; then
rm -f '/usr/bin/ztools'
fi

# 刷新桌面入口数据库,缺失命令时静默跳过。
if hash update-desktop-database 2>/dev/null; then
update-desktop-database /usr/share/applications || true
fi

# 刷新 hicolor 图标缓存,缺失命令时静默跳过。
if hash gtk-update-icon-cache 2>/dev/null; then
gtk-update-icon-cache -f /usr/share/icons/hicolor || true
fi
40 changes: 40 additions & 0 deletions build/ztools-launcher.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env sh

# ZTools 命令行唤起启动器。
# 打包时被 electron-builder 放入应用 resources/ztools/ 目录,
# 安装器会将 /usr/bin/ztools 符号链接指向本脚本。

# 脚本实际所在目录(resources/ztools)。通过符号链接调用时先解析真实路径。
# macOS 自带的 readlink 不支持 -f,这里逐层解析相对/绝对目标并限制深度,
# 避免死链或循环链导致脚本卡死。
SCRIPT_PATH=$0
SCRIPT_DEPTH=0
while [ -L "$SCRIPT_PATH" ]; do
SCRIPT_LINK=$(readlink "$SCRIPT_PATH")
case "$SCRIPT_LINK" in
/*) SCRIPT_PATH=$SCRIPT_LINK ;;
*) SCRIPT_PATH=$(dirname -- "$SCRIPT_PATH")/$SCRIPT_LINK ;;
esac
SCRIPT_DEPTH=$((SCRIPT_DEPTH + 1))
if [ "$SCRIPT_DEPTH" -gt 40 ]; then
echo "符号链接解析深度超限: $0" >&2
exit 1
fi
done
# pwd -P 输出物理路径,确保目录部分也不残留符号链接。
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$SCRIPT_PATH")" && pwd -P)

# 依次探测 Linux 与 macOS 打包布局中的真实可执行文件。
# 只接受普通文件(-f),避免像旧版那样把 resources/ztools 目录当作可执行文件 exec。
for BIN in \
"$SCRIPT_DIR/../../MacOS/ZTools" \
"$SCRIPT_DIR/../../ztools" \
"$SCRIPT_DIR/../../ZTools"
do
if [ -f "$BIN" ] && [ -x "$BIN" ]; then
exec "$BIN" --ztools-wake
fi
done

echo "未找到 ZTools 可执行文件(已探测 $SCRIPT_DIR/../../MacOS/ZTools、$SCRIPT_DIR/../../ztools、$SCRIPT_DIR/../../ZTools)" >&2
exit 1
8 changes: 6 additions & 2 deletions docs/examples/provider-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
```

```js
ztools.registerProvider('baidu', async (input) => { /* ... */ })
ztools.registerProvider('google', async (input) => { /* ... */ })
ztools.registerProvider('baidu', async (input) => {
/* ... */
})
ztools.registerProvider('google', async (input) => {
/* ... */
})
```

详见主程序 `docs/provider-development-guide.md`。
Expand Down
10 changes: 7 additions & 3 deletions docs/provider-development-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,20 @@ ZTools 把「翻译」「OCR」等能力抽象为 **Provider(提供商)**。
```json
{
"providers": {
"baidu": { "type": "translation", "label": "百度翻译" },
"baidu": { "type": "translation", "label": "百度翻译" },
"google": { "type": "translation", "label": "谷歌翻译" }
}
}
```

```js
// preload.js
ztools.registerProvider('baidu', async (input) => { /* 调用百度 */ })
ztools.registerProvider('google', async (input) => { /* 调用谷歌 */ })
ztools.registerProvider('baidu', async (input) => {
/* 调用百度 */
})
ztools.registerProvider('google', async (input) => {
/* 调用谷歌 */
})
```

两条都会出现在「设置 → 提供商 → 翻译」,用户可分别启用并选其中一个为默认。
Expand Down
18 changes: 18 additions & 0 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,31 @@ mac:
dmg:
artifactName: ${name}-${version}-${os}-${arch}.${ext}
linux:
# 显式指向多尺寸图标集 build/icons/(16x16…512x512),
# 避免自动发现优先命中 build/icon.png 而只向 hicolor 安装单尺寸图标。
icon: build/icons
target:
- AppImage
- deb
- pacman
maintainer: electronjs.org
category: Utility
appImage:
artifactName: ${name}-${version}-${os}-${arch}.${ext}
npmRebuild: false

extraResources:
- from: build/ztools-launcher.sh
to: ztools/ztools-launcher.sh
filter:
- '**/*'

deb:
afterInstall: build/deb-after-install.sh
afterRemove: build/deb-after-remove.sh

pacman:
afterInstall: build/pacman-after-install.sh
afterRemove: build/pacman-after-remove.sh

afterPack: ./build/afterPack.js
2 changes: 2 additions & 0 deletions internal-plugins/setting/src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ declare global {
enabled: boolean
) => Promise<{ success: boolean; error?: string }>
updateWindowPositionStrategy: (strategy: string) => Promise<void>
updateCssAppRegionDrag: (enabled: boolean) => Promise<void>
updateShowRecentInSearch: (showRecentInSearch: boolean) => Promise<void>
updateMatchRecommendation: (showMatchRecommendation: boolean) => Promise<void>
updateLocalAppSearch: (enabled: boolean) => Promise<void>
Expand Down Expand Up @@ -431,6 +432,7 @@ declare global {
getAppName: () => Promise<string>
getSystemVersions: () => Promise<NodeJS.ProcessVersions>
getPlatform: () => NodeJS.Platform
getLinuxSession: () => { isWayland: boolean }
isWindows11: () => Promise<boolean>

// 软件更新
Expand Down
Loading