登录后可以跳转到用户首页
This commit is contained in:
46
src/home.ts
46
src/home.ts
@@ -345,7 +345,7 @@ export default class DSHome {
|
||||
loginStatus.classList.add('logged-in');
|
||||
statusText.textContent = '已登录';
|
||||
usernameDisplay.textContent = username ? ' - 用户: ' + username : '';
|
||||
mainActionButton.textContent = '跳转到本地服务 (端口 80)';
|
||||
mainActionButton.textContent = '跳转到个人主页';
|
||||
} else {
|
||||
loginStatus.classList.remove('logged-in');
|
||||
loginStatus.classList.add('logged-out');
|
||||
@@ -358,18 +358,44 @@ export default class DSHome {
|
||||
// 处理主要功能点击 - 修复消息发送格式
|
||||
function handleMainAction() {
|
||||
if (isLoggedIn) {
|
||||
// 已登录:跳转到本地80端口
|
||||
vscodePostMessage('showInformationNotification', {message: '跳转到本地服务 http://localhost:80'});
|
||||
// 修复:直接发送包含 url 的消息
|
||||
vscode.postMessage({
|
||||
command: 'openExternalUrl',
|
||||
need_return: false,
|
||||
url: 'http://localhost:80'
|
||||
});
|
||||
// 已登录:跳转到 hostname/username
|
||||
// 使用 async 函数处理异步操作
|
||||
(async () => {
|
||||
try {
|
||||
// 获取必要的用户信息
|
||||
const devstarDomainResult = await communicateVSCode('getDevstarDomain', {});
|
||||
const usernameResult = await communicateVSCode('getUsername', {});
|
||||
|
||||
const devstarDomain = devstarDomainResult.devstarDomain;
|
||||
const username = usernameResult.username;
|
||||
|
||||
if (devstarDomain && username) {
|
||||
const targetUrl = \`\${devstarDomain}/\${username}\`;
|
||||
|
||||
vscodePostMessage('showInformationNotification', {
|
||||
message: \`跳转到 \${targetUrl}\`
|
||||
});
|
||||
|
||||
vscode.postMessage({
|
||||
command: 'openExternalUrl',
|
||||
need_return: false,
|
||||
url: targetUrl
|
||||
});
|
||||
} else {
|
||||
vscodePostMessage('showErrorNotification', {
|
||||
message: '无法获取域名或用户名信息'
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('跳转失败:', error);
|
||||
vscodePostMessage('showErrorNotification', {
|
||||
message: '跳转失败,请重试'
|
||||
});
|
||||
}
|
||||
})();
|
||||
} else {
|
||||
// 未登录:跳转到 DevStar 官网
|
||||
vscodePostMessage('showInformationNotification', {message: '跳转到 DevStar 官网'});
|
||||
// 修复:直接发送包含 url 的消息
|
||||
vscode.postMessage({
|
||||
command: 'openExternalUrl',
|
||||
need_return: false,
|
||||
|
||||
@@ -84,9 +84,6 @@ export class DevStarExtension {
|
||||
this.dsHome.setUser(this.user)
|
||||
this.dsHome.setRemoteContainer(this.remoteContainer)
|
||||
|
||||
//防止进入HOME页面
|
||||
// vscode.commands.executeCommand('devstar.showHome');
|
||||
|
||||
// 将devstar domain存在global state中
|
||||
context.globalState.update('devstarDomain', devstarDomain)
|
||||
|
||||
@@ -147,9 +144,6 @@ export class DevStarExtension {
|
||||
this.dsHome.setUser(this.user)
|
||||
this.dsHome.setRemoteContainer(this.remoteContainer)
|
||||
|
||||
//防止进入HOME页面
|
||||
// vscode.commands.executeCommand('devstar.showHome');
|
||||
|
||||
// 将devstar domain存在global state中
|
||||
context.globalState.update('devstarDomain', devstarDomain)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user