diff --git a/electron/lib/api.js b/electron/lib/api.js index d57e6ea..28322e1 100644 --- a/electron/lib/api.js +++ b/electron/lib/api.js @@ -1,4 +1,5 @@ 'use strict'; + const fs = require('fs'); const http = require('http'); const path = require('path'); @@ -6,11 +7,12 @@ const _ = require('lodash'); const storage = require('./storage'); const socketIo = require('socket.io'); const eLogger = require('./eLogger').get(); -const {app} = require('electron'); +// const {app} = require('electron'); const apis = {}; exports.setup = async function () { + eLogger.info('[api] [setup] start'); setApi(); // use api server @@ -87,16 +89,24 @@ exports.setup = async function () { }; function setApi() { - const baseDir = app.getAppPath(); - const apiDir = path.join(baseDir, 'electron/apis'); + // fs读文件的时候,用path正规化 [打包读文件问题] + const apiDir = path.normalize(__dirname + '/../apis/'); + eLogger.info('[setApi] apiDir: ', apiDir); + // const baseDir = app.getAppPath(); + // const apiDir = path.join(baseDir, 'electron/apis'); fs.readdirSync(apiDir).forEach(function(filename) { + eLogger.info('[setApi] filename: ', filename); if (path.extname(filename) === '.js' && filename !== 'index.js') { const name = path.basename(filename, '.js'); - const fileObj = require(`${apiDir}/${filename}`); + // require文件的时候,用相对路径并且不能path处理 [打包读文件问题] + //const fileObj = require(`../apis/${filename}`); + const filepath = '../apis/' + filename; + eLogger.info('[setApi] filepath: ', filepath); + const fileObj = require(`${filepath}`); _.map(fileObj, function(fn, method) { let methodName = getApiName(name, method); apis[methodName] = fn; - // eLogger.info('[ Monitor ]', methodName); + eLogger.info('[setApi] method Name', methodName); }); } }); diff --git a/main.js b/main.js index fd3339c..ff0a63c 100644 --- a/main.js +++ b/main.js @@ -4,7 +4,6 @@ const eggLauncher = require('./electron/lib/lanucher') const setup = require('./electron/setup') const electronConfig = require('./electron/config') const storage = require('./electron/lib/storage') -const setTray = require('./electron/lib/tray') const preferences = require('./electron/preferences') // main window @@ -48,22 +47,10 @@ async function initialize () { app.quit() } }) - - // Open url with the default browser - // app.on('web-contents-created', (e, webContents) => { - // webContents.on('new-window', (event, url) => { - // event.preventDefault() - // shell.openExternal(url) - // }); - // }); } async function createWindow () { MAIN_WINDOW = new BrowserWindow(electronConfig.get('windowsOption')) - - // if (process.platform === 'linux') { - // windowOptions.icon = path.join(__dirname, '/assets/app-icon/png/512.png') - // } if (eggConfig.env === 'prod') { // hidden menu @@ -83,6 +70,10 @@ async function createWindow () { // egg server await startServer(eggConfig) + process.on('uncaughtException', function(err) { + eLogger.error(err); + }); + return MAIN_WINDOW }