钜星新版审处方客户端初始提交
This commit is contained in:
132
src/index.js
Normal file
132
src/index.js
Normal file
@ -0,0 +1,132 @@
|
||||
/**
|
||||
* 入口函数
|
||||
*/
|
||||
const electron = require('electron');
|
||||
const app=electron.app;
|
||||
const path=require('path');
|
||||
let ipcMain = electron.ipcMain;
|
||||
const autoUpdater =require('electron-updater').autoUpdater;
|
||||
|
||||
let apppath = app.getAppPath();
|
||||
//判断是否是开发状态-1 是
|
||||
let is_dev=apppath.lastIndexOf("JUSTAR"+path.sep+"resources");
|
||||
let respath=apppath.substring(0, apppath.lastIndexOf("resources") - 1);
|
||||
|
||||
let update_url=null;
|
||||
|
||||
let main=require(apppath+path.sep+"src"+path.sep+"js"+path.sep+"main.js");
|
||||
let read_config=require(apppath+path.sep+"src"+path.sep+"js"+path.sep+"setting"+path.sep+"read_config.js");
|
||||
let log=require(apppath+path.sep+"src"+path.sep+"js"+path.sep+"setting"+path.sep+"set_log.js").clog;
|
||||
|
||||
app.whenReady().then(()=>{
|
||||
//读取及加载配置的文件
|
||||
if(is_dev==-1){
|
||||
read_config.readConfig(apppath);
|
||||
read_config.loadConfig(apppath,runMain);
|
||||
}else{
|
||||
read_config.readConfig(respath);
|
||||
read_config.loadConfig(respath,runMain);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//运行main函数(main_dev、main)
|
||||
function runMain(configs){
|
||||
update_url=configs.update_url;
|
||||
//区分开发和应用的区别
|
||||
if(is_dev==-1){
|
||||
log.info("【开发模式下运行】")
|
||||
log.info("项目根目录为:"+apppath);
|
||||
log.info("项目资源目录为:"+apppath);
|
||||
log.info("项目配置文件内容:【");
|
||||
log.info(configs);
|
||||
log.info("】");
|
||||
main.createMainWindow(configs,apppath,apppath,updateHandle);
|
||||
}else{
|
||||
log.info("【应用模式下运行】")
|
||||
log.info("项目根目录为:"+apppath);
|
||||
log.info("项目资源目录为:"+respath);
|
||||
log.info("项目配置文件内容:【");
|
||||
log.info(configs);
|
||||
log.info("】");
|
||||
main.createMainWindow(configs,apppath,respath,updateHandle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动检测更新程序实现
|
||||
* @param mainWindow
|
||||
*/
|
||||
function updateHandle(mainWindow) {
|
||||
let message = {
|
||||
error: '检查更新出错',
|
||||
checking: '正在检查更新……',
|
||||
updateAva: '检测到新版本,正在下载……',
|
||||
updateNotAva: '现在使用的就是最新版本,不用更新',
|
||||
};
|
||||
|
||||
if(update_url==''){
|
||||
return;
|
||||
}
|
||||
autoUpdater.setFeedURL(update_url);
|
||||
/**
|
||||
* 更新出错
|
||||
*/
|
||||
autoUpdater.on('error', function (error) {
|
||||
mainWindow.webContents.send('message', [-1,message.error]);
|
||||
});
|
||||
/**
|
||||
* 检查可用更新
|
||||
*/
|
||||
autoUpdater.on('checking-for-update', function () {
|
||||
mainWindow.webContents.send('message', [1,message.checking]);
|
||||
});
|
||||
/**
|
||||
* 有可用更新,会自动进行下载
|
||||
*/
|
||||
autoUpdater.on('update-available', function (info) {
|
||||
mainWindow.webContents.send('message', [2,message.updateAva,info]);
|
||||
});
|
||||
/**
|
||||
* 无可用更新
|
||||
*/
|
||||
autoUpdater.on('update-not-available', function (info) {
|
||||
|
||||
mainWindow.webContents.send('message', [0,message.updateNotAva]);
|
||||
});
|
||||
|
||||
/**
|
||||
* 更新进度
|
||||
*/
|
||||
autoUpdater.on('download-progress', function (progressObj) {
|
||||
log.info("传过来的数据百分数样式:"+progressObj.percent);
|
||||
mainWindow.webContents.send('downloadProgress', progressObj)
|
||||
});
|
||||
/**
|
||||
* 更新完成后进行程序重启操作
|
||||
* event Event
|
||||
* releaseNotes String - 新版本更新公告
|
||||
* releaseName String - 新的版本号
|
||||
* releaseDate Date - 新版本发布的日期
|
||||
* updateURL String - 更新地址
|
||||
* */
|
||||
autoUpdater.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
|
||||
ipcMain.on('isQuitAndInstall', (e, arg) => {
|
||||
//是否静默更新,更新完成是否立即重启程序
|
||||
autoUpdater.quitAndInstall(true,arg[0]);
|
||||
app.exit();
|
||||
});
|
||||
mainWindow.webContents.send('isQuitAndInstall')
|
||||
});
|
||||
|
||||
ipcMain.on("checkForUpdate",()=>{
|
||||
//执行自动更新检查
|
||||
autoUpdater.checkForUpdates();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user