Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
feat: add support for hiding notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
oae committed Oct 26, 2021
1 parent 0cef93d commit 7e70e9c
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src/prefs/otherPrefs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { registerClass } from '@imports/gobject2';
import { Align, Box, Label, ListBoxRow, Orientation, Switch } from '@imports/gtk4';
import { PrefsTab } from './prefsTab';

export const OtherPrefs = registerClass(
{},
class OtherPrefs extends PrefsTab {
_init() {
super._init({
title: 'Other Settings',
orientation: Orientation.VERTICAL,
marginTop: 24,
marginBottom: 24,
marginStart: 12,
marginEnd: 12,
});

this.createShowTrayIconSetting();
this.createShowNotificationsSetting();
}

createShowTrayIconSetting(): void {
const showTrayIcon = this.settings.get_boolean('show-tray-icon');
this.createSetting('Show Tray Icon', 'Controls the visibility of the tray icon.', showTrayIcon, (state) => {
this.settings.set_boolean('show-tray-icon', state);
});
}

createShowNotificationsSetting(): void {
const showNotifications = this.settings.get_boolean('show-notifications');
this.createSetting(
'Show Notifications',
'Controls the visibility of the notifications.',
showNotifications,
(state) => {
this.settings.set_boolean('show-notifications', state);
},
);
}

createSetting(
label: string,
description: string,
initialSwitchValue: boolean,
onStateSet: (state: boolean) => void,
): void {
const row = new ListBoxRow({
halign: Align.FILL,
valign: Align.FILL,
widthRequest: 100,
activatable: true,
});
const rowContainer = new Box({
marginTop: 24,
marginBottom: 24,
marginStart: 15,
marginEnd: 15,
widthRequest: 100,
orientation: Orientation.HORIZONTAL,
});

const rowLabelContainer = new Box({
orientation: Orientation.VERTICAL,
halign: Align.FILL,
valign: Align.FILL,
hexpand: true,
vexpand: true,
});
rowLabelContainer.append(
new Label({
label,
halign: Align.START,
valign: Align.FILL,
}),
);
rowLabelContainer.append(
new Label({
label: description,
halign: Align.START,
valign: Align.FILL,
cssClasses: ['dim-label', 'setting-description'],
}),
);
const rowSwitch = new Switch({
halign: Align.END,
valign: Align.CENTER,
active: initialSwitchValue,
});

rowSwitch.connect('state-set', (_, state) => {
onStateSet(state);
});

rowContainer.append(rowLabelContainer);
rowContainer.append(rowSwitch);

row.set_child(rowContainer);
this.append(row);
}
},
);

0 comments on commit 7e70e9c

Please sign in to comment.