Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #19 from LINCnil/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
LaboCNIL authored Jan 19, 2018
2 parents f8e49ff + a61636d commit 4f9b5a6
Show file tree
Hide file tree
Showing 28 changed files with 2,109 additions and 16 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
release-builds
dist
node_modules/
dist/
releases/
private/
*.log
Binary file added icon.icns
Binary file not shown.
Binary file renamed icons/win/icon.ico → icon.ico
Binary file not shown.
Binary file added icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/256x256.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed icons/default/16x16.png
Binary file not shown.
Binary file removed icons/default/24x24.png
Binary file not shown.
Binary file removed icons/default/32x32.png
Binary file not shown.
Binary file removed icons/default/48x48.png
Binary file not shown.
Binary file removed icons/default/96x96.png
Binary file not shown.
Binary file removed icons/default/icon.png
Binary file not shown.
Binary file removed icons/default/[email protected]
Binary file not shown.
Binary file removed icons/default/[email protected]
Binary file not shown.
Binary file removed icons/default/[email protected]
Binary file not shown.
Binary file removed icons/mac/icon.icns
Binary file not shown.
101 changes: 95 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const electron = require('electron')
// Module to control application life.
const app = electron.app
const globalShortcut = electron.globalShortcut
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow
const { app, BrowserWindow } = electron
const updater = require('./updater')
// Keep window state
const windowStateKeeper = require('electron-window-state')

const path = require('path')
const url = require('url')
Expand All @@ -12,18 +12,105 @@ const url = require('url')
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow

function createWindow () {
const template = [
{
label: 'Edit',
submenu: [
{role: 'undo'},
{role: 'redo'},
{type: 'separator'},
{role: 'cut'},
{role: 'copy'},
{role: 'paste'},
{role: 'pasteandmatchstyle'},
{role: 'delete'},
{role: 'selectall'}
]
},
{
label: 'View',
submenu: [
{role: 'resetzoom'},
{role: 'zoomin'},
{role: 'zoomout'},
{type: 'separator'},
{role: 'togglefullscreen'}
]
},
{
role: 'window',
submenu: [
{role: 'minimize'},
{role: 'close'}
]
}
]

if (process.platform === 'darwin') {
template.unshift({
label: 'PIA',
submenu: [
{role: 'hide'},
{role: 'hideothers'},
{role: 'unhide'},
{type: 'separator'},
{role: 'quit'}
]
})

// Edit menu
template[1].submenu.push(
{type: 'separator'},
{
label: 'Speech',
submenu: [
{role: 'startspeaking'},
{role: 'stopspeaking'}
]
}
)

// Window menu
template[3].submenu = [
{role: 'close'},
{role: 'minimize'},
{role: 'zoom'},
{type: 'separator'},
{role: 'front'}
]
}

const menu = electron.Menu.buildFromTemplate(template)



function createWindow() {
let winState = windowStateKeeper({
defaultWidth: 900,
defaultHeight: 600
})

electron.Menu.setApplicationMenu(menu)

// Create the browser window.
mainWindow = new BrowserWindow({
width: winState.width,
height: winState.height,
x: winState.x,
y: winState.y,
minWidth: 900,
minHeight: 600,
alwaysOnTop: false,
fullscreen: false,
kiosk: false,
icon: path.join(__dirname, 'icons/default/icon.png'),
icon: `$(__dirname)/icons/64x64.png`,
webPreferences: {
nodeIntegration: false, plugins: true
}
})

winState.manage(mainWindow)

// and load the index.html of the app.
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'dist', 'index.html'),
Expand All @@ -46,6 +133,8 @@ function createWindow () {
e.preventDefault();
require('electron').shell.openExternal(url);
});

setTimeout(updater.check, 2000);
}

