-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.js
95 lines (60 loc) · 2.28 KB
/
preload.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
89
// cSpell:disable
// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
const { remote }= require('electron');
window.remote = remote;
window.customTitlebar = require('custom-electron-titlebar');
const dialog= remote.dialog;
window.ipcRenderer = require('electron').ipcRenderer;
window.clipboard = require('electron').clipboard;
const {clearWhitespaces,sleep} = require("./misc");
window.clearWhitespaces = clearWhitespaces;
window.sleep = sleep;
window.PDFViewSyncController = require('./PDFViewSyncController').PDFViewSyncController;
const {DataController, Assignment} = require("./DataController.js");
window.DataController = DataController;
window.Assignment = Assignment;
const path = require('path');
//const pify = require('pify');
window.saveAssignment = async()=>{
const dialogopts = {
"title":"Choose a Destination for Saving the Assingments"
};
const s_chooser_res = await dialog.showOpenDialog(dialogopts);
if(s_chooser_res.canceled)
return;
};
// window.assignTranslationDialog = async() => {
// const dialogopts = {
// type:"question",
// buttons:["yes","no"],
// title:"Confirm assignment"
// message:"Would you like to assign:"
// };
// await dialog.showMessageBox(fchooser_opts);
// }
// window.dialog = dialog;
window.loadPDFfile = async (viewer_id)=>{
// limit the picker to just pdfs
const fchooser_opts = {
properties: ['openFile'], // set to use openFileDialog
filters: [ { name: "PDFs", extensions: ['pdf'] } ]
};
const fchooser_res = await dialog.showOpenDialog(fchooser_opts);
if(fchooser_res.canceled)
return;
// Since we only allow one file, just use the first one
const filePath = fchooser_res.filePaths[0];
const iframe = document.getElementById(viewer_id);
// tell PDF.js to open the file that was selected from the file picker.
iframe.src = path.resolve( `pdfjs/web/viewer.html?file=${filePath}`);
};
window.addEventListener('DOMContentLoaded', () => {
const replaceText = (selector, text) => {
const element = document.getElementById(selector);
if (element) element.innerText = text;
};
for (const type of ['chrome', 'node', 'electron']) {
replaceText(`${type}-version`, process.versions[type]);
}
});