Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
"command": "packy-usage.showExplorer",
"title": "Show Usage Explorer",
"category": "Packy Usage"
},
{
"command": "packy-usage.toggleSidebar",
"title": "Toggle Sidebar",
"category": "Packy Usage"
}
],
"configuration": {
Expand All @@ -75,6 +80,12 @@
"default": "https://www.packycode.com/api/backend/users/info",
"description": "API endpoint for budget data",
"scope": "application"
},
"packy-usage.showSidebar": {
"type": "boolean",
"default": true,
"description": "Show or hide the Packy Usage sidebar panel",
"scope": "application"
}
}
},
Expand All @@ -92,7 +103,7 @@
{
"id": "packy-usage.explorer",
"name": "Usage Explorer",
"when": "true"
"when": "config.packy-usage.showSidebar"
}
]
},
Expand Down
18 changes: 18 additions & 0 deletions src/controllers/command.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export class CommandController {
),
vscode.commands.registerCommand("packy-usage.showExplorer", () =>
this.handleShowExplorer()
),
vscode.commands.registerCommand("packy-usage.toggleSidebar", () =>
this.handleToggleSidebar()
)
]
}
Expand Down Expand Up @@ -174,6 +177,21 @@ export class CommandController {
vscode.commands.executeCommand("packy-usage.explorer.focus")
}

/**
* 处理切换侧边栏显示状态命令
*/
private async handleToggleSidebar(): Promise<void> {
try {
const newVisible = await this.configService.toggleSidebarVisible()
const message = newVisible ? "侧边栏已显示" : "侧边栏已隐藏"
vscode.window.showInformationMessage(message)
} catch (error) {
vscode.window.showErrorMessage(
`切换侧边栏状态失败: ${(error as Error).message}`
)
}
}

/**
* 显示Token设置提示
*/
Expand Down
43 changes: 42 additions & 1 deletion src/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
pollingInterval: number
/** 状态栏刷新间隔(毫秒) */
statusBarRefreshInterval: number
/** 是否显示侧边栏 */
showSidebar: boolean

Check failure on line 18 in src/services/config.service.ts

View workflow job for this annotation

GitHub Actions / test

Expected "showSidebar" to come before "statusBarRefreshInterval"
}

/**
Expand All @@ -30,7 +32,8 @@
apiEndpoint: "https://www.packycode.com/api/backend/users/info",
enablePolling: true,
pollingInterval: 30000, // 30秒
statusBarRefreshInterval: 1000 // 1秒
statusBarRefreshInterval: 1000, // 1秒
showSidebar: true

Check failure on line 36 in src/services/config.service.ts

View workflow job for this annotation

GitHub Actions / test

Expected "showSidebar" to come before "statusBarRefreshInterval"
}

/**
Expand Down Expand Up @@ -76,6 +79,10 @@
statusBarRefreshInterval: config.get<number>(
"statusBarRefreshInterval",
ConfigService.DEFAULT_CONFIG.statusBarRefreshInterval
),
showSidebar: config.get<boolean>(

Check failure on line 83 in src/services/config.service.ts

View workflow job for this annotation

GitHub Actions / test

Expected "showSidebar" to come before "statusBarRefreshInterval"
"showSidebar",
ConfigService.DEFAULT_CONFIG.showSidebar
)
}
}
Expand All @@ -90,6 +97,7 @@
- 轮询间隔: ${config.pollingInterval}ms
- 启用轮询: ${config.enablePolling}
- 状态栏刷新: ${config.statusBarRefreshInterval}ms
- 侧边栏显示: ${config.showSidebar}
- Token配置: ${config.apiToken ? "已配置" : "未配置"}`
}

Expand Down Expand Up @@ -126,6 +134,15 @@
.get<boolean>("enablePolling", ConfigService.DEFAULT_CONFIG.enablePolling)
}

/**
* 获取是否显示侧边栏
*/
isSidebarVisible(): boolean {
return vscode.workspace
.getConfiguration(ConfigService.CONFIG_SECTION)
.get<boolean>("showSidebar", ConfigService.DEFAULT_CONFIG.showSidebar)
}

/**
* 监听配置变更
*/
Expand Down Expand Up @@ -167,6 +184,11 @@
"statusBarRefreshInterval",
ConfigService.DEFAULT_CONFIG.statusBarRefreshInterval,
vscode.ConfigurationTarget.Global
),
config.update(
"showSidebar",
ConfigService.DEFAULT_CONFIG.showSidebar,
vscode.ConfigurationTarget.Global
)
])
}
Expand All @@ -180,6 +202,25 @@
.update("apiToken", token, vscode.ConfigurationTarget.Global)
}

/**
* 设置侧边栏显示状态
*/
async setSidebarVisible(visible: boolean): Promise<void> {
await vscode.workspace
.getConfiguration(ConfigService.CONFIG_SECTION)
.update("showSidebar", visible, vscode.ConfigurationTarget.Global)
}

/**
* 切换侧边栏显示状态
*/
async toggleSidebarVisible(): Promise<boolean> {
const currentVisible = this.isSidebarVisible()
const newVisible = !currentVisible
await this.setSidebarVisible(newVisible)
return newVisible
}

/**
* 验证配置是否有效
*/
Expand Down
Loading