forked from ReDEnergy/SessionSync
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
179 lines (144 loc) · 4.26 KB
/
Copy pathconfig.js
File metadata and controls
179 lines (144 loc) · 4.26 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
define(function(require, exports) {
'use strict';
// *****************************************************************************
// Custom Modules
// Utils
const { GlobalEvents } = require('./utils/global-events');
// *****************************************************************************
// API
var Config = (function() {
var localSettings = {};
var isPanelUI = (document.body.clientWidth == 0);
// ------------------------------------------------------------------------
// API
function getConfigValue(key, defaultValue)
{
browser.storage.local.get(key).then(function (obj) {
if (Object.keys(obj).length === 0 && obj.constructor === Object && defaultValue != undefined)
{
set(key, defaultValue);
}
else
{
localSettings[key] = obj[key];
GlobalEvents.emit(key, obj[key]);
}
});
}
var setupConfig = function setupConfig()
{
// Styling
getConfigValue('style.panel.width', 800);
getConfigValue('style.panel.height', 600);
getConfigValue('style.sessions.list.width', 220);
getConfigValue('style.scale.toolbar', 12);
getConfigValue('style.scale.header', 18);
getConfigValue('style.scale.sessions', 12);
getConfigValue('style.scale.bookmarks', 14);
getConfigValue('state.scrollTop.current', 0);
getConfigValue('state.scrollTop.restore', 0);
getConfigValue('state.scrollTop.history', 0);
// Session saving settings
getConfigValue('session.save', {
pinned: false,
allWindows: false
});
// Management configuration
getConfigValue('session.view', undefined);
getConfigValue('session.sorting', 'position-asc');
getConfigValue('session.active.filter', '');
getConfigValue('session.selected', null);
getConfigValue('session.history.selected', null);
// Bookmarks configuration
getConfigValue('bookmark.click.new.tab', false);
// General settings
getConfigValue('detach.window', true);
getConfigValue('context.menu.icons', true);
getConfigValue('storageID');
getConfigValue('hide.trash.can', true);
getConfigValue('undo.events', []);
};
var set = function set(key, value, onSuccess)
{
browser.storage.local.set({ [key] : value })
.then(function success() {
localSettings[key] = value;
GlobalEvents.emit(key, value);
if (typeof onSuccess === 'function') {
onSuccess();
}
}, function onError(error) {
console.log(error);
});
};
var get = function get(key)
{
if (localSettings[key] === undefined) {
console.log('[ERROR] Settings key [' + key + '] was not found!');
}
return localSettings[key];
};
var initState = true;
var isInitState = function isInitState()
{
if (initState == true) {
initState = false;
return true;
}
return false;
};
var isPanel = function isPanel()
{
return isPanelUI;
};
var isAddonContext = function isAddonContext()
{
return typeof browser === 'object';
};
// ------------------------------------------------------------------------
// Startup
var init = function init()
{
setupConfig();
if (isAddonContext()) {
browser.commands.getAll().
then(function (commands) {
GlobalEvents.emit('config.hotkey.init', commands);
});
}
// console.log(localSettings);
};
if (isAddonContext()) {
// console.log('');
// console.log('------------------------------------------');
// var manifest = browser.runtime.getManifest();
// console.log(manifest);
// console.log(manifest.name + ' v' + manifest.version);
// console.log('------------------------------------------');
setupConfig();
GlobalEvents.on('hotkey.update', function (command) {
browser.commands.update({
name: command.name,
shortcut: command.shortcut
});
});
}
// ------------------------------------------------------------------------
// Public API
return {
set: set,
get: get,
init : init,
isPanel: isPanel,
isInitState: isInitState,
isAddonContext: isAddonContext
};
})();
// ------------------------------------------------------------------------
// Events
// ------------------------------------------------------------------------
// Init
// ------------------------------------------------------------------------
// Module exports
exports.AppConfig = Config;
});