forked from The-Panacea-Projects/Gnomenu
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webOpera.js
141 lines (116 loc) · 3.73 KB
/
webOpera.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
/* ========================================================================================================
* CREDITS: Code borrowed from SearchBookmarks extension by bmh1980
* at https://extensions.gnome.org/extension/557/search-bookmarks/
* ========================================================================================================
*/
/**
* Copyright (C) 2012 Marcus Habermehl <[email protected]>
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
// External imports
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;
const Shell = imports.gi.Shell;
// Gjs imports
const Lang = imports.lang;
// Internal imports
const Main = imports.ui.main;
const _appSystem = Shell.AppSystem.get_default();
//const _foundApps = _appSystem.initial_search(['opera']);
const _foundApps = _appSystem.lookup_desktop_wmclass('opera');
var _appInfo = null;
var _bookmarksFile = null;
var _bookmarksMonitor = null;
var _callbackId = null;
var bookmarks = [];
function _readBookmarks() {
bookmarks = [];
let content;
let size;
let success;
try {
[success, content, size] = _bookmarksFile.load_contents(null);
} catch(e) {
log("ERROR: " + e.message);
return;
}
if (! success) {
return;
}
let lines = String(content).split("\n");
let isURL = false;
let name = null;
let url = null;
for (let i = 0; i < lines.length; i++) {
let line = lines[i].trim();
if (line == "#URL") {
isURL = true;
} else {
if (isURL) {
if (line.indexOf("NAME=") == 0) {
name = line.split("NAME=")[1];
} else if (line.indexOf("URL=") == 0) {
url = line.split("URL=")[1];
} else if (line == "") {
bookmarks.push({
appInfo: _appInfo,
name: name,
score: 0,
uri: url
});
isURL = false;
name = null;
url = null;
}
}
}
}
}
function _reset() {
_appInfo = null;
_bookmarksFile = null;
_bookmarksMonitor = null;
_callbackId = null;
bookmarks = [];
}
function init() {
if (_foundApps == null || _foundApps.length == 0) {
return;
}
//_appInfo = _foundApps[0].get_app_info();
_appInfo = _foundApps.get_app_info();
_bookmarksFile = Gio.File.new_for_path(GLib.build_filenamev(
[GLib.get_home_dir(), '.opera', 'bookmarks.adr']));
if (! _bookmarksFile.query_exists(null)) {
_reset();
return;
}
_bookmarksMonitor = _bookmarksFile.monitor_file(
Gio.FileMonitorFlags.NONE, null);
_callbackId = _bookmarksMonitor.connect(
'changed', _readBookmarks.bind(this));
_readBookmarks();
}
function deinit() {
if (_bookmarksMonitor) {
if (_callbackId) {
_bookmarksMonitor.disconnect(_callbackId);
}
_bookmarksMonitor.cancel();
}
_reset();
}