54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
/* app */
|
|
const { app, session, Menu, ipcMain } = require('electron')
|
|
const { join } = require('path')
|
|
const fs = require('fs')
|
|
|
|
// const createTray = require('./tools/tray')
|
|
const { createMainWindow } = require('./tools/windows')
|
|
|
|
const ROOT = __dirname
|
|
const APP_DIR = join(app.getPath('appData'), './clash')
|
|
const CONFIG_FILE = join(APP_DIR, './config.json')
|
|
|
|
/* ----------------------------------------------------- */
|
|
|
|
app.commandLine.appendSwitch('lang', 'zh-CN')
|
|
app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required')
|
|
|
|
Menu.setApplicationMenu(null)
|
|
|
|
/* ----------------------------------------------------- */
|
|
|
|
// 初始化应用
|
|
app.once('ready', () => {
|
|
let win = createMainWindow(join(ROOT, './images/app.png'))
|
|
|
|
// app.toggleTray = createTray(win)
|
|
})
|
|
|
|
ipcMain.on('app', (ev, conn) => {
|
|
switch (conn.type) {
|
|
case 'saveToken':
|
|
fs.writeFile(CONFIG_FILE, conn.data, function (err) {})
|
|
ev.returnValue = true
|
|
break
|
|
|
|
case 'readToken':
|
|
{
|
|
let cache = ''
|
|
try {
|
|
cache = fs.readFileSync(CONFIG_FILE).toString()
|
|
} catch (err) {}
|
|
ev.returnValue = cache
|
|
}
|
|
break
|
|
|
|
case 'toggleTray':
|
|
{
|
|
app.toggleTray(conn.data)
|
|
ev.returnValue = true
|
|
}
|
|
break
|
|
}
|
|
})
|