/** * 试用期过期检测服务 * 功能:检查插件试用用户是否过期 * 依赖:vscode, userService * 使用场景:用户使用功能前检查是否过期 */ import * as vscode from 'vscode'; import { getCachedUserInfo } from './userService'; export class TrialExpirationService { private context: vscode.ExtensionContext; private panel?: vscode.WebviewPanel; constructor(context: vscode.ExtensionContext, panel?: vscode.WebviewPanel) { this.context = context; this.panel = panel; } /** * 检查是否过期 * @returns true=已过期,false=未过期 */ public async checkExpiration(): Promise { const userInfo = getCachedUserInfo(); // 不是插件试用用户,不需要检查 if (!userInfo?.isPluginTrial) { return false; } // 没有过期时间,不检查 if (!userInfo.pluginTrialExpiresAt) { return false; } // 检查是否过期 const now = Date.now(); if (now >= userInfo.pluginTrialExpiresAt) { // 已过期 await this.handleExpired(); return true; } return false; } /** * 处理过期逻辑 */ private async handleExpired(): Promise { // 通知前端显示过期弹窗 if (this.panel) { this.panel.webview.postMessage({ command: 'showExpiredModal' }); console.log('[TrialExpirationService] 已通知前端显示过期弹窗'); } else { console.warn('[TrialExpirationService] panel 未提供,无法显示过期弹窗'); } } }