Add toggle for app grouping

This commit is contained in:
Rudra Saraswat 2023-04-21 20:03:28 +05:30
parent 38e93d1218
commit 87467b6105
2 changed files with 68 additions and 1 deletions

View file

@ -92,6 +92,13 @@ function check_state_creation() {
}
}
function check_app_grouping() {
if (require('fs').existsSync(`${require('os').homedir()}/.config/categorize_apps_gnome_disable`)) {
document.getElementById('app-grouping-toggle').setAttribute('checked', '')
}
}
check_app_grouping()
check_state_creation()
check_rollback()
@ -133,4 +140,49 @@ $('#automatic-state-toggle').on('change', () => {
}
}
}
});
});
$('#app-grouping-toggle').on('change', () => {
if (!document.getElementById('app-grouping-toggle').checked) {
let enable_autogrouping_worker = new Worker(
`data:text/javascript,
let s = require('child_process').spawnSync('rm', ['-f', '${require('os').homedir()}/.config/categorize_apps_gnome_disable']).status
if (s === 0) {
postMessage('success')
} else {
postMessage('failure')
}
`
)
enable_autogrouping_worker.onmessage = e => {
if (e.data == 'success') {
document.getElementById('app-grouping-toggle').checked = false
} else {
document.getElementById('app-grouping-toggle').checked = true
}
}
} else {
let disable_autogrouping_worker = new Worker(
`data:text/javascript,
require('child_process').spawnSync('mkdir', ['-p', '${require('os').homedir()}/.config']).status
let s = require('child_process').spawnSync('touch', ['${require('os').homedir()}/.config/categorize_apps_gnome_disable']).status
if (s === 0) {
postMessage('success')
} else {
postMessage('failure')
}
`
)
disable_autogrouping_worker.onmessage = e => {
if (e.data == 'success') {
document.getElementById('app-grouping-toggle').checked = true
} else {
document.getElementById('app-grouping-toggle').checked = false
}
}
}
});
if (require('process').env.XDG_CURRENT_DESKTOP.includes('GNOME')) {
$('#app-grouping-item').removeClass('d-none')
}

View file

@ -45,6 +45,21 @@
</div>
</div>
</div>
<div class="list-group-item d-none" id="app-grouping-item">
<div class="row align-items-center">
<div class="col">
<strong class="mb-0">Disable app grouping</strong>
<p class="text-muted mb-0">
Do not automatically group apps of different categories/web apps/Android apps.
</p>
</div>
<div class="col-auto">
<div class="form-check form-switch align-middle">
<input class="form-check-input align-middle" type="checkbox" role="switch" id="app-grouping-toggle">
</div>
</div>
</div>
</div>
</div>
</div>
</div>