Skip to content

Commit b357b78

Browse files
Ability to close windows from Spaces (#23)
* Ability to close windows from Spaces * extract a function that handles backed-up spaces and remove unnecessary test case * Fix issue #21 and add some unit tests * Fix issue #22: Filter out PWAs. * solve-comments --------- Co-authored-by: Jeff Schiller <[email protected]>
1 parent 57c4ad1 commit b357b78

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

js/background/background.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,21 @@ async function processMessage(request, sender) {
328328
}
329329
return undefined;
330330

331+
case 'closeWindow':
332+
windowId = cleanParameter(request.windowId);
333+
if(windowId) {
334+
try {
335+
const window = await chrome.windows.get(windowId);
336+
if (window) {
337+
await chrome.windows.remove(windowId);
338+
return true;
339+
}
340+
} catch (error) {
341+
console.error("Error closing window:", error);
342+
}
343+
return false;
344+
}
345+
331346
case 'updateSessionName':
332347
sessionId = cleanParameter(request.sessionId);
333348
if (sessionId && request.sessionName) {

js/spaces.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ function updateButtons(space) {
131131
sessionId || windowId ? 'inline-block' : 'none';
132132
nodes.actionDelete.style.display =
133133
!windowId && sessionId ? 'inline-block' : 'none';
134+
nodes.actionClose.style.display = windowId ? 'inline-block' : 'none';
134135
}
135136

136137
function renderTabs(space) {
@@ -368,6 +369,29 @@ async function handleDelete() {
368369
}
369370
}
370371

372+
async function handleClose() {
373+
if (!globalSelectedSpace || !globalSelectedSpace.windowId) {
374+
console.error("No opened window is currently selected.");
375+
return;
376+
}
377+
const { windowId, sessionId } = globalSelectedSpace;
378+
379+
// Only show confirm if the space is unnamed
380+
if (!sessionId) {
381+
const confirm = window.confirm(
382+
"Are you sure you want to close this window?"
383+
);
384+
if (!confirm) return;
385+
}
386+
387+
chrome.runtime.sendMessage({ action: 'closeWindow', windowId });
388+
await updateSpacesList();
389+
390+
// Clear the detail view since the closed window was selected
391+
globalSelectedSpace = null;
392+
renderSpaceDetail(false, false);
393+
}
394+
371395
// import accepts either a newline separated list of urls or a json backup object
372396
async function handleImport() {
373397
let urlList;
@@ -590,6 +614,9 @@ function addEventListeners() {
590614
nodes.actionDelete.addEventListener('click', () => {
591615
handleDelete();
592616
});
617+
nodes.actionClose.addEventListener('click', () => {
618+
handleClose();
619+
});
593620
nodes.actionImport.addEventListener('click', e => {
594621
e.preventDefault();
595622
toggleModal(true);
@@ -688,6 +715,7 @@ if (typeof window !== 'undefined') {
688715
nodes.actionSwitch = document.getElementById('actionSwitch');
689716
nodes.actionOpen = document.getElementById('actionOpen');
690717
nodes.actionEdit = document.getElementById('actionEdit');
718+
nodes.actionClose = document.getElementById('actionClose');
691719
nodes.actionExport = document.getElementById('actionExport');
692720
nodes.actionBackup = document.getElementById('actionBackup');
693721
nodes.actionDelete = document.getElementById('actionDelete');

spaces.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ <h2>Import / Export:</h2>
5050
<button id='actionEdit' title="Rename space" class="button fa fa-pencil"></button>
5151
<button id='actionExport' title="Export space" class="button fa fa-download"></button>
5252
<button id='actionDelete' title="Delete space" class="button fa fa-trash"></button>
53+
<button id='actionClose' title="Close space" class="button fa fa-times-circle"></button>
5354
</div>
5455
</div>
5556

0 commit comments

Comments
 (0)