Просмотр исходного кода

[update] show error if necessary on init pathsˆ.

oldj 7 лет назад
Родитель
Сommit
d94f33aa0b
2 измененных файлов с 13 добавлено и 22 удалено
  1. 1 5
      app/server/initWorkPath.js
  2. 12 17
      app/server/paths.js

+ 1 - 5
app/server/initWorkPath.js

@@ -10,11 +10,7 @@ const path = require('path')
 const version = require('../version').version
 
 module.exports = (work_path, sys_hosts_path) => {
-  try {
-    fs.mkdirSync(work_path)
-  } catch (e) {
-    console.log(e)
-  }
+  fs.mkdirSync(work_path)
 
   let cnt = fs.readFileSync(sys_hosts_path, 'utf-8')
   let fn_data = path.join(work_path, 'data.json')

+ 12 - 17
app/server/paths.js

@@ -6,12 +6,12 @@
 'use strict'
 
 const path = require('path')
+const {dialog} = require('electron')
 const io = require('./io')
 const platform = process.platform
 
 // Windows 系统有可能不安装在 C 盘
-const sys_hosts_path = platform === 'win32' ? `${process.env.windir ||
-  'C:\\WINDOWS'}\\system32\\drivers\\etc\\hosts` : '/etc/hosts'
+const sys_hosts_path = platform === 'win32' ? `${process.env.windir || 'C:\\WINDOWS'}\\system32\\drivers\\etc\\hosts` : '/etc/hosts'
 
 const home_path = io.getUserHome()
 const work_path = path.join(home_path, '.SwitchHosts')
@@ -19,23 +19,18 @@ const data_path = path.join(work_path, 'data.json')
 const preference_path = path.join(work_path, 'preferences.json')
 
 if (!io.isDirectory(work_path) || !io.isFile(path.join(work_path, 'data.json'))) {
-  require('./initWorkPath')(work_path, sys_hosts_path)
+  try {
+    require('./initWorkPath')(work_path, sys_hosts_path)
+  } catch (e) {
+    console.log(e)
+    dialog.showMessageBox({
+      type: 'error',
+      title: 'Error',
+      message: e.message
+    })
+  }
 }
 
-//function getCurrentAppPath () {
-//  let a = __dirname.split(path.sep)
-//  // console.log(a);
-//  while (a.length > 0) {
-//    let i = a[a.length - 1]
-//    if (i.endsWith('.app')) {
-//      return a.join(path.sep)
-//    }
-//    a.pop()
-//  }
-//
-//  return null
-//}
-
 module.exports = {
   home_path: home_path
   , work_path: work_path