-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
88 lines (76 loc) · 2.33 KB
/
index.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
import osjs from 'osjs';
import {name as applicationName} from './metadata.json';
import {app, h} from 'hyperapp';
import {Box, BoxContainer, Menubar, MenubarItem} from '@osjs/gui';
const register = (core, args, options, metadata) => {
const _ = core.make('osjs/locale').translate;
const vfs = core.make('osjs/vfs');
const proc = core.make('osjs/application', {args, options, metadata});
const win = proc.createWindow({
id: 'WebODFWindow',
title: metadata.title.en_EN,
icon: proc.resource(metadata.icon),
dimension: {width: 640, height: 480}
});
const basic = core.make('osjs/basic-application', proc, win, {});
win.on('drop', (ev, data) => {
if (data.isFile && data.mime) {
const found = proc.metadata.mimes.find(m => (new RegExp(m)).test(data.mime));
if (found) {
basic.open(data);
}
}
});
proc.on('destroy', () => basic.destroy());
win.render($content => {
const ha = app({
url: ''
}, {
setUrl: url => ({url}),
load: item => (state, actions) => {
vfs.url(item)
.then(url => actions.setUrl(url))
.catch(error => console.error(error)); // FIXME: Dialog
},
menu: ev => (state, actions) => {
core.make('osjs/contextmenu').show({
position: ev.target,
menu: [
{label: _('LBL_OPEN'), onclick: () => actions.menuOpen()},
{label: _('LBL_QUIT'), onclick: () => actions.menuQuit()}
]
});
},
menuOpen: () => state => basic.createOpenDialog(),
menuQuit: () => state => proc.destroy()
}, (state, actions) => {
return h(Box, {flex: 1, grow: 1}, [
h(Menubar, {}, [
h(MenubarItem, {
onclick: ev => actions.menu(ev)
}, _('LBL_FILE'))
]),
h(BoxContainer, {
grow: 1,
shrink: 1,
style: {overflow: 'auto'},
class: 'osjs-gui-box-styled'
}, [
h('div', {
key: state.url,
oncreate: el => {
if (state.url) {
const odfcanvas = new window.odf.OdfCanvas(el);
odfcanvas.load(state.url);
}
}
})
])
]);
}, $content);
basic.on('open-file', ha.load);
basic.init();
});
return proc;
};
osjs.register(applicationName, register);