Skip to content

Commit 8a71af9

Browse files
committed
Fix merge conflicts
2 parents e2063f3 + 0f9ff40 commit 8a71af9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+369
-281
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.DS_Store
22
.bundle
3+
log
34
tmp
45
public/assets
56
public/fonts

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ cache: bundler
55
before_script:
66
- gem update --system
77
- gem install bundler
8+
9+
deploy:
10+
provider: heroku
11+
app: devdocs
12+
on:
13+
branch: master
14+
api_key:
15+
secure: "4p1klvWJZSOImzFcKOduILjP93hlOlAhceWlYMKS4tU+TCFE8qTBzdKdFPSCsCgjB+YR9pBss+L0lJpVVMjSwFHXqpKe6EeUSltO2k7DFHfW7kXLUM/L0AfqXz+YXk76XUyZMhvOEbldPfaMaj10e8vgDOQCSHABDyK/4CU+hnI="

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM ruby:2.6.0
22

33
ENV LANG=C.UTF-8
4+
ENV ENABLE_SERVICE_WORKER=true
45

56
WORKDIR /devdocs
67

Dockerfile-alpine

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM ruby:2.6.0-alpine
22

33
ENV LANG=C.UTF-8
4+
ENV ENABLE_SERVICE_WORKER=true
45