// This method will be called when Electron has finished
Expand Down
50 changes: 50 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 38 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
{
"name": "PIA",
"version": "0.0.5",
"version": "1.5.0",
"description": "Version Portable Outil PIA",
"main": "main.js",
"scripts": {
"start": "./node_modules/.bin/electron .",
"package-mac": "electron-packager . --electron-version=1.7.9 --overwrite --prune=true --asar=true --platform=darwin --arch=x64 --icon=icons/mac/icon.icns --out=release-builds",
"package-win32": "electron-packager . --electron-version=1.7.9 --overwrite --prune=true --asar=true --platform=win32 --arch=ia32 --icon=icons/win/icon.ico --out=release-builds",
"package-win": "electron-packager . --electron-version=1.7.9 --overwrite --prune=true --asar=true --platform=win32 --arch=x64 --icon=icons/win/icon.ico --out=release-builds",
"package-linux": "electron-packager . --electron-version=1.7.9 --overwrite --prune=true --asar=true --platform=linux --arch=x64 --out=release-builds"
"start": "electron .",
"mac": "electron-builder -m",
"win": "electron-builder -w --x64 --ia32",
"linux": "electron-builder -l",
"win-cert": "electron-builder create-self-signed-cert -p atnos",
"publish-to-github": "electron-builder build -mwl --x64 --ia32 -p onTagOrDraft"
},
"author": "ATNOS",
"repository": "https://github.com/LINCnil/pia-app",
"keywords": [
"Electron",
"PIA"
],
"author": "ATNOS"
"build": {
"appId": "com.atnos.pia",
"directories": {
"buildResources": ".",
"output": "releases"
},
"mac": {
"publish": ["github"],
"category": "public.app.category.productivity"
},
"win": {
"publish": ["github"],
"certificateFile": "private/atnos.pfx",
"verifyUpdateCodeSignature": false,
"publisherName": "ATNOS"
},
"linux": {
"publish": ["github"],
"category": "Network"
}
},
"devDependencies": {
"electron": "~1.7.10",
"electron-builder": "^19.54.0"
},
"dependencies": {
"electron-window-state": "^4.1.1",
"electron-log": "^2.2.14",
"electron-updater": "^2.19.1"
}
}
17 changes: 17 additions & 0 deletions renderer/progress.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Downloading PIA Update</title>
</head>
<body>
<progress style="width:100%;" value="0" max="100"></progress>
<script>
const {ipcRenderer} = require('electron')
setInterval(() => {
let progress = ipcRenderer.sendSync('download-progress-request')
document.querySelector('progress').value = progress
}, 1000)
</script>
</body>
</html>
72 changes: 72 additions & 0 deletions updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const {dialog, BrowserWindow, ipcMain} = require('electron')
const {autoUpdater} = require('electron-updater')

const path = require('path')
const url = require('url')

autoUpdater.logger = require('electron-log')
autoUpdater.logger.transports.file.level = 'info'

autoUpdater.autoDownload = false

exports.check = () => {
autoUpdater.checkForUpdates()

autoUpdater.on('update-available', () => {

let downloadProgress = 0

dialog.showMessageBox({
type: 'info',
title: 'Update Available',
message: 'A new version of PIA is available. Do you want to update now?',
buttons: ['Update', 'No']
}, (buttonIndex) => {
if(buttonIndex !== 0) return

autoUpdater.downloadUpdate()

let progressWin = new BrowserWindow({
width: 350,
height: 35,
useContentSize: true,
autoHideMenuBar: true,
maximizable: false,
fullscreen: false,
fullscreenable: false,
resizable: false
})

progressWin.loadURL(url.format({
pathname: path.join(__dirname, 'renderer', 'progress.html'),
protocol: 'file:',
slashes: true
}))

progressWin.on('closed', () => {
progressWin = null
})

ipcMain.on('download-progress-request', (e) => {
e.returnValue = downloadProgress
})

autoUpdater.on('download-progress', (d) => {
console.log(d.percent);
downloadProgress = d.percent
})

autoUpdater.on('update-downloaded', () => {
if (progressWin) progressWin.close()
dialog.showMessageBox({
type: 'info',
title: 'Update ready',
message: 'A new version of PIA is ready. Quit and install now?',
buttons: ['Yes', 'Later']
}, (buttonIndex) => {
if (buttonIndex === 0) autoUpdater.quitAndInstall()
})
})
})
})
}
Loading

0 comments on commit 4f9b5a6

Please sign in to comment.