Skip to content

Commit 1d0ce59

Browse files
committed
feat: vscode 把确认框向上移动一些,避免鼠标移动距离太远
1 parent 040fa56 commit 1d0ce59

File tree

1 file changed

+94
-2
lines changed

1 file changed

+94
-2
lines changed

killport-vscode/src/SidebarProvider.ts

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,57 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
202202
}
203203
.kill-btn:hover { background: #E60000; }
204204
.status-bar { font-size: 12px; color: var(--vscode-descriptionForeground); margin-top: 5px; }
205+
206+
/* Confirmation Overlay */
207+
.overlay {
208+
position: fixed;
209+
top: 0; left: 0; right: 0; bottom: 0;
210+
background: rgba(0, 0, 0, 0.5);
211+
display: flex;
212+
align-items: center;
213+
justify-content: center;
214+
z-index: 100;
215+
visibility: hidden;
216+
opacity: 0;
217+
transition: opacity 0.2s;
218+
}
219+
.overlay.visible {
220+
visibility: visible;
221+
opacity: 1;
222+
}
223+
.confirm-box {
224+
background: var(--vscode-editor-background);
225+
border: 1px solid var(--vscode-panel-border);
226+
padding: 15px;
227+
border-radius: 5px;
228+
box-shadow: 0 4px 10px rgba(0,0,0,0.3);
229+
width: 80%;
230+
max-width: 300px;
231+
text-align: center;
232+
top: 200px;
233+
position: absolute;
234+
}
235+
.confirm-title {
236+
font-weight: bold;
237+
margin-bottom: 10px;
238+
font-size: 14px;
239+
}
240+
.confirm-msg {
241+
margin-bottom: 15px;
242+
font-size: 13px;
243+
}
244+
.confirm-actions {
245+
display: flex;
246+
justify-content: center;
247+
gap: 10px;
248+
}
249+
.btn-cancel {
250+
background: var(--vscode-button-secondaryBackground);
251+
color: var(--vscode-button-secondaryForeground);
252+
}
253+
.btn-cancel:hover {
254+
background: var(--vscode-button-secondaryHoverBackground);
255+
}
205256
</style>
206257
</head>
207258
<body>
@@ -228,6 +279,18 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
228279
</div>
229280
230281
<div class="status-bar" id="statusBar">Ready</div>
282+
283+
<!-- Confirmation Modal -->
284+
<div class="overlay" id="confirmOverlay">
285+
<div class="confirm-box">
286+
<div class="confirm-title">Kill Process?</div>
287+
<div class="confirm-msg" id="confirmMsg">Are you sure you want to kill this process?</div>
288+
<div class="confirm-actions">
289+
<button class="btn-cancel" id="btnCancel">Cancel</button>
290+
<button class="kill-btn" id="btnConfirmKill">Yes, Kill</button>
291+
</div>
292+
</div>
293+
</div>
231294
</div>
232295
233296
<script>
@@ -236,6 +299,14 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
236299
const searchBtn = document.getElementById('searchBtn');
237300
const tableBody = document.getElementById('processTableBody');
238301
const statusBar = document.getElementById('statusBar');
302+
303+
// Overlay elements
304+
const confirmOverlay = document.getElementById('confirmOverlay');
305+
const confirmMsg = document.getElementById('confirmMsg');
306+
const btnCancel = document.getElementById('btnCancel');
307+
const btnConfirmKill = document.getElementById('btnConfirmKill');
308+
309+
let processToKill = null;
239310
240311
searchBtn.addEventListener('click', () => {
241312
const value = portInput.value;
@@ -253,6 +324,27 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
253324
}
254325
});
255326
327+
// Confirmation Logic
328+
function showConfirm(pid) {
329+
processToKill = pid;
330+
confirmMsg.innerText = \`Are you sure you want to kill PID \${pid}?\`;
331+
confirmOverlay.classList.add('visible');
332+
}
333+
334+
function hideConfirm() {
335+
processToKill = null;
336+
confirmOverlay.classList.remove('visible');
337+
}
338+
339+
btnCancel.addEventListener('click', hideConfirm);
340+
341+
btnConfirmKill.addEventListener('click', () => {
342+
if (processToKill) {
343+
vscode.postMessage({ type: 'kill', value: processToKill });
344+
hideConfirm();
345+
}
346+
});
347+
256348
window.addEventListener('message', event => {
257349
const message = event.data;
258350
switch (message.type) {
@@ -269,12 +361,12 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
269361
<td>\${p.pid}</td>
270362
<td>\${p.processName}</td>
271363
<td>\${p.protocol}</td>
272-
<td><button class="kill-btn" onclick="killProcess('\${p.pid}')">Kill</button></td>
364+
<td><button class="kill-btn">Kill</button></td>
273365
\`;
274366
// Binding click event properly
275367
const btn = tr.querySelector('.kill-btn');
276368
btn.onclick = () => {
277-
vscode.postMessage({ type: 'kill', value: p.pid });
369+
showConfirm(p.pid);
278370
};
279371
tableBody.appendChild(tr);
280372
});

0 commit comments

Comments
 (0)