Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zhb2000 committed Mar 17, 2024
0 parents commit db807ed
Show file tree
Hide file tree
Showing 91 changed files with 10,840 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.db filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/icon.ico filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/Square310x310Logo.png filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/128x128.png filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/Square150x150Logo.png filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/Square89x89Logo.png filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/Square71x71Logo.png filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/icon.png filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/Square107x107Logo.png filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/Square142x142Logo.png filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/Square30x30Logo.png filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/Square44x44Logo.png filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/[email protected] filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/32x32.png filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/icon.icns filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/Square284x284Logo.png filter=lfs diff=lfs merge=lfs -text
src-tauri/icons/StoreLogo.png filter=lfs diff=lfs merge=lfs -text
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
*.local.*
*.local/

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"Vue.volar",
"tauri-apps.tauri-vscode",
"rust-lang.rust-analyzer"
]
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# 更新日志
## [0.0.1] - 2024-03-17

第一个版本。
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<div align="center">
<img src="./src-tauri/icons/icon.png" alt="Anki 划词助手" title="Anki 划词助手" width="64">
</div>

<div align="center"><h1>Anki 划词助手</h1></div>

Anki 划词助手是一个制作 Anki 卡片的工具,你可以用它标记句子中的生词,通过“单词结合上下文”的方式更好地背单词。

