-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefs.js
146 lines (126 loc) · 5.06 KB
/
prefs.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
136
137
138
139
140
141
142
143
144
145
146
const GObject = imports.gi.GObject;
const Gtk = imports.gi.Gtk;
const Lang = imports.lang;
//const Config = imports.misc.config;
//const Gio = imports.gi.Gio;
const Soup = imports.gi.Soup;
const Gettext = imports.gettext.domain('steam-indicator');
const _ = Gettext.gettext;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Lib = Me.imports.lib;
function init() {
Lib.initTranslations();
}
const SteamIndicatorSettings = new GObject.Class({
Name: 'SteamIndicatorPrefs',
Extends: Gtk.Grid,
_init: function(params) {
this.parent(params);
this.margin = 24;
this.spacing = 30;
this.row_spacing = 10;
this._settings = Lib.getSettings();
let label = null
let widget = null;
let value = null;
// Steam ID
label = new Gtk.Label({
label: _('Steam ID <small>(Enter your <a href=\'steam://url/SteamIDMyProfile\' title=\'Either one works: http:\/\/steamcommunity.com\/profiles\/7656119xxxxxxxxxx http:\/\/steamcommunity.com\/id\/custom_name\'>public profile URL</a> and hit <tt>Enter</tt>)</small>'),
useMarkup: true,
trackVisitedLinks: false,
hexpand: true,
halign: Gtk.Align.START
});
widget = new Gtk.Entry({halign: Gtk.Align.END});
widget.set_text(this._settings.get_string('steam-id'));
// Reset Progress Bar
let resetProgress = function(w) {w.set_progress_fraction(0.0);}
widget.connect('move-cursor', resetProgress);
widget.connect('backspace', resetProgress);
widget.connect('delete-from-cursor', resetProgress);
// Fill in Steam Profile ID on `Enter`
widget.connect('activate', Lang.bind(this, function(w) {
resetProgress(w);
value = w.get_text().trim();
this.steamIDWidget = w; // temp reference
// case 1: http://steamcommunity.com/profiles/76561198000532251
let idPattern = /steamcommunity\.com\/profiles\/(\d+)/i;
// case 2: http://steamcommunity.com/id/synapsos
let vanityPattern = /steamcommunity\.com\/id\/(\w+)/i;
if (idPattern.test(value)) { // case 1
steamID = value.match(idPattern)[1];
this.setSteamID(steamID);
}
else if (vanityPattern.test(value)) { // case 2
let vanity = value.match(vanityPattern)[1];
w.set_progress_fraction(0.5);
this.findSteamID(vanity);
}
else {
w.set_text(_('Not a valid profile link'));
w.select_region(0,-1);
}
}));
this.attach(label, 0, 1, 1, 1);
this.attach(widget, 1, 1, 1, 1);
// Steam Web API Key
label = new Gtk.Label({
label: _('Steam Web API Key <small>(optional: Get your own key <a href=\'http://steamcommunity.com/dev/apikey\'>here</a>)</small>'),
useMarkup: true,
trackVisitedLinks: false,
hexpand: true,
halign: Gtk.Align.START
});
widget = new Gtk.Entry({halign: Gtk.Align.END});
widget.set_text(this._settings.get_string('api-key'));
widget.connect('activate', Lang.bind(this, function(w) {
value = w.get_text();
this._settings.set_string('api-key', value);
}));
this.attach(label, 0, 2, 1, 1);
this.attach(widget, 1, 2, 1, 1);
// Visible menu items
label = new Gtk.Label({
label: _('Visible Menu items'),
hexpand: true,
halign: Gtk.Align.START
});
widget = new Gtk.Entry({halign: Gtk.Align.END});
widget.set_text(this._settings.get_string('menu-items'));
widget.connect('activate', Lang.bind(this, function(w) {
value = w.get_text();
this._settings.set_string('menu-items', value);
}));
this.attach(label, 0, 3, 1, 1);
this.attach(widget, 1, 3, 1, 1);
},
findSteamID: function(vanityUrl) {
let steamID = "";
let url = 'http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/';
let params = {
key: this._settings.get_string('api-key'),
vanityurl: vanityUrl,
format: 'json'
};
//this._httpRequest('GET', url, params, Lang.bind(this, function(json) {
Lib.httpRequest('GET', url, params, Lang.bind(this, function(json) {
if (json.response.success == 1) {
this.setSteamID(json.response.steamid);
} else {
this.steamIDWidget.set_text(json.response.message);
this.steamIDWidget.select_region(0,-1);
}
}));
},
setSteamID: function(steamID) {
this._settings.set_string('steam-id', steamID);
this.steamIDWidget.set_text(steamID);
this.steamIDWidget.set_progress_fraction(1.0);
},
});
function buildPrefsWidget() {
let widget = new SteamIndicatorSettings();
widget.show_all();
return widget;
}