Commit b52d4404 authored by Mihkel Putrinš's avatar Mihkel Putrinš

Merge branch 'upgrade' into 'master'

Upgrade to 2.0.0

See merge request !1
parents 5ce7e060 e971f7f9
bin
node_modules
old
Panustaja-*/*
\ No newline at end of file
var app = require('app')
// var op = require('object-path')
var path = require('path')
var fs = require('fs')
var ipc = require('ipc')
var clipboard = require('clipboard')
var BrowserWindow = require('browser-window')
const path = require('path')
const fs = require('fs')
const util = require('util')
const { app, clipboard, BrowserWindow, ipcMain } = require('electron')
var windows = {}
var mainWindow
......@@ -13,7 +11,8 @@ var userUrl = 'https://entu.keeleressursid.ee/api2/user'
var authUrl = userUrl + '/auth'
ISDEV = process.env.DEV ? true : false
ISDEV = true
// ISDEV = process.env.DEV ? true : false
var pjsonPath = path.join(__dirname, '..', 'package.json')
var pjson = require(pjsonPath)
......@@ -23,67 +22,83 @@ if (ISDEV) {
}
console.log('----==== ' + pjson.name + ' v.' + pjson.version + ' (build ' + (pjson.build) + ') ====----')
var webPreferences = {
'partition': 'persist:panustaja (build ' + (pjson.build) + ')',
'page-visibility': true, // Prevent throttling DOM timers (app gets less priority while in background)
const appWebPreferences = {
partition: 'persist:panustaja (build ' + (pjson.build) + ')',
pageVisibility: true
}
const rendererWebPreferences = {
partition: 'persist:panustaja (build ' + (pjson.build) + ')',
pageVisibility: true,
nodeIntegration: true,
enableRemoteModule: true
}
app.on('ready', function() {
windows.authWindow = new BrowserWindow({ width: 900, height: 600, show: true, 'web-preferences': webPreferences })
// windows.authWindow.webContents.openDevTools(true)
const authWin = new BrowserWindow({
width: 600,
height: 900,
webPreferences: appWebPreferences
})
authWin.loadURL(authUrl, {userAgent: 'Chrome'})
var title = pjson.name + ' v.' + pjson.version + (pjson.version.indexOf('-') > -1 ? pjson.build : '') + ' | Logi sisse'
windows.authWindow.center()
windows.authWindow.setTitle(title)
windows.authWindow.loadUrl(authUrl)
windows.authWindow.webContents.on('did-get-response-details', function(e, s, newUrl) {
windows.authWindow.setTitle(title)
authWin.center()
authWin.setTitle(title)
authWin.webContents.on('did-get-response-details', function(e, s, newUrl) {
authWin.setTitle(title)
if (newUrl === userUrl || newUrl === userUrl + '#') {
windows.authWindow.hide()
authWin.hide()
}
})
windows.authWindow.webContents.on('did-finish-load', function() {
windows.authWindow.setTitle(title)
var newUrl = windows.authWindow.webContents.getUrl()
authWin.webContents.on('did-finish-load', function() {
authWin.setTitle(title)
var newUrl = authWin.webContents.getURL()
if (newUrl === userUrl || newUrl === userUrl + '#') {
clipboard.clear()
windows.authWindow.webContents.selectAll()
windows.authWindow.webContents.copy()
authWin.webContents.selectAll()
authWin.webContents.copy()
setTimeout(function () {
mainWindow = new BrowserWindow({ width: 900, height: 600, show: true, 'web-preferences': webPreferences })
mainWindow = new BrowserWindow({ width: 900, height: 600, show: true, webPreferences: rendererWebPreferences })
mainWindow.setTitle('Panustaja')
mainWindow.center()
var viewPath = path.join(app.getAppPath(), 'code', 'panuView.html')
mainWindow.webContents.loadUrl('file://' + viewPath)
mainWindow.webContents.loadURL('file://' + viewPath)
if (ISDEV) {
mainWindow.webContents.openDevTools(true)
}
windows.authWindow.close()
delete windows.authWindow
authWin.close()
delete authWin
}, 1000)
} else {
return
}
})
})
ipc.on('log', function(event, message) {
ipcMain.on('log', function(event, message) {
console.log('message: ', message)
})
ipc.on('data', function(event, message) {
ipcMain.on('data', function(event, message) {
console.log('data: ' + JSON.stringify(message, null, 4))
})
ipc.on('setTitle', function(event, message) {
ipcMain.on('setTitle', function(event, message) {
mainWindow.setTitle(message)
})
var userData = false
// console.log('userData: ' + JSON.stringify(userData, null, 4))
ipc.on('setUser', function(event, data) {
ipcMain.on('setUser', function(event, data) {
userData = data
// console.log('setUser: ' + JSON.stringify(userData, null, 4))
})
ipc.on('getUser', function(event) {
ipcMain.on('getUser', function(event) {
event.returnValue = userData
// console.log('getUser: ' + JSON.stringify(userData, null, 4))
})
......
// var request = require('request')
var fs = require('fs')
var op = require('object-path')
var path = require('path')
var async = require('async')
var mime = require('mime')
var remote = require('remote')
// var app = remote.require('app')
var dialog = remote.require('dialog')
var clipboard = remote.require('clipboard')
const { clipboard, dialog } = require('electron').remote
const { ipcRenderer } = require('electron')
var pjson = require(path.join(__dirname, '..', 'package.json'))
UPLOADERVERSION = pjson.name + ' v.' + pjson.version + (pjson.version.indexOf('-') > -1 ? pjson.build : '')
var ipc = require('ipc')
var b2s = require(path.join(__dirname, 'bytesToSize.js'))
var uploader = require(path.join(__dirname, 'upload.js'))
var userData = {}
var data = ipc.sendSync('getUser', null)
var data = ipcRenderer.sendSync('getUser', null)
function setFormState(state) {
console.log('Entering form state:', state)
switch(state) {
case 'select':
document.getElementById('selectLocal').removeAttribute('hidden')
......@@ -107,7 +104,7 @@ function resourceLoaded() {
renderResource()
setFormState('loaded')
clearInterval(rendererInterval)
// ipc.send('data', resource)
// ipcRenderer.send('data', resource)
document.getElementById('uploadResourceButton').onclick = function uploadResource() {
uploader.upload()
}
......@@ -156,33 +153,38 @@ function recurseLocal(parentResource, paths, loadedCB) {
document.getElementById('selectLocalButton').onclick = function selectLocal () {
resource = {name: 'root'}
resourceStats = {files: {count: 0, size: 0}, directories: {count: 0}, mime:{}}
dialog.showOpenDialog({properties:['openFile', 'openDirectory']}, function selectedPath(myPaths) {
if (!myPaths) { return }
rendererInterval = setInterval(function () { renderResource() }, 100)
setFormState('loading')
if (myPaths.length === 1) {
var singleFile = myPaths[0]
op.set(resource, 'name', path.basename(singleFile))
document.getElementById('resourceName').value = resource.name
fs.stat(singleFile, function(err, stats) {
if (err) { throw (err) }
if (stats.isDirectory()) {
fs.readdir(singleFile, function(err, files) {
if (err) { throw (err) }
myPaths = files.map(function(file) {
var fullpath = path.join(singleFile, file)
return fullpath
})
recurseLocal(resource, myPaths, resourceLoaded)
const dialogOptions = {
message: "Vali meelepärane kataloog",
properties: ['openFile', 'openDirectory']
}
let myPaths = dialog.showOpenDialogSync(dialogOptions)
if (!myPaths) { return }
rendererInterval = setInterval(function () { renderResource() }, 100)
setFormState('loading')
if (myPaths.length === 1) {
var singleFile = myPaths[0]
op.set(resource, 'name', path.basename(singleFile))
document.getElementById('resourceName').value = resource.name
fs.stat(singleFile, function(err, stats) {
if (err) { throw (err) }
if (stats.isDirectory()) {
fs.readdir(singleFile, function(err, files) {
if (err) { throw (err) }
myPaths = files.map(function(file) {
var fullpath = path.join(singleFile, file)
return fullpath
})
} else {
recurseLocal(resource, myPaths, resourceLoaded)
}
})
} else {
recurseLocal(resource, myPaths, resourceLoaded)
}
})
})
} else {
recurseLocal(resource, myPaths, resourceLoaded)
}
})
} else {
recurseLocal(resource, myPaths, resourceLoaded)
}
}
......@@ -190,7 +192,7 @@ document.getElementById('selectLocalButton').onclick = function selectLocal () {
if (!data) {
data = JSON.parse(clipboard.readText())
clipboard.clear()
ipc.send('setUser', data)
ipcRenderer.send('setUser', data)
}
if (op.get(data, 'result.user_id', false)) {
userData.userId = op.get(data, 'result.user_id')
......@@ -198,10 +200,10 @@ if (op.get(data, 'result.user_id', false)) {
userData.name = op.get(data, 'result.name')
document.getElementById('userName').innerHTML = userData.name
var title = UPLOADERVERSION + ' | ' + userData.name
ipc.send('setTitle', title)
ipcRenderer.send('setTitle', title)
setFormState('select')
} else {
ipc.send('log', 'User data incomplete.')
ipc.send('data', data)
ipcRenderer.send('log', 'User data incomplete.')
ipcRenderer.send('data', data)
}
ipc.send('closeAuth')
ipcRenderer.send('closeAuth')
......@@ -4,6 +4,8 @@ var op = require('object-path')
var path = require('path')
var async = require('async')
const { shell } = require('electron').remote
// var remote = require('remote')
// var dialog = remote.require('dialog')
......@@ -190,7 +192,7 @@ function upload() {
document.getElementById('resourceEntuLink').setAttribute('href', 'https://entu.keeleressursid.ee/entity/resource/' + newEid)
document.getElementById('resourceEntuLink').innerHTML = 'https://entu.keeleressursid.ee/entity/resource/' + newEid
document.getElementById('resourceEntuLink').onclick = function openResourceInBrowser() {
require('shell').openExternal('https://entu.keeleressursid.ee/entity/resource/' + newEid)
shell.openExternal('https://entu.keeleressursid.ee/entity/resource/' + newEid)
return false
}
// ipc.send('data', resource)
......
This diff is collapsed.
{
"name": "Panustaja",
"name": "panustaja",
"description": "Ressursikataloogi upitamiseks keeleressurside Entu repositooriumisse.",
"version": "1.0.1-d",
"build": 103,
"version": "2.0.0",
"build": 149,
"main": "./code/app.js",
"license": "CC-SA",
"private": true,
......@@ -10,11 +10,17 @@
"type": "git",
"url": "git@gitlab.keeleressursid.ee:michelek/panustaja.git"
},
"scripts": {
"start": "electron ."
},
"dependencies": {
"async": "^1.5.0",
"mime": "^1.3.4",
"object-path": "^0.9.2",
"request": "^2.65.0"
},
"devDependencies": {}
}
"devDependencies": {
"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