Skip to content

Commit 533ff7d

Browse files
committed
Merge branch 'develop'
2 parents bc93b22 + 0f2372d commit 533ff7d

File tree

14 files changed

+476
-250
lines changed

14 files changed

+476
-250
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v2.1.0
2+
- NEW: Allow using an extension key to secure entered credentials
3+
- FIX: Various fixes for Firefox
4+
15
## v2.0.6
26
- FIX: Correctly escape paths in tags
37
- FIX: Wait a certain time before starting sync when detecting changes

gulpfile.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ var zip = require('gulp-zip')
77
const VERSION = require('./package.json').version
88
const paths = {
99
zip: [
10-
'dist/*'
11-
, 'icons/*'
12-
, 'views/*'
13-
, 'CHANGELOG.md'
14-
, 'README.md'
15-
, 'manifest.json'
16-
, 'package.json'
17-
, 'LICENSE.txt'
10+
'**'
11+
, '!src/**'
12+
, '!node_modules/**'
13+
, '!img/**'
14+
, '!ISSUE_TEMPLATE.md'
15+
, '!gulpfile.js'
1816
]
1917
, views: './views/*.html'
2018
, entries: 'src/entries/*.js'

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33
"name": "floccus",
44
"short_name": "floccus",
5-
"version": "2.0.6",
5+
"version": "2.1.0",
66
"description": "Sync your bookmarks with nextcloud",
77
"icons": {
88
"48": "icons/logo.png"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "floccus",
3-
"version": "2.0.6",
3+
"version": "2.1.0",
44
"description": "Sync your bookmarks with nextcloud",
55
"main": "index.js",
66
"scripts": {

src/entries/background-script.js

Lines changed: 2 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,4 @@
1-
import browser from '../lib/browser-api'
2-
import Account from '../lib/Account'
3-
import Tree from '../lib/Tree'
4-
import packageJson from '../../package.json'
5-
6-
const STATUS_ERROR = Symbol('error')
7-
const STATUS_SYNCING = Symbol('syncing')
8-
const STATUS_ALLGOOD = Symbol('allgood')
9-
const INACTIVITY_TIMEOUT = 1000 * 60
10-
11-
class AlarmManger {
12-
constructor (ctl) {
13-
this.ctl = ctl
14-
}
15-
16-
syncAllAccounts () {
17-
browser.storage.local.get('accounts')
18-
.then((d) => {
19-
var accounts = d['accounts']
20-
for (var accountId in accounts) {
21-
this.ctl.syncAccount(accountId)
22-
}
23-
})
24-
}
25-
}
26-
27-
class Controller {
28-
constructor () {
29-
this.syncing = {}
30-
this.schedule = {}
31-
32-
this.alarms = new AlarmManger(this)
33-
34-
// set up change listener
35-
browser.bookmarks.onChanged.addListener((localId, details) => this.onchange(localId, details))
36-
browser.bookmarks.onMoved.addListener((localId, details) => this.onchange(localId, details))
37-
browser.bookmarks.onRemoved.addListener((localId, details) => this.onchange(localId, details))
38-
browser.bookmarks.onCreated.addListener((localId, details) => this.onchange(localId, details))
39-
40-
// Set up the alarms
41-
42-
browser.alarms.create('syncAllAccounts', {periodInMinutes: 15})
43-
browser.alarms.onAlarm.addListener(alarm => {
44-
this.alarms[alarm.name]()
45-
})
46-
47-
window.syncAccount = (accountId) => this.syncAccount(accountId)
48-
this.setEnabled(true)
49-
50-
browser.storage.local.get('currentVersion')
51-
.then(async d => {
52-
if (packageJson.version === d.currentVersion) return
53-
const accounts = await Account.getAllAccounts()
54-
await Promise.all(
55-
accounts.map(account => account.init())
56-
)
57-
await browser.storage.local.set({
58-
currentVersion: packageJson.version
59-
})
60-
browser.runtime.openOptionsPage()
61-
})
62-
}
63-
64-
setEnabled (enabled) {
65-
this.enabled = enabled
66-
}
67-
68-
async onchange (localId, details) {
69-
if (!this.enabled) {
70-
return
71-
}
72-
const allAccounts = await Account.getAllAccounts()
73-
74-
// Check which accounts contain the bookmark and which used to contain (track) it
75-
var trackingAccountsFilter = await Promise.all(
76-
allAccounts
77-
.map(async account => {
78-
return account.tracksBookmark(localId)
79-
})
80-
)
81-
82-
const accountsToSync = allAccounts
83-
// Filter out any accounts that are not tracking the bookmark
84-
.filter((account, i) => (trackingAccountsFilter[i]))
85-
// Filter out any accounts that are presently syncing
86-
.filter(account => !this.syncing[account.id])
87-
88-
// We should now sync all accounts that are involved in this change (2 at max)
89-
accountsToSync.forEach((account) => {
90-
this.scheduleSyncAccount(account.id)
91-
})
92-
93-
var ancestors
94-
try {
95-
ancestors = await Tree.getIdPathFromLocalId(localId)
96-
} catch (e) {
97-
return
98-
}
99-
100-
const containingAccount = await Account.getAccountContainingLocalId(localId, ancestors, allAccounts)
101-
if (containingAccount &&
102-
!this.syncing[containingAccount.id] &&
103-
!accountsToSync.some(acc => acc.id === containingAccount.id)) {
104-
this.scheduleSyncAccount(containingAccount.id)
105-
}
106-
}
107-
108-
scheduleSyncAccount (accountId) {
109-
if (this.schedule[accountId]) {
110-
clearTimeout(this.schedule[accountId])
111-
}
112-
this.schedule[accountId] = setTimeout(() => this.syncAccount(accountId), INACTIVITY_TIMEOUT)
113-
}
114-
115-
syncAccount (accountId) {
116-
if (!this.enabled) {
117-
return
118-
}
119-
if (this.syncing[accountId]) {
120-
return this.syncing[accountId].then(() => {
121-
return this.syncAccount(accountId)
122-
})
123-
}
124-
this.syncing[accountId] = Account.get(accountId)
125-
.then((account) => {
126-
setTimeout(() => this.updateBadge(), 500)
127-
return account.sync()
128-
})
129-
.then(() => {
130-
this.syncing[accountId] = false
131-
this.updateBadge()
132-
}, (error) => {
133-
console.error(error)
134-
this.syncing[accountId] = false
135-
this.updateBadge()
136-
})
137-
return this.syncing[accountId]
138-
}
139-
140-
async updateBadge () {
141-
const accounts = await Account.getAllAccounts()
142-
const overallStatus = accounts
143-
.reduce((status, account) => {
144-
const accData = account.getData()
145-
if (accData.error && !accData.syncing) {
146-
return STATUS_ERROR
147-
} else if (accData.syncing && status !== STATUS_ERROR) {
148-
return STATUS_SYNCING
149-
} else {
150-
return STATUS_ALLGOOD
151-
}
152-
}, STATUS_ALLGOOD)
153-
this.setStatusBadge(overallStatus)
154-
}
155-
156-
async setStatusBadge (status) {
157-
switch (status) {
158-
case STATUS_ALLGOOD:
159-
browser.browserAction.setBadgeText({text: ''})
160-
break
161-
case STATUS_SYNCING:
162-
browser.browserAction.setBadgeText({text: '<->'})
163-
browser.browserAction.setBadgeBackgroundColor({color: '#0088dd'})
164-
break
165-
case STATUS_ERROR:
166-
browser.browserAction.setBadgeText({text: '!'})
167-
browser.browserAction.setBadgeBackgroundColor({color: '#dd4d00'})
168-
break
169-
}
170-
}
171-
}
1+
import Controller from '../lib/Controller'
1722

1733
window.controller = new Controller()
4+
window.syncAccount = (accountId) => window.controller.syncAccount(accountId)

0 commit comments

Comments
 (0)