Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update list on install #142

Merged
merged 5 commits into from
Jul 30, 2024
Merged
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"no-bitwise": "off",
"no-inner-declarations": "off",
"no-new": "off",
"no-self-assign": "off",
"unicorn/prefer-top-level-await": "off"
},
"overrides": [
Expand Down
38 changes: 26 additions & 12 deletions source/app.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@
);
}

// eslint-disable-next-line no-self-assign -- Signals to Svelte that the content was updated
extensions = extensions;
}


function fillInTheBlanks(extension) {
extension.shown = true;
extension.indexedName = extension.name.toLowerCase();
return extension;
}

function hideInfoMessage() {
localStorage.setItem('undo-info-message', 1);
showInfoMessage = false;
Expand Down Expand Up @@ -72,12 +78,8 @@

undoStack.do(toggle => {
for (const extension of affectedExtensions) {
extension.enabled = enable ? toggle : !toggle;
chrome.management.setEnabled(extension.id, extension.enabled);
chrome.management.setEnabled(extension.id, enable ? toggle : !toggle);
}

// eslint-disable-next-line no-self-assign -- Signals to Svelte that the content was updated
extensions = extensions;
});
}

Expand All @@ -92,16 +94,28 @@

return a.enabled < b.enabled ? 1 : -1; // Sort by state
})
.map(extension => {
extension.shown = true;
extension.indexedName = extension.name.toLowerCase();
return extension;
});
.map(extension => fillInTheBlanks(extension));

// Update list on uninstall
// Update list on global events
chrome.management.onUninstalled.addListener(deleted => {
extensions = extensions.filter(({id}) => id !== deleted);
});
chrome.management.onInstalled.addListener(installed => {
if (installed.type === 'extension') {
// Place new extension at the top
extensions = [fillInTheBlanks(installed), ...extensions];
}
});
chrome.management.onEnabled.addListener(updated => {
const extension = extensions.find(({id}) => id === updated.id);
extension.enabled = true;
extensions = extensions;
});
chrome.management.onDisabled.addListener(updated => {
const extension = extensions.find(({id}) => id === updated.id);
extension.enabled = false;
extensions = extensions;
});
});

// Toggle extra buttons on right click on the name
Expand Down
3 changes: 1 addition & 2 deletions source/extension.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
const wasEnabled = enabled;

undoStack.do(toggle => {
enabled = toggle !== wasEnabled;
chrome.management.setEnabled(id, enabled);
chrome.management.setEnabled(id, toggle !== wasEnabled);
});
}

Expand Down
Loading