fix: fix home path on windows (#47)

This commit is contained in:
Felix Häusler 2018-03-21 12:00:45 +01:00 committed by 冉四夕
parent 6e856735ab
commit 90ea35ac68
3 changed files with 10 additions and 6 deletions

View File

@ -6,7 +6,7 @@ import path from 'path'
import { app, dialog, ipcMain, BrowserWindow } from 'electron' import { app, dialog, ipcMain, BrowserWindow } from 'electron'
import createWindow, { windows } from '../createWindow' import createWindow, { windows } from '../createWindow'
import { EXTENSIONS, EXTENSION_HASN } from '../config' import { EXTENSIONS, EXTENSION_HASN } from '../config'
import { getUserPreference, setUserPreference } from '../utils' import { getPath, getUserPreference, setUserPreference } from '../utils'
const watchAndReload = (pathname, win) => { // when i build, and failed. const watchAndReload = (pathname, win) => { // when i build, and failed.
// const watcher = chokidar.watch(pathname, { // const watcher = chokidar.watch(pathname, {
@ -51,7 +51,7 @@ const forceClose = win => {
const handleResponseForExport = (e, { type, content, filename, pathname }) => { const handleResponseForExport = (e, { type, content, filename, pathname }) => {
const win = BrowserWindow.fromWebContents(e.sender) const win = BrowserWindow.fromWebContents(e.sender)
const extension = EXTENSION_HASN[type] const extension = EXTENSION_HASN[type]
const dirname = pathname ? path.dirname(pathname) : '~' const dirname = pathname ? path.dirname(pathname) : getPath('documents')
const nakedFilename = pathname ? path.basename(pathname, '.md') : 'untitled' const nakedFilename = pathname ? path.basename(pathname, '.md') : 'untitled'
const defaultPath = `${dirname}/${nakedFilename}${extension}` const defaultPath = `${dirname}/${nakedFilename}${extension}`
const filePath = dialog.showSaveDialog(win, { const filePath = dialog.showSaveDialog(win, {
@ -76,7 +76,7 @@ const handleResponseForSave = (e, { markdown, pathname }) => {
}) })
} else { } else {
const filePath = dialog.showSaveDialog(win, { const filePath = dialog.showSaveDialog(win, {
defaultPath: '~/Untitled.md' defaultPath: getPath('documents') + '/Untitled.md'
}) })
writeFile(filePath, markdown, '.md', win, e) writeFile(filePath, markdown, '.md', win, e)
} }
@ -85,7 +85,7 @@ const handleResponseForSave = (e, { markdown, pathname }) => {
ipcMain.on('AGANI::response-file-save-as', (e, { markdown, pathname }) => { ipcMain.on('AGANI::response-file-save-as', (e, { markdown, pathname }) => {
const win = BrowserWindow.fromWebContents(e.sender) const win = BrowserWindow.fromWebContents(e.sender)
let filePath = dialog.showSaveDialog(win, { let filePath = dialog.showSaveDialog(win, {
defaultPath: pathname || '~/Untitled.md' defaultPath: pathname || getPath('documents') + '/Untitled.md'
}) })
writeFile(filePath, markdown, '.md', win, e) writeFile(filePath, markdown, '.md', win, e)
}) })

View File

@ -47,7 +47,7 @@ autoUpdater.on('update-downloaded', () => {
}) })
export const userSetting = (menuItem, browserWindow) => { export const userSetting = (menuItem, browserWindow) => {
const settingPath = path.join(__static, '/preference.md') const settingPath = path.join(__static, 'preference.md')
createWindow(settingPath) createWindow(settingPath)
} }

View File

@ -1,6 +1,6 @@
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import { Menu } from 'electron' import { app, Menu } from 'electron'
const JSON_REG = /```json(.+)```/g const JSON_REG = /```json(.+)```/g
const preferencePath = path.join(__static, 'preference.md') const preferencePath = path.join(__static, 'preference.md')
@ -45,3 +45,7 @@ export const setUserPreference = (key, value) => {
}) })
}) })
} }
export const getPath = directory => {
return app.getPath(directory)
}