add news page
This commit is contained in:
parent
30937087dd
commit
e43431a725
3
.gitignore
vendored
3
.gitignore
vendored
@ -17,4 +17,5 @@ resources/service
|
||||
.turbo
|
||||
stats.html
|
||||
.openmcp
|
||||
test-vsix
|
||||
test-vsix
|
||||
resources/changelog/index.html
|
@ -2,6 +2,7 @@ import * as vscode from 'vscode';
|
||||
import { setRunningCWD, setVscodeWorkspace } from '../openmcp-sdk/service/index.js';
|
||||
import { launch } from './common/entry.js';
|
||||
import { initialiseI18n, getAvailableKeys } from './i18n/index.js';
|
||||
import { checkNews } from './webview/webview.service.js';
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
console.log('activate openmcp');
|
||||
@ -19,6 +20,7 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
console.log('Available i18n keys:', getAvailableKeys().length);
|
||||
|
||||
launch(context);
|
||||
checkNews(context);
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,9 +18,6 @@ export function getWebviewContent(context: vscode.ExtensionContext, panel: vscod
|
||||
return replaceHref;
|
||||
});
|
||||
|
||||
console.log(html);
|
||||
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
@ -151,7 +148,25 @@ export function getDefaultLanunchSignature(path: string, cwd: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export function revealOpenMcpWebviewPanel(
|
||||
|
||||
export function getNewsWebviewContent(context: vscode.ExtensionContext, panel: vscode.WebviewPanel): string | undefined {
|
||||
const viewRoot = fspath.join(context.extensionPath, 'resources', 'changelog');
|
||||
const htmlIndexPath = fspath.join(viewRoot, 'index.html');
|
||||
|
||||
const html = fs.readFileSync(htmlIndexPath, { encoding: 'utf-8' })?.replace(/(<link.+?href="|<script.+?src="|<img.+?src="|url\()(.+?)(\)|")/g, (m, $1, $2) => {
|
||||
const importFile = $2 as string;
|
||||
const rel = importFile.startsWith('/') ? importFile.substring(1) : importFile;
|
||||
const absLocalPath = fspath.resolve(viewRoot, rel);
|
||||
|
||||
const webviewUri = panel.webview.asWebviewUri(vscode.Uri.file(absLocalPath));
|
||||
const replaceHref = $1 + webviewUri?.toString() + '"';
|
||||
return replaceHref;
|
||||
});
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
export function revealOpenMcpNewsWebviewPanel(
|
||||
context: vscode.ExtensionContext,
|
||||
) {
|
||||
|
||||
@ -167,19 +182,27 @@ export function revealOpenMcpWebviewPanel(
|
||||
);
|
||||
|
||||
// 设置HTML内容
|
||||
const html = getWebviewContent(context, panel);
|
||||
const html = getNewsWebviewContent(context, panel);
|
||||
panel.webview.html = html || '';
|
||||
panel.iconPath = vscode.Uri.file(fspath.join(context.extensionPath, 'openmcp-sdk', 'renderer', 'images', 'openmcp.png'));
|
||||
|
||||
panel.onDidDispose(async () => {
|
||||
// 删除
|
||||
panels.delete(panelKey);
|
||||
|
||||
// TODO: 通过引用计数器关闭后端的 clientMap
|
||||
|
||||
// 退出
|
||||
panel.dispose();
|
||||
});
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
export async function checkNews(context: vscode.ExtensionContext) {
|
||||
const versionKey = 'openmcp-news-version';
|
||||
const lastVersion = context.globalState.get<string>(versionKey) || '';
|
||||
|
||||
const currentVersion = context.extension.packageJSON.version;
|
||||
if (lastVersion !== currentVersion) {
|
||||
// 记录新版本
|
||||
await context.globalState.update(versionKey, currentVersion);
|
||||
// 展示新闻面板
|
||||
revealOpenMcpNewsWebviewPanel(context);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user