Skip to content

Commit

Permalink
Trim code.
Browse files Browse the repository at this point in the history
  • Loading branch information
cweijan committed Mar 8, 2024
1 parent 18901f8 commit c579641
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as vscode from 'vscode';
import { autoClearCacheStorage } from './service/autoClearCacheStorage';
import { JavaDecompilerProvider } from './provider/javaDecompilerProvider';
import { MarkdownEditorProvider } from './provider/markdownEditorProvider';
import { OfficeViewerProvider } from './provider/officeViewerProvider';
Expand All @@ -12,7 +11,6 @@ const httpExt = require('./bundle/extension');

export function activate(context: vscode.ExtensionContext) {
activeHTTP(context)
autoClearCacheStorage();
const viewOption = { webviewOptions: { retainContextWhenHidden: true, enableFindWidget: true } };
FileUtil.init(context)
ViewManager.init(context)
Expand Down
18 changes: 7 additions & 11 deletions src/service/autoClearCacheStorage.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
/*
本扩展的 markdown 编辑器会创建 WebView 实例,而 VS Code 则每次都随之在 "Service Worker\CacheStorage" 里创建对应的缓存文件。但之后,这些文件不会被自动清理……
为了避免无限膨胀,就需要你时不时地去手动清理。显然,这样做是个麻烦,所以应当自动化。
该缓存文件夹的具体位置为:
%appdata%\Roaming\Code\Service Worker\CacheStorage
而 %appdata% 在 Windows 里,是 C:\Users\[用户名]\AppData
*/
import { Output } from "@/common/Output";
import { existsSync, rm } from "fs";
import { homedir } from "os";
import { join } from "path";

/**
* 清空vscode webview缓存
*/
/*
旧版本的VS Code每次打开webview都会对资源文件进行缓存, 导致占用大量空间, 新版本不会再重复缓存, 因此不再需要自动清理了.
缓存路径:
- Windows: C:\Users\<userid>\AppData\Roaming\Code\Service Worker\CacheStorage
- Linux: /home/<userid>/.config/Code/Service Worker/CacheStorage
- macOS: /Users/<userid>/Library/Application Support/Code/Service Worker/CacheStorage
*/
export function autoClearCacheStorage() {
const dir = join(homedir(), 'AppData/Roaming/Code/Service Worker/CacheStorage')
if (!existsSync(dir)) return;
Expand Down

0 comments on commit c579641

Please sign in to comment.