Skip to content

Commit

Permalink
feat: 添加打开本地目录按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
aooiuu committed May 15, 2024
1 parent 45705cd commit dae639d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "any-reader",
"description": "自定义规则多站点聚合搜索阅读小说、漫画。包含JS规则解析库和VSCode插件。支持本地小说 TXT、EPUB",
"icon": "resources/icon.png",
"version": "1.0.0",
"version": "1.0.1",
"publisher": "aooiu",
"qna": "https://github.com/aooiuu/any-reader/issues",
"bugs": {
Expand Down
11 changes: 10 additions & 1 deletion packages/vscode/src/webview/WebviewEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import * as vscode from 'vscode';
import * as EasyPostMessage from 'easy-post-message';
import { ContentType, Rule, RuleManager } from '@any-reader/core';
import { CONSTANTS } from '@any-reader/shared';
import * as localBookManager from '@any-reader/shared/localBookManager';
import type { BookChapter } from '@any-reader/shared/localBookManager';
import { COMMANDS } from '../constants';
import * as ruleFileManager from '../utils/ruleFileManager';
import { createAdapter } from '../utils/easyPostMessage';
import favoritesProvider from '../sidebar/favorites';
import favoritesManager from '../utils/favoritesManager';
import historyManager from '../utils/historyManager';
import * as localBookManager from '@any-reader/shared/localBookManager';
import openExplorer from 'explorer-opener';

function success(data: any, msg = '') {
return {
Expand Down Expand Up @@ -57,6 +59,7 @@ export class WebviewEvent {
this._pm.answer('post@vscode/getChapter', this._vscGetChapter.bind(this));
this._pm.answer('get@vscode/editBookSource', this._vscEditBookSource.bind(this));
this._pm.answer('get@vscode/github', this._vscGithub.bind(this));
this._pm.answer('get@vscode/openLocalBookDir', this._vscOpenLocalBookDir.bind(this));

this._pm.answer('get@discoverMap', this._discoverMap.bind(this));
this._pm.answer('get@getFavorites', this._getFavorites.bind(this));
Expand All @@ -74,6 +77,12 @@ export class WebviewEvent {
this._pm.answer('post@getChapter', this._getChapter.bind(this));
}

// 打开本地书籍目录
_vscOpenLocalBookDir() {
localBookManager.checkDir();
openExplorer(CONSTANTS.LOCAL_BOOK_DIR);
}

// github
private _vscGithub() {
const doc = 'https://github.com/aooiuu/any-reader';
Expand Down
7 changes: 7 additions & 0 deletions packages/web/src/api/vsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ export function github() {
url: 'vscode/github'
});
}

export function openLocalBookDir() {
return request({
method: 'get',
url: 'vscode/openLocalBookDir'
});
}
18 changes: 14 additions & 4 deletions packages/web/src/pages/home/Local.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
<template>
<div class="w-full">
<TreeItem v-for="item in list" :key="item.path" @click="showChapter(item)">
{{ item.name }}
</TreeItem>
<div class="w-full h-full flex flex-col">
<div class="flex-1 overflow-auto">
<TreeItem v-for="item in list" :key="item.path" @click="showChapter(item)">
{{ item.name }}
</TreeItem>
</div>

<vscode-divider />
<div class="my-4 mx-8 flex items-center" @click="openLocalBookDir">
<i class="codicon codicon-folder-opened mr-2"></i>
打开本地目录
</div>
<vscode-divider />
</div>
</template>

<script setup>
import { getLocalBooks } from '@/api';
import { openLocalBookDir } from '@/api/vsc';
import TreeItem from '@/components/vsc/TreeItem.vue';
const router = useRouter();
Expand Down
6 changes: 4 additions & 2 deletions packages/web/src/plugins/vsc-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
vsCodeTextField,
vsCodeDropdown,
vsCodeOption,
vsCodeProgressRing
vsCodeProgressRing,
vsCodeDivider
} from '@vscode/webview-ui-toolkit';

provideVSCodeDesignSystem().register(
Expand All @@ -21,5 +22,6 @@ provideVSCodeDesignSystem().register(
vsCodeTextField(),
vsCodeDropdown(),
vsCodeOption(),
vsCodeProgressRing()
vsCodeProgressRing(),
vsCodeDivider()
);

0 comments on commit dae639d

Please sign in to comment.