Fix multiple JS issues (#2893)

This commit is contained in:
Felix Häusler 2022-01-16 16:05:46 +01:00 committed by GitHub
parent cb8b60ac96
commit 3f15e048f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 14 additions and 10 deletions

View File

@ -27,7 +27,7 @@ const exceptionToString = (error, type) => {
return `Version: ${global.MARKTEXT_VERSION_STRING || app.getVersion()}\n` + return `Version: ${global.MARKTEXT_VERSION_STRING || app.getVersion()}\n` +
`OS: ${getOSInformation()}\n` + `OS: ${getOSInformation()}\n` +
`Type: ${type}\n` + `Type: ${type}\n` +
`Date: ${new Date().toGMTString()}\n` + `Date: ${new Date().toUTCString()}\n` +
`Message: ${message}\n` + `Message: ${message}\n` +
`Stack: ${stack}\n` `Stack: ${stack}\n`
} }

View File

@ -11,7 +11,7 @@ import setupEnvironment from './app/env'
import { getLogLevel } from './utils' import { getLogLevel } from './utils'
const initializeLogger = appEnvironment => { 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.rendererConsole = null
log.transports.file.resolvePath = () => path.join(appEnvironment.paths.logPath, 'main.log') log.transports.file.resolvePath = () => path.join(appEnvironment.paths.logPath, 'main.log')
log.transports.file.level = getLogLevel() log.transports.file.level = getLogLevel()

View File

@ -71,7 +71,7 @@ const handleResponseForExport = async (e, { type, content, pathname, title, page
Object.assign(options, getPdfPageOptions(pageOptions)) Object.assign(options, getPdfPageOptions(pageOptions))
const data = await win.webContents.printToPDF(options) const data = await win.webContents.printToPDF(options)
removePrintServiceFromWindow(win) removePrintServiceFromWindow(win)
await writeFile(filePath, data, extension, {}) await writeFile(filePath, data, extension, 'binary')
} else { } else {
if (!content) { if (!content) {
throw new Error('No HTML content found.') 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))) Promise.all(unsavedFiles.map(file => handleResponseForSave(e, file)))
.then(arr => { .then(arr => {
const tabIds = arr.filter(id => id != null) 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 => { .catch(err => {
log.error('Error while save all:', err.error) log.error('Error while save all:', err)
}) })
} else { } else {
const tabIds = unsavedFiles.map(f => f.id) 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)
} }
}) })

View File

@ -43,7 +43,7 @@ class Preference extends EventEmitter {
defaultSettings.theme = 'dark' defaultSettings.theme = 'dark'
} }
} catch (err) { } catch (err) {
log(err) log.error(err)
} }
if (!defaultSettings) { if (!defaultSettings) {

View File

@ -203,7 +203,8 @@ class EditorWindow extends BaseWindow {
* @param {boolean} [selected] Whether the tab should become the selected tab (true if not set). * @param {boolean} [selected] Whether the tab should become the selected tab (true if not set).
*/ */
openTab (filePath, options = {}, selected = true) { 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 }]) 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. * @param {{filePath: string, selected: boolean, options: any}[]} filePath A list of markdown file paths and options to open.
*/ */
openTabs (fileList) { 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 { browserWindow } = this
const { preferences } = this._accessor const { preferences } = this._accessor
@ -259,6 +261,7 @@ class EditorWindow extends BaseWindow {
* @param {[string]} markdown The markdown string. * @param {[string]} markdown The markdown string.
*/ */
openUntitledTab (selected = true, markdown = '') { openUntitledTab (selected = true, markdown = '') {
// TODO: Don't allow new files if quitting.
if (this.lifecycle === WindowLifecycle.QUITTED) return if (this.lifecycle === WindowLifecycle.QUITTED) return
if (this.lifecycle === WindowLifecycle.READY) { if (this.lifecycle === WindowLifecycle.READY) {
@ -275,6 +278,7 @@ class EditorWindow extends BaseWindow {
* @param {string} pathname The directory path. * @param {string} pathname The directory path.
*/ */
openFolder (pathname) { openFolder (pathname) {
// TODO: Don't allow new files if quitting.
if (!pathname || this.lifecycle === WindowLifecycle.QUITTED || if (!pathname || this.lifecycle === WindowLifecycle.QUITTED ||
isSamePathSync(pathname, this._openedRootDirectory)) { isSamePathSync(pathname, this._openedRootDirectory)) {
return return

View File

@ -7,7 +7,7 @@ let exceptionLogger = s => console.error(s)
const configureLogger = () => { const configureLogger = () => {
const { debug, paths, windowId } = global.marktext.env 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.mainConsole = null
log.transports.file.resolvePath = () => path.join(paths.logPath, `editor-${windowId}.log`) log.transports.file.resolvePath = () => path.join(paths.logPath, `editor-${windowId}.log`)
log.transports.file.level = debug ? 'debug' : 'info' log.transports.file.level = debug ? 'debug' : 'info'