-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprefs.js
More file actions
714 lines (617 loc) · 22.3 KB
/
prefs.js
File metadata and controls
714 lines (617 loc) · 22.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
import Gtk from "gi://Gtk";
import Adw from "gi://Adw";
import Gio from "gi://Gio";
import Gdk from "gi://Gdk";
import {
ExtensionPreferences,
gettext as _,
} from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js";
export default class GitHubTrayPreferences extends ExtensionPreferences {
fillPreferencesWindow(window) {
let iconTheme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default());
let UIFolderPath = `${this.path}/ui`;
iconTheme.add_search_path(`${UIFolderPath}/icons`);
const settings = this.getSettings();
// Add header bar with support menu
this._addHeaderBar(window);
// --- Main page ---
const page = new Adw.PreferencesPage({
title: _("GitHub Tray"),
icon_name: "folder-remote-symbolic",
});
// --- Welcome group ---
const welcomeGroup = new Adw.PreferencesGroup({
title: _("Welcome"),
});
const welcomeRow = new Adw.ActionRow({
title: _("Thank you for using GitHub Tray!"),
subtitle: _(
"Join our Discord community or leave a star on GitHub to support the project",
),
});
// Discord button with custom icon and Discord purple color
const discordIconPath = `${this.path}/icons/discord.svg`;
const discordButton = new Gtk.Button({
icon_name: "discord-symbolic",
valign: Gtk.Align.CENTER,
tooltip_text: _("Join Discord"),
css_classes: ["flat"],
});
// Load Discord button styles from stylesheet.css
const cssProvider = new Gtk.CssProvider();
cssProvider.load_from_path(`${this.path}/stylesheet.css`);
discordButton
.get_style_context()
.add_provider(cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
discordButton.connect("clicked", () => {
Gtk.show_uri(window, "https://discord.gg/YrZPHAwMSG", 0);
});
welcomeRow.add_suffix(discordButton);
// GitHub star button
const starButton = new Gtk.Button({
icon_name: "github-symbolic",
valign: Gtk.Align.CENTER,
tooltip_text: _("Star on GitHub"),
css_classes: ["flat"],
});
starButton.connect("clicked", () => {
Gtk.show_uri(
window,
"https://github.com/debba/github-tray-gnome-extension",
0,
);
});
welcomeRow.add_suffix(starButton);
welcomeGroup.add(welcomeRow);
page.add(welcomeGroup);
// --- Authentication group ---
const authGroup = new Adw.PreferencesGroup({
title: _("Authentication"),
description: _(
"Create a token at github.com/settings/tokens\nRequired scopes: repo (private) or public_repo (public only)\nFor GitHub Enterprise Server, enter the base URL below.",
),
});
// Username (apply button instead of saving per-keystroke)
const usernameRow = new Adw.EntryRow({
title: _("GitHub Username"),
text: settings.get_string("github-username"),
show_apply_button: true,
});
usernameRow.connect("apply", () => {
settings.set_string("github-username", usernameRow.get_text());
});
authGroup.add(usernameRow);
// Token (password field with apply)
const tokenRow = new Adw.PasswordEntryRow({
title: _("Personal Access Token"),
text: settings.get_string("github-token"),
show_apply_button: true,
});
tokenRow.connect("apply", () => {
settings.set_string("github-token", tokenRow.get_text());
});
authGroup.add(tokenRow);
// GitHub Enterprise Server URL (optional)
const enterpriseRow = new Adw.EntryRow({
title: _("GitHub Enterprise Server URL"),
text: settings.get_string("github-enterprise-url"),
show_apply_button: true,
});
enterpriseRow.connect("apply", () => {
settings.set_string("github-enterprise-url", enterpriseRow.get_text().trim());
});
authGroup.add(enterpriseRow);
page.add(authGroup);
// --- Sorting group ---
const sortGroup = new Adw.PreferencesGroup({
title: _("Sorting"),
description: _("Configure how repositories are sorted"),
});
// Sort by
const sortByRow = new Adw.ComboRow({
title: _("Sort by"),
subtitle: _("Criteria for sorting repositories"),
model: Gtk.StringList.new([
_("Last Updated"),
_("Last Pushed"),
_("Created Date"),
_("Stars"),
_("Name"),
]),
});
const sortByMap = ["updated", "pushed", "created", "stars", "name"];
const currentSortBy = settings.get_string("sort-by");
const sortByIdx = sortByMap.indexOf(currentSortBy);
sortByRow.selected = sortByIdx !== -1 ? sortByIdx : 0;
sortByRow.connect("notify::selected", () => {
settings.set_string("sort-by", sortByMap[sortByRow.selected]);
});
sortGroup.add(sortByRow);
// Sort order
const sortOrderRow = new Adw.ComboRow({
title: _("Sort order"),
subtitle: _("Ascending or descending order"),
model: Gtk.StringList.new([_("Descending"), _("Ascending")]),
});
const sortOrderMap = ["desc", "asc"];
const currentSortOrder = settings.get_string("sort-order");
const sortOrderIdx = sortOrderMap.indexOf(currentSortOrder);
sortOrderRow.selected = sortOrderIdx !== -1 ? sortOrderIdx : 0;
sortOrderRow.connect("notify::selected", () => {
settings.set_string("sort-order", sortOrderMap[sortOrderRow.selected]);
});
sortGroup.add(sortOrderRow);
page.add(sortGroup);
// --- Display group ---
const displayGroup = new Adw.PreferencesGroup({
title: _("Display"),
description: _("Configure how repositories are shown"),
});
// Panel position
const panelRow = new Adw.ComboRow({
title: _("Panel position"),
subtitle: _("Where the icon appears in the top bar (requires restart)"),
model: Gtk.StringList.new([_("Left"), _("Center"), _("Right")]),
});
const panelBoxMap = ["left", "center", "right"];
const currentPanelBox = settings.get_string("panel-box");
const idx = panelBoxMap.indexOf(currentPanelBox);
panelRow.selected = idx !== -1 ? idx : 2;
panelRow.connect("notify::selected", () => {
settings.set_string("panel-box", panelBoxMap[panelRow.selected]);
});
displayGroup.add(panelRow);
// Max repos
const maxReposRow = new Adw.SpinRow({
title: _("Max repositories"),
subtitle: _("Maximum number of repositories to display"),
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 50,
step_increment: 1,
value: settings.get_int("max-repos"),
}),
});
maxReposRow.connect("notify::value", () => {
settings.set_int("max-repos", maxReposRow.value);
});
displayGroup.add(maxReposRow);
// Font size
const fontSizeRow = new Adw.ComboRow({
title: _("Font Size"),
subtitle: _("Adjust the size of text in the menu"),
model: Gtk.StringList.new([_("Small"), _("Medium"), _("Large")]),
});
const fontSizeMap = ["small", "medium", "large"];
const currentFontSize = settings.get_string("font-size");
const fontSizeIdx = fontSizeMap.indexOf(currentFontSize);
fontSizeRow.selected = fontSizeIdx !== -1 ? fontSizeIdx : 0;
fontSizeRow.connect("notify::selected", () => {
settings.set_string("font-size", fontSizeMap[fontSizeRow.selected]);
});
displayGroup.add(fontSizeRow);
page.add(displayGroup);
// --- Local Projects group ---
const localGroup = new Adw.PreferencesGroup({
title: _("Local Projects"),
description: _("Configure local editor for opening projects"),
});
// Editor command
const editorRow = new Adw.EntryRow({
title: _("Editor Command"),
text: settings.get_string("local-editor"),
show_apply_button: true,
});
editorRow.connect("apply", () => {
settings.set_string("local-editor", editorRow.get_text());
});
localGroup.add(editorRow);
page.add(localGroup);
// --- Notifications group ---
const notificationsGroup = new Adw.PreferencesGroup({
title: _("Notifications"),
description: _("Configure GitHub notifications display"),
});
// Show notifications toggle
const showNotificationsRow = new Adw.SwitchRow({
title: _("Show GitHub Notifications"),
subtitle: _("Display GitHub notifications in the menu"),
active: settings.get_boolean("show-notifications"),
});
showNotificationsRow.connect("notify::active", () => {
settings.set_boolean("show-notifications", showNotificationsRow.active);
});
notificationsGroup.add(showNotificationsRow);
// Desktop notifications toggle
const desktopNotificationsRow = new Adw.SwitchRow({
title: _("Desktop Notifications"),
subtitle: _("Show desktop notifications for new GitHub notifications"),
active: settings.get_boolean("desktop-notifications"),
});
desktopNotificationsRow.connect("notify::active", () => {
settings.set_boolean("desktop-notifications", desktopNotificationsRow.active);
});
notificationsGroup.add(desktopNotificationsRow);
// Notification refresh interval
const intervalRow = new Adw.SpinRow({
title: _("Refresh Interval"),
subtitle: _("Seconds between notification checks"),
adjustment: new Gtk.Adjustment({
lower: 30,
upper: 600,
step_increment: 30,
value: settings.get_int("notification-interval"),
}),
});
intervalRow.connect("notify::value", () => {
settings.set_int("notification-interval", intervalRow.value);
});
notificationsGroup.add(intervalRow);
page.add(notificationsGroup);
// --- Notification Types group ---
const notificationTypesGroup = new Adw.PreferencesGroup({
title: _("Notification Types"),
description: _("Choose which notification types to show"),
});
// Review requests
const reviewRequestsRow = new Adw.SwitchRow({
title: _("Review Requests"),
subtitle: _("When someone requests your review on a PR"),
active: settings.get_boolean("notify-review-requests"),
});
reviewRequestsRow.connect("notify::active", () => {
settings.set_boolean("notify-review-requests", reviewRequestsRow.active);
});
notificationTypesGroup.add(reviewRequestsRow);
// Mentions
const mentionsRow = new Adw.SwitchRow({
title: _("Mentions"),
subtitle: _("When someone mentions you"),
active: settings.get_boolean("notify-mentions"),
});
mentionsRow.connect("notify::active", () => {
settings.set_boolean("notify-mentions", mentionsRow.active);
});
notificationTypesGroup.add(mentionsRow);
// Assignments
const assignmentsRow = new Adw.SwitchRow({
title: _("Assignments"),
subtitle: _("When you are assigned to an issue or PR"),
active: settings.get_boolean("notify-assignments"),
});
assignmentsRow.connect("notify::active", () => {
settings.set_boolean("notify-assignments", assignmentsRow.active);
});
notificationTypesGroup.add(assignmentsRow);
// PR comments
const prCommentsRow = new Adw.SwitchRow({
title: _("Pull Request Comments"),
subtitle: _("Comments on pull requests"),
active: settings.get_boolean("notify-pr-comments"),
});
prCommentsRow.connect("notify::active", () => {
settings.set_boolean("notify-pr-comments", prCommentsRow.active);
});
notificationTypesGroup.add(prCommentsRow);
// Issue comments
const issueCommentsRow = new Adw.SwitchRow({
title: _("Issue Comments"),
subtitle: _("Comments on issues"),
active: settings.get_boolean("notify-issue-comments"),
});
issueCommentsRow.connect("notify::active", () => {
settings.set_boolean("notify-issue-comments", issueCommentsRow.active);
});
notificationTypesGroup.add(issueCommentsRow);
page.add(notificationTypesGroup);
// --- GitHub Actions group ---
const actionsGroup = new Adw.PreferencesGroup({
title: _("GitHub Actions"),
description: _("Configure workflow runs display. Click the workflow icon on any repository to view its workflow runs."),
});
// Max workflow runs to display
const maxWorkflowRunsRow = new Adw.SpinRow({
title: _("Max Workflow Runs"),
subtitle: _("Maximum number of workflow runs to display per repository"),
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 50,
step_increment: 1,
value: settings.get_int("workflow-runs-max-display"),
}),
});
maxWorkflowRunsRow.connect("notify::value", () => {
settings.set_int("workflow-runs-max-display", maxWorkflowRunsRow.value);
});
actionsGroup.add(maxWorkflowRunsRow);
page.add(actionsGroup);
// --- Workflow Notifications group ---
const workflowNotificationsGroup = new Adw.PreferencesGroup({
title: _("Workflow Notifications"),
description: _("Choose which workflow events to notify about. Notifications are only sent for repositories with a configured local path."),
});
// Workflow started
const workflowStartedRow = new Adw.SwitchRow({
title: _("Workflow Started"),
subtitle: _("When a workflow run starts"),
active: settings.get_boolean("notify-workflow-started"),
});
workflowStartedRow.connect("notify::active", () => {
settings.set_boolean("notify-workflow-started", workflowStartedRow.active);
});
workflowNotificationsGroup.add(workflowStartedRow);
// Workflow success
const workflowSuccessRow = new Adw.SwitchRow({
title: _("Workflow Succeeded"),
subtitle: _("When a workflow run completes successfully"),
active: settings.get_boolean("notify-workflow-success"),
});
workflowSuccessRow.connect("notify::active", () => {
settings.set_boolean("notify-workflow-success", workflowSuccessRow.active);
});
workflowNotificationsGroup.add(workflowSuccessRow);
// Workflow failure
const workflowFailureRow = new Adw.SwitchRow({
title: _("Workflow Failed"),
subtitle: _("When a workflow run fails"),
active: settings.get_boolean("notify-workflow-failure"),
});
workflowFailureRow.connect("notify::active", () => {
settings.set_boolean("notify-workflow-failure", workflowFailureRow.active);
});
workflowNotificationsGroup.add(workflowFailureRow);
// Workflow cancelled
const workflowCancelledRow = new Adw.SwitchRow({
title: _("Workflow Cancelled"),
subtitle: _("When a workflow run is cancelled"),
active: settings.get_boolean("notify-workflow-cancelled"),
});
workflowCancelledRow.connect("notify::active", () => {
settings.set_boolean("notify-workflow-cancelled", workflowCancelledRow.active);
});
workflowNotificationsGroup.add(workflowCancelledRow);
page.add(workflowNotificationsGroup);
// --- Local Path Mappings group ---
const mappingsGroup = new Adw.PreferencesGroup({
title: _("Repository Path Mappings"),
description: _("Manage local paths for your repositories"),
});
// Load existing mappings
this._updateMappingsList(mappingsGroup, settings);
// Add button to add new mapping
const addMappingButton = new Gtk.Button({
label: _("Add New Mapping"),
halign: Gtk.Align.START,
margin_top: 10,
});
addMappingButton.connect("clicked", () => {
this._showAddMappingDialog(window, settings, mappingsGroup);
});
const addButtonRow = new Adw.ActionRow();
addButtonRow.set_child(addMappingButton);
mappingsGroup.add(addButtonRow);
page.add(mappingsGroup);
// --- Debug group ---
const debugGroup = new Adw.PreferencesGroup({
title: _("Debug"),
description: _("Enable debug features for testing"),
});
// Debug mode toggle
const debugRow = new Adw.SwitchRow({
title: _("Debug Mode"),
subtitle: _("Show debug button in menu to test notifications"),
active: settings.get_boolean("debug-mode"),
});
debugRow.connect("notify::active", () => {
settings.set_boolean("debug-mode", debugRow.active);
});
debugGroup.add(debugRow);
page.add(debugGroup);
window.add(page);
}
_updateMappingsList(group, settings) {
// Remove all existing rows except the last one (add button)
let child = group.get_first_child();
const rowsToRemove = [];
while (child) {
if (
child instanceof Adw.ActionRow &&
child.get_title() !== "Add New Mapping"
) {
rowsToRemove.push(child);
}
child = child.get_next_sibling();
}
rowsToRemove.forEach((row) => group.remove(row));
try {
const localProjectsJson = settings.get_string("local-projects");
const localProjects = JSON.parse(localProjectsJson);
const entries = Object.entries(localProjects);
if (entries.length === 0) {
const emptyRow = new Adw.ActionRow({
title: _("No mappings configured"),
subtitle: _('Click "Add New Mapping" to set up local paths'),
});
group.add(emptyRow);
return;
}
for (const [repoName, path] of entries) {
const row = new Adw.ActionRow({
title: repoName,
subtitle: path,
});
// Remove button
const removeButton = new Gtk.Button({
icon_name: "user-trash-symbolic",
valign: Gtk.Align.CENTER,
css_classes: ["destructive-action"],
});
removeButton.connect("clicked", () => {
this._removeMapping(settings, repoName, group);
});
row.add_suffix(removeButton);
group.add(row);
}
} catch (e) {
console.log(`Error loading mappings: ${e}`);
}
}
_showAddMappingDialog(parent, settings, group) {
// Create a simple window instead of deprecated Gtk.Dialog
const dialog = new Adw.Window({
title: _("Add Repository Mapping"),
transient_for: parent,
modal: true,
default_width: 400,
default_height: 300,
});
// Create header bar
const headerBar = new Adw.HeaderBar();
const cancelButton = new Gtk.Button({
label: _("Cancel"),
});
cancelButton.connect("clicked", () => {
dialog.close();
});
headerBar.pack_start(cancelButton);
const addButton = new Gtk.Button({
label: _("Add"),
css_classes: ["suggested-action"],
});
headerBar.pack_end(addButton);
// Create content
const toolbarView = new Adw.ToolbarView();
toolbarView.add_top_bar(headerBar);
const contentBox = new Gtk.Box({
orientation: Gtk.Orientation.VERTICAL,
spacing: 12,
margin_top: 24,
margin_bottom: 24,
margin_start: 24,
margin_end: 24,
});
// Repository name input
const repoEntry = new Adw.EntryRow({
title: _("Repository (owner/name)"),
});
repoEntry.set_text("");
contentBox.append(repoEntry);
// Local path input with browse button
const pathEntry = new Adw.EntryRow({
title: _("Local Path"),
});
pathEntry.set_text("");
const browseButton = new Gtk.Button({
icon_name: "folder-open-symbolic",
valign: Gtk.Align.CENTER,
tooltip_text: _("Browse..."),
});
browseButton.connect("clicked", () => {
const fileChooser = new Gtk.FileChooserDialog({
title: _("Select Repository Path"),
action: Gtk.FileChooserAction.SELECT_FOLDER,
transient_for: dialog,
modal: true,
});
fileChooser.add_button(_("Cancel"), Gtk.ResponseType.CANCEL);
fileChooser.add_button(_("Select"), Gtk.ResponseType.ACCEPT);
fileChooser.connect("response", (chooser, response) => {
if (response === Gtk.ResponseType.ACCEPT) {
const file = chooser.get_file();
if (file) {
pathEntry.set_text(file.get_path());
}
}
chooser.close();
});
fileChooser.show();
});
pathEntry.add_suffix(browseButton);
contentBox.append(pathEntry);
toolbarView.set_content(contentBox);
dialog.set_content(toolbarView);
// Add button handler
addButton.connect("clicked", () => {
const repoName = repoEntry.get_text().trim();
const path = pathEntry.get_text().trim();
if (repoName && path) {
this._addMapping(settings, repoName, path, group);
dialog.close();
}
});
dialog.present();
}
_addMapping(settings, repoName, path, group) {
try {
const localProjectsJson = settings.get_string("local-projects");
const localProjects = JSON.parse(localProjectsJson);
localProjects[repoName] = path;
settings.set_string("local-projects", JSON.stringify(localProjects));
this._updateMappingsList(group, settings);
} catch (e) {
console.log(`Error adding mapping: ${e}`);
}
}
_removeMapping(settings, repoName, group) {
try {
const localProjectsJson = settings.get_string("local-projects");
const localProjects = JSON.parse(localProjectsJson);
delete localProjects[repoName];
settings.set_string("local-projects", JSON.stringify(localProjects));
this._updateMappingsList(group, settings);
} catch (e) {
console.log(`Error removing mapping: ${e}`);
}
}
find(n, name) {
if (n.get_name() == name) {
return n;
}
let c = n.get_first_child();
while (c) {
let cn = this.find(c, name);
if (cn) {
return cn;
}
c = c.get_next_sibling();
}
return null;
}
_addHeaderBar(window) {
// Load menu UI
const builder = new Gtk.Builder();
builder.add_from_file(`${this.path}/ui/menu.ui`);
// Find the AdwHeaderBar in the window
let headerbar = this.find(window, "AdwHeaderBar");
if (!headerbar) {
console.log("Could not find AdwHeaderBar");
return;
}
headerbar.pack_start(builder.get_object("info_menu"));
// Setup menu actions
const actionGroup = new Gio.SimpleActionGroup();
window.insert_action_group("prefs", actionGroup);
// A list of actions with their associated links
const actions = [
{
name: "open-project",
link: "https://github.com/debba/github-tray-gnome-extension",
},
{
name: "open-issues",
link: "https://github.com/debba/github-tray-gnome-extension/issues",
},
{
name: "open-discord",
link: "https://discord.gg/YrZPHAwMSG",
},
];
actions.forEach((action) => {
let act = new Gio.SimpleAction({ name: action.name });
act.connect("activate", (_) =>
Gtk.show_uri(window, action.link, Gdk.CURRENT_TIME),
);
actionGroup.add_action(act);
});
}
}