forked from marktext/marktext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarktext.js
More file actions
91 lines (74 loc) · 2.26 KB
/
marktext.js
File metadata and controls
91 lines (74 loc) · 2.26 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
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
import { autoUpdater } from 'electron-updater'
import { ipcMain, BrowserWindow, Menu } from 'electron'
import { COMMANDS } from '../../commands'
import { isOsx } from '../../config'
let runningUpdate = false
let win = null
autoUpdater.autoDownload = false
autoUpdater.on('error', error => {
if (win) {
win.webContents.send('mt::UPDATE_ERROR', error === null ? 'Error: unknown' : (error.message || error).toString())
}
})
autoUpdater.on('update-available', () => {
if (win) {
win.webContents.send('mt::UPDATE_AVAILABLE', 'Found an update, do you want download and install now?')
}
runningUpdate = false
})
autoUpdater.on('update-not-available', () => {
if (win) {
win.webContents.send('mt::UPDATE_NOT_AVAILABLE', 'Current version is up-to-date.')
}
runningUpdate = false
})
autoUpdater.on('update-downloaded', () => {
// TODO: We should ask the user, so that the user can save all documents and
// not just force close the application.
if (win) {
win.webContents.send('mt::UPDATE_DOWNLOADED', 'Update downloaded, application will be quit for update...')
}
setImmediate(() => autoUpdater.quitAndInstall())
})
ipcMain.on('mt::NEED_UPDATE', (e, { needUpdate }) => {
if (needUpdate) {
autoUpdater.downloadUpdate()
} else {
runningUpdate = false
}
})
ipcMain.on('mt::check-for-update', e => {
const win = BrowserWindow.fromWebContents(e.sender)
checkUpdates(win)
})
// --------------------------------------------------------
export const userSetting = () => {
ipcMain.emit('app-create-settings-window')
}
export const checkUpdates = browserWindow => {
if (!runningUpdate) {
runningUpdate = true
win = browserWindow
autoUpdater.checkForUpdates()
}
}
export const osxHide = () => {
if (isOsx) {
Menu.sendActionToFirstResponder('hide:')
}
}
export const osxHideAll = () => {
if (isOsx) {
Menu.sendActionToFirstResponder('hideOtherApplications:')
}
}
export const osxShowAll = () => {
if (isOsx) {
Menu.sendActionToFirstResponder('unhideAllApplications:')
}
}
// --- Commands -------------------------------------------------------------
export const loadMarktextCommands = commandManager => {
commandManager.add(COMMANDS.MT_HIDE, osxHide)
commandManager.add(COMMANDS.MT_HIDE_OTHERS, osxHideAll)
}