-
Notifications
You must be signed in to change notification settings - Fork 18
/
Conf.js
135 lines (121 loc) · 3.9 KB
/
Conf.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
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
/*
* Copyright (c) 2012-2017 Gnome Email Notifications contributors
*
* Gnome Email Notifications is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* Gnome Email Notifications is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with Gnome Documents; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
* Adam Jabłoński <jablona123@gmail.com>
* Shuming Chan <shuming0207@gmail.com>
*
*/
"use strict";
const Gettext = imports.gettext;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const {Gio, GLib} = imports.gi;
/**
* Controls configuration for extension.
*/
var Conf = class {
/**
* Creates a new conf for an extension
* @param {Extension} extension - the extension to control
*/
constructor(extension) {
this.settings = Conf.getSettings();
if (extension === undefined) return;
this.settings.connect("changed::timeout", () => {
extension.stopTimeout();
extension.startTimeout();
});
}
/**
* Gets time between calls to email server.
* @returns {number}
*/
getTimeout() {
return this.settings.get_int('timeout');
}
/**
* Sets time between calls to email server.
* @param {number} timeout
*/
setTimeout(timeout) {
this.settings.set_int('timeout', timeout);
}
/**
* Returns 1 if we should use default email client instead of browser. 0 otherwise.
* @returns {number}
*/
getReader() {
return this.settings.get_int('usemail');
}
/**
* Sets 1 if we should use default email client instead of browser. 0 otherwise.
* @param {number} reader
*/
setReader(reader) {
return this.settings.set_int('usemail', reader);
}
/**
* Returns an array of ids of messages already shown
* @returns {Array} array of ids
*/
getMessagesShown() {
const val = this.settings.get_value('messagesshown');
return val.deep_unpack();
}
/**
* Replaces the array of ids of messages already shown
* @param {Array} array - array of ids
*/
setMessagesShown(array) {
const gVariant = new GLib.Variant('as', array);
this.settings.set_value('messagesshown', gVariant);
}
/**
* Returns the Gmail system label for the mailbox to read
* @returns {string}
*/
getGmailSystemLabel() {
return this.settings.get_string('gmailsystemlabel');
}
/**
* Sets the Gmail system label for the mailbox to read
* @param {number} reader
*/
setGmailSystemLabel(gmail_system_label) {
return this.settings.set_string('gmailsystemlabel', gmail_system_label);
}
/**
* Gets the settings from Gio.
* @returns {Gio.Settings}
*/
static getSettings() {
let schemaName = 'org.gnome.shell.extensions.gmailmessagetray';
let schemaDir = Me.dir.get_child('schemas').get_path();
let schemaSource = Gio.SettingsSchemaSource.new_from_directory(schemaDir,
Gio.SettingsSchemaSource.get_default(),
false);
let schema = schemaSource.lookup(schemaName, false);
return new Gio.Settings({settings_schema: schema});
}
/**
* Sets up translations from locale directory.
*/
static setupTranslations() {
const localeDir = Me.dir.get_child('locale').get_path();
Gettext.bindtextdomain('gmail_notify', localeDir);
}
};