本项目受到了 [mmjang / ankihelper](https://github.com/mmjang/ankihelper) 的启发。由于原项目是 Android 应用,而且已经不再维护,而我自己用电脑的时间更多,于是自己用 [Tauri](https://github.com/tauri-apps/tauri) 写了一个类似的工具。

<p align="center">
<img src="./docs/assets/main-screenshot.png" width="600" alt="主界面" title="主界面">
</p>

# 安装
## 安装划词助手本体

[Releases 页面](https://github.com/zhb2000/anki-marker/releases)提供了 Windows 平台的便携式应用(.zip)和安装包(.msi/.exe),其余平台请自行编译。

Anki 划词助手是一个基于 Tauri 的桌面应用,你的 Windows 系统需要带有 [Microsoft Edge WebView2](https://developer.microsoft.com/zh-cn/microsoft-edge/webview2/) 才能运行(Windows 10 2004 及以上版本已经自带)。

## 安装辅助工具

Anki 划词助手需要通过 AnkiConnect 插件与 Anki 进行通信,你需要先安装 **Anki 应用****AnkiConnect 插件**

1. 安装 Anki 应用:[Anki - powerful, intelligent flashcards](https://apps.ankiweb.net/)
1. 安装 AnkiConnect 插件:[AnkiConnect - AnkiWeb](https://ankiweb.net/shared/info/2055492159)。安装方法如下:
1. 打开 Anki,点击“工具-插件”。
1. 点击“获取插件”,输入 AnkiConnect 的代码 `2055492159`,点击“确定”。
1. 重启 Anki 应用。

# 使用

使用 Anki 划词助手时,请确保 **Anki 应用已经打开**,AnkiConnect 的服务会在 Anki 启动时自动开启。

AnkiConnect 默认会在 `localhost:8765` 上启动一个 HTTP 服务,如果你修改了 AnkiConnect 的端口号,请在设置中将“AnkiConnect 服务”这一项修改为对应的 URL:

<p align="center">
<img src="./docs/assets/settings-screenshot.png" width="600" alt="应用设置" title="应用设置">
</p>

划词界面:

<p align="center">
<img src="./docs/assets/main-screenshot.png" width="600" alt="主界面" title="主界面">
</p>

添加的 Anki 卡片(正面/背面):

<p align="center">
<img src="./docs/assets/anki-card-front.png" alt="Anki 卡片正面" title="Anki 卡片正面" width="300">
<img src="./docs/assets/anki-card-back.png" alt="Anki 卡片背面" title="Anki 卡片背面" width="300">
</p>

# 开发

开发模式:

```shell
cargo tauri dev
# 或者
npm run tauri dev
```

打包成 Windows 安装包和便携式应用:

```shell
node build-for-windows.js
```

打包好的便携式应用位于 `src-tauri/target/release/portable` 目录下,安装包位于 `src-tauri/target/release/bundle` 目录下。
89 changes: 89 additions & 0 deletions build-for-windows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/** Build portable zip and bundle installer for Windows. */

import { spawn } from 'child_process';
import fs from 'fs';
import path from 'path';
import archiver from 'archiver';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
// ES模块中处理__dirname
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

/**
* @param {string} productName
* @param {string} portableName
*/
function makePortable(productName, portableName) {
const releaseDir = path.join(__dirname, 'src-tauri/target/release');
const portableDir = path.join(releaseDir, 'portable');
const packDir = path.join(portableDir, portableName);

// 在 release 目录下创建 portable 目录
if (!fs.existsSync(packDir)) {
fs.mkdirSync(packDir, { recursive: true });
}
// 拷贝 exe 和 resources 目录到 portable 目录
fs.copyFileSync(
path.join(releaseDir, `${productName}.exe`),
path.join(packDir, `${productName}.exe`)
);
fs.cpSync(
path.join(releaseDir, 'resources'),
path.join(packDir, 'resources'),
{ recursive: true }
);
fs.unlinkSync(path.join(packDir, 'resources/icon.ico'));
// 拷贝并重命名 config-template.toml 为 config.toml
fs.copyFileSync(
path.join(releaseDir, 'resources/config-template.toml'),
path.join(packDir, 'config.toml')
);

// 将压缩 portable 目录为 zip
console.log(`开始压缩 ${portableName}.zip ...`);
const output = fs.createWriteStream(path.join(portableDir, `${portableName}.zip`));
output.on('close', function () {
const sizeInBytes = archive.pointer();
const sizeInMegabytes = (sizeInBytes / (1024 * 1024)).toFixed(2);
console.log(`${portableName}.zip 压缩完成,总大小: ${sizeInMegabytes} MB`);
});
const archive = archiver('zip', {
zlib: { level: 9 } // 设置压缩级别
});
archive.on('error', function (err) {
throw err;
});
archive.pipe(output);
archive.directory(packDir, false);
archive.finalize();
}

function main() {
/** @type {boolean} */
const skipBuild = process.argv.includes('--skip-build');
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
/** @type {string} */
const version = packageJson.version;
const tauriJson = JSON.parse(fs.readFileSync(path.join(__dirname, 'src-tauri/tauri.conf.json'), 'utf8'));
/** @type {string} */
const productName = tauriJson.package.productName;
const portableName = `${productName}_${version}_windows-portable`;
if (skipBuild) {
console.log('tauri build 已跳过');
makePortable(productName, portableName);
return;
}
// 使用 spawn 替代 exec 来实时显示输出
// 使用 stdio: 'inherit' 保证 tauri 的彩色输出
const buildProcess = spawn('npm', ['run', 'tauri', 'build'], { shell: true, stdio: 'inherit' });
buildProcess.on('close', code => {
if (code !== 0) {
console.error(`tauri build 失败,退出码 ${code}`);
return;
}
makePortable(productName, portableName);
});
}

main();
Binary file added docs/assets/anki-card-back.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 docs/assets/anki-card-front.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 docs/assets/main-screenshot.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 docs/assets/settings-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions docs/tauri-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Tauri + Vue 3 + TypeScript

This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.

## Recommended IDE Setup

- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)

## Type Support For `.vue` Imports in TS

Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's Take Over mode by following these steps:

1. Run `Extensions: Show Built-in Extensions` from VS Code's command palette, look for `TypeScript and JavaScript Language Features`, then right click and select `Disable (Workspace)`. By default, Take Over mode will enable itself if the default TypeScript extension is disabled.
2. Reload the VS Code window by running `Developer: Reload Window` from the command palette.

You can learn more about Take Over mode [here](https://github.com/johnsoncodehk/volar/discussions/471).
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/tauri.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Anki 划词助手</title>
</head>

<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
Loading

0 comments on commit db807ed

Please sign in to comment.