56
WORKDIR /devdocs
67

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ The web app is all client-side JavaScript, written in [CoffeeScript](http://coff
5959

6060
Many of the code's design decisions were driven by the fact that the app uses XHR to load content directly into the main frame. This includes stripping the original documents of most of their HTML markup (e.g. scripts and stylesheets) to avoid polluting the main frame, and prefixing all CSS class names with an underscore to prevent conflicts.
6161

62-
Another driving factor is performance and the fact that everything happens in the browser. `applicationCache` (which comes with its own set of constraints) and `localStorage` are used to speed up the boot time, while memory consumption is kept in check by allowing the user to pick his/her own set of documentations. The search algorithm is kept simple because it needs to be fast even searching through 100,000 strings.
62+
Another driving factor is performance and the fact that everything happens in the browser. A service worker (which comes with its own set of constraints) and `localStorage` are used to speed up the boot time, while memory consumption is kept in check by allowing the user to pick his/her own set of documentations. The search algorithm is kept simple because it needs to be fast even searching through 100,000 strings.
6363

6464
DevDocs being a developer tool, the browser requirements are high:
6565

6666
* Recent versions of Firefox, Chrome, or Opera
67-
* Safari 9.1+
68-
* Edge 16+
69-
* iOS 10+
67+
* Safari 11.1+
68+
* Edge 17+
69+
* iOS 11.3+
7070

7171
This allows the code to take advantage of the latest DOM and HTML5 APIs and make developing DevDocs a lot more fun!
7272

@@ -156,7 +156,7 @@ Contributions are welcome. Please read the [contributing guidelines](./.github/C
156156
* [Doc Browser](https://github.com/qwfy/doc-browser) is a native Linux app that supports DevDocs docsets
157157
* [GNOME Application](https://github.com/hardpixel/devdocs-desktop) GTK3 application with search integrated in headerbar
158158
* [macOS Application](https://github.com/dteoh/devdocs-macos)
159-
* [Android Application](https://github.com/Merith-TK/devdocs_webapp_kotlin) is a fully working, advanced WebView with AppCache enabled
159+
* [Android Application](https://github.com/Merith-TK/devdocs_webapp_kotlin) is a fully working, advanced WebView
160160

161161
## Copyright / License
162162

assets/javascripts/app/app.coffee

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313

1414
@el = $('._app')
1515
@localStorage = new LocalStorageStore
16-
@appCache = new app.AppCache if app.AppCache.isEnabled()
16+
@serviceWorker = new app.ServiceWorker if app.ServiceWorker.isEnabled()
1717
@settings = new app.Settings
1818
@db = new app.DB()
1919

20+
@settings.initLayout()
21+
2022
@docs = new app.collections.Docs
2123
@disabledDocs = new app.collections.Docs
2224
@entries = new app.collections.Entries
@@ -138,7 +140,10 @@
138140
@docs.sort()
139141
@initDoc(doc)
140142
@saveDocs()
141-
_onSuccess()
143+
if app.settings.get('autoInstall')
144+
doc.install(_onSuccess, onError)
145+
else
146+
_onSuccess()
142147
return
143148

144149
doc.load onSuccess, onError, writeCache: true
@@ -147,7 +152,7 @@
147152
saveDocs: ->
148153
@settings.setDocs(doc.slug for doc in @docs.all())
149154
@db.migrate()
150-
@appCache?.updateInBackground()
155+
@serviceWorker?.updateInBackground()
151156

152157
welcomeBack: ->
153158
visitCount = @settings.get('count')
@@ -167,14 +172,14 @@
167172
reload: ->
168173
@docs.clearCache()
169174
@disabledDocs.clearCache()
170-
if @appCache then @appCache.reload() else @reboot()
175+
if @serviceWorker then @serviceWorker.reload() else @reboot()
171176
return
172177

173178
reset: ->
174179
@localStorage.reset()
175180
@settings.reset()
176181
@db?.reset()
177-
@appCache?.update()
182+
@serviceWorker?.update()
178183
window.location = '/'
179184
return
180185

@@ -193,9 +198,9 @@
193198
return
194199

195200
indexHost: ->
196-
# Can't load the index files from the host/CDN when applicationCache is
201+
# Can't load the index files from the host/CDN when service worker is
197202
# enabled because it doesn't support caching URLs that use CORS.
198-
@config[if @appCache and @settings.hasDocs() then 'index_path' else 'docs_origin']
203+
@config[if @serviceWorker and @settings.hasDocs() then 'index_path' else 'docs_origin']
199204

200205
onBootError: (args...) ->
201206
@trigger 'bootError'
@@ -252,7 +257,7 @@
252257
matchMedia: !!window.matchMedia
253258
insertAdjacentHTML: !!document.body.insertAdjacentHTML
254259
defaultPrevented: document.createEvent('CustomEvent').defaultPrevented is false
255-
cssVariables: CSS.supports and CSS.supports('(--t: 0)')
260+
cssVariables: !!CSS?.supports?('(--t: 0)')
256261

257262
for key, value of features when not value
258263
Raven.captureMessage "unsupported/#{key}", level: 'info'

assets/javascripts/app/appcache.coffee

Lines changed: 0 additions & 42 deletions
This file was deleted.

assets/javascripts/app/config.coffee.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ app.config =
1313
version: <%= Time.now.to_i %>
1414
release: <%= Time.now.utc.httpdate.to_json %>
1515
mathml_stylesheet: '<%= App.cdn_origin %>/mathml.css'
16+
service_worker_path: '/service-worker.js'
17+
service_worker_enabled: <%= App.environment == :production || ENV['ENABLE_SERVICE_WORKER'] == 'true' %>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
class app.ServiceWorker
2+
$.extend @prototype, Events
3+
4+
@isEnabled: ->
5+
!!navigator.serviceWorker and app.config.service_worker_enabled
6+
7+
constructor: ->
8+
@registration = null
9+
@notifyUpdate = true
10+
11+
navigator.serviceWorker.register(app.config.service_worker_path, {scope: '/'})
12+
.then(
13+
(registration) => @updateRegistration(registration),
14+
(error) -> console.error('Could not register service worker:', error)
15+
)
16+
17+
update: ->
18+
return unless @registration
19+
@notifyUpdate = true
20+
return @registration.update().catch(->)
21+
22+
updateInBackground: ->
23+
return unless @registration
24+
@notifyUpdate = false
25+
return @registration.update().catch(->)
26+
27+
reload: ->
28+
return @updateInBackground().then(() -> app.reboot())
29+
30+
updateRegistration: (registration) ->
31+
@registration = registration
32+
$.on @registration, 'updatefound', @onUpdateFound
33+
return
34+
35+
onUpdateFound: =>
36+
$.off @installingRegistration, 'statechange', @onStateChange() if @installingRegistration
37+
@installingRegistration = @registration.installing
38+
$.on @installingRegistration, 'statechange', @onStateChange
39+
return
40+
41+
onStateChange: =>
42+
if @installingRegistration and @installingRegistration.state == 'installed' and navigator.serviceWorker.controller
43+
@installingRegistration = null
44+
@onUpdateReady()
45+
return
46+
47+
onUpdateReady: ->
48+
@trigger 'updateready' if @notifyUpdate
49+
return

assets/javascripts/app/settings.coffee

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ class app.Settings
55
'manualUpdate'
66
'fastScroll'
77
'arrowScroll'
8+
'analyticsConsent'
89
'docs'
910
'dark'
1011
'layout'
1112
'size'
1213
'tips'
14+
'autoInstall'
1315
]
1416

1517
INTERNAL_KEYS = [
@@ -19,13 +21,16 @@ class app.Settings
1921
'news'
2022
]
2123

24+
LAYOUTS: ['_max-width', '_sidebar-hidden', '_native-scrollbars']
25+
2226
@defaults:
2327
count: 0
2428
hideDisabled: false
2529
hideIntro: false
2630
news: 0
2731
manualUpdate: false
2832
schema: 1
33+
analyticsConsent: false
2934

3035
constructor: ->
3136
@store = new CookieStore
@@ -38,6 +43,7 @@ class app.Settings
3843
set: (key, value) ->
3944
@store.set(key, value)
4045
delete @cache[key]
46+
@toggleDark(value) if key == 'dark'
4147
return
4248

4349
del: (key) ->
@@ -63,6 +69,8 @@ class app.Settings
6369
return
6470

6571
setLayout: (name, enable) ->
72+
@toggleLayout(name, enable)
73+
6674
layout = (@store.get('layout') || '').split(' ')
6775
$.arrayDelete(layout, '')
6876

@@ -104,3 +112,28 @@ class app.Settings
104112
@store.reset()
105113
@cache = {}
106114
return
115+
116+
initLayout: ->
117+
@toggleDark(@get('dark') is 1)
118+
@toggleLayout(layout, @hasLayout(layout)) for layout in @LAYOUTS
119+
@initSidebarWidth()
120+
return
121+
122+
toggleDark: (enable) ->
123+
classList = document.documentElement.classList
124+
classList.toggle('_theme-default', !enable)
125+
classList.toggle('_theme-dark', enable)
126+
color = getComputedStyle(document.documentElement).getPropertyValue('--headerBackground').trim()
127+
$('meta[name=theme-color]').setAttribute('content', color)
128+
return
129+
130+
toggleLayout: (layout, enable) ->
131+
classList = document.body.classList
132+
classList.toggle(layout, enable) unless layout is '_sidebar-hidden'
133+
classList.toggle('_overlay-scrollbars', $.overlayScrollbarsEnabled())
134+
return
135+
136+
initSidebarWidth: ->
137+
size = @get('size')
138+
document.documentElement.style.setProperty('--sidebarWidth', size + 'px') if size
139+
return

0 commit comments

Comments
 (0)