可以实现跳转到devstar
This commit is contained in:
BIN
assets/images/logo.png
Normal file
BIN
assets/images/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
39
src/home.ts
39
src/home.ts
@@ -65,7 +65,6 @@ export default class DSHome {
|
|||||||
vscode.ViewColumn.One,
|
vscode.ViewColumn.One,
|
||||||
{
|
{
|
||||||
enableScripts: true,
|
enableScripts: true,
|
||||||
enableForms: true,
|
|
||||||
retainContextWhenHidden: true,
|
retainContextWhenHidden: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -163,6 +162,22 @@ export default class DSHome {
|
|||||||
case 'showErrorNotification':
|
case 'showErrorNotification':
|
||||||
await utils.showErrorNotification(data.message);
|
await utils.showErrorNotification(data.message);
|
||||||
break;
|
break;
|
||||||
|
case 'openExternalUrl':
|
||||||
|
// 修复:直接从 message 中获取 url,而不是从 data
|
||||||
|
const url = message.url || (data && data.url);
|
||||||
|
if (url) {
|
||||||
|
try {
|
||||||
|
await vscode.env.openExternal(vscode.Uri.parse(url));
|
||||||
|
vscode.window.showInformationMessage(`已在浏览器中打开: ${url}`);
|
||||||
|
} catch (error) {
|
||||||
|
vscode.window.showErrorMessage(`打开链接失败: ${url}`);
|
||||||
|
console.error('打开外部链接失败:', error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error('openExternalUrl: url is undefined', message);
|
||||||
|
vscode.window.showErrorMessage('打开链接失败: 链接地址无效');
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -243,12 +258,6 @@ export default class DSHome {
|
|||||||
<li class="feature-item" onclick="handleMainAction()" id="mainActionButton">
|
<li class="feature-item" onclick="handleMainAction()" id="mainActionButton">
|
||||||
主要功能
|
主要功能
|
||||||
</li>
|
</li>
|
||||||
<li class="feature-item" onclick="vscodePostMessage('showInformationNotification', {message: '功能2点击'})">
|
|
||||||
功能 2
|
|
||||||
</li>
|
|
||||||
<li class="feature-item" onclick="vscodePostMessage('showInformationNotification', {message: '功能3点击'})">
|
|
||||||
功能 3
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -328,16 +337,26 @@ export default class DSHome {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理主要功能点击
|
// 处理主要功能点击 - 修复消息发送格式
|
||||||
function handleMainAction() {
|
function handleMainAction() {
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
// 已登录:跳转到本地80端口
|
// 已登录:跳转到本地80端口
|
||||||
vscodePostMessage('showInformationNotification', {message: '跳转到本地服务 http://localhost:80'});
|
vscodePostMessage('showInformationNotification', {message: '跳转到本地服务 http://localhost:80'});
|
||||||
window.open('http://localhost:80', '_blank');
|
// 修复:直接发送包含 url 的消息
|
||||||
|
vscode.postMessage({
|
||||||
|
command: 'openExternalUrl',
|
||||||
|
need_return: false,
|
||||||
|
url: 'http://localhost:80'
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// 未登录:跳转到 DevStar 官网
|
// 未登录:跳转到 DevStar 官网
|
||||||
vscodePostMessage('showInformationNotification', {message: '跳转到 DevStar 官网'});
|
vscodePostMessage('showInformationNotification', {message: '跳转到 DevStar 官网'});
|
||||||
window.open('https://devstar.cn', '_blank');
|
// 修复:直接发送包含 url 的消息
|
||||||
|
vscode.postMessage({
|
||||||
|
command: 'openExternalUrl',
|
||||||
|
need_return: false,
|
||||||
|
url: 'https://devstar.cn'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user