Skip to content

Commit 4b4cb22

Browse files
committed
activate codesy home page on install to fix #117
1 parent 61f9cfd commit 4b4cb22

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const headerComment = require('gulp-header-comment');
1111
// Settings for building packages
1212
const settings = {
1313
name: 'codesy',
14-
version: '0.0.0.7',
14+
version: '0.0.0.8',
1515
source: './src',
1616
destination: './dist',
1717
static_files: {

src/on_install.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,57 @@
11
function find_these (query) {
22
return new Promise((resolve)=>{
3-
chrome.tabs.query(query, resolve);
3+
if (Object.keys(query).includes('title')) {
4+
// this is necessary until FF tab.title search works like Chrome
5+
chrome.tabs.query({}, (all_tabs)=>{
6+
tabs = all_tabs.filter(tab=>tab.title.includes(query.title))
7+
resolve(tabs)
8+
});
9+
} else {
10+
return chrome.tabs.query(query, resolve);
11+
}
412
});
513
}
614

7-
function wait_for (id, resolve) {
15+
function wait_for (tab, resolve) {
816
let times_checked = 0;
917
let timerID, load_status;
1018
const set_status = ({status}) =>load_status=status
1119
const check_until = (status) => {
1220
if (load_status === status || (times_checked += 1) > 150){
1321
window.clearTimeout(timerID)
14-
return resolve()
22+
return resolve(tab)
1523
}
16-
chrome.tabs.get(id, set_status)
24+
chrome.tabs.get(tab.id, set_status)
1725
timerID = window.setTimeout(check_until, 100, status);
1826
}
1927
check_until ( 'complete' )
2028
}
2129

22-
function reload (id) {
30+
function reload (tab) {
2331
return new Promise((resolve) => {
24-
chrome.tabs.reload(id)
25-
wait_for(id, resolve)
32+
chrome.tabs.reload(tab.id)
33+
wait_for(tab, resolve)
2634
});
2735
}
2836

2937
function reload_them (tabs) {
30-
const reloads = tabs.map(({id})=>reload(id))
31-
return Promise.all(reloads)
38+
const reloaded = tabs.map((tab)=>reload(tab))
39+
return Promise.all(reloaded)
3240
}
3341

34-
function select_them (tabs) {
35-
tabs.map( ({id}) => chrome.tabs.update(id, {selected:true}) )
36-
return tabs
42+
function activate_them (tabs) {
43+
activated = tabs.map( (tab)=>chrome.tabs.update(tab.id,{'active': true}) )
44+
return Promise.all(activated)
3745
}
3846

3947
function when_installed ({reason}) {
40-
find_these({ title: "*codesy.io*" })
41-
.then(select_them)
42-
.then(reload_them)
43-
.then(()=>{
44-
find_these({ url: "*://*.github.com/*" })
45-
.then(reload_them)
46-
})
48+
find_these( {title:"codesy.io"} )
49+
.then(reload_them)
50+
.then(activate_them)
51+
.then(()=>{
52+
find_these( {url: "*://*.github.com/*"} )
53+
.then(reload_them)
54+
})
4755
}
4856

4957
chrome.runtime.onInstalled.addListener(when_installed);

0 commit comments

Comments
 (0)