Skip to content

Commit f4a6e14

Browse files
authored
add update notification - fix #51 (#52)
1 parent 0417941 commit f4a6e14

File tree

8 files changed

+146
-31
lines changed

8 files changed

+146
-31
lines changed

app/electron.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,24 @@ const path = require( 'path' );
55
const menu = require( './main/menu' );
66
const fixPath = require( 'fix-path' );
77
const windowStateKeeper = require( 'electron-window-state' );
8+
const GitHubApi = require( 'github' );
9+
const github = new GitHubApi( {
10+
protocol : 'https',
11+
headers : {
12+
'user-agent' : 'Forrest - npm desktop client'
13+
},
14+
timeout : 5000
15+
} );
16+
817

918
// configuration for the available static windows
10-
const staticWindows = {
19+
const initialBgColor = '#f1f1f1';
20+
const staticWindows = {
1121
about : {
1222
config : {
1323
height : 625,
1424
width : 475,
15-
backgroundColor : '#f1f1f1',
25+
backgroundColor : initialBgColor,
1626
titleBarStyle : 'hidden',
1727
resizable : false
1828
},
@@ -23,12 +33,23 @@ const staticWindows = {
2333
config : {
2434
height : 400,
2535
width : 800,
26-
backgroundColor : '#f1f1f1',
36+
backgroundColor : initialBgColor,
2737
titleBarStyle : 'hidden',
2838
resizable : false
2939
},
3040
hash : '#!/help',
3141
initializedWindow : null
42+
},
43+
updateAvailable : {
44+
config : {
45+
height : 300,
46+
width : 300,
47+
backgroundColor : initialBgColor,
48+
titleBarStyle : 'hidden',
49+
resizable : false
50+
},
51+
hash : '#!/update-available',
52+
initializedWindow : null
3253
}
3354
};
3455

@@ -112,7 +133,7 @@ function createWindow( event, hash ) {
112133
width : mainWindowState.width,
113134
x : mainWindowState.x,
114135
y : mainWindowState.y,
115-
backgroundColor : '#f1f1f1',
136+
backgroundColor : initialBgColor,
116137
minWidth : 250,
117138
titleBarStyle : 'hidden',
118139
'web-preferences' : {
@@ -159,6 +180,21 @@ function createWindow( event, hash ) {
159180
console.log( 'window opened' );
160181
}
161182

183+
if ( process.env.NODE_ENV !== 'development' ) {
184+
github.repos.getReleases(
185+
{ user : 'stefanjudis', repo : 'forrest' },
186+
( error, releases ) => {
187+
if ( error ) {
188+
return;
189+
}
190+
191+
if ( releases.length && releases[ 0 ].tag_name !== `v${ app.getVersion() }` ) {
192+
openStaticWindow( 'updateAvailable' );
193+
}
194+
}
195+
);
196+
}
197+
162198
app.on( 'ready', createWindow );
163199

164200
app.on( 'window-all-closed', () => {

app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"vue": "^1.0.24",
1313
"vue-electron": "^1.0.0",
1414
"vue-router": "^0.7.13",
15-
"vuex": "^0.6.3"
15+
"vuex": "^0.6.3",
16+
"github": "~2.3.0"
1617
},
1718
"author": "stefan judis <stefanjudis@gmail.com>",
1819
"license": "MIT"

app/src/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@
143143

144144
<template>
145145
<header-bar
146-
v-if="$route.name !== 'about-page' && $route.name !== 'help-page'">
146+
v-if="! $route.isStatic">
147147
</header-bar>
148148
<main
149149
v-key-tracker
150150
:on-cmd-comma="handleCommandComma">
151-
<settings v-if="showSettings && $route.name !== 'about-page' && $route.name !== 'help-page'"></settings>
151+
<settings v-if="showSettings && ! $route.isStatic"></settings>
152152
<router-view v-on:activate="toggleSettings( false )"></router-view>
153153
</main>
154154
</template>

app/src/components/RepoListView/OpenRepoButton.vue

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
1-
<style scoped>
2-
button {
3-
background-color : var(--npm-red);
4-
display : block;
5-
6-
width : 100%;
7-
8-
border : none;
9-
10-
padding : .5em;
11-
12-
color : var(--main-bg-color);
13-
font-size : inherit;
14-
font-family : inherit;
15-
16-
margin-left : auto;
17-
margin-right : auto;
18-
}
19-
</style>
20-
211
<template>
22-
<button type="button" v-on:click="openFileDialog">Add new Project</button>
2+
<button class="o-primaryBtn" type="button" v-on:click="openFileDialog">Add new Project</button>
233
</template>
244

255
<script>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<style lang="scss">
2+
.c-updateAvailable {
3+
padding : 1em;
4+
5+
text-align : center;
6+
}
7+
</style>
8+
9+
<template>
10+
<div class="c-updateAvailable">
11+
<div class="c-dragHandle"></div>
12+
<div class="c-logo" transition="project">
13+
<svg width="330" height="330" viewBox="0 0 330 330" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
14+
<title>Forrest logo</title>
15+
<defs>
16+
<linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="c">
17+
<stop stop-color="#EEEBEB" offset="0%" />
18+
<stop stop-color="#FCFBFB" offset="18.142%" />
19+
<stop stop-color="#CFCFCF" offset="100%" />
20+
</linearGradient>
21+
<ellipse id="b" cx="161.175" cy="161.175" rx="161.175" ry="161.175" />
22+
<filter x="-50%" y="-50%" width="200%" height="200%" filterUnits="objectBoundingBox" id="a">
23+
<feOffset dy="1" in="SourceAlpha" result="shadowOffsetOuter1" />
24+
<feGaussianBlur stdDeviation="1" in="shadowOffsetOuter1" result="shadowBlurOuter1" />
25+
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0" in="shadowBlurOuter1" />
26+
</filter>
27+
<linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="d">
28+
<stop stop-color="#344352" offset="0%" />
29+
<stop stop-color="#2A333C" offset="100%" />
30+
</linearGradient>
31+
<ellipse id="e" cx="161.175" cy="161.175" rx="150.059" ry="150.059" />
32+
<filter x="-50%" y="-50%" width="200%" height="200%" filterUnits="objectBoundingBox" id="f">
33+
<feGaussianBlur stdDeviation="1.5" in="SourceAlpha" result="shadowBlurInner1" />
34+
<feOffset dy="1" in="shadowBlurInner1" result="shadowOffsetInner1" />
35+
<feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"
36+
/>
37+
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0" in="shadowInnerInner1" />
38+
</filter>
39+
</defs>
40+
<g fill="none" fill-rule="evenodd">
41+
<g transform="translate(4 3)">
42+
<use fill="#000" filter="url(#a)" xlink:href="#b" />
43+
<use fill="url(#c)" xlink:href="#b" />
44+
</g>
45+
<g transform="translate(4 3)">
46+
<use fill="url(#d)" xlink:href="#e" />
47+
<use fill="#000" filter="url(#f)" xlink:href="#e" />
48+
</g>
49+
<g stroke-width="5">
50+
<path d="M102.013 105.372l49.846 103.795H52.167l49.846-103.795zM87.06 209.167h29.908v10.38H87.059v-10.38zM215.235 209.167h29.908v10.38h-29.908v-10.38zm14.954-103.795l49.846 103.795h-99.692l49.846-103.795z"
51+
stroke="#F1F1F1" />
52+
<path d="M194.584 240.954h49.847L166.1 69.693l-78.33 171.261h49.847v14.843h56.966v-14.843z" stroke="#2A333C" fill="#CD3632"
53+
/>
54+
</g>
55+
</g>
56+
</svg>
57+
</div>
58+
59+
<h1 class="o-headline-2">Forrest {{ version }}</h1>
60+
61+
<p class="o-paragraph u-marginTopSmall">There is a new version available.</p>
62+
<p class="o-paragraph u-marginTopSmall">We're working on the auto update but for now you have to grab the new version at the <button class="o-linkBtn" type="button" v-open-external="'https://github.com/stefanjudis/forrest/releases'">releases page</button> yourself. :)</p>
63+
64+
<button class="o-primaryBtn u-marginTop" type="button" v-open-external="'https://github.com/stefanjudis/forrest/releases'">Download</button>
65+
</div>
66+
</template>
67+
68+
<script>
69+
export default {
70+
data() {
71+
return {
72+
version : this.$electron.remote.require( 'electron' ).app.getVersion()
73+
};
74+
}
75+
};
76+
</script>

app/src/routes.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ export default {
99
},
1010
'/about' : {
1111
component : require( './components/AboutView' ),
12-
name : 'about-page'
12+
name : 'about-page',
13+
isStatic : true
1314
},
1415
'/help' : {
1516
component : require( './components/HelpView' ),
16-
name : 'help-page'
17+
name : 'help-page',
18+
isStatic : true
19+
},
20+
'/update-available' : {
21+
component : require( './components/UpdateAvailableView' ),
22+
name : 'update-available-page',
23+
isStatic : true
1724
}
1825
};

app/src/styles/objects/_buttons.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,19 @@
1212

1313
border : none;
1414
display : inline-block;
15+
}
16+
17+
.o-primaryBtn {
18+
display : block;
19+
width : 100%;
20+
21+
padding : .5em;
22+
23+
color : var(--main-bg-color);
24+
background : var(--npm-red);
25+
26+
border : none;
27+
28+
font-size : 1em;
29+
font-family : inherit;
1530
}

config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const config = {
1111
vueDevTools : false,
1212
build : {
1313
'app-version' : pkg.version,
14-
packagesToBeIncluded : [ 'fix-path', 'electron-window-state', 'ps-tree' ],
14+
packagesToBeIncluded : [ 'fix-path', 'electron-window-state', 'ps-tree', 'github' ],
1515
overwrite : true,
1616
asar : true,
1717
dmg : {

0 commit comments

Comments
 (0)