Commit 0f518d4c authored by Mihkel Putrinš's avatar Mihkel Putrinš

dont transport user-data thru IPC

parent 63ade4dc
var app = require('app')
var op = require('object-path')
var path = require('path')
var fs = require('fs')
var ipc = require('ipc')
BrowserWindow = require('browser-window')
var j = require('electron-jade')({pretty: true}, {})
var BrowserWindow = require('browser-window')
var windows = {}
var user_url = 'https://entu.keeleressursid.ee/api2/user'
var auth_url = user_url + '/auth'
// var authWindow
// var mainWindow
var user_data = {}
var home_path = process.env.HOME ? process.env.HOME : process.env.HOMEPATH
USER_PATH = path.join(home_path, 'user.json')
IS_DEV = process.env.DEV ? true : false
if (IS_DEV) {
var pjson_path = path.join(__dirname, '..', 'package.json')
var pjson = require(pjson_path)
console.log('----==== ' + pjson.name + ' v.' + pjson.version + ' (build ' + (++pjson.build) + ') ====----')
fs.writeFileSync(pjson_path, JSON.stringify(pjson, null, 4))
}
app.on('ready', function() {
authWindow = new BrowserWindow({ width: 300, height: 600, show: true })
authWindow.setTitle('Panustaja - log in')
authWindow.loadUrl(auth_url)
authWindow.webContents.on('did-finish-load', function() {
authWindow.webContents.savePage('./user.json', 'HTMLOnly', function(err) {
windows['authWindow'] = new BrowserWindow({ width: 300, height: 600, show: true })
windows['authWindow'].setTitle('Panustaja - log in')
windows['authWindow'].loadUrl(auth_url)
windows['authWindow'].webContents.on('did-finish-load', function() {
// require('dialog').showMessageBox({type:'info', message:'enne salvestamist: ' + USER_PATH, buttons:['ok']})
windows['authWindow'].webContents.savePage(USER_PATH, 'HTMLOnly', function(err) {
if (err) {
require('dialog').showMessageBox({type:'info', message:'peale salvestamist: katki' + err, buttons:['ok']})
console.log("Error:", err)
process.exit()
} else {
fs.readFile('./user.json', 'utf8', function(err, data) {
data = JSON.parse(data)
if (op.get(data, 'result.user_id', false)) {
user_data['user_id'] = op.get(data, 'result.user_id')
user_data['session_key'] = op.get(data, 'result.session_key')
user_data['name'] = op.get(data, 'result.name')
// console.log(JSON.stringify(data, null, 4))
} else {
console.log('User data incomplete.')
console.log(JSON.stringify(data, null, 4))
}
fs.unlink('./user.json', function (err) {
if (err) {
console.log("Error:", err)
process.exit()
}
})
mainWindow = new BrowserWindow({ width: 900, height: 600, show: true })
mainWindow.setTitle('Panustaja - ' + user_data['name'])
mainWindow.center()
mainWindow.loadUrl('file://' + __dirname + '/views/main.jade')
authWindow.close()
// require('dialog').showMessageBox({type:'info', message:'peale salvestamist: korras', buttons:['ok']})
mainWindow = new BrowserWindow({ width: 900, height: 600, show: true })
mainWindow.setTitle('Panustaja')
mainWindow.center()
mainWindow.loadUrl('file://' + __dirname + '/views/main.jade')
// windows['authWindow'].hide()
if (IS_DEV) {
mainWindow.webContents.openDevTools(true)
// var dialog = require('dialog')
// dialog.showErrorBox('FOO', 'bar, baz')
// console.log(dialog.showOpenDialog(mainWindow, { properties: [ 'openDirectory' ]}))
})
}
// require('dialog').showMessageBox({type:'info', message:'fail suletud: ' + USER_PATH, buttons:['ok']})
}
})
})
......@@ -62,7 +57,17 @@ ipc.on('data', function(event, message) {
console.log('data: ' + JSON.stringify(message, null, 4))
})
ipc.on('userdata-query', function(event) {
console.log('Sent user data', JSON.stringify(user_data, null, 4))
event.sender.send('userdata-reply', user_data)
ipc.on('setTitle', function(event, message) {
mainWindow.setTitle(message)
})
ipc.on('closeAuth', function(event) {
if (windows['authWindow']) {
windows['authWindow'].close()
delete windows['authWindow']
}
})
app.on('window-all-closed', function() {
app.quit()
})
This diff is collapsed.
#resourceProgressbarOuter {
width: 100%;
height: 10px;
background-color: #cdf;
border: 1px solid black;
}
#resourceProgressbarInner {
width: 10%;
height: 100%;
background-color: #79b;
/*border: 1px solid green;*/
}
#fileProgressbarOuter {
width: 100%;
height: 10px;
background-color: #cdf;
border: 1px solid black;
}
#fileProgressbarInner {
width: 27%;
height: 100%;
background-color: #79b;
/*border: 1px solid green;*/
}
......@@ -8,15 +8,35 @@ html
body
h1#userName Panustaja
div#selectLocalMessage Palun vali fail või kataloog, mida soovid üles laadida.
button#selectLocal(onclick='selectLocal()') Vali fail
input#resourceName(type='text' placeholder='Ressursi nimi' style='width:100%;' hidden='')
div#contents
h3#loading(hidden='') Loading...
ul#resourceStats(hidden='')
h1#userName(hidden='') Panustaja
div#selectLocal
p#selectLocalMessage Palun vali fail või kataloog, mida soovid üles laadida.
button#selectLocalButton(onclick='selectLocal()') Vali fail
div#resourceName(hidden='')
p#resourceNameMessage Muuda ressursi nimi sobivaks.
input#resourceNameInput(type='text' placeholder='Ressursi nimi' style='width:100%;')
div#loading(hidden='')
h3 Loen failisüsteemist ...
div#resourceStats(hidden='')
ul#resourceStatsList
li#resourceDirectories
li#resourceFiles
ul#mimeStats
div#uploadResource(hidden='')
p#uploadResourceMessage Ressurss on üleslaadimiseks valmis.
button#uploadResourceButton(onclick='uploadResource()') Panusta!
div#uploading(hidden='')
span= 'Kataloogid: '
span#uploadedResources 0
span /
span#uploadTotalResources 0
div#resourceProgressbarOuter
div#resourceProgressbarInner
span= 'Failid: '
span#uploadedSize 0
span /
span#uploadTotalSize 0
div#fileProgressbarOuter
div#fileProgressbarInner
script(src='../main.js')
{
"name": "Panustaja",
"description": "Ressursikataloogi upitamiseks keeleressurside Entu repositooriumisse.",
"version": "1.0.1",
"main": "./code/app.js",
"license": "CC-SA",
"private": true,
"repository": {
"type": "git",
"url": "git@gitlab.keeleressursid.ee:michelek/panustaja.git"
},
"dependencies": {
"async": "^1.5.0",
"electron-jade": "^1.3.0",
"marked": "^0.3.5",
"mmmagic": "^0.4.1",
"moment": "^2.10.6",
"object-path": "^0.9.2",
"request": "^2.65.0"
}
}
"name": "Panustaja",
"description": "Ressursikataloogi upitamiseks keeleressurside Entu repositooriumisse.",
"version": "1.0.1-d",
"build": 41,
"main": "./code/app.js",
"license": "CC-SA",
"private": true,
"repository": {
"type": "git",
"url": "git@gitlab.keeleressursid.ee:michelek/panustaja.git"
},
"dependencies": {
"async": "^1.5.0",
"electron-jade": "^1.3.0",
"marked": "^0.3.5",
"mmmagic": "^0.4.1",
"moment": "^2.10.6",
"object-path": "^0.9.2",
"request": "^2.65.0"
},
"devDependencies": {
"electron-packager": "^5.1.1"
}
}
\ No newline at end of file
#! /bin/bash
rm -r Panustaja*
electron-packager . Panustaja --platform=all --arch=x64 --version=0.34.1 --ignore Panustaja
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