-
Notifications
You must be signed in to change notification settings - Fork 85
/
TextureDesktopAppChrome.js
69 lines (61 loc) · 1.97 KB
/
TextureDesktopAppChrome.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
import { DefaultDOMElement } from 'substance'
import { InMemoryDarBuffer } from './dar'
import TextureAppChrome from './TextureAppChrome'
export default class TextureDesktopAppChrome extends TextureAppChrome {
didMount () {
super.didMount()
DefaultDOMElement.getBrowserWindow().on('click', this._click, this)
}
_getBuffer () {
return new InMemoryDarBuffer()
}
_getStorage () {
// Note: in the Desktop app, the storage is maintained by the main process
// and passed as a prop directly. In contrast to the web-version
// there is no control via HTTP param possible
return this.props.storage
}
// emit an event on this component. The Electron binding in app.js listens to it and
// handles it
_handleSave () {
this.emit('save')
}
_saveAs (newDarPath, cb) {
console.info('saving as', newDarPath)
let archive = this.state.archive
archive.saveAs(newDarPath, err => {
if (err) {
console.error(err)
return cb(err)
}
// HACK: this is kind of an optimization but formally it is not
// 100% correct to continue with the same archive instance
// Instead one would expect that cloning an archive returns
// a new archive instance
// Though, this would have other undesired implications
// such as loosing the scroll position or undo history
// Thus we move on with this solution, but we need to clear
// the isReadOnly flag now.
archive.isReadOnly = false
this._updateTitle()
cb()
})
}
_updateTitle () {
const archive = this.state.archive
if (!archive) return
let newTitle = archive.getTitle()
if (archive.hasPendingChanges()) {
newTitle += ' *'
}
document.title = newTitle
}
_click (event) {
const target = DefaultDOMElement.wrapNativeElement(event.target)
let url = target.getAttribute('href')
if (target.is('a') && url !== '#') {
event.preventDefault()
this.emit('openExternal', url)
}
}
}