Skip to content

Commit

Permalink
feat: 修改自动启动的获取值
Browse files Browse the repository at this point in the history
  • Loading branch information
xxss0903 committed Oct 24, 2024
1 parent 8a1a3d5 commit afd392c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ async function createWindow() {
await initDatabase()
// 初始化数据库之后开始设置闹钟
await initSetDiaryReminder(win)
if (process.env.NODE_ENV !== 'development') {
const isDebug = false
if (isDebug) {
console.log('process.env.NODE_ENV:', process.env.NODE_ENV, 'development')
win.loadURL('http://localhost:5173')
// win.webContents.executeJavaScript(`alert('当前环境: 开发环境');`)
Expand Down
2 changes: 2 additions & 0 deletions electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ contextBridge.exposeInMainWorld('electronAPI', {
getFilePath: () => ipcRenderer.invoke('get-file-path'),
onScreenBlockerStatusChange: (callback: (event: any, status: boolean) => void) =>
ipcRenderer.on('screen-blocker-status-change', callback),
getAutoLaunch: () => ipcRenderer.invoke('get-auto-launch'),
setAutoLaunch: (enable: boolean) => ipcRenderer.invoke('set-auto-launch', enable),
})

console.log('electronAPI exposed')
4 changes: 2 additions & 2 deletions src/components/widgets/AutoLaunchWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const autoLaunch = ref(false)
onMounted(async () => {
// 获取当前的自启动状态
autoLaunch.value = await window.electron.ipcRenderer.invoke('get-auto-launch')
autoLaunch.value = await window.electronAPI.getAutoLaunch()
})
const toggleAutoLaunch = async () => {
autoLaunch.value = await window.electron.ipcRenderer.invoke('set-auto-launch', autoLaunch.value)
autoLaunch.value = await window.electronAPI.setAutoLaunch(autoLaunch.value)
}
</script>

Expand Down

0 comments on commit afd392c

Please sign in to comment.