exam-simulator / simulator

👩‍🎓 JSON based exam simulator.
https://exam-simulator.gitbook.io/exam-simulator
MIT License
78 stars 44 forks source link

Unable to import exams in macos #12

Open rubenandre opened 2 years ago

rubenandre commented 2 years ago

Describe the bug When importing a file in macos they generate a exception

To Reproduce Steps to reproduce the behavior:

  1. Import file

Expected behavior The exam file should be loaded

Desktop (please complete the following information):

Additional context The error it's located in showFileDialog.js line 31. The following code only works on windows:

const filename = filepaths[0].split('\\').pop()

One possible solution for this problem is create the following function

const getOs = () => {
  const os = ['Windows', 'Linux', 'Mac']; // add your OS values
  return os.find(v=>window.navigator.appVersion.indexOf(v) >= 0);
}

and replace line 31 with:

const os = getOs()

let filename = null
if (os == 'Windows') {
    filename = filepaths[0].split('\\').pop()
} else {
    filename = filepaths[0].split('/').pop()
}