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