|
@@ -1,12 +1,14 @@
|
|
|
const electron = require('electron');
|
|
const electron = require('electron');
|
|
|
|
|
+const ipc = electron.ipcMain;//用于接收命令的ipc模块
|
|
|
|
|
+const app = electron.app;
|
|
|
|
|
+const BrowserWindow = electron.BrowserWindow;//引入一个BrowserWindow
|
|
|
const path = require('path');
|
|
const path = require('path');
|
|
|
-const url = require('url');
|
|
|
|
|
|
|
+const url = require('url');//引入url处理模块
|
|
|
const autoUpdater = require('electron-updater').autoUpdater;
|
|
const autoUpdater = require('electron-updater').autoUpdater;
|
|
|
-const ipc = electron.ipcMain;
|
|
|
|
|
const {ipcMain} = require('electron');
|
|
const {ipcMain} = require('electron');
|
|
|
-const app = electron.app;
|
|
|
|
|
-const BrowserWindow = electron.BrowserWindow;
|
|
|
|
|
-let mainWindow,BrowserHistory,BrowserFeedback,AboutUsW;
|
|
|
|
|
|
|
+const regedit = require('regedit'); //引入regedit
|
|
|
|
|
+const Menu = electron.Menu;//引入菜单慕课
|
|
|
|
|
+const debug = (process.argv.indexOf('--debug')>0);
|
|
|
let message={
|
|
let message={
|
|
|
appName:'有思浏览器',
|
|
appName:'有思浏览器',
|
|
|
error:'检查更新出错, 请联系开发人员',
|
|
error:'检查更新出错, 请联系开发人员',
|
|
@@ -15,13 +17,56 @@ let message={
|
|
|
updateNotAva:'现在使用的就是最新版本,不用更新',
|
|
updateNotAva:'现在使用的就是最新版本,不用更新',
|
|
|
downloaded: '最新版本已下载,点击安装已进行更新'
|
|
downloaded: '最新版本已下载,点击安装已进行更新'
|
|
|
};
|
|
};
|
|
|
-const debug = (process.argv.indexOf('--debug')>0);
|
|
|
|
|
|
|
+let childProcess =require('child_process');
|
|
|
|
|
+let CampusWindow,mainWindow,BrowserHistory,BrowserFeedback,AboutUsW;
|
|
|
|
|
+app.commandLine.appendSwitch('ppapi-flash-path',app.getPath('pepperFlashSystemPlugin'));
|
|
|
var version=require(__dirname+"/package.json").version;
|
|
var version=require(__dirname+"/package.json").version;
|
|
|
|
|
+function createCampusWindow(flag) {
|
|
|
|
|
+ createIndexWindow(false);
|
|
|
|
|
+ if(!flag) {
|
|
|
|
|
+ setTimeout(function () {
|
|
|
|
|
+ if (CampusWindow) {
|
|
|
|
|
+ CampusWindow.show();
|
|
|
|
|
+ CampusWindow.restore();
|
|
|
|
|
+ CampusWindow.focus();
|
|
|
|
|
+ }
|
|
|
|
|
+ }, 1000 * 60*5);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ CampusWindow.show();
|
|
|
|
|
+ CampusWindow.restore();
|
|
|
|
|
+ CampusWindow.focus();
|
|
|
|
|
+}
|
|
|
|
|
+function createIndexWindow(flag) {
|
|
|
|
|
+ CampusWindow = new BrowserWindow({ width: 750, height: 540, maxWidth: 750, maxHeight: 540,resizable:false,frame: false });
|
|
|
|
|
+ CampusWindow.loadURL(url.format({
|
|
|
|
|
+ pathname: path.join(__dirname, 'index.html'),
|
|
|
|
|
+ protocol: 'file:',
|
|
|
|
|
+ slashes: true
|
|
|
|
|
+ }));
|
|
|
|
|
+ if(debug) {
|
|
|
|
|
+ CampusWindow.webContents.openDevTools();
|
|
|
|
|
+ }
|
|
|
|
|
+ CampusWindow.on('closed', function () {
|
|
|
|
|
+ CampusWindow = null
|
|
|
|
|
+ });
|
|
|
|
|
+ if(!flag) {
|
|
|
|
|
+ CampusWindow.hide();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
autoUpdater.setFeedURL('http://client.1473.cn/update');//设置检查更新的 url,并且初始化自动更新。这个 url 一旦设置就无法更改。
|
|
autoUpdater.setFeedURL('http://client.1473.cn/update');//设置检查更新的 url,并且初始化自动更新。这个 url 一旦设置就无法更改。
|
|
|
-function createWindow() {
|
|
|
|
|
|
|
+function createWindow(request_url) {
|
|
|
|
|
+ if(mainWindow){
|
|
|
|
|
+ mainWindow.focus();
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
mainWindow = new BrowserWindow({//游览器窗口
|
|
mainWindow = new BrowserWindow({//游览器窗口
|
|
|
width: 1920,
|
|
width: 1920,
|
|
|
height: 1080,
|
|
height: 1080,
|
|
|
|
|
+ backgroundColor:'#fff',
|
|
|
|
|
+ webPreferences:{
|
|
|
|
|
+ 'plugins': true
|
|
|
|
|
+ },
|
|
|
frame: false
|
|
frame: false
|
|
|
});
|
|
});
|
|
|
mainWindow.loadURL(url.format({
|
|
mainWindow.loadURL(url.format({
|
|
@@ -32,9 +77,19 @@ function createWindow() {
|
|
|
if(debug) {
|
|
if(debug) {
|
|
|
mainWindow.webContents.openDevTools();
|
|
mainWindow.webContents.openDevTools();
|
|
|
}
|
|
}
|
|
|
|
|
+ mainWindow.webContents.openDevTools();
|
|
|
mainWindow.on('closed', function () {
|
|
mainWindow.on('closed', function () {
|
|
|
mainWindow = null
|
|
mainWindow = null
|
|
|
});
|
|
});
|
|
|
|
|
+ mainWindow.webContents.on('did-finish-load', function(){
|
|
|
|
|
+ if(request_url) {
|
|
|
|
|
+ mainWindow.webContents.send('flag', '1');
|
|
|
|
|
+ mainWindow.webContents.send('url', request_url)
|
|
|
|
|
+ }else {
|
|
|
|
|
+ mainWindow.webContents.send('flag', '-1');
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ mainWindow.focus();
|
|
|
}
|
|
}
|
|
|
function CreateHistory() {
|
|
function CreateHistory() {
|
|
|
if(BrowserHistory){
|
|
if(BrowserHistory){
|
|
@@ -131,9 +186,48 @@ function CheckUpdate(event) {
|
|
|
//执行自动更新检查
|
|
//执行自动更新检查
|
|
|
}
|
|
}
|
|
|
function BindIpc(){
|
|
function BindIpc(){
|
|
|
|
|
+ ipc.on('window-min', function () {
|
|
|
|
|
+ CampusWindow.minimize();
|
|
|
|
|
+ });
|
|
|
|
|
+ ipc.on('window-max', function () {
|
|
|
|
|
+ if (CampusWindow.isMaximized()) {
|
|
|
|
|
+ CampusWindow.restore();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ CampusWindow.maximize();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ ipc.on('window-close', function () {
|
|
|
|
|
+ CampusWindow.close();
|
|
|
|
|
+ });
|
|
|
|
|
+ /*校园资讯写注册表*/
|
|
|
|
|
+ regedit.putValue({
|
|
|
|
|
+ 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run':{
|
|
|
|
|
+ 'CampusInfo' : {
|
|
|
|
|
+ value : process.argv[0]+' start',
|
|
|
|
|
+ type : 'REG_SZ'
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ },function () {
|
|
|
|
|
+ });
|
|
|
|
|
+ /*校园资讯打开浏览器*/
|
|
|
|
|
+ ipcMain.on('open-browers',function (e,arg) {
|
|
|
|
|
+ mainWindow.webContents.send('url', arg)
|
|
|
|
|
+ });
|
|
|
/*浏览器ipc*/
|
|
/*浏览器ipc*/
|
|
|
|
|
+ ipc.on('newBrowersWindow',function () {
|
|
|
|
|
+ childProcess.exec(process.argv[0]);//启动新的浏览器
|
|
|
|
|
+ });
|
|
|
|
|
+ ipc.on('CampusInfo',function () {
|
|
|
|
|
+ if(CampusWindow){
|
|
|
|
|
+ CampusWindow.show();
|
|
|
|
|
+ CampusWindow.restore();
|
|
|
|
|
+ CampusWindow.focus();
|
|
|
|
|
+ }else{
|
|
|
|
|
+ createCampusWindow(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
ipc.on('window-all-closed', function () {//退出
|
|
ipc.on('window-all-closed', function () {//退出
|
|
|
- app.quit();
|
|
|
|
|
|
|
+ mainWindow.close();
|
|
|
});
|
|
});
|
|
|
ipc.on('hide-window', function () {//小化
|
|
ipc.on('hide-window', function () {//小化
|
|
|
mainWindow.minimize();
|
|
mainWindow.minimize();
|
|
@@ -142,7 +236,7 @@ function BindIpc(){
|
|
|
mainWindow.maximize();
|
|
mainWindow.maximize();
|
|
|
});
|
|
});
|
|
|
ipc.on('orignal-window', function () {//还原
|
|
ipc.on('orignal-window', function () {//还原
|
|
|
- mainWindow.unmaximize();
|
|
|
|
|
|
|
+ mainWindow.restore();
|
|
|
});
|
|
});
|
|
|
/*反馈窗口ipc*/
|
|
/*反馈窗口ipc*/
|
|
|
ipc.on('BrowserFeedback-show', function () {
|
|
ipc.on('BrowserFeedback-show', function () {
|
|
@@ -175,7 +269,7 @@ function BindIpc(){
|
|
|
});
|
|
});
|
|
|
/*接收打开历史记录*/
|
|
/*接收打开历史记录*/
|
|
|
ipc.on('open-history', function (event,arg) {//隐藏
|
|
ipc.on('open-history', function (event,arg) {//隐藏
|
|
|
- mainWindow.webContents.send('open-history', arg)
|
|
|
|
|
|
|
+ mainWindow.webContents.send('open-history', arg)
|
|
|
});
|
|
});
|
|
|
/*检查更新*/
|
|
/*检查更新*/
|
|
|
ipc.on('check-for-update', function(event, arg) {
|
|
ipc.on('check-for-update', function(event, arg) {
|
|
@@ -186,23 +280,37 @@ function BindIpc(){
|
|
|
autoUpdater.quitAndInstall();
|
|
autoUpdater.quitAndInstall();
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
-app.on('ready', function (){
|
|
|
|
|
- createWindow();//打开窗口
|
|
|
|
|
|
|
+const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => {
|
|
|
|
|
+ if (CampusWindow) {
|
|
|
|
|
+ if (CampusWindow.isMinimized()){
|
|
|
|
|
+ CampusWindow.restore()
|
|
|
|
|
+ }
|
|
|
|
|
+ CampusWindow.focus();
|
|
|
|
|
+ CampusWindow.show();
|
|
|
|
|
+ }
|
|
|
|
|
+});
|
|
|
|
|
+app.on('ready',function () {
|
|
|
BindIpc();//ipc通信绑定
|
|
BindIpc();//ipc通信绑定
|
|
|
- CreateAboutUs();
|
|
|
|
|
- mainWindow.webContents.on('did-finish-load', function(){
|
|
|
|
|
|
|
+ if(process.argv[1]==='start'){
|
|
|
|
|
+ createCampusWindow();
|
|
|
|
|
+ }else{
|
|
|
if(process.argv[1]&&process.argv[1].indexOf('--')<0) {
|
|
if(process.argv[1]&&process.argv[1].indexOf('--')<0) {
|
|
|
- mainWindow.webContents.send('url', process.argv[1])
|
|
|
|
|
|
|
+ createWindow(process.argv[1]);
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
-});
|
|
|
|
|
|
|
+ createWindow();
|
|
|
|
|
+ CreateAboutUs();
|
|
|
|
|
+ if(!CampusWindow&&!shouldQuit){//让校园资讯在多个浏览器窗口开启的情况下也只有一个实例存在
|
|
|
|
|
+ createCampusWindow();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+} );
|
|
|
app.on('window-all-closed', function () {
|
|
app.on('window-all-closed', function () {
|
|
|
if (process.platform !== 'darwin') {
|
|
if (process.platform !== 'darwin') {
|
|
|
app.quit()
|
|
app.quit()
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
app.on('activate', function () {
|
|
app.on('activate', function () {
|
|
|
- if (mainWindow === null) {
|
|
|
|
|
- createWindow()
|
|
|
|
|
|
|
+ if (CampusWindow === null&&process.argv[1]==='browers') {
|
|
|
|
|
+ createIndexWindow(true)
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|