Skip to content

Commit 976c20a

Browse files
committed
Merge branch 'electron' of https://github.com/aviraldg/vector-web into aviraldg-electron
2 parents 20a7aa0 + 919cc8c commit 976c20a

9 files changed

Lines changed: 173 additions & 7 deletions

File tree

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
/node_modules
66
/packages/
77
/vector/bundle.*
8+
/vector/electron-main.*
89
/vector/components.css
910
/vector/emojione/
11+
/vector/electron/
1012
/vector/config.json
1113
/vector/olm.js
1214
.DS_Store

‎package.json‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"name": "vector-web",
3+
"productName": "Riot",
4+
"main": "vector/electron-main.js",
35
"version": "0.8.3",
46
"description": "Vector webapp",
57
"author": "matrix.org",
@@ -16,15 +18,16 @@
1618
"build:modernizr": "modernizr -c .modernizr.json -d src/vector/modernizr.js",
1719
"build:css": "catw \"src/skins/vector/css/**/*.css\" -o vector/components.css --no-watch",
1820
"build:compile": "babel --source-maps -d lib src",
19-
"build:bundle": "NODE_ENV=production webpack -p lib/vector/index.js vector/bundle.js",
21+
"build:bundle": "NODE_ENV=production webpack",
2022
"build:bundle:dev": "webpack --optimize-occurence-order lib/vector/index.js vector/bundle.js",
2123
"build:staticfiles": "cpx -v node_modules/olm/olm.js vector/",
24+
"build:electron": "build -lwm",
2225
"build": "node scripts/babelcheck.js && npm run build:staticfiles && npm run build:emojione && npm run build:css && npm run build:compile && npm run build:bundle",
2326
"build:dev": "npm run build:staticfiles && npm run build:emojione && npm run build:css && npm run build:compile && npm run build:bundle:dev",
2427
"package": "scripts/package.sh",
2528
"start:emojione": "cpx \"node_modules/emojione/assets/svg/*\" vector/emojione/svg/ -w",
26-
"start:js": "webpack -w src/vector/index.js vector/bundle.js",
27-
"start:js:prod": "NODE_ENV=production webpack -w src/vector/index.js vector/bundle.js",
29+
"start:js": "webpack -w",
30+
"start:js:prod": "NODE_ENV=production webpack -w",
2831
"start:skins:css": "catw \"src/skins/vector/css/**/*.css\" -o vector/components.css",
2932
"start:staticfiles": "cpx -Lwv node_modules/olm/olm.js vector/",
3033
"//cache": "Note the -c 1 below due to https://code.google.com/p/chromium/issues/detail?id=508270",
@@ -42,6 +45,7 @@
4245
"classnames": "^2.1.2",
4346
"draft-js": "^0.8.1",
4447
"extract-text-webpack-plugin": "^0.9.1",
48+
"favico.js": "^0.3.10",
4549
"filesize": "^3.1.2",
4650
"flux": "~2.0.3",
4751
"gemini-scrollbar": "matrix-org/gemini-scrollbar#b302279",
@@ -79,6 +83,7 @@
7983
"catw": "^1.0.1",
8084
"cpx": "^1.3.2",
8185
"css-raw-loader": "^0.1.1",
86+
"electron-builder": "^7.10.2",
8287
"emojione": "^2.2.3",
8388
"expect": "^1.16.0",
8489
"fs-extra": "^0.30.0",
@@ -103,5 +108,22 @@
103108
},
104109
"optionalDependencies": {
105110
"olm": "https://matrix.org/packages/npm/olm/olm-1.3.0.tgz"
111+
},
112+
"build": {
113+
"appId": "im.riot.app",
114+
"category": "Network",
115+
"electronVersion": "1.4.2",
116+
"//asar=false": "https://github.com/electron-userland/electron-builder/issues/675",
117+
"asar": false,
118+
"dereference": true,
119+
"//files": "We bundle everything, so we only need to include vector/",
120+
"files": [
121+
"!**/*",
122+
"vector/**",
123+
"package.json"
124+
]
125+
},
126+
"directories": {
127+
"output": "vector/electron"
106128
}
107129
}

‎src/electron-main.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @flow
2+
const {app, BrowserWindow} = require('electron');
3+
4+
let window = null;
5+
6+
app.on('ready', () => {
7+
window = new BrowserWindow({
8+
icon: `${__dirname}/img/logo.png`,
9+
});
10+
window.loadURL(`file://${__dirname}/index.html`);
11+
window.on('closed', () => {
12+
window = null;
13+
})
14+
});
15+
16+
app.on('window-all-closed', () => {
17+
app.quit();
18+
});

‎src/vector/index.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ require('gfm.css/gfm.css');
3636
require('highlight.js/styles/github.css');
3737
require('draft-js/dist/Draft.css');
3838

39-
4039
// add React and ReactPerf to the global namespace, to make them easier to
4140
// access via the console
4241
global.React = require("react");
@@ -57,6 +56,7 @@ import UAParser from 'ua-parser-js';
5756
import url from 'url';
5857

5958
import {parseQs, parseQsFromFragment} from './url_utils';
59+
import IntegrationManager from './integration';
6060

6161
var lastLocationHashSet = null;
6262

