forked from The-Panacea-Projects/Gnomenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebGoogleChrome.js
135 lines (111 loc) · 3.55 KB
/
webGoogleChrome.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
/* ========================================================================================================
* 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(['google-chrome']);
const _foundApps = _appSystem.lookup_desktop_wmclass('google-chrome');
var _appInfo = null;
var _bookmarksFile = null;
var _bookmarksMonitor = null;
var _callbackId = null;
var bookmarks = [];
function _readBookmarks() {
bookmarks = [];
let content;
let jsonResult;
let size;
let success;
try {
[success, content, size] = _bookmarksFile.load_contents(null);
} catch(e) {
log("ERROR: " + e.message);
return;
}
if (! success) {
return;
}
try {
jsonResult = JSON.parse(content);
} catch(e) {
log("ERROR: " + e.message);
return;
}
if (! jsonResult.hasOwnProperty('roots')) {
return;
}
for (let bookmarkLocation in jsonResult.roots) {
let children = jsonResult.roots[bookmarkLocation].children;
for (let idx in children) {
if (children[idx].type == 'url') {
bookmarks.push({
appInfo: _appInfo,
name: children[idx].name,
score: 0,
uri: children[idx].url
});
}
}
}
}
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_user_config_dir(), 'google-chrome', 'Default', 'Bookmarks']));
if (! _bookmarksFile.query_exists(null)) {
_reset();
return;
}
_bookmarksMonitor = _bookmarksFile.monitor_file(
Gio.FileMonitorFlags.NONE, null);
_callbackId = _bookmarksMonitor.connect(
'changed', Lang.bind(this, _readBookmarks));
_readBookmarks();
}
function deinit() {
if (_bookmarksMonitor) {
if (_callbackId) {
_bookmarksMonitor.disconnect(_callbackId);
}
_bookmarksMonitor.cancel();
}
_reset();
}