From 70b06680dbe5479176f69a9f756d2dcd534e43bc Mon Sep 17 00:00:00 2001
From: Will Stone
Date: Thu, 14 Dec 2017 22:14:13 +0000
Subject: [PATCH 01/19] start update checker
---
.eslintrc.json | 43 ++++++++++++++++++++++---------------------
package.json | 24 +++++++++++++++++++-----
src/main.js | 21 +++++++++++++++++++++
yarn.lock | 2 +-
4 files changed, 63 insertions(+), 27 deletions(-)
diff --git a/.eslintrc.json b/.eslintrc.json
index 7db57548..6997fc71 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -1,23 +1,24 @@
{
- "env": {
- "browser": true,
- "commonjs": true,
- "es6": true,
- "node": true
+ "env": {
+ "browser": true,
+ "commonjs": true,
+ "es6": true,
+ "node": true
+ },
+ "parserOptions": {
+ "ecmaVersion": 2017,
+ "ecmaFeatures": {
+ "jsx": true
},
- "parserOptions": {
- "ecmaFeatures": {
- "jsx": true
- },
- "sourceType": "module"
- },
- "rules": {
- "no-const-assign": "warn",
- "no-this-before-super": "warn",
- "no-undef": "warn",
- "no-unreachable": "warn",
- "no-unused-vars": "warn",
- "constructor-super": "warn",
- "valid-typeof": "warn"
- }
-}
\ No newline at end of file
+ "sourceType": "module"
+ },
+ "rules": {
+ "no-const-assign": "warn",
+ "no-this-before-super": "warn",
+ "no-undef": "warn",
+ "no-unreachable": "warn",
+ "no-unused-vars": "warn",
+ "constructor-super": "warn",
+ "valid-typeof": "warn"
+ }
+}
diff --git a/package.json b/package.json
index 6c2815be..dc41870f 100644
--- a/package.json
+++ b/package.json
@@ -16,7 +16,10 @@
"bugs": {
"url": "https://github.com/will-stone/browserosaurus/issues"
},
- "keywords": ["Electron", "Browser chooser"],
+ "keywords": [
+ "Electron",
+ "Browser chooser"
+ ],
"author": "Will Stone",
"license": "MIT",
"devDependencies": {
@@ -39,28 +42,39 @@
"electron-store": "^1.3.0",
"jsonpath": "^0.2.11",
"mousetrap": "^1.6.1",
+ "node-fetch": "^1.7.3",
"opn": "^5.1.0",
"pretty-checkbox": "^3.0.3",
+ "semver": "^5.4.1",
"sortablejs": "^1.7.0",
"xml2json": "^0.11.0"
},
"config": {
"forge": {
"make_targets": {
- "darwin": ["dmg"]
+ "darwin": [
+ "dmg"
+ ]
},
"electronPackagerConfig": {
"packageManager": "yarn",
"icon": "src/images/icon/icon.icns",
- "ignore": ["docs"],
+ "ignore": [
+ "docs"
+ ],
"protocols": [
{
"name": "HTTP link",
- "schemes": ["http", "https"]
+ "schemes": [
+ "http",
+ "https"
+ ]
},
{
"name": "File",
- "schemes": ["file"]
+ "schemes": [
+ "file"
+ ]
}
]
}
diff --git a/src/main.js b/src/main.js
index f929ad56..b01add3f 100644
--- a/src/main.js
+++ b/src/main.js
@@ -4,6 +4,8 @@ import { app, BrowserWindow, Tray, Menu, ipcMain } from 'electron'
import Store from 'electron-store'
import jp from 'jsonpath'
import parser from 'xml2json'
+import fetch from 'node-fetch'
+import semver from 'semver'
import defaultBrowsers from './browsers'
@@ -155,6 +157,12 @@ function createTrayIcon() {
tray.setPressedImage(`${__dirname}/images/icon/tray_iconHighlight.png`)
const contextMenu = Menu.buildFromTemplate([
+ {
+ label: 'Check for update...',
+ click: function() {
+ createUpdateWindow()
+ }
+ },
{
label: 'Preferences',
click: function() {
@@ -188,6 +196,19 @@ function createTrayIcon() {
return null
}
+function checkForUpdate() {
+ return fetch(
+ 'https://api.github.com/repos/will-stone/browserosaurus/releases/latest'
+ )
+ .then(response => response.json())
+ .then(response => semver.gt(response.tag_name, app.getVersion()))
+}
+
+async function createUpdateWindow() {
+ const updateAvailable = await checkForUpdate()
+ console.log(updateAvailable)
+}
+
/**
* Send URL to picker
*
diff --git a/yarn.lock b/yarn.lock
index bbb542ea..55555677 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4066,7 +4066,7 @@ node-expat@^2.3.15:
bindings "^1.2.1"
nan "^2.3.5"
-node-fetch@^1.6.3:
+node-fetch@^1.6.3, node-fetch@^1.7.3:
version "1.7.3"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
dependencies:
From ec5a923092d9732a2dc32a81d85174e9a9036390 Mon Sep 17 00:00:00 2001
From: Will Stone
Date: Fri, 15 Dec 2017 18:14:32 +0000
Subject: [PATCH 02/19] update window. button sends download link to
Browserosaurus
---
package.json | 22 +++++-----------------
src/main.js | 39 ++++++++++++++++++++++++++++++++++-----
src/main.scss | 40 ++++++++++++++++++++++++++++++++++++++++
src/update.html | 27 +++++++++++++++++++++++++++
src/updateRenderer.js | 17 +++++++++++++++++
5 files changed, 123 insertions(+), 22 deletions(-)
create mode 100644 src/update.html
create mode 100644 src/updateRenderer.js
diff --git a/package.json b/package.json
index dc41870f..edd0ccf3 100644
--- a/package.json
+++ b/package.json
@@ -16,10 +16,7 @@
"bugs": {
"url": "https://github.com/will-stone/browserosaurus/issues"
},
- "keywords": [
- "Electron",
- "Browser chooser"
- ],
+ "keywords": ["Electron", "Browser chooser"],
"author": "Will Stone",
"license": "MIT",
"devDependencies": {
@@ -52,29 +49,20 @@
"config": {
"forge": {
"make_targets": {
- "darwin": [
- "dmg"
- ]
+ "darwin": ["dmg"]
},
"electronPackagerConfig": {
"packageManager": "yarn",
"icon": "src/images/icon/icon.icns",
- "ignore": [
- "docs"
- ],
+ "ignore": ["docs"],
"protocols": [
{
"name": "HTTP link",
- "schemes": [
- "http",
- "https"
- ]
+ "schemes": ["http", "https"]
},
{
"name": "File",
- "schemes": [
- "file"
- ]
+ "schemes": ["file"]
}
]
}
diff --git a/src/main.js b/src/main.js
index b01add3f..082c8595 100644
--- a/src/main.js
+++ b/src/main.js
@@ -13,6 +13,7 @@ import defaultBrowsers from './browsers'
// be closed automatically when the JavaScript object is garbage collected.
let pickerWindow = null
let preferencesWindow = null
+let updateWindow = null
let tray = null
let appIsReady = false
let installedBrowsers = []
@@ -201,14 +202,42 @@ function checkForUpdate() {
'https://api.github.com/repos/will-stone/browserosaurus/releases/latest'
)
.then(response => response.json())
- .then(response => semver.gt(response.tag_name, app.getVersion()))
+ .then(response => {
+ if (semver.gt(response.tag_name, app.getVersion())) {
+ return response.assets[0].browser_download_url
+ } else {
+ return false
+ }
+ })
}
-async function createUpdateWindow() {
- const updateAvailable = await checkForUpdate()
- console.log(updateAvailable)
+function createUpdateWindow() {
+ updateWindow = new BrowserWindow({
+ width: 400,
+ height: 200,
+ icon: `${__dirname}/images/icon/icon.png`,
+ resizable: false,
+ show: true,
+ alwaysOnTop: true,
+ frame: true,
+ hasShadow: true,
+ minimizable: false,
+ maximizable: false
+ })
+
+ updateWindow.loadURL(`file://${__dirname}/update.html`)
}
+ipcMain.on('check-for-update', async () => {
+ const updateAvailable = await checkForUpdate()
+ updateWindow.webContents.send('updateAvailable', updateAvailable)
+})
+
+ipcMain.on('open-download-link', (event, url) => {
+ updateWindow.close()
+ sendUrlToPicker(url)
+})
+
/**
* Send URL to picker
*
@@ -242,8 +271,8 @@ function createPreferencesWindow(callback) {
maximizable: false
})
- // preferencesWindow.installedBrowsers = installedBrowsers
preferencesWindow.loadURL(`file://${__dirname}/preferences.html`)
+
// allow window to be opened again
preferencesWindow.on('close', e => {
if (wantToQuit == false) {
diff --git a/src/main.scss b/src/main.scss
index 3bf7f424..d96df799 100644
--- a/src/main.scss
+++ b/src/main.scss
@@ -100,3 +100,43 @@ body {
cursor: pointer;
}
}
+
+#update {
+ padding: 1rem;
+ text-align: center;
+
+ .showUpdate,
+ .noUpdate {
+ display: none;
+ }
+
+ &.updateAvailable {
+ .checking,
+ .noUpdate {
+ display: none;
+ }
+
+ .showUpdate {
+ display: block;
+ }
+ }
+
+ &.noUpdate {
+ .checking,
+ .showUpdate {
+ display: none;
+ }
+
+ .noUpdate {
+ display: block;
+ }
+ }
+}
+
+.button {
+ padding: 1rem;
+ color: white;
+ border: 0;
+ background-color: #126edb;
+ font-size: inherit;
+}
diff --git a/src/update.html b/src/update.html
new file mode 100644
index 00000000..d4eb2ec7
--- /dev/null
+++ b/src/update.html
@@ -0,0 +1,27 @@
+
+
+
+
+
+ Browserosaurus Update
+
+
+
+
+
+ Checking…
+
+
+
Update available!
+
+
+
+ You have the latest version.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/updateRenderer.js b/src/updateRenderer.js
new file mode 100644
index 00000000..963cec13
--- /dev/null
+++ b/src/updateRenderer.js
@@ -0,0 +1,17 @@
+const electron = require('electron')
+
+electron.ipcRenderer.on('updateAvailable', (event, updateUrl) => {
+ const update = document.getElementById('update')
+ const downloadButton = document.getElementById('downloadButton')
+
+ if (updateUrl) {
+ downloadButton.addEventListener('click', () =>
+ electron.ipcRenderer.send('open-download-link', updateUrl)
+ )
+ update.classList.add('updateAvailable')
+ } else {
+ update.classList.add('noUpdate')
+ }
+})
+
+electron.ipcRenderer.send('check-for-update')
From 5416581a31a530b2e9cea6e861eec7e96ebb78e2 Mon Sep 17 00:00:00 2001
From: Will Stone
Date: Sun, 17 Dec 2017 22:40:04 +0000
Subject: [PATCH 03/19] merge about into prefs. Tabs in prefs
---
.compilerc | 36 ++++++
.eslintrc.json | 1 +
package.json | 23 +++-
src/main.js | 132 +++++++++-------------
src/main.scss | 79 ++++++++------
src/picker.html | 3 +-
src/preferences.html | 20 +++-
src/preferencesRenderer.js | 218 ++++++++++++++++++++++---------------
src/update.html | 27 -----
yarn.lock | 11 ++
10 files changed, 310 insertions(+), 240 deletions(-)
create mode 100644 .compilerc
delete mode 100644 src/update.html
diff --git a/.compilerc b/.compilerc
new file mode 100644
index 00000000..6ecf29bf
--- /dev/null
+++ b/.compilerc
@@ -0,0 +1,36 @@
+{
+ "env": {
+ "development": {
+ "application/javascript": {
+ "presets": [
+ [
+ "env",
+ {
+ "targets": {
+ "chrome": 58
+ }
+ }
+ ]
+ ],
+ "plugins": ["transform-object-rest-spread"],
+ "sourceMaps": "inline"
+ }
+ },
+ "production": {
+ "application/javascript": {
+ "presets": [
+ [
+ "env",
+ {
+ "targets": {
+ "chrome": 58
+ }
+ }
+ ]
+ ],
+ "plugins": ["transform-object-rest-spread"],
+ "sourceMaps": "none"
+ }
+ }
+ }
+}
diff --git a/.eslintrc.json b/.eslintrc.json
index 6997fc71..f806e9df 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -1,4 +1,5 @@
{
+ "parser": "babel-eslint",
"env": {
"browser": true,
"commonjs": true,
diff --git a/package.json b/package.json
index edd0ccf3..90ebb431 100644
--- a/package.json
+++ b/package.json
@@ -16,12 +16,16 @@
"bugs": {
"url": "https://github.com/will-stone/browserosaurus/issues"
},
- "keywords": ["Electron", "Browser chooser"],
+ "keywords": [
+ "Electron",
+ "Browser chooser"
+ ],
"author": "Will Stone",
"license": "MIT",
"devDependencies": {
"babel-eslint": "7.2.3",
"babel-plugin-transform-async-to-generator": "^6.24.1",
+ "babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.5.1",
"babel-preset-react": "^6.24.1",
"electron-forge": "^4.1.3",
@@ -49,20 +53,29 @@
"config": {
"forge": {
"make_targets": {
- "darwin": ["dmg"]
+ "darwin": [
+ "dmg"
+ ]
},
"electronPackagerConfig": {
"packageManager": "yarn",
"icon": "src/images/icon/icon.icns",
- "ignore": ["docs"],
+ "ignore": [
+ "docs"
+ ],
"protocols": [
{
"name": "HTTP link",
- "schemes": ["http", "https"]
+ "schemes": [
+ "http",
+ "https"
+ ]
},
{
"name": "File",
- "schemes": ["file"]
+ "schemes": [
+ "file"
+ ]
}
]
}
diff --git a/src/main.js b/src/main.js
index 082c8595..9a1b62e4 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,4 +1,4 @@
-import openAboutWindow from 'about-window'
+// import openAboutWindow from 'about-window'
import { spawn } from 'child_process'
import { app, BrowserWindow, Tray, Menu, ipcMain } from 'electron'
import Store from 'electron-store'
@@ -71,39 +71,41 @@ function loadConfig() {
* if rejected.
*/
function findInstalledBrowsers() {
- return new Promise((fulfill, reject) => {
- const sp = spawn('system_profiler', ['-xml', 'SPApplicationsDataType'])
+ // return new Promise((fulfill, reject) => {
+ const sp = spawn('system_profiler', ['-xml', 'SPApplicationsDataType'])
- let profile = ''
+ let profile = ''
- sp.stdout.setEncoding('utf8')
- sp.stdout.on('data', data => {
- profile += data
- })
- sp.stderr.on('data', data => {
- console.log(`stderr: ${data}`)
- reject(data)
- })
- sp.stdout.on('end', () => {
- profile = parser.toJson(profile, { object: true })
- const installedApps = jp.query(
- profile,
- 'plist.array.dict.array[1].dict[*].string[0]'
- )
- installedBrowsers = userConfig.browsers
- .map(browser => {
- for (let i = 0; i < installedApps.length; i++) {
- //const browser = installedApps[i]
- if (browser.name === installedApps[i]) {
- return browser
- }
+ sp.stdout.setEncoding('utf8')
+ sp.stdout.on('data', data => {
+ profile += data
+ })
+ sp.stderr.on('data', data => {
+ console.log(`stderr: ${data}`)
+ // reject(data)
+ })
+ sp.stdout.on('end', () => {
+ profile = parser.toJson(profile, { object: true })
+ const installedApps = jp.query(
+ profile,
+ 'plist.array.dict.array[1].dict[*].string[0]'
+ )
+ installedBrowsers = userConfig.browsers
+ .map(browser => {
+ for (let i = 0; i < installedApps.length; i++) {
+ //const browser = installedApps[i]
+ if (browser.name === installedApps[i]) {
+ return browser
}
- return false
- })
- .filter(x => x) // remove empties
- fulfill(installedBrowsers)
- })
+ }
+ return false
+ })
+ .filter(x => x) // remove empties
+ // fulfill(installedBrowsers)
+ pickerWindow.webContents.send('incomingBrowsers', installedBrowsers)
+ preferencesWindow.webContents.send('incomingBrowsers', installedBrowsers)
})
+ // })
}
/**
@@ -126,7 +128,7 @@ function createPickerWindow(callback) {
show: false,
title: 'Browserosaurus',
hasShadow: true,
- backgroundColor: '#111111'
+ backgroundColor: '#21252b'
})
pickerWindow.loadURL(`file://${__dirname}/picker.html`)
@@ -158,29 +160,10 @@ function createTrayIcon() {
tray.setPressedImage(`${__dirname}/images/icon/tray_iconHighlight.png`)
const contextMenu = Menu.buildFromTemplate([
- {
- label: 'Check for update...',
- click: function() {
- createUpdateWindow()
- }
- },
{
label: 'Preferences',
click: function() {
- togglePreferencesWindow(() => {
- preferencesWindow.webContents.send(
- 'incomingBrowsers',
- installedBrowsers
- )
- })
- }
- },
- {
- label: 'About',
- click: function() {
- openAboutWindow({
- icon_path: `${__dirname}/images/icon/icon.png`
- })
+ togglePreferencesWindow()
}
},
{
@@ -211,22 +194,9 @@ function checkForUpdate() {
})
}
-function createUpdateWindow() {
- updateWindow = new BrowserWindow({
- width: 400,
- height: 200,
- icon: `${__dirname}/images/icon/icon.png`,
- resizable: false,
- show: true,
- alwaysOnTop: true,
- frame: true,
- hasShadow: true,
- minimizable: false,
- maximizable: false
- })
-
- updateWindow.loadURL(`file://${__dirname}/update.html`)
-}
+ipcMain.on('scan-for-browsers', () => {
+ findInstalledBrowsers()
+})
ipcMain.on('check-for-update', async () => {
const updateAvailable = await checkForUpdate()
@@ -255,12 +225,11 @@ function sendUrlToPicker(url) {
*
* Creates the window used to display the preferences, triggered from the
* menubar icon.
- * @param {Function} callback function to run after this one finishes.
*/
-function createPreferencesWindow(callback) {
+function createPreferencesWindow() {
preferencesWindow = new BrowserWindow({
width: 400,
- height: 64 + 24,
+ height: 146,
icon: `${__dirname}/images/icon/icon.png`,
resizable: false,
show: false,
@@ -268,6 +237,10 @@ function createPreferencesWindow(callback) {
frame: true,
hasShadow: true,
minimizable: false,
+ maximizable: false,
+ titleBarStyle: 'hidden',
+ backgroundColor: '#21252b',
+ minimizable: false,
maximizable: false
})
@@ -280,26 +253,20 @@ function createPreferencesWindow(callback) {
preferencesWindow.hide()
}
})
-
- if (callback) {
- callback()
- }
}
/**
* Toggle Preferences Window
*
* Shows and brings preferences window to front.
- * @param {Function} callback function to run after this one finishes.
*/
-function togglePreferencesWindow(callback) {
+function togglePreferencesWindow() {
if (!preferencesWindow) {
- createPreferencesWindow(callback)
+ createPreferencesWindow()
} else {
// Bring to front
preferencesWindow.center()
preferencesWindow.show()
- callback()
}
}
@@ -379,12 +346,11 @@ app.on('ready', () => {
})
})
createPreferencesWindow()
- findInstalledBrowsers().then(installedBrowsers => {
- pickerWindow.webContents.send('incomingBrowsers', installedBrowsers)
- preferencesWindow.webContents.send('incomingBrowsers', installedBrowsers)
- })
+ findInstalledBrowsers() //.then(installedBrowsers => {
+ // pickerWindow.webContents.send('incomingBrowsers', installedBrowsers)
+ // preferencesWindow.webContents.send('incomingBrowsers', installedBrowsers)
+ // })
})
- //)
})
// Hide dock icon. Also prevents Browserosaurus from appearing in cmd-tab.
diff --git a/src/main.scss b/src/main.scss
index d96df799..0266c8da 100644
--- a/src/main.scss
+++ b/src/main.scss
@@ -14,6 +14,7 @@ body {
body {
margin: 0;
padding: 0;
+ color: white;
}
#url {
@@ -81,55 +82,59 @@ body {
font-weight: bold;
}
+#titleBar {
+ height: 2rem;
+ -webkit-app-region: drag;
+ text-align: center;
+ line-height: 2rem;
+}
+
#preferences {
- color: #111111;
+ #navbar {
+ display: flex;
+ justify-content: space-around;
+ height: 64px;
+ margin: 0;
+ padding: 0;
+ list-style: none;
+ -webkit-app-region: drag;
+ border-bottom: 1px solid #111111;
+ line-height: 64px;
+
+ li {
+ cursor: default;
+ -webkit-app-region: no-drag;
+ opacity: 0.5;
+
+ &.is-active,
+ &:hover {
+ opacity: 1;
+ }
+ }
+ }
- #browserList > li {
- cursor: default;
+ #browserList {
+ > li {
+ cursor: default;
- &.sortable-ghost {
- opacity: 0;
+ &.sortable-ghost {
+ opacity: 0;
+ }
}
}
}
#picker {
- color: white;
-
#browserList > li {
cursor: pointer;
}
}
-#update {
- padding: 1rem;
- text-align: center;
+.tab-pane {
+ display: none;
- .showUpdate,
- .noUpdate {
- display: none;
- }
-
- &.updateAvailable {
- .checking,
- .noUpdate {
- display: none;
- }
-
- .showUpdate {
- display: block;
- }
- }
-
- &.noUpdate {
- .checking,
- .showUpdate {
- display: none;
- }
-
- .noUpdate {
- display: block;
- }
+ &.is-active {
+ display: block;
}
}
@@ -140,3 +145,7 @@ body {
background-color: #126edb;
font-size: inherit;
}
+
+.text-center {
+ text-align: center;
+}
diff --git a/src/picker.html b/src/picker.html
index a557e35e..3b95d4e8 100644
--- a/src/picker.html
+++ b/src/picker.html
@@ -12,8 +12,7 @@
- - Loading...
-
-
+
- Loading...
-
- - Loading…
-
-
+
Preferences
+
+
+
+
+
+
+
+
+
Browserosaurus
+
+
+