forked from cross-platform/icloud-for-linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
52 lines (42 loc) · 1.25 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
const { app, BrowserWindow, Menu, shell } = require('electron')
const fs = require('fs')
const levelDbDir = 'config/icloud-for-linux/Local Storage/leveldb'
const levelDbFile = '/000003.log'
if (!fs.existsSync(process.env.SNAP_USER_DATA + '/.' + levelDbDir)) {
fs.mkdirSync(process.env.SNAP_USER_DATA + '/.' + levelDbDir, { recursive: true })
fs.copyFileSync(process.env.SNAP + '/' + levelDbDir + levelDbFile, process.env.SNAP_USER_DATA + '/.' + levelDbDir + levelDbFile)
}
let tld
try {
tld = fs.readFileSync(process.env.SNAP_USER_COMMON + '/tld', 'utf8').trim()
}
catch {
tld = '.com'
fs.writeFileSync(process.env.SNAP_USER_COMMON + '/tld', tld)
}
const appName = 'iCloud'
const appUrl = 'https://www.icloud' + tld + '/'
function createWindow() {
Menu.setApplicationMenu(null)
const mainWindow = new BrowserWindow({
width: 1000,
height: 600,
title: appName
})
mainWindow.loadURL(appUrl + process.argv[2])
mainWindow.webContents.on('will-navigate', (event, url) => {
if (!url.startsWith(appUrl)) {
event.preventDefault()
shell.openExternal(url)
}
})
mainWindow.on('close', () => {
app.exit(0)
})
}
app.whenReady().then(() => {
createWindow()
})
app.on('window-all-closed', function () {
app.quit()
})