2022-04-23 23:48:21 +00:00
|
|
|
/**
|
|
|
|
* Get configuration
|
|
|
|
*
|
|
|
|
* @returns {Promise<string>}
|
|
|
|
*/
|
2022-05-03 05:44:57 +00:00
|
|
|
async function getCfg() {
|
2022-05-03 05:48:03 +00:00
|
|
|
const defaultConf = {
|
|
|
|
gameexe: '',
|
|
|
|
serverFolder: '',
|
|
|
|
lastConnect: '',
|
|
|
|
enableKillswitch: false,
|
|
|
|
serverLaunchPanel: false,
|
|
|
|
language: 'en',
|
|
|
|
useHttps: true,
|
|
|
|
grasscutterBranch: '',
|
|
|
|
}
|
|
|
|
const cfgStr = await Neutralino.storage.getData('config').catch(e => {
|
2022-04-23 23:48:21 +00:00
|
|
|
// The data isn't set, so this is our first time opening
|
2022-05-03 05:48:03 +00:00
|
|
|
Neutralino.storage.setData('config', JSON.stringify(defaultConf))
|
2022-04-23 23:48:21 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
// Show the first time notice if there is no config
|
|
|
|
document.querySelector('#firstTimeNotice').style.display = 'block'
|
|
|
|
})
|
2022-04-23 23:48:21 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
const config = cfgStr ? JSON.parse(cfgStr) : defaultConf
|
2022-04-23 23:48:21 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
return config
|
2022-04-23 23:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of favorite IPs
|
|
|
|
*
|
|
|
|
* @returns {Promise<string[]>}
|
|
|
|
*/
|
2022-05-03 05:44:57 +00:00
|
|
|
async function getFavIps() {
|
2022-05-03 05:48:03 +00:00
|
|
|
const ipStr = await Neutralino.storage.getData('favorites').catch(e => {
|
2022-04-23 23:48:21 +00:00
|
|
|
// The data isn't set, so this is our first time opening
|
2022-05-03 05:48:03 +00:00
|
|
|
Neutralino.storage.setData('favorites', JSON.stringify([]))
|
|
|
|
})
|
2022-04-23 23:48:21 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
const ipArr = ipStr ? JSON.parse(ipStr) : []
|
2022-04-23 23:48:21 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
return ipArr
|
2022-04-23 23:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function proxyIsInstalled() {
|
2022-05-03 05:48:03 +00:00
|
|
|
// Check if the proxy server is installed
|
|
|
|
const curDirList = await filesystem.readDirectory(NL_CWD)
|
2022-04-23 23:48:21 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
if (curDirList.find(f => f.entry === 'ext')) {
|
|
|
|
const extFiles = await filesystem.readDirectory(NL_CWD + '/ext')
|
2022-04-23 23:48:21 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
if (extFiles.find(f => f.entry === 'mitmdump.exe')) {
|
|
|
|
return true
|
2022-04-23 23:48:21 +00:00
|
|
|
}
|
2022-05-03 05:48:03 +00:00
|
|
|
}
|
2022-04-23 23:48:21 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
return false
|
2022-04-23 23:48:21 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 08:56:00 +00:00
|
|
|
async function checkForUpdates() {
|
2022-05-03 05:48:03 +00:00
|
|
|
const url = 'https://api.github.com/repos/Grasscutters/GrassClipper/releases/latest'
|
2022-04-30 08:56:00 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
const { data } = await axios.get(url)
|
|
|
|
const latest = data.tag_name
|
2022-04-30 08:56:00 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
return latest
|
2022-04-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
|
2022-04-30 08:58:58 +00:00
|
|
|
async function displayUpdate() {
|
2022-05-03 05:48:03 +00:00
|
|
|
const latest = await checkForUpdates()
|
|
|
|
const versionDisplay = document.querySelector('#newestVersion')
|
|
|
|
const notif = document.querySelector('#downloadNotif')
|
2022-04-30 08:56:00 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
if (latest === `v${NL_APPVERSION}`) return
|
2022-04-30 08:56:00 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
versionDisplay.innerText = latest
|
2022-04-30 08:56:00 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
notif.classList.add('displayed')
|
2022-04-30 08:56:00 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
setTimeout(() => {
|
|
|
|
notif.classList.remove('displayed')
|
|
|
|
}, 5000)
|
2022-04-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function openLatestDownload() {
|
2022-05-03 05:48:03 +00:00
|
|
|
const downloadLink = 'https://github.com/Grasscutters/GrassClipper/releases/latest/'
|
2022-04-30 08:56:00 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
Neutralino.os.open(downloadLink)
|
2022-04-30 08:56:00 +00:00
|
|
|
}
|
|
|
|
|
2022-04-26 09:12:58 +00:00
|
|
|
async function openGameFolder() {
|
2022-05-03 05:48:03 +00:00
|
|
|
const config = await getCfg()
|
2022-05-04 03:34:53 +00:00
|
|
|
const folder = config.gameexe.match(/.*\\|.*\//g, '')
|
2022-05-04 04:14:02 +00:00
|
|
|
|
2022-05-04 03:34:53 +00:00
|
|
|
if (folder.length > 0) openInExplorer(folder[0])
|
2022-04-26 09:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function openGrasscutterFolder() {
|
2022-05-03 05:48:03 +00:00
|
|
|
const config = await getCfg()
|
2022-05-04 03:34:53 +00:00
|
|
|
const folder = config.serverFolder.match(/.*\\|.*\//g, '')
|
2022-04-26 09:12:58 +00:00
|
|
|
|
2022-05-04 03:34:53 +00:00
|
|
|
if (folder.length > 0) openInExplorer(folder[0])
|
2022-04-26 09:12:58 +00:00
|
|
|
}
|
|
|
|
|
2022-05-04 04:06:01 +00:00
|
|
|
// https://www.jimzhao.us/2015/09/javascript-detect-chinese-character.html
|
|
|
|
function hasChineseChars(str) {
|
2022-05-04 04:14:02 +00:00
|
|
|
let re1 = new RegExp(/[\u4E00-\uFA29]/) //Chinese character range
|
|
|
|
let re2 = new RegExp(/[\uE7C7-\uE7F3]/) //non Chinese character range
|
2022-05-04 04:06:01 +00:00
|
|
|
str = str.replace(/\s/g, '')
|
|
|
|
|
|
|
|
if (!re1.test(str) || re2.test(str)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-04-23 23:48:21 +00:00
|
|
|
/**
|
|
|
|
* Minimize the window
|
|
|
|
*/
|
2022-05-03 05:44:57 +00:00
|
|
|
function minimizeWin() {
|
2022-05-03 05:48:03 +00:00
|
|
|
Neutralino.window.minimize()
|
2022-04-23 23:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close the window
|
|
|
|
*/
|
|
|
|
function closeWin() {
|
2022-05-03 05:48:03 +00:00
|
|
|
Neutralino.app.exit()
|
2022-04-25 05:40:03 +00:00
|
|
|
|
2022-05-03 05:48:03 +00:00
|
|
|
window.close()
|
2022-04-23 23:48:21 +00:00
|
|
|
}
|