Skip to content

Commit db602f2

Browse files
authored
Merge branch 'develop' into t3chguy/electron_profiles
2 parents e63baf6 + 543f4ef commit db602f2

58 files changed

Lines changed: 1953 additions & 370 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
/.npmrc
1313
.DS_Store
1414
npm-debug.log
15+
electron/dist
16+
electron/pub
17+
/.idea
1518
/config.json
1619
/src/component-index.js

‎README.md‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,19 @@ If any of these steps error with, `file table overflow`, you are probably on a m
281281
which has a very low limit on max open files. Run `ulimit -Sn 1024` and try again.
282282
You'll need to do this in each new terminal you open before building Riot.
283283
284+
How to add a new translation?
285+
=============================
286+
287+
[<img src="https://translate.nordgedanken.de/widgets/riot-web/-/multi-auto.svg" alt="translationsstatus" width="340">](https://translate.nordgedanken.de/engage/riot-web/?utm_source=widget)
288+
289+
290+
Head to the [translating doc](docs/translating.md)
291+
292+
Adding Strings to the translations (Developer Guide)
293+
====================================================
294+
295+
Head to the [translating dev doc](docs/translating-dev.md)
296+
284297
Triaging issues
285298
===============
286299
@@ -300,7 +313,7 @@ bug or feature:
300313
* feature
301314
302315
bug severity:
303-
316+
304317
* cosmetic - feature works functionally but UI/UX is broken
305318
* critical - whole app doesn't work
306319
* major - entire feature doesn't work

‎docs/translating-dev.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# How to translate riot-web (Dev Guide)
2+
3+
## Requirements
4+
5+
- A working [Development Setup](../../#setting-up-a-dev-environment)
6+
- Be able to understand English
7+
- Be able to understand the language you want to translate riot-web into
8+
9+
## Adding new strings
10+
11+
1. Check if the import ``import _t from 'counterpart-riot'`` is present. If not add it to the other import statements.
12+
2. Add ``_t()`` to your string. (Don't forget curly braces when you assign an expression to JSX attributes in the render method)
13+
3. Add the String to the ``en_EN.json`` file in ``src/i18n`` or if you are working in matrix-react-sdk you can find the json file in ``src/i18n/strings``
14+
15+
## Adding variables inside a string.
16+
17+
1. Extend your ``_t()`` call. Instead of ``_t(STRING)`` use ``_t(STRING, {})``
18+
2. Decide how to name it. Please think about if the person who has to translate it can understand what it does.
19+
3. Add it to the array in ``_t`` for example ``_t(STRING, {variable: this.variable})``
20+
4. Add the variable inside the string. The syntax for variables is ``%(variable)s``. Please note the s at the end. The name of the variable has to match the previous used name.
21+
22+
## Things to know/Style Guides
23+
24+
- Do not use it inside ``getDefaultProps`` at the point where ``getDefaultProps`` is initialized the translations aren't loaded yet and it causes missing translations.
25+
- If using translated strings as constants, translated strings can't be in constants loaded at class-load time since the translations won't be loaded.
26+
- If a string is presented in the UI with punctuation like a full stop, include this in the translation strings, since punctuation varies between languages too.

‎docs/translating.md‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# How to translate riot-web
2+
3+
## Requirements
4+
5+
- Web Browser
6+
- Be able to understand English
7+
- Be able to understand the language you want to translate riot-web into
8+
9+
## Step 0: Join #riotweb-translations:matrix.org
10+
11+
1. Come and join https://riot.im/develop/#/room/#riotweb-translations:matrix.org
12+
2. Read scrollback and/or ask if anyone else is working on your language, and co-ordinate if needed. In general little-or-no coordination is needed though :)
13+
14+
## Step 1: Preparing your Weblate Profile
15+
16+
1. Head to https://translate.nordgedanken.de and register either via Github or email
17+
2. After registering check if you got an email to verify your account and click the link (if there is none head to step 1.4)
18+
3. Log into weblate
19+
4. Head to https://translate.nordgedanken.de/accounts/profile/ and select the languages you know and maybe another language you know too.
20+
6. Head to https://translate.nordgedanken.de/accounts/profile/#subscriptions and select Riot Web as Project
21+
22+
## How to check if your language already is being translated
23+
24+
Go to https://translate.nordgedanken.de/projects/riot-web/ and visit the 2 sub-projects.
25+
If your language is listed go to Step 2a and if not go to Step 2b
26+
27+
## Step 2a: Helping on existing languages.
28+
29+
1. Head to one of the projects listed https://translate.nordgedanken.de/projects/riot-web/
30+
2. Click on the ``translate`` button on the right side of your language
31+
3. Fill in the translations in the writeable field. You will see the original English string and the string of your second language above.
32+
33+
Head to the explanations under Steb 2b
34+
35+
## Step 2b: Adding a new language
36+
37+
1. Go to one of the projects listed https://translate.nordgedanken.de/projects/riot-web/
38+
2. Click the ``Start new language`` button at the bottom
39+
3. Select a language
40+
4. Start translating like in 2a.3
41+
5. Repeat these steps for the other projects which are listed at the link of step 2b.1
42+
43+
### What means the green button under the text field?
44+
45+
The green button let you save our translations directly. Please only use it if you are 100% sure about that translation. If you do not know a translation please DO NOT click that button. Use the arrows above the translations field and click to the right.
46+
47+
### What means the yellow button under the text field?
48+
49+
The yellow button has to be used if you are unsure about the translation but you have a rough idea. It adds a new suggestion to the string which can than be reviewed by others.
50+
51+
### What are "%(something)s"?
52+
53+
These things are variables that are expanded when displayed by Riot. They can be room names, usernames or similar. If you find one, you can move to the right place for your language, but not delete it as the variable will be missing if you do.
54+
55+
A special case is `%(urlStart)s` and `%(urlEnd)s` which are used to mark the beginning of a hyperlink (i.e. `<a href="/somewhere">` and `</a>`. You must keep these markers surrounding the equivalent string in your language that needs to be hyperlinked.
56+
57+
### "I want to come back to this string. How?"
58+
59+
You can use inside the translation field "Review needed" checkbox. It will be shown as Strings that need to be reviewed.
60+
61+
62+
### Further reading
63+
64+
The official Weblate doc provides some more in-deepth explanation on how to do translations and talks about do and don'ts. You can find it at: https://docs.weblate.org/en/latest/user/translating.html

‎electron_app/src/electron-main.js‎

Lines changed: 84 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @flow
2-
31
/*
42
Copyright 2016 Aviral Dasgupta
53
Copyright 2016 OpenMarket Ltd
@@ -20,15 +18,14 @@ limitations under the License.
2018
// Squirrel on windows starts the app with various flags
2119
// as hooks to tell us when we've been installed/uninstalled
2220
// etc.
23-
const check_squirrel_hooks = require('./squirrelhooks');
24-
if (check_squirrel_hooks()) return;
21+
const checkSquirrelHooks = require('./squirrelhooks');
22+
if (checkSquirrelHooks()) return;
2523

2624
const argv = require('minimist')(process.argv);
2725
const electron = require('electron');
2826

2927
const tray = require('./tray');
30-
31-
const VectorMenu = require('./vectormenu');
28+
const vectorMenu = require('./vectormenu');
3229
const webContentsHandler = require('./webcontents-handler');
3330

3431
const windowStateKeeper = require('electron-window-state');
@@ -53,6 +50,47 @@ const INITIAL_UPDATE_DELAY_MS = 30 * 1000;
5350
let mainWindow = null;
5451
let appQuitting = false;
5552

53+
function safeOpenURL(target) {
54+
// openExternal passes the target to open/start/xdg-open,
55+
// so put fairly stringent limits on what can be opened
56+
// (for instance, open /bin/sh does indeed open a terminal
57+
// with a shell, albeit with no arguments)
58+
const parsedUrl = url.parse(target);
59+
if (PERMITTED_URL_SCHEMES.indexOf(parsedUrl.protocol) > -1) {
60+
// explicitly use the URL re-assembled by the url library,
61+
// so we know the url parser has understood all the parts
62+
// of the input string
63+
const newTarget = url.format(parsedUrl);
64+
electron.shell.openExternal(newTarget);
65+
}
66+
}
67+
68+
function onWindowOrNavigate(ev, target) {
69+
// always prevent the default: if something goes wrong,
70+
// we don't want to end up opening it in the electron
71+
// app, as we could end up opening any sort of random
72+
// url in a window that has node scripting access.
73+
ev.preventDefault();
74+
safeOpenURL(target);
75+
}
76+
77+
function onLinkContextMenu(ev, params) {
78+
const popupMenu = new electron.Menu();
79+
80+
popupMenu.append(new electron.MenuItem({
81+
label: params.linkURL,
82+
click() { safeOpenURL(params.linkURL); },
83+
}));
84+
85+
popupMenu.append(new electron.MenuItem({
86+
label: 'Copy Link Address',
87+
click() { electron.clipboard.writeText(params.linkURL); },
88+
}));
89+
90+
popupMenu.popup();
91+
ev.preventDefault();
92+
}
93+
5694
function installUpdate() {
5795
// for some reason, quitAndInstall does not fire the
5896
// before-quit event, so we need to set the flag here.
@@ -64,38 +102,37 @@ function pollForUpdates() {
64102
try {
65103
electron.autoUpdater.checkForUpdates();
66104
} catch (e) {
67-
console.log("Couldn't check for update", e);
105+
console.log('Couldn\'t check for update', e);
68106
}
69107
}
70108

71-
function startAutoUpdate(update_base_url) {
72-
if (update_base_url.slice(-1) !== '/') {
73-
update_base_url = update_base_url + '/';
109+
function startAutoUpdate(updateBaseUrl) {
110+
if (updateBaseUrl.slice(-1) !== '/') {
111+
updateBaseUrl = updateBaseUrl + '/';
74112
}
75113
try {
76114
// For reasons best known to Squirrel, the way it checks for updates
77115
// is completely different between macOS and windows. On macOS, it
78116
// hits a URL that either gives it a 200 with some json or
79117
// 204 No Content. On windows it takes a base path and looks for
80118
// files under that path.
81-
if (process.platform == 'darwin') {
119+
if (process.platform === 'darwin') {
82120
// include the current version in the URL we hit. Electron doesn't add
83121
// it anywhere (apart from the User-Agent) so it's up to us. We could
84122
// (and previously did) just use the User-Agent, but this doesn't
85123
// rely on NSURLConnection setting the User-Agent to what we expect,
86124
// and also acts as a convenient cache-buster to ensure that when the
87125
// app updates it always gets a fresh value to avoid update-looping.
88126
electron.autoUpdater.setFeedURL(
89-
update_base_url +
90-
'macos/?localVersion=' + encodeURIComponent(electron.app.getVersion())
91-
);
92-
} else if (process.platform == 'win32') {
93-
electron.autoUpdater.setFeedURL(update_base_url + 'win32/' + process.arch + '/');
127+
`${updateBaseUrl}macos/?localVersion=${encodeURIComponent(electron.app.getVersion())}`);
128+
129+
} else if (process.platform === 'win32') {
130+
electron.autoUpdater.setFeedURL(`${updateBaseUrl}win32/${process.arch}/`);
94131
} else {
95132
// Squirrel / electron only supports auto-update on these two platforms.
96133
// I'm not even going to try to guess which feed style they'd use if they
97134
// implemented it on Linux, or if it would be different again.
98-
console.log("Auto update not supported on this platform");
135+
console.log('Auto update not supported on this platform');
99136
}
100137
// We check for updates ourselves rather than using 'updater' because we need to
101138
// do it in the main process (and we don't really need to check every 10 minutes:
@@ -108,7 +145,7 @@ function startAutoUpdate(update_base_url) {
108145
setInterval(pollForUpdates, UPDATE_POLL_INTERVAL_MS);
109146
} catch (err) {
110147
// will fail if running in debug mode
111-
console.log("Couldn't enable update checking", err);
148+
console.log('Couldn\'t enable update checking', err);
112149
}
113150
}
114151

@@ -119,7 +156,7 @@ function startAutoUpdate(update_base_url) {
119156
// Assuming we generally run from the console when developing,
120157
// this is far preferable.
121158
process.on('uncaughtException', function(error) {
122-
console.log("Unhandled exception", error);
159+
console.log('Unhandled exception', error);
123160
});
124161

125162
electron.ipcMain.on('install_update', installUpdate);
@@ -143,6 +180,24 @@ electron.ipcMain.on('setBadgeCount', function(ev, count) {
143180
}
144181
});
145182

183+
let powerSaveBlockerId;
184+
electron.ipcMain.on('app_onAction', function(ev, payload) {
185+
switch (payload.action) {
186+
case 'call_state':
187+
if (powerSaveBlockerId && powerSaveBlockerId.isStarted(powerSaveBlockerId)) {
188+
if (payload.state === 'ended') {
189+
electron.powerSaveBlocker.stop(powerSaveBlockerId);
190+
}
191+
} else {
192+
if (payload.state === 'connected') {
193+
powerSaveBlockerId = electron.powerSaveBlocker.start('prevent-display-sleep');
194+
}
195+
}
196+
break;
197+
}
198+
});
199+
200+
146201
electron.app.commandLine.appendSwitch('--enable-usermedia-screen-capturing');
147202

148203
const shouldQuit = electron.app.makeSingleInstance((commandLine, workingDirectory) => {
@@ -155,30 +210,28 @@ const shouldQuit = electron.app.makeSingleInstance((commandLine, workingDirector
155210
});
156211

157212
if (shouldQuit) {
158-
console.log("Other instance detected: exiting");
213+
console.log('Other instance detected: exiting');
159214
electron.app.exit();
160215
}
161216

162217
electron.app.on('ready', () => {
163218
if (vectorConfig.update_base_url) {
164-
console.log("Starting auto update with base URL: " + vectorConfig.update_base_url);
219+
console.log(`Starting auto update with base URL: ${vectorConfig.update_base_url}`);
165220
startAutoUpdate(vectorConfig.update_base_url);
166221
} else {
167-
console.log("No update_base_url is defined: auto update is disabled");
222+
console.log('No update_base_url is defined: auto update is disabled');
168223
}
169224

170-
const icon_path = `${__dirname}/../img/riot.` + (
171-
process.platform == 'win32' ? 'ico' : 'png'
172-
);
225+
const iconPath = `${__dirname}/../img/riot.${process.platform === 'win32' ? 'ico' : 'png'}`;
173226

174227
// Load the previous window state with fallback to defaults
175-
let mainWindowState = windowStateKeeper({
228+
const mainWindowState = windowStateKeeper({
176229
defaultWidth: 1024,
177230
defaultHeight: 768,
178231
});
179232

180233
mainWindow = new electron.BrowserWindow({
181-
icon: icon_path,
234+
icon: iconPath,
182235
show: false,
183236
autoHideMenuBar: true,
184237

@@ -188,12 +241,12 @@ electron.app.on('ready', () => {
188241
height: mainWindowState.height,
189242
});
190243
mainWindow.loadURL(`file://${__dirname}/../../webapp/index.html`);
191-
electron.Menu.setApplicationMenu(VectorMenu);
244+
electron.Menu.setApplicationMenu(vectorMenu);
192245

193246
// Create trayIcon icon
194247
tray.create(mainWindow, {
195-
icon_path: icon_path,
196-
brand: vectorConfig.brand || 'Riot'
248+
icon_path: iconPath,
249+
brand: vectorConfig.brand || 'Riot',
197250
});
198251

199252
if (!argv.hidden) {
@@ -206,7 +259,7 @@ electron.app.on('ready', () => {
206259
mainWindow = null;
207260
});
208261
mainWindow.on('close', (e) => {
209-
if (!appQuitting && (tray.hasTray() || process.platform == 'darwin')) {
262+
if (!appQuitting && (tray.hasTray() || process.platform === 'darwin')) {
210263
// On Mac, closing the window just hides it
211264
// (this is generally how single-window Mac apps
212265
// behave, eg. Mail.app)

0 commit comments

Comments
 (0)