Skip to content
This repository was archived by the owner on Jan 14, 2022. It is now read-only.

Commit e298dfd

Browse files
committed
added product info popup
1 parent f965b4e commit e298dfd

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

app/app-menu.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
const electron = require('electron')
2+
const os = require('os')
23
const BrowserWindow = electron.BrowserWindow
34
const dialog = electron.dialog
45

6+
function getAppInfo () {
7+
const info = `
8+
Version: ${process.getVersion()}
9+
Commit: ${process.getCommit()}
10+
Electron: ${process.versions.electron}
11+
Chrome: ${process.versions.chrome}
12+
Node.js: ${process.versions.node}
13+
V8: ${process.versions.v8}
14+
OS: ${os.type()} ${os.arch()} ${os.release()}`
15+
return info
16+
}
17+
518
function getMenu (app, mainWindow) {
619
const macOS = process.platform === 'darwin'
720

@@ -99,6 +112,18 @@ function getMenu (app, mainWindow) {
99112
click () {
100113
BrowserWindow.getFocusedWindow().reload()
101114
}
115+
},
116+
{
117+
label: 'About',
118+
click () {
119+
dialog.showMessageBox({
120+
type: 'info',
121+
title: 'Snippet Store',
122+
message: 'Snippet Store',
123+
detail: getAppInfo(),
124+
buttons: ['OK']
125+
})
126+
}
102127
}
103128
]
104129
}

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
function runMainApp () {
22
require('./app/app-main')
33
}
4+
5+
process.getCommit = () => {
6+
if (process.env.npm_package_gitHead) return process.env.npm_package_gitHead
7+
return require('./product.json').commit
8+
}
9+
10+
process.getVersion = () => {
11+
if (process.env.npm_package_version) return process.env.npm_package_version
12+
return require('./product.json').version
13+
}
14+
415
runMainApp()

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"fix": "eslint . --fix",
99
"lint": "eslint .",
1010
"build": "node scripts/build.js",
11+
"product": "node scripts/product.js",
1112
"dist:linux": "npm run build && rimraf dist/ && electron-builder --linux",
1213
"dist:win": "npm run build && rimraf dist/ && electron-builder --win",
1314
"dist:mac": "npm run build && rimraf dist/ && electron-builder --mac",
@@ -28,6 +29,7 @@
2829
},
2930
"files": [
3031
"index.js",
32+
"product.json",
3133
"compiled/**/*",
3234
"app/**/*",
3335
"resources/**/*",

product.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"0.2.10","commit":"f965b4e453682a27162685d9415f86999116bef5"}

scripts/product.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
4+
const pkgPath = path.join(__dirname, '../package.json')
5+
const productPath = path.join(__dirname, '../product.json')
6+
const pkg = require(pkgPath)
7+
8+
function generateProductInfo () {
9+
const product = {
10+
version: pkg.version,
11+
commit: require('child_process')
12+
.execSync('git rev-parse HEAD')
13+
.toString()
14+
.trim()
15+
}
16+
fs.writeFileSync(productPath, JSON.stringify(product))
17+
}
18+
19+
generateProductInfo()

0 commit comments

Comments
 (0)