-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrenderer.js
More file actions
49 lines (41 loc) · 1.16 KB
/
renderer.js
File metadata and controls
49 lines (41 loc) · 1.16 KB
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
'use strict';
const {dialog} = require('electron').remote;
const fs = require('fs');
const path = require('path');
const ui = require('./ui.js');
const BookEditor = require('./bookeditor');
let ebookConvertLocation = "/Applications/calibre.app/Contents/MacOS/ebook-convert";
let editor = null;
function init() {
document.querySelector("#book_file").onclick = opendir;
var editorActions = Array.from(document.querySelectorAll("button.editoraction"));
editorActions.map(b => b.onclick = () => editorAction(b.id));
check();
}
function editorAction(action) {
if (!editor) {
ui.message("Please select a file first");
return;
}
editor.perform(action);
}
async function opendir() {
let result = await dialog.showOpenDialog({
properties: ['openDirectory']
});
if (Array.isArray(result) && result.length > 0) {
editor = new BookEditor(result[0]);
}
}
async function savebook() {
if (editor) {
} else {
ui.message("Please select a file first");
}
}
function check() {
if (!fs.existsSync(ebookConvertLocation)) {
ui.message("No calibre app found", true);
}
}
init()