TidGi-Desktop/public/windows/code-injection.js
2020-05-10 14:29:02 +07:00

59 lines
1.1 KiB
JavaScript

const { BrowserWindow } = require('electron');
const path = require('path');
const { REACT_PATH } = require('../constants/paths');
const { getPreference } = require('../libs/preferences');
const mainWindow = require('./main');
let win;
let activeType = null;
const get = () => win;
const create = (type) => {
const attachToMenubar = getPreference('attachToMenubar');
activeType = type;
global.codeInjectionType = type;
win = new BrowserWindow({
width: 640,
height: 560,
resizable: false,
maximizable: false,
minimizable: false,
fullscreenable: false,
autoHideMenuBar: false,
webPreferences: {
nodeIntegration: true,
preload: path.join(__dirname, '..', 'preload', 'code-injection.js'),
},
parent: attachToMenubar ? null : mainWindow.get(),
});
win.setMenuBarVisibility(false);
win.loadURL(REACT_PATH);
win.on('closed', () => {
win = null;
});
};
const show = (id) => {
if (win == null) {
create(id);
} else if (id !== activeType) {
win.close();
create(id);
} else {
win.show();
}
};
module.exports = {
get,
create,
show,
};