-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
151 lines (136 loc) · 3.8 KB
/
main.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const electron = require('electron')
const { ipcMain, app, BrowserWindow, clipboard, Menu, MenuItem, ipcRenderer, webContents, dialog, shell } = require('electron')
const path = require("path");
const fs = require("fs");
const RandomOrg = require('random-org');
const { request } = require("@octokit/request");
const iconv = require('iconv-lite');
const remote = require('@electron/remote/main');
const menutemp = [
{
label: '新建',
accelerator: 'CmdOrCtrl+N',
click() {
if (contentUnsave) {
const options = {
type: "none",
buttons: ["确定"],
title: "提示",
message: "请先保存"
}
dialog.showMessageBox(win, options)
return
}
filePath = ""
win.webContents.send("newcontent")
}
},
{
label: '读取',
click() {
win.webContents.send("loadcontent");
},
},
{
label: '保存',
accelerator: 'CmdOrCtrl+S',
click() { win.webContents.send("getcontentandsave"); }
},
{
label: '导出HTML',
click() { win.webContents.send("gethtmlandexport") }
},
{
label: '搜索',
accelerator: 'CmdOrCtrl+F',
click() {
searchwin.show();
}
},
{
label: '生成长截图',
click() {
win.webContents.send("toPng");
}
},
{
label: '开发者工具',
click() { win.webContents.openDevTools(); }
},
{
label: '统计字数',
click() { win.webContents.send("countWord"); }
},
]
let win;
let searchwin;
let filePath = "";
let contentUnsave = false;
let random = null;
app.whenReady().then(() => {
win = new BrowserWindow({
width: 800,
height: 800,
webPreferences: {
worldSafeExecuteJavaScript: true,
contextIsolation: false,
nodeIntegration: true,
enableRemoteModule: true,
// preload: path.join(__dirname, './perload.js') // use a preload script
}
});
remote.initialize();
remote.enable(win.webContents);
win.loadFile('index.html');
Menu.setApplicationMenu(null)
win.setMenu(Menu.buildFromTemplate(menutemp));
win.maximize();
// win.webContents.openDevTools();
win.on('close', (e) => {
e.preventDefault();
win.webContents.send("onquit")
})
searchwin = new BrowserWindow({
parent: win,
width: 300, height: 50,
maximizable: false, minimizable: false,
frame: false,
transparent: true,
useContentSize: true,
webPreferences: {
worldSafeExecuteJavaScript: true,
contextIsolation: false,
nodeIntegration: true,
enableRemoteModule: false, // turn off remote
preload: path.join(__dirname, './perload.js') // use a preload script
}
})
searchwin.loadFile('searchPage.html');
// searchwin.webContents.openDevTools();
searchwin.hide();
searchwin.on("close", (evt) => {
evt.preventDefault(); // This will cancel the close
searchwin.hide();
win.webContents.stopFindInPage("activateSelection");
win.focus();
});
// searchwin.webContents.openDevTools();
searchwin.on('blur', function () {
searchwin.hide();
win.webContents.stopFindInPage("activateSelection");
win.focus();
})
})
app.on('window-all-closed', () => {
app.quit();
})
app.on("ready", () => {
app.setAppUserModelId("et.electron.editor");
})
//搜索
ipcMain.on("search", function (event, arg) {
// console.log("Search " +arg);
if (arg != "") {
win.webContents.findInPage(arg);
}
});