use Hyprland.sendMessage; add more async catches

This commit is contained in:
end-4
2024-02-19 20:18:14 +07:00
parent c7a7cce618
commit fb376edfe4
11 changed files with 60 additions and 58 deletions
+1 -1
View File
@@ -113,7 +113,7 @@ export default ({
notificationContent.toggleClassName(`${isPopup ? 'popup-' : ''}notif-clicked-${notifObject.urgency}`, true);
Utils.timeout(800, () => {
if (wholeThing?.attribute.held) {
Utils.execAsync(['wl-copy', `${notifObject.body}`])
Utils.execAsync(['wl-copy', `${notifObject.body}`]).catch(print);
notifTextSummary.label = notifObject.summary + " (copied)";
Utils.timeout(3000, () => notifTextSummary.label = notifObject.summary)
}
+2 -2
View File
@@ -20,7 +20,7 @@ export async function firstRunWelcome() {
Utils.writeFile(FIRST_RUN_FILE_CONTENT, FIRST_RUN_PATH)
.then(() => {
// Note that we add a little delay to make sure the cool circular progress works
Utils.execAsync(['hyprctl', 'keyword', 'bind', "Super,Slash,exec,ags -t cheatsheet"]);
Utils.execAsync(['hyprctl', 'keyword', 'bind', "Super,Slash,exec,ags -t cheatsheet"]).catch(print);
Utils.execAsync(['bash', '-c',
`sleep 0.5; notify-send "Millis since epoch" "$(date +%s%N | cut -b1-13)"; sleep 0.5; notify-send '${FIRST_RUN_NOTIF_TITLE}' '${FIRST_RUN_NOTIF_BODY}' -a '${APP_NAME}' &`
]).catch(print)
@@ -54,5 +54,5 @@ async function batteryMessage() {
// Run them
firstRunWelcome();
Utils.timeout(1, () => {
Battery.connect('changed', () => batteryMessage());
Battery.connect('changed', () => batteryMessage().catch(print));
})
+1 -1
View File
@@ -152,7 +152,7 @@ class WaifuService extends Service {
}
this.emit('updateResponse', newMessageId);
})
.catch(console.error)
.catch(print);
}
}
+5 -5
View File
@@ -9,11 +9,11 @@ import { showMusicControls } from '../../variables.js';
function trimTrackTitle(title) {
if (!title) return '';
const cleanRegexes = [
const cleanPatterns = [
/【[^】]*】/, // Touhou n weeb stuff
/\[FREE DOWNLOAD\]/, // F-777
" [FREE DOWNLOAD]", // F-777
];
cleanRegexes.forEach((expr) => title.replace(expr, ''));
cleanPatterns.forEach((expr) => title = title.replace(expr, ''));
return title;
}
@@ -85,7 +85,7 @@ const TrackProgress = () => {
const switchToRelativeWorkspace = async (self, num) => {
try {
const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default;
Hyprland.sendMessage(`dispatch workspace ${num > 0 ? '+' : ''}${num}`);
Hyprland.messageAsync(`dispatch workspace ${num > 0 ? '+' : ''}${num}`).catch(print);
} catch {
execAsync([`${App.configDir}/scripts/sway/swayToRelativeWs.sh`, `${num}`]).catch(print);
}
@@ -169,7 +169,7 @@ export default () => {
onScrollUp: (self) => switchToRelativeWorkspace(self, -1),
onScrollDown: (self) => switchToRelativeWorkspace(self, +1),
onPrimaryClickRelease: () => showMusicControls.setValue(!showMusicControls.value),
onSecondaryClickRelease: () => execAsync(['bash', '-c', 'playerctl next || playerctl position `bc <<< "100 * $(playerctl metadata mpris:length) / 1000000 / 100"` &']),
onSecondaryClickRelease: () => execAsync(['bash', '-c', 'playerctl next || playerctl position `bc <<< "100 * $(playerctl metadata mpris:length) / 1000000 / 100"` &']).catch(print),
onMiddleClickRelease: () => execAsync('playerctl play-pause').catch(print),
child: Box({
className: 'spacing-h-5',
+3 -2
View File
@@ -200,7 +200,8 @@ const BatteryModule = () => Stack({
.then(output => {
return JSON.parse(output)['city'].toLowerCase();
})
.then(updateWeatherForCity);
.then(updateWeatherForCity)
.catch(print)
}
}),
})
@@ -215,7 +216,7 @@ const BatteryModule = () => Stack({
const switchToRelativeWorkspace = async (self, num) => {
try {
const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default;
Hyprland.sendMessage(`dispatch workspace ${num > 0 ? '+' : ''}${num}`);
Hyprland.messageAsync(`dispatch workspace ${num > 0 ? '+' : ''}${num}`).catch(print);
} catch {
execAsync([`${App.configDir}/scripts/sway/swayToRelativeWs.sh`, `${num}`]).catch(print);
}
+10 -8
View File
@@ -17,7 +17,7 @@ const dummyOccupiedWs = Box({ className: 'bar-ws bar-ws-occupied' }); // Not sho
// Font size = workspace id
const WorkspaceContents = (count = 10) => {
return DrawingArea({
// css: `transition: 90ms cubic-bezier(0.1, 1, 0, 1);`,
// css: `transition: 300ms cubic-bezier(0.1, 1, 0, 1);`,
attribute: {
initialized: false,
workspaceMask: 0,
@@ -50,8 +50,8 @@ const WorkspaceContents = (count = 10) => {
const previousGroup = self.attribute.workspaceGroup;
const currentGroup = Math.floor((Hyprland.active.workspace.id - 1) / count);
if (currentGroup !== previousGroup) {
self.attribute.updateMask(self);
self.attribute.workspaceGroup = currentGroup;
self.attribute.updateMask(self);
self.attribute.workspaceGroup = currentGroup;
}
})
.hook(Hyprland, (self) => self.attribute.updateMask(self), 'notify::workspaces')
@@ -148,8 +148,8 @@ const WorkspaceContents = (count = 10) => {
}
export default () => EventBox({
onScrollUp: () => Hyprland.sendMessage(`dispatch workspace -1`),
onScrollDown: () => Hyprland.sendMessage(`dispatch workspace +1`),
onScrollUp: () => Hyprland.messageAsync(`dispatch workspace -1`).catch(print),
onScrollDown: () => Hyprland.messageAsync(`dispatch workspace +1`).catch(print),
onMiddleClickRelease: () => App.toggleWindow('overview'),
onSecondaryClickRelease: () => App.toggleWindow('osk'),
attribute: {
@@ -172,7 +172,8 @@ export default () => EventBox({
const [_, cursorX, cursorY] = event.get_coords();
const widgetWidth = self.get_allocation().width;
const wsId = Math.ceil(cursorX * NUM_OF_WORKSPACES_SHOWN / widgetWidth);
Utils.execAsync([`${App.configDir}/scripts/hyprland/workspace_action.sh`, 'workspace', `${wsId}`]);
Utils.execAsync([`${App.configDir}/scripts/hyprland/workspace_action.sh`, 'workspace', `${wsId}`])
.catch(print);
})
self.on('button-press-event', (self, event) => {
if (!(event.get_button()[1] === 1)) return; // We're only interested in left-click here
@@ -180,9 +181,10 @@ export default () => EventBox({
const [_, cursorX, cursorY] = event.get_coords();
const widgetWidth = self.get_allocation().width;
// const wsId = Math.ceil(cursorX * NUM_OF_WORKSPACES_PER_GROUP / widgetWidth) + self.attribute.ws_group * NUM_OF_WORKSPACES_PER_GROUP;
// Hyprland.sendMessage(`dispatch workspace ${wsId}`);
// Hyprland.messageAsync(`dispatch workspace ${wsId}`).catch(print);
const wsId = Math.ceil(cursorX * NUM_OF_WORKSPACES_SHOWN / widgetWidth);
Utils.execAsync([`${App.configDir}/scripts/hyprland/workspace_action.sh`, 'workspace', `${wsId}`]);
Utils.execAsync([`${App.configDir}/scripts/hyprland/workspace_action.sh`, 'workspace', `${wsId}`])
.catch(print);
})
self.on('button-release-event', (self) => self.attribute.clicked = false);
}
+2 -2
View File
@@ -21,7 +21,7 @@ function substitute(str) {
{ from: 'code-url-handler', to: 'visual-studio-code' },
{ from: 'Code', to: 'visual-studio-code' },
{ from: 'GitHub Desktop', to: 'github-desktop' },
{ from: 'wpsoffice', to: 'wps-office2019-kprometheus' },
{ from: 'wps', to: 'wps-office2019-kprometheus' },
{ from: 'gnome-tweaks', to: 'org.gnome.tweaks' },
{ from: 'Minecraft* 1.20.1', to: 'minecraft' },
{ from: '', to: 'image-missing' },
@@ -35,7 +35,7 @@ function substitute(str) {
return str;
}
const focus = ({ address }) => Utils.execAsync(`hyprctl dispatch focuswindow address:${address}`);
const focus = ({ address }) => Utils.execAsync(`hyprctl dispatch focuswindow address:${address}`).catch(print);
const DockSeparator = (props = {}) => Box({
...props,
@@ -24,12 +24,12 @@ class ShiftMode {
static Off = new ShiftMode('Off');
static Normal = new ShiftMode('Normal');
static Locked = new ShiftMode('Locked');
constructor(name) {
this.name = name;
this.name = name;
}
toString() {
return `ShiftMode.${this.name}`;
return `ShiftMode.${this.name}`;
}
}
var modsPressed = false;
@@ -103,26 +103,26 @@ const keyboardItself = (kbJson) => {
className: `osk-key osk-key-${key.shape}`,
hexpand: ["space", "expand"].includes(key.shape),
label: key.label,
attribute:
{key: key},
attribute:
{ key: key },
setup: (button) => {
let pressed = false;
allButtons = allButtons.concat(button);
if (key.keytype == "normal") {
button.connect('pressed', () => { // mouse down
execAsync(`ydotool key ${key.keycode}:1`);
execAsync(`ydotool key ${key.keycode}:1`).catch(print);
});
button.connect('clicked', () => { // release
execAsync(`ydotool key ${key.keycode}:0`);
execAsync(`ydotool key ${key.keycode}:0`).catch(print);
if (shiftMode == ShiftMode.Normal) {
shiftMode = ShiftMode.Off;
if (typeof shiftButton !== 'undefined') {
execAsync(`ydotool key 42:0`);
execAsync(`ydotool key 42:0`).catch(print);
shiftButton.toggleClassName('osk-key-active', false);
}
if (typeof rightShiftButton !== 'undefined') {
execAsync(`ydotool key 54:0`);
execAsync(`ydotool key 54:0`).catch(print);
rightShiftButton.toggleClassName('osk-key-active', false);
}
allButtons.forEach(button => {
@@ -134,7 +134,7 @@ const keyboardItself = (kbJson) => {
else if (key.keytype == "modkey") {
button.connect('pressed', () => { // release
if (pressed) {
execAsync(`ydotool key ${key.keycode}:0`);
execAsync(`ydotool key ${key.keycode}:0`).catch(print);
button.toggleClassName('osk-key-active', false);
pressed = false;
if (key.keycode == 100) { // Alt Gr button
@@ -142,7 +142,7 @@ const keyboardItself = (kbJson) => {
}
}
else {
execAsync(`ydotool key ${key.keycode}:1`);
execAsync(`ydotool key ${key.keycode}:1`).catch(print);
button.toggleClassName('osk-key-active', true);
if (!(key.keycode == 42 || key.keycode == 54)) pressed = true;
else switch (shiftMode.name) { // This toggles the shift button state
@@ -171,10 +171,11 @@ const keyboardItself = (kbJson) => {
rightShiftButton.label = key.label;
rightShiftButton.toggleClassName('osk-key-active', false);
}
execAsync(`ydotool key ${key.keycode}:0`);
execAsync(`ydotool key ${key.keycode}:0`).catch(print);
allButtons.forEach(button => { if (typeof button.attribute.key.labelShift !== 'undefined') button.label = button.attribute.key.label; }
)};
)
};
}
if (key.keycode == 100) { // Alt Gr button
allButtons.forEach(button => { if (typeof button.attribute.key.labelAlt !== 'undefined') button.label = button.attribute.key.labelAlt; });
@@ -220,7 +221,7 @@ const gesture = Gtk.GestureDrag.new(gestureEvBox);
gesture.connect('drag-begin', async () => {
try {
const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default;
Hyprland.sendMessage('j/cursorpos').then((out) => {
Hyprland.messageAsync('j/cursorpos').then((out) => {
gesture.startY = JSON.parse(out).y;
}).catch(print);
} catch {
@@ -230,15 +231,15 @@ gesture.connect('drag-begin', async () => {
gesture.connect('drag-update', async () => {
try {
const Hyprland = (await import('resource:///com/github/Aylur/ags/service/hyprland.js')).default;
Hyprland.sendMessage('j/cursorpos').then((out) => {
Hyprland.messageAsync('j/cursorpos').then((out) => {
const currentY = JSON.parse(out).y;
const offset = gesture.startY - currentY;
if (offset > 0) return;
keyboardWindow.setCss(`
margin-bottom: ${offset}px;
`);
margin-bottom: ${offset}px;
`);
}).catch(print);
} catch {
return;
@@ -23,25 +23,23 @@ export function launchCustomCommand(command) {
}
else if (args[0] == '>light') { // Light mode
execAsync([`bash`, `-c`, `mkdir -p ${GLib.get_user_cache_dir()}/ags/user && echo "-l" > ${GLib.get_user_cache_dir()}/ags/user/colormode.txt`])
.then(execAsync(['bash', '-c', `${App.configDir}/scripts/color_generation/switchwall.sh --noswitch`]).catch(print))
.then(execAsync(['bash', '-c', `${App.configDir}/scripts/color_generation/switchwall.sh --noswitch`]))
.catch(print);
}
else if (args[0] == '>dark') { // Dark mode
execAsync([`bash`, `-c`, `mkdir -p ${GLib.get_user_cache_dir()}/ags/user && echo "" > ${GLib.get_user_cache_dir()}/ags/user/colormode.txt`])
.then(execAsync(['bash', '-c', `${App.configDir}/scripts/color_generation/switchwall.sh --noswitch`]).catch(print))
.then(execAsync(['bash', '-c', `${App.configDir}/scripts/color_generation/switchwall.sh --noswitch`]))
.catch(print);
}
else if (args[0] == '>badapple') { // Light mode
else if (args[0] == '>badapple') { // Black and white
execAsync([`bash`, `-c`, `${App.configDir}/scripts/color_generation/applycolor.sh --bad-apple`]).catch(print)
.then(execAsync(['bash', '-c', `${App.configDir}/scripts/color_generation/switchwall.sh --noswitch`]).catch(print))
.catch(print);
}
else if (args[0] == '>material') { // Light mode
else if (args[0] == '>material') { // Use material colors
execAsync([`bash`, `-c`, `mkdir -p ${GLib.get_user_cache_dir()}/ags/user && echo "material" > ${GLib.get_user_cache_dir()}/ags/user/colorbackend.txt`]).catch(print)
.then(execAsync(['bash', '-c', `${App.configDir}/scripts/color_generation/switchwall.sh --noswitch`]).catch(print))
.catch(print);
}
else if (args[0] == '>pywal') { // Dark mode
else if (args[0] == '>pywal') { // Use Pywal (ik it looks shit but I'm not removing)
execAsync([`bash`, `-c`, `mkdir -p ${GLib.get_user_cache_dir()}/ags/user && echo "pywal" > ${GLib.get_user_cache_dir()}/ags/user/colorbackend.txt`]).catch(print)
.then(execAsync(['bash', '-c', `${App.configDir}/scripts/color_generation/switchwall.sh --noswitch`]).catch(print))
.catch(print);
@@ -35,7 +35,7 @@ function substitute(str) {
{ from: 'code-url-handler', to: 'visual-studio-code' },
{ from: 'Code', to: 'visual-studio-code' },
{ from: 'GitHub Desktop', to: 'github-desktop' },
{ from: 'wpsoffice', to: 'wps-office2019-kprometheus' },
{ from: 'wps', to: 'wps-office2019-kprometheus' },
{ from: 'gnome-tweaks', to: 'org.gnome.tweaks' },
{ from: 'Minecraft* 1.20.1', to: 'minecraft' },
{ from: '', to: 'image-missing' },
@@ -113,10 +113,10 @@ export default () => {
margin-bottom: -${Math.round((y + h) * OVERVIEW_SCALE)}px;
`,
onClicked: (self) => {
Hyprland.sendMessage(`dispatch focuswindow address:${address}`);
Hyprland.messageAsync(`dispatch focuswindow address:${address}`);
App.closeWindow('overview');
},
onMiddleClickRelease: () => Hyprland.sendMessage(`dispatch closewindow address:${address}`),
onMiddleClickRelease: () => Hyprland.messageAsync(`dispatch closewindow address:${address}`),
onSecondaryClick: (button) => {
button.toggleClassName('overview-tasks-window-selected', true);
const menu = Widget.Menu({
@@ -127,7 +127,7 @@ export default () => {
xalign: 0,
label: "Close (Middle-click)",
}),
onActivate: () => Hyprland.sendMessage(`dispatch closewindow address:${address}`),
onActivate: () => Hyprland.messageAsync(`dispatch closewindow address:${address}`),
}),
ContextMenuWorkspaceArray({
label: "Dump windows to workspace",
@@ -253,13 +253,13 @@ export default () => {
hexpand: true,
vexpand: true,
onPrimaryClick: () => {
Hyprland.sendMessage(`dispatch workspace ${index}`)
Hyprland.messageAsync(`dispatch workspace ${index}`)
App.closeWindow('overview');
},
setup: (eventbox) => {
eventbox.drag_dest_set(Gtk.DestDefaults.ALL, TARGET, Gdk.DragAction.COPY);
eventbox.connect('drag-data-received', (_w, _c, _x, _y, data) => {
Hyprland.sendMessage(`dispatch movetoworkspacesilent ${index},address:${data.get_text()}`)
Hyprland.messageAsync(`dispatch movetoworkspacesilent ${index},address:${data.get_text()}`)
overviewTick.setValue(!overviewTick.value);
});
},
@@ -342,7 +342,7 @@ export default () => {
update: (box) => {
const offset = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN) * NUM_OF_WORKSPACES_SHOWN;
if (!App.getWindow(windowName).visible) return;
Hyprland.sendMessage('j/clients').then(clients => {
Hyprland.messageAsync('j/clients').then(clients => {
const allClients = JSON.parse(clients);
const kids = box.get_children();
kids.forEach(kid => kid.clear());
@@ -381,7 +381,7 @@ export default () => {
id <= offset + startWorkspace + workspaces
)) return;
// if (!App.getWindow(windowName).visible) return;
Hyprland.sendMessage('j/clients').then(clients => {
Hyprland.messageAsync('j/clients').then(clients => {
const allClients = JSON.parse(clients);
const kids = box.get_children();
for (let i = 0; i < allClients.length; i++) {
@@ -97,8 +97,8 @@ export const ModuleNightLight = (props = {}) => Widget.Button({ // TODO: Make th
self.attribute.enabled = !self.attribute.enabled;
self.toggleClassName('sidebar-button-active', self.attribute.enabled);
// if (self.attribute.enabled) Utils.execAsync(['bash', '-c', 'wlsunset & disown'])
if (self.attribute.enabled) Utils.execAsync('wlsunset')
else Utils.execAsync('pkill wlsunset');
if (self.attribute.enabled) Utils.execAsync('wlsunset').catch(print)
else Utils.execAsync('pkill wlsunset').catch(print);
},
child: MaterialIcon('nightlight', 'norm'),
setup: (self) => {
@@ -117,7 +117,7 @@ export const ModuleInvertColors = async (props = {}) => {
tooltipText: 'Color inversion',
onClicked: (button) => {
// const shaderPath = JSON.parse(exec('hyprctl -j getoption decoration:screen_shader')).str;
Hyprland.sendMessage('j/getoption decoration:screen_shader')
Hyprland.messageAsync('j/getoption decoration:screen_shader')
.then((output) => {
const shaderPath = JSON.parse(output)["str"].trim();
if (shaderPath != "[[EMPTY]]" && shaderPath != "") {
@@ -125,7 +125,7 @@ export const ModuleInvertColors = async (props = {}) => {
button.toggleClassName('sidebar-button-active', false);
}
else {
Hyprland.sendMessage(`j/keyword decoration:screen_shader ${expandTilde('~/.config/hypr/shaders/invert.frag')}`)
Hyprland.messageAsync(`j/keyword decoration:screen_shader ${expandTilde('~/.config/hypr/shaders/invert.frag')}`)
.catch(print);
button.toggleClassName('sidebar-button-active', true);
}