Commit 14c9de8a authored by michelek's avatar michelek

refactor to comply with new electron

parent 15a248a5
{
"folders": [
{
"path": "."
},
{
"path": "../entulib"
}
],
"settings": {}
}
\ No newline at end of file
......@@ -4,68 +4,67 @@ const util = require('util')
const { app, clipboard, BrowserWindow, ipcMain } = require('electron')
var windows = {}
var mainWindow
let mainWindow
var userUrl = 'https://entu.keeleressursid.ee/api2/user'
var authUrl = userUrl + '/auth'
const userUrl = 'https://entu.keeleressursid.ee/api2/user'
const authUrl = userUrl + '/auth'
const ISDEV = process.env.DEV ? true : false
ISDEV = process.env.DEV ? true : false
var pjsonPath = path.join(__dirname, '..', 'package.json')
var pjson = require(pjsonPath)
const pjsonPath = path.join(__dirname, '..', 'package.json')
let pjson = require(pjsonPath)
if (ISDEV) {
pjson.build++
fs.writeFileSync(pjsonPath, JSON.stringify(pjson, null, 2))
}
console.log('----==== ' + pjson.name + ' v.' + pjson.version + ' (build ' + (pjson.build) + ') ====----')
const appBuildNr = pjson.build
const appVersion = pjson.version
const appName = pjson.name
console.log('----==== ' + appName + ' v.' + appVersion + ' (build ' + (appBuildNr) + ') ====----')
const authWindowTitle = appName + ' v.' + appVersion + (appVersion.indexOf('-') > -1 ? appBuildNr : '') + ' | Logi sisse'
const appWebPreferences = {
partition: 'persist:panustaja (build ' + (pjson.build) + ')',
pageVisibility: true
partition: 'persist:panustaja (build ' + (appBuildNr) + ')',
pageVisibility: true,
worldSafeExecuteJavaScript: true
}
const rendererWebPreferences = {
partition: 'persist:panustaja (build ' + (pjson.build) + ')',
partition: 'persist:panustaja (build ' + (appBuildNr) + ')',
pageVisibility: true,
nodeIntegration: true,
enableRemoteModule: true
enableRemoteModule: true,
worldSafeExecuteJavaScript: true
}
app.on('ready', function() {
const authWin = new BrowserWindow({
width: 600,
height: 900,
width: 793, height: 490,
webPreferences: appWebPreferences
})
authWin.loadURL(authUrl, {userAgent: 'Chrome'})
var title = pjson.name + ' v.' + pjson.version + (pjson.version.indexOf('-') > -1 ? pjson.build : '') + ' | Logi sisse'
authWin.center()
authWin.setTitle(title)
authWin.setTitle(authWindowTitle)
authWin.webContents.on('did-get-response-details', function(e, s, newUrl) {
authWin.setTitle(title)
authWin.setTitle(authWindowTitle)
if (newUrl === userUrl || newUrl === userUrl + '#') {
authWin.hide()
}
})
authWin.webContents.on('did-finish-load', function() {
authWin.setTitle(title)
var newUrl = authWin.webContents.getURL()
authWin.setTitle(authWindowTitle)
const newUrl = authWin.webContents.getURL()
if (newUrl === userUrl || newUrl === userUrl + '#') {
clipboard.clear()
authWin.webContents.selectAll()
authWin.webContents.copy()
setTimeout(function () {
mainWindow = new BrowserWindow({ width: 900, height: 600, show: true, webPreferences: rendererWebPreferences })
mainWindow = new BrowserWindow({ width: 793, height: 490, show: true, webPreferences: rendererWebPreferences })
mainWindow.setTitle('Panustaja')
mainWindow.center()
var viewPath = path.join(app.getAppPath(), 'code', 'panuView.html')
const viewPath = path.join(app.getAppPath(), 'code', 'panuView.html')
mainWindow.webContents.loadURL('file://' + viewPath)
if (ISDEV) {
mainWindow.webContents.openDevTools(true)
......
......@@ -194,8 +194,8 @@ if (!data) {
clipboard.clear()
ipcRenderer.send('setUser', data)
}
if (op.get(data, 'result.user_id', false)) {
userData.userId = op.get(data, 'result.user_id')
if (op.get(data, 'result.id', false)) {
userData.userId = op.get(data, 'result.id')
userData.sessionKey = op.get(data, 'result.session_key')
userData.name = op.get(data, 'result.name')
document.getElementById('userName').innerHTML = userData.name
......
......@@ -5,6 +5,7 @@
<link rel="stylesheet" type="text/css" href="./style.css">
<link rel="icon" type="image/png" href="/images/murakas.ico" sizes="96x96">
<link rel="shortcut icon" href="/images/murakas.ico">
<meta http-equiv="Content-Security-Policy" content="script-src 'self';">
</head>
<body>
<div id="murakas">
......
This diff is collapsed.
......@@ -714,12 +714,12 @@
"integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE="
},
"form-data": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz",
"integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz",
"integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.6",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
},
......@@ -1461,6 +1461,18 @@
"tough-cookie": "~2.5.0",
"tunnel-agent": "^0.6.0",
"uuid": "^3.3.2"
},
"dependencies": {
"form-data": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz",
"integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.6",
"mime-types": "^2.1.12"
}
}
}
},
"resolve": {
......
......@@ -17,6 +17,7 @@
},
"dependencies": {
"async": "^1.5.0",
"form-data": "^3.0.0",
"mime": "^1.3.4",
"object-path": "^0.9.2",
"request": "^2.65.0"
......@@ -25,4 +26,4 @@
"electron": "^10.1.1",
"electron-packager": "^15.1.0"
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment