forked from sqlectron/sqlectron-gui
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwindow.js
83 lines (68 loc) · 2.59 KB
/
window.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var {resolve } =require('path');
var { BrowserWindow } =require('electron'); // eslint-disable-line import/no-unresolved
var { attachMenuToWindow } =require('./menu');
var { checkUpdate } =require('./update-checker');
var config =require('./config');
var createLogger =require('./logger');
const path=require("path");
// console.log("=============");
// console.log(createLogger);
const logger = createLogger('window');
// console.log(logger);
console.log(process.argv);
const devMode = (process.argv || []).indexOf('--dev') !== -1;
const localMode = (process.argv || []).indexOf('--local') !== -1;
const localBuildMode = (process.argv || []).indexOf('--build') !== -1;
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
const WINDOWS = {};
// Indicate the number of windows has already been opened.
// Also used as identifier to for each window.
let windowsNumber = 0;
function buildNewWindow(app) {
const appConfig = config.get();//getConfig();
windowsNumber += 1;
const mainWindow = new BrowserWindow({
title: appConfig.name,
//icon: resolve(__dirname, '..', '..', 'build', 'app.png'),
width: 1024,
height: 700,
minWidth: 512,
minHeight: 350,
webPreferences: {
// preload: resolve(__dirname, 'preload.js'),
contextIsolation: false,
nodeIntegration:true,
enableRemoteModule: true
},
});
attachMenuToWindow(app, buildNewWindow, appConfig);
// and load the index.html of the app.
// const entryBasePath = devMode ? 'http://localhost:8080' : ('file://' + resolve(__dirname, '..'));
// mainWindow.loadURL(entryBasePath + '/static/index.html');
//console.log(__dirname);
var cp=__dirname;
//console.log(cp);
let entryBasePath;
if(localMode){//local mode
if(localBuildMode){
entryBasePath = 'file://' + cp+ '/dist/index.html';
}
else{
entryBasePath = 'file://' + cp+ `/src/index.html`;
}
}
else{ //devMode productionMode
entryBasePath = devMode ? 'http://localhost:3000' : 'file://' + cp+ '/resources/app/build/index.html';
}
console.log(entryBasePath);
mainWindow.loadURL(entryBasePath);// + '/static/index.html');
// Emitted when the window is closed.
mainWindow.on('closed', () => delete WINDOWS[windowsNumber]);
if (devMode) {
mainWindow.openDevTools();
}
// checkUpdate(mainWindow, appConfig)
// .catch(err => logger.error('Unable to check for updates', err));
}
exports.buildNewWindow=buildNewWindow;