Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/renderer/utils/showFileDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { EXAM_DIR_PATH } from './filepaths'
const readFile = promisify(fs.readFile)
const writeFile = promisify(fs.writeFile)

const getOS = () => {
const os = ['Windows', 'Linux', 'Mac']
return os.find(v => window.navigator.userAgent.indexOf(v) >= 0)
}

/**
* Show native file dialog then parse and validate JSON file
* @param {object} win - Instance of electron BrowserWindow
Expand All @@ -28,7 +33,10 @@ export default win => {
resolve(false)
} else {
// isolate filename from path
const filename = filepaths[0].split('\\').pop()
const os = getOS()
const filename = os === 'Windows'
? filepaths[0].split('\\').pop()
: filepaths[0].split('/').pop()
// path to application data directory
const dstFilepath = path.join(EXAM_DIR_PATH, filename)
// read contents of new exam file
Expand Down