forked from heiyehk/electron-vue3-inote
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
250 additions
and
136 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,11 @@ | ||
import { app, protocol, BrowserWindow, globalShortcut } from 'electron'; | ||
import { | ||
createProtocol | ||
// installVueDevtools | ||
} from 'vue-cli-plugin-electron-builder/lib'; | ||
import { app } from 'electron'; | ||
import startWindow from './start'; | ||
|
||
import { browserWindowOption, winURL, disabledKeys } from './config'; | ||
// 获取锁,判断是否已经启动 | ||
const gotTheLock = app.requestSingleInstanceLock(); | ||
|
||
const isDevelopment = process.env.NODE_ENV !== 'production'; | ||
|
||
let win: BrowserWindow | null; | ||
|
||
// 将计划注册为标准将允许通过文件系统 API访问文件。否则,渲染器将为计划抛出一个安全错误。 | ||
// 此方法只能在模块事件发出之前使用,并且只能调用一次。`ready app` | ||
protocol.registerSchemesAsPrivileged([ | ||
{ | ||
scheme: 'app', | ||
privileges: { | ||
secure: true, | ||
standard: true | ||
} | ||
} | ||
]); | ||
|
||
function createWindow() { | ||
// 如果有webpack启动的server | ||
if (process.env.WEBPACK_DEV_SERVER_URL) { | ||
win = new BrowserWindow(browserWindowOption()); | ||
// 默认打开webpack启动的serve | ||
win.loadURL(process.env.WEBPACK_DEV_SERVER_URL); | ||
if (!process.env.IS_TEST) win.webContents.openDevTools(); | ||
} else { | ||
const argv = process.argv[1]; | ||
// 注册一个协议 | ||
createProtocol('app'); | ||
|
||
// 判断是否是新增 | ||
if (argv === '--editor') { | ||
const editorWinOptions = browserWindowOption(); | ||
win = new BrowserWindow(editorWinOptions); | ||
win.loadURL(`${winURL}#/editor`); | ||
} else { | ||
win = new BrowserWindow(browserWindowOption()); | ||
win.loadURL(winURL); | ||
} | ||
} | ||
// win.webContents.openDevTools(); | ||
// sequelizeInit(); | ||
|
||
win.on('closed', () => { | ||
win = null; | ||
}); | ||
} | ||
|
||
app.on('window-all-closed', () => { | ||
if (process.platform !== 'darwin') { | ||
app.quit(); | ||
} | ||
}); | ||
|
||
app.on('activate', () => { | ||
if (win === null) { | ||
createWindow(); | ||
} | ||
}); | ||
|
||
app.on('ready', async () => { | ||
// 快捷键禁用 | ||
for (const key of disabledKeys()) { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
globalShortcut.register(key, () => {}); | ||
} | ||
createWindow(); | ||
}); | ||
|
||
// TODO 待开发的内容 | ||
// app.setUserTasks(userTasks); | ||
|
||
if (isDevelopment) { | ||
if (process.platform === 'win32') { | ||
process.on('message', data => { | ||
if (data === 'graceful-exit') { | ||
app.quit(); | ||
} | ||
}); | ||
} else { | ||
process.on('SIGTERM', () => { | ||
app.quit(); | ||
}); | ||
} | ||
if (!gotTheLock) { | ||
app.quit(); | ||
} else { | ||
startWindow(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,20 @@ | ||
import { classNames } from './inotesConfig'; | ||
import { browserWindowOption, winURL, disabledKeys, userTasks } from './electronConfig'; | ||
|
||
export { classNames, browserWindowOption, winURL, disabledKeys, userTasks }; | ||
const isDev = process.env.NODE_ENV === 'development'; | ||
|
||
/** 日志地址 */ | ||
const constErrorLogPath = `/resources/inotesError${isDev ? '-dev' : ''}.log`; | ||
|
||
/** db地址 */ | ||
const constStoragePath = `/resources/db/notes${isDev ? '-dev' : ''}.db`; | ||
|
||
export { | ||
classNames, | ||
browserWindowOption, | ||
winURL, | ||
disabledKeys, | ||
userTasks, | ||
constErrorLogPath, | ||
constStoragePath | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.