UNPKG

pag-player

Version:

pag预览插件

85 lines (74 loc) 3.18 kB
/* * @Author: wangpan pan.wang@ushow.media * @Date: 2025-03-11 23:39:56 * @LastEditors: wangpan pan.wang@ushow.media * @LastEditTime: 2025-03-13 14:28:51 * @FilePath: /pag-preview/src/extension.ts * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ import * as vscode from 'vscode'; import PagPreview, {PagCustomEditorProvider} from './pag-preview'; import * as fs from 'fs'; export function activate(context: vscode.ExtensionContext) { // fileSizeStatusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100); console.log('进来了吗?'); context.subscriptions.push(PagPreview(context)); // context.subscriptions.push(FileSize(context, fileSizeStatusBarItem)); // 监听标签变化 const tabChangeDisposable = vscode.window.tabGroups.onDidChangeTabs((e) => { e.changed.forEach((tab) => { // if (tab.input instanceof vscode.TabInputText) { // console.log('切换到文本标签:', tab.input.uri.fsPath); // } else if (tab.input instanceof vscode.TabInputCustom) { // console.log('切换到自定义标签:', tab.input.viewType); // } if (tab.input instanceof vscode.TabInputCustom && tab.input.viewType === PagCustomEditorProvider.viewType) { console.log('切换到 PAG 预览标签'); } }); }); context.subscriptions.push(tabChangeDisposable); // 注册命令 const fileDetailCommand = vscode.commands.registerCommand('pag-preview.fileDetail', async() => { // 获取文件详情 // console.log(uri, 3333333); // const fileSize = getFileSize(uri.fsPath); // const fileInfo = `File: ${uri.fsPath}\nSize: ${fileSize} bytes`; const msg = 'Hello World!'; // 显示文件详情 // vscode.window.showInformationMessage(msg); // // 显示弹窗 // // const result = await vscode.window.showWarningMessage(msg, { modal: true }, 'OK', 'Cancel'); // const result = await vscode.window.showWarningMessage(msg, { modal: true }, 'OK'); // // const result = await vscode.window.showErrorMessage(msg, { modal: true }, 'OK'); // if (result === 'OK') { // vscode.window.showInformationMessage('You clicked OK'); // } else { // vscode.window.showInformationMessage('You clicked Cancel'); // } // // 显示弹窗选择列表 // const options = [ // { label: 'File Path', description: './a.pag' }, // { label: 'File Size', description: `2048 bytes` }, // ]; // const selected = await vscode.window.showQuickPick(options, { // placeHolder: 'PAG File Details', // canPickMany: false, // }); // if (selected) { // vscode.window.showInformationMessage(`You selected: ${selected.label}`); // } }); context.subscriptions.push(fileDetailCommand); } // 获取文件大小 function getFileSize(filePath: string): number { try { const stats = fs.statSync(filePath); return stats.size; } catch (error) { console.error("Failed to get file size:", error); return 0; } } export function deactivate() {}