mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 00:51:26 +08:00
Fix multiple JS issues (#2893)
This commit is contained in:
parent
cb8b60ac96
commit
3f15e048f5
@ -27,7 +27,7 @@ const exceptionToString = (error, type) => {
|
||||
return `Version: ${global.MARKTEXT_VERSION_STRING || app.getVersion()}\n` +
|
||||
`OS: ${getOSInformation()}\n` +
|
||||
`Type: ${type}\n` +
|
||||
`Date: ${new Date().toGMTString()}\n` +
|
||||
`Date: ${new Date().toUTCString()}\n` +
|
||||
`Message: ${message}\n` +
|
||||
`Stack: ${stack}\n`
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import setupEnvironment from './app/env'
|
||||
import { getLogLevel } from './utils'
|
||||
|
||||
const initializeLogger = appEnvironment => {
|
||||
log.transports.console.level = process.env.NODE_ENV === 'development' ? true : 'error'
|
||||
log.transports.console.level = process.env.NODE_ENV === 'development' ? 'info' : 'error'
|
||||
log.transports.rendererConsole = null
|
||||
log.transports.file.resolvePath = () => path.join(appEnvironment.paths.logPath, 'main.log')
|
||||
log.transports.file.level = getLogLevel()
|
||||
|
@ -71,7 +71,7 @@ const handleResponseForExport = async (e, { type, content, pathname, title, page
|
||||
Object.assign(options, getPdfPageOptions(pageOptions))
|
||||
const data = await win.webContents.printToPDF(options)
|
||||
removePrintServiceFromWindow(win)
|
||||
await writeFile(filePath, data, extension, {})
|
||||
await writeFile(filePath, data, extension, 'binary')
|
||||
} else {
|
||||
if (!content) {
|
||||
throw new Error('No HTML content found.')
|
||||
@ -221,14 +221,14 @@ ipcMain.on('mt::save-and-close-tabs', async (e, unsavedFiles) => {
|
||||
Promise.all(unsavedFiles.map(file => handleResponseForSave(e, file)))
|
||||
.then(arr => {
|
||||
const tabIds = arr.filter(id => id != null)
|
||||
win.send('mt::force-close-tabs-by-id', tabIds)
|
||||
win.webContents.send('mt::force-close-tabs-by-id', tabIds)
|
||||
})
|
||||
.catch(err => {
|
||||
log.error('Error while save all:', err.error)
|
||||
log.error('Error while save all:', err)
|
||||
})
|
||||
} else {
|
||||
const tabIds = unsavedFiles.map(f => f.id)
|
||||
win.send('mt::force-close-tabs-by-id', tabIds)
|
||||
win.webContents.send('mt::force-close-tabs-by-id', tabIds)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -43,7 +43,7 @@ class Preference extends EventEmitter {
|
||||
defaultSettings.theme = 'dark'
|
||||
}
|
||||
} catch (err) {
|
||||
log(err)
|
||||
log.error(err)
|
||||
}
|
||||
|
||||
if (!defaultSettings) {
|
||||
|
@ -203,7 +203,8 @@ class EditorWindow extends BaseWindow {
|
||||
* @param {boolean} [selected] Whether the tab should become the selected tab (true if not set).
|
||||
*/
|
||||
openTab (filePath, options = {}, selected = true) {
|
||||
if (this.lifecycle === WindowLifecycle.QUITTING) return
|
||||
// TODO: Don't allow new files if quitting.
|
||||
if (this.lifecycle === WindowLifecycle.QUITTED) return
|
||||
this.openTabs([{ filePath, options, selected }])
|
||||
}
|
||||
|
||||
@ -226,7 +227,8 @@ class EditorWindow extends BaseWindow {
|
||||
* @param {{filePath: string, selected: boolean, options: any}[]} filePath A list of markdown file paths and options to open.
|
||||
*/
|
||||
openTabs (fileList) {
|
||||
if (this.lifecycle === WindowLifecycle.QUITTING) return
|
||||
// TODO: Don't allow new files if quitting.
|
||||
if (this.lifecycle === WindowLifecycle.QUITTED) return
|
||||
|
||||
const { browserWindow } = this
|
||||
const { preferences } = this._accessor
|
||||
@ -259,6 +261,7 @@ class EditorWindow extends BaseWindow {
|
||||
* @param {[string]} markdown The markdown string.
|
||||
*/
|
||||
openUntitledTab (selected = true, markdown = '') {
|
||||
// TODO: Don't allow new files if quitting.
|
||||
if (this.lifecycle === WindowLifecycle.QUITTED) return
|
||||
|
||||
if (this.lifecycle === WindowLifecycle.READY) {
|
||||
@ -275,6 +278,7 @@ class EditorWindow extends BaseWindow {
|
||||
* @param {string} pathname The directory path.
|
||||
*/
|
||||
openFolder (pathname) {
|
||||
// TODO: Don't allow new files if quitting.
|
||||
if (!pathname || this.lifecycle === WindowLifecycle.QUITTED ||
|
||||
isSamePathSync(pathname, this._openedRootDirectory)) {
|
||||
return
|
||||
|
2
src/renderer/bootstrap.js
vendored
2
src/renderer/bootstrap.js
vendored
@ -7,7 +7,7 @@ let exceptionLogger = s => console.error(s)
|
||||
|
||||
const configureLogger = () => {
|
||||
const { debug, paths, windowId } = global.marktext.env
|
||||
log.transports.console.level = process.env.NODE_ENV === 'development' // mirror to window console
|
||||
log.transports.console.level = process.env.NODE_ENV === 'development' ? 'info' : false // mirror to window console
|
||||
log.transports.mainConsole = null
|
||||
log.transports.file.resolvePath = () => path.join(paths.logPath, `editor-${windowId}.log`)
|
||||
log.transports.file.level = debug ? 'debug' : 'info'
|
||||
|
Loading…
Reference in New Issue
Block a user