Commit 06a3010b authored by Mihkel Putrinš's avatar Mihkel Putrinš

use clipboard instead of intermediate file

parent 1f3cf0f6
......@@ -3,6 +3,7 @@ var op = require('object-path')
var path = require('path')
var fs = require('fs')
var ipc = require('ipc')
var clipboard = require('clipboard')
var j = require('electron-jade')({pretty: true}, {})
var BrowserWindow = require('browser-window')
......@@ -41,38 +42,20 @@ app.on('ready', function() {
windows['authWindow'].setTitle(title)
var new_url = windows['authWindow'].webContents.getUrl()
if (new_url === user_url || new_url === user_url + '#') {
clipboard.clear()
windows['authWindow'].webContents.selectAll()
windows['authWindow'].webContents.copy()
mainWindow = new BrowserWindow({ width: 900, height: 600, show: true })
mainWindow.setTitle('Panustaja')
mainWindow.center()
// require('dialog').showMessageBox({type:'info', message:'OK\n"' + windows['authWindow'].webContents.getUrl() + '"'
// + '\n==='
// + '\n"' + user_url + '"'
// , buttons:['ok']
// })
// console.log(windows['authWindow'].webContents.session.cookies);
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 {
var view_path = path.join(app.getAppPath(), 'code', 'views', 'main.jade')
// require('dialog').showMessageBox({type:'info', message:'peale salvestamist: korras\n'
// + 'Laen lehte: file://' + view_path, buttons:['ok']})
mainWindow.webContents.loadUrl('file://' + view_path)
windows['authWindow'].hide()
if (IS_DEV) {
mainWindow.webContents.openDevTools(true)
}
// require('dialog').showMessageBox({type:'info', message:'fail suletud: ' + USER_PATH, buttons:['ok']})
}
})
var view_path = path.join(app.getAppPath(), 'code', 'main.jade')
mainWindow.webContents.loadUrl('file://' + view_path)
windows['authWindow'].hide()
if (IS_DEV) {
mainWindow.webContents.openDevTools(true)
}
} else {
// require('dialog').showMessageBox({type:'info', message:'"' + new_url + '"'
// + '\n!=='
// + '\n"' + user_url + '"'
// , buttons:['ok']
// })
return
}
})
......
......@@ -2,7 +2,7 @@ doctype html
html
head
meta(charset='utf-8')
link(rel='stylesheet', type='text/css', href='../style/style.css')
link(rel='stylesheet', type='text/css', href='./style.css')
link(rel='icon' type='image/png', href='/favicon-96x96.png' sizes='96x96')
link(rel='shortcut icon', href='/favicon.ico')
......@@ -41,4 +41,4 @@ html
pre#status
div#thankYou(hidden='') Aitäh!
script(src='../main.js')
script(src='./main.js')
......@@ -11,14 +11,15 @@ var magic = new Magic(mmm.MAGIC_MIME_TYPE | mmm.MAGIC_MIME_ENCODING)
var remote = require('remote')
var app = remote.require('app')
var dialog = remote.require('dialog')
var clipboard = remote.require('clipboard')
// console.log(path.join(__dirname)) ==> panustaja/code/views
var pjson = require(path.join(__dirname, '..', '..', 'package.json'))
var pjson = require(path.join(__dirname, '..', 'package.json'))
UPLOADER_VERSION = pjson.name + ' v.' + pjson.version + (pjson.version.indexOf('-') > -1 ? pjson.build : '')
var ipc = require('ipc')
var b2s = require(path.join(__dirname, '..', 'bytesToSize.js'))
var b2s = require(path.join(__dirname, 'bytesToSize.js'))
var user_data = {}
var resource = {}
......@@ -27,28 +28,22 @@ var dom_resource_name = document.getElementById('resourceNameInput')
var dom_resource_stats = document.getElementById('resourceStats')
var renderer_interval
setTimeout(function () {
USER_PATH = path.join(app.getPath('temp'), 'user.json')
fs.readFile(USER_PATH, 'utf8', function(err, data_json) {
if (err) throw (err)
// dialog.showMessageBox({type:'info', message:'fail avatud: ' + USER_PATH, buttons:['ok']})
// dialog.showMessageBox({type:'info', message:data_json, buttons:['ok']})
var data = JSON.parse(data_json)
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')
document.getElementById('userName').innerHTML = user_data.name
var title = UPLOADER_VERSION + ' | ' + user_data['name']
ipc.send('setTitle', title)
setFormState('select')
} else {
ipc.send('log', 'User data incomplete.')
ipc.send('data', data)
}
ipc.send('closeAuth')
})
}, 10)
var initialize = function initialize() {
var data = JSON.parse(clipboard.readText())
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')
document.getElementById('userName').innerHTML = user_data.name
var title = UPLOADER_VERSION + ' | ' + user_data['name']
ipc.send('setTitle', title)
setFormState('select')
} else {
ipc.send('log', 'User data incomplete.')
ipc.send('data', data)
}
ipc.send('closeAuth')
}
function selectLocal () {
resource = {name: 'root'}
......@@ -163,7 +158,7 @@ var recurseLocal = function recurseLocal(parent_resource, paths, loadedCB) {
})
}
var uploadResource = require(path.join(__dirname, '..', 'upload.js'))
var uploadResource = require(path.join(__dirname, 'upload.js'))
var setFormState = function setFormState(state) {
switch(state) {
......@@ -219,3 +214,5 @@ var setFormState = function setFormState(state) {
break
}
}
initialize()
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