perf(ags): replace exec with execAsync

This commit is contained in:
matt1432 2023-09-26 13:33:30 -04:00
parent f14f45ca72
commit b9807c29cf
5 changed files with 21 additions and 31 deletions

View file

@ -1,4 +1,4 @@
import { exec } from 'resource:///com/github/Aylur/ags/utils.js'; import { exec, execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
import { Powermenu } from './js/powermenu.js'; import { Powermenu } from './js/powermenu.js';
import { Bar } from './js/bar/main.js'; import { Bar } from './js/bar/main.js';
import { NotificationCenter } from './js/notifications/center.js'; import { NotificationCenter } from './js/notifications/center.js';
@ -15,7 +15,7 @@ const css = ags.App.configDir + '/style.css';
exec(`sassc ${scss} ${css}`); exec(`sassc ${scss} ${css}`);
exec(`bash -c "$AGS_PATH/startup.sh"`); execAsync(['bash', '-c', '$AGS_PATH/startup.sh']).catch(print);
export default { export default {
style: css, style: css,

View file

@ -1,5 +1,5 @@
const { Label, Icon, Stack, ProgressBar, Overlay, Box } = ags.Widget; const { ProgressBar, Overlay, Box } = ags.Widget;
const { exec } = ags.Utils; const { execAsync } = ags.Utils;
import { Separator } from '../misc/separator.js'; import { Separator } from '../misc/separator.js';
import { Heart } from './heart.js'; import { Heart } from './heart.js';
@ -11,14 +11,16 @@ export const Brightness = Overlay({
className: 'toggle-off brightness', className: 'toggle-off brightness',
connections: [ connections: [
[200, progress => { [200, progress => {
let br = exec('brightnessctl get') / 255; execAsync('brightnessctl get').then(out => {
if (br > 0.33) { let br = out / 255;
progress.value = br; if (br > 0.33) {
} progress.value = br;
else { }
progress.value = 0.33; else {
} progress.value = 0.33;
}] }
}).catch(print);
}],
], ],
}), }),
overlays: [ overlays: [

View file

@ -1,5 +1,5 @@
const { Box, Label } = ags.Widget; const { Box, Label } = ags.Widget;
const { subprocess, exec } = ags.Utils; const { subprocess, execAsync } = ags.Utils;
const deflisten = subprocess; const deflisten = subprocess;
import { EventBox } from '../misc/cursorbox.js'; import { EventBox } from '../misc/cursorbox.js';
@ -13,7 +13,7 @@ deflisten(
export const Heart = EventBox({ export const Heart = EventBox({
halign: 'center', halign: 'center',
onPrimaryClickRelease: () => { onPrimaryClickRelease: () => {
exec("bash -c '$AGS_PATH/heart.sh toggle'"); execAsync(['bash', '-c', '$AGS_PATH/heart.sh toggle']).catch(print);
}, },
child: Box({ child: Box({
className: 'heart-toggle', className: 'heart-toggle',

View file

@ -1,5 +1,5 @@
const { Box, Label } = ags.Widget; const { Box, Label } = ags.Widget;
const { subprocess, exec } = ags.Utils; const { subprocess } = ags.Utils;
const deflisten = subprocess; const deflisten = subprocess;
import { EventBox } from '../misc/cursorbox.js'; import { EventBox } from '../misc/cursorbox.js';

View file

@ -1,6 +1,6 @@
const { Box, Slider, Label, Icon, EventBox } = ags.Widget; const { Box, Slider, Icon, EventBox } = ags.Widget;
const { Audio } = ags.Service; const { Audio } = ags.Service;
const { exec } = ags.Utils; const { execAsync } = ags.Utils;
const items = { const items = {
101: 'audio-volume-overamplified-symbolic', 101: 'audio-volume-overamplified-symbolic',
@ -10,18 +10,6 @@ const items = {
0: 'audio-volume-muted-symbolic', 0: 'audio-volume-muted-symbolic',
}; };
let throttleTimer;
const throttle = (callback, time) => {
if (throttleTimer) return;
throttleTimer = true;
setTimeout(() => {
callback();
throttleTimer = false;
}, time);
}
export const SliderBox = Box({ export const SliderBox = Box({
className: 'slider-box', className: 'slider-box',
vertical: true, vertical: true,
@ -84,11 +72,11 @@ export const SliderBox = Box({
['canChange', true], ['canChange', true],
], ],
onChange: ({ value }) => { onChange: ({ value }) => {
throttle(() => exec('brightnessctl set ' + value + ' %'), 20); execAsync(`brightnessctl set ${value}`).catch(print);
}, },
connections: [[1000, slider => { connections: [[1000, slider => {
if (slider._canChange) { if (slider._canChange) {
slider.value = exec('brightnessctl get'); execAsync('brightnessctl get').then(out => slider.value = out).catch(print);
} }
}]], }]],
min: 0, min: 0,