This repository was archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpreferences.js
96 lines (85 loc) · 3.38 KB
/
preferences.js
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
(function(globals) {
'use strict';
globals.Gmrle = globals.Gmrle || {};
globals.Gmrle.PreferencesManager = class {
get defaults() {
return {
display_source_and_target_branches: true,
enable_buttons_to_copy_source_and_target_branches_name: true,
enable_button_to_copy_mr_info: true,
copy_mr_info_format: 'MR {MR_ID} (from {MR_AUTHOR_NAME}): {MR_TITLE}\n{MR_URL}',
enable_jira_ticket_link: false,
base_jira_url: '',
jira_ticket_link_label_type: 'ticket_id',
enable_button_to_toggle_wip_status: true,
enable_unresolved_discussions_indicator: true
};
}
/**
* This class holds all the logic related to user preferences persistance.
*/
constructor() {
if (globals.browser) { // Firefox and Edge uses `browser`, Chrome and Opera uses `chrome`
this.getAll = this.getAllBrowser;
this.setAll = this.setAllBrowser;
} else if (globals.chrome) {
this.getAll = this.getAllChrome;
this.setAll = this.setAllChrome;
} else {
console.error('Unsupported browser');
}
}
/**
* Get all the user's preferences.
*
* Used as `getAll` if the current browser is Firefox or Edge.
*/
getAllBrowser(successCallback) {
browser.storage.local.get(this.defaults).then(successCallback, function() {
alert('Error retrieving extension preferences.');
});
}
/**
* Save all the user's preferences.
*
* Used as `setAll` if the current browser is Firefox or Edge.
*/
setAllBrowser(preferences, successCallback, errorCallback) {
browser.storage.local.set(preferences).then(successCallback, function() {
errorCallback();
alert('Error saving extension preferences.');
});
}
/**
* Get all the user's preferences.
*
* Used as `getAll` if the current browser is Chrome or Opera.
*/
getAllChrome(successCallback) {
chrome.storage.local.get(this.defaults, function(preferences) {
if (chrome.runtime.lastError) {
alert('Error retrieving extension preferences, check console for more information.');
console.error('Error retrieving extension preferences:', chrome.runtime.lastError);
} else {
successCallback(preferences);
}
});
}
/**
* Save all the user's preferences.
*
* Used as `setAll` if the current browser is Chrome or Opera.
*/
setAllChrome(preferences, successCallback, errorCallback) {
chrome.storage.local.set(preferences, function() {
if (chrome.runtime.lastError) {
errorCallback();
alert('Error saving extension preferences, check console for more information.');
console.error('Error saving extension preferences:', chrome.runtime.lastError);
} else {
successCallback();
}
});
}
}
}(this));