Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 49 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
let root = document.querySelector(':root');
let isClassCountdown = true
let isClassHidden = true
let isUseLocalConfig = false
let lastScheduleData = {
currentHighlight: {
index: null,
Expand Down Expand Up @@ -168,6 +169,21 @@
leftSidebar.style.display = scheduleConfig.week_display ? 'block' : 'none'
}

function setStyle(){
for(key in scheduleConfig.css_style){
root.style.setProperty(key, scheduleConfig.css_style[key])
}
}

function setAll(){
setCountdownerContent()
setScheduleClass()
setCountdownerPosition()
setSidebar()
setBackgroundDisplay()
setStyle()
}

function tick(reset = false) {
scheduleData = getScheduleData();
setCountdownerContent()
Expand All @@ -192,9 +208,7 @@
}
}, 20);

for (key in scheduleConfig.css_style) {
root.style.setProperty(key, scheduleConfig.css_style[key])
}
setStyle();

let timer = undefined
window.addEventListener("mousemove", event => {
Expand Down Expand Up @@ -230,6 +244,34 @@
})
}

ipcRenderer.on('openLoadConfig', (e, arg) => {
ipcRenderer.send('selectConfig', {
options: {
title: '选取本地配置文件(config.json)',
filters: [
{
name: 'config',
extensions: ['json']
}
]
}
})
})

ipcRenderer.on('setScheduleConfig', (e, arg) => {
console.log(arg.data)
isUseLocalConfig = true
scheduleConfig = JSON.parse(arg.data)
})

ipcRenderer.on('modifyScheduleConfig', (e, arg) => {
let filePath = arg.path
let fileContent = arg.data
scheduleConfig = JSON.parse(fileContent)
scheduleData = getScheduleData()
setAll()
})

ipcRenderer.on('getSelectedClassIndex', (e, arg) => {
if (arg.index == -1) return
let text = arg.arg.options.buttons[arg.index]
Expand Down Expand Up @@ -267,7 +309,9 @@
});

ipcRenderer.on('setWeekIndex', (e, arg) => {
scheduleConfig = JSON.parse(JSON.stringify(_scheduleConfig))
if(!isUseLocalConfig){
scheduleConfig = JSON.parse(JSON.stringify(_scheduleConfig))
}
weekIndex = arg
localStorage.setItem('weekIndex', weekIndex.toString())
})
Expand Down Expand Up @@ -298,4 +342,4 @@
})
</script>

</html>
</html>
54 changes: 53 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ app.whenReady().then(() => {
createWindow()
Menu.setApplicationMenu(null)
win.webContents.on('did-finish-load', () => {
if(store.get('isUseLocalConfig',false)){
dialog.showMessageBox(win,{
message: store.get('configPath')
})
fs.readFileSync(store.get('configPath'), { encoding: "utf8" } ,(err, data) => {
if(err) {
store.set('isUseLocalConfig',false)
throw err
}
if(data){
dialog.showMessageBox(win,{
message: data
})
win.webContents.send('setScheduleConfig',data);
}
})
}
win.webContents.send('getWeekIndex');
})
const handle = win.getNativeWindowHandle();
Expand Down Expand Up @@ -167,6 +184,17 @@ ipcMain.on('getWeekIndex', (e, arg) => {
setAutoLaunch()
}
},
{
label: '使用本地配置文件',
type: 'checkbox',
checked: store.get('isUseLocalConfig', false),
click: (e) => {
store.set('isUseLocalConfig', e.checked)
if(e.checked){
win.webContents.send('openLoadConfig')
}
}
},
{
type: 'separator'
},
Expand Down Expand Up @@ -214,6 +242,30 @@ ipcMain.on('dialog', (e, arg) => {
})
})

ipcMain.on('selectConfig', (e, arg) => {
dialog.showOpenDialog(win, arg.options).then((res) => {
if(!res.canceled){
fs.readFile(res.filePaths[0], { encoding: 'utf8' }, (err, data) => {
if(err) {
console.log('[selectFile] Error while reading selected File.Please check if you have access to the file.')
store.set('isUseLocalConfig', false)
store.set('configPath', undefined)
return;
}
if(data) {
store.set('configPath', res.filePaths[0])
e.sender.send('modifyScheduleConfig', { 'path': res.filePaths[0], 'data': data})
return;
}
})
}
else {
console.log("[selectFile] user cancelled")
store.set('isUseLocalConfig',false)
}
})
})

ipcMain.on('pop', (e, arg) => {
tray.popUpContextMenu(form)
})
Expand All @@ -237,4 +289,4 @@ ipcMain.on('getTimeOffset', (e, arg) => {
win.webContents.send('setTimeOffset', Number(r) % 10000000000000)
}
})
})
})