@@ -209,6 +209,7 @@ function onLoadCompleted() {
209209
async function loadApp() {
210210
const fragparts = parseQsFromFragment(window.location);
211211
const params = parseQs(window.location);
212+
const integrationManager = new IntegrationManager();
212213

213214
// don't try to redirect to the native apps if we're
214215
// verifying a 3pid
@@ -262,6 +263,7 @@ async function loadApp() {
262263
enableGuest={true}
263264
onLoadCompleted={onLoadCompleted}
264265
defaultDeviceDisplayName={getDefaultDeviceDisplayName()}
266+
integrationManager={integrationManager}
265267
/>,
266268
document.getElementById('matrixchat')
267269
);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @flow
2+
3+
export default class BaseIntegrationManager {
4+
constructor() {
5+
this.notificationCount = 0;
6+
this.errorDidOccur = false;
7+
}
8+
9+
setNotificationCount(count: number) {
10+
this.notificationCount = count;
11+
}
12+
13+
setErrorStatus(errorDidOccur: boolean) {
14+
this.errorDidOccur = errorDidOccur;
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @flow
2+
import BaseIntegrationManager from './BaseIntegrationManager';
3+
4+
// index.js imports us unconditionally, so we need this check here as well
5+
let electron = null, remote = null;
6+
if (window && window.process && window.process && window.process.type === 'renderer') {
7+
electron = require('electron');
8+
remote = electron.remote;
9+
}
10+
11+
export default class ElectronIntegrationManager extends BaseIntegrationManager {
12+
setNotificationCount(count: number) {
13+
super.setNotificationCount(count);
14+
remote.app.setBadgeCount(count);
15+
}
16+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// @flow
2+
import BaseIntegrationManager from './BaseIntegrationManager';
3+
import Favico from 'favico.js';
4+
5+
export default class WebIntegrationManager extends BaseIntegrationManager {
6+
constructor() {
7+
super();
8+
this.favicon = new Favico({animation: 'popFade'});
9+
this.updateFavicon();
10+
}
11+
12+
updateFavicon() {
13+
try {
14+
// This needs to be in in a try block as it will throw
15+
// if there are more than 100 badge count changes in
16+
// its internal queue
17+
let bgColor = "#d00",
18+
notif = this.notificationCount;
19+
20+
if (this.errorDidOccur) {
21+
notif = notif || "×";
22+
bgColor = "#f00";
23+
}
24+
25+
this.favicon.badge(notif, {
26+
bgColor: bgColor
27+
});
28+
} catch (e) {
29+
console.warn(`Failed to set badge count: ${e.message}`);
30+
}
31+
}
32+
33+
setNotificationCount(count: number) {
34+
super.setNotificationCount(count);
35+
this.updateFavicon();
36+
}
37+
38+
setErrorStatus(errorDidOccur: boolean) {
39+
super.setErrorStatus(errorDidOccur);
40+
this.updateFavicon();
41+
}
42+
}

‎src/vector/integration/index.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @flow
2+
3+
import ElectronIntegrationManager from './ElectronIntegrationManager';
4+
import WebIntegrationManager from './WebIntegrationManager';
5+
6+
let IntegrationManager = null;
7+
8+
if (window && window.process && window.process && window.process.type === 'renderer') {
9+
// we're running inside electron
10+
IntegrationManager = ElectronIntegrationManager;
11+
} else {
12+
IntegrationManager = WebIntegrationManager;
13+
}
14+
15+
export default IntegrationManager;

‎webpack.config.js‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ var path = require('path');
22
var webpack = require('webpack');
33
var ExtractTextPlugin = require("extract-text-webpack-plugin");
44

5-
module.exports = {
5+
module.exports = [{
6+
entry: './src/vector/index.js',
67
module: {
78
preLoaders: [
89
{ test: /\.js$/, loader: "source-map-loader" }
@@ -32,7 +33,9 @@ module.exports = {
3233
// various levels of '.' and '..'
3334
// Also, sometimes the resource path is absolute.
3435
return path.relative(process.cwd(), info.resourcePath).replace(/^[\/\.]*/, '');
35-
}
36+
},
37+
path: './vector/',
38+
filename: 'bundle.js'
3639
},
3740
resolve: {
3841
alias: {
@@ -52,6 +55,7 @@ module.exports = {
5255
// loads it into the browser global `Olm`), and reference it as an
5356
// external here.
5457
"olm": "Olm",
58+
"electron": 'commonjs electron'
5559
},
5660
plugins: [
5761
new webpack.DefinePlugin({
@@ -65,4 +69,33 @@ module.exports = {
6569
}),
6670
],
6771
devtool: 'source-map'
68-
};
72+
}, {
73+
entry: './src/electron-main.js',
74+
target: "electron",
75+
output: {
76+
devtoolModuleFilenameTemplate: function(info) {
77+
// Reading input source maps gives only relative paths here for
78+
// everything. Until I figure out how to fix this, this is a
79+
// workaround.
80+
// We use the relative resource path with any '../'s on the front
81+
// removed which gives a tree with matrix-react-sdk and vector
82+
// trees smashed together, but this fixes everything being under
83+
// various levels of '.' and '..'
84+
// Also, sometimes the resource path is absolute.
85+
return path.relative(process.cwd(), info.resourcePath).replace(/^[\/\.]*/, '');
86+
},
87+
filename: 'vector/electron-main.js'
88+
},
89+
node: {
90+
__dirname: false,
91+
__filename: false
92+
},
93+
plugins: [
94+
new webpack.DefinePlugin({
95+
'process.env': {
96+
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
97+
}
98+
}),
99+
],
100+
devtool: 'source-map',
101+
}];

0 commit comments

Comments
 (0)