Skip to content

Commit ff5adef

Browse files
authored
Merge branch 'develop' into t3chguy/tidy_electron_files
2 parents 8994c2b + 445a55c commit ff5adef

44 files changed

Lines changed: 1465 additions & 193 deletions

Some content is hidden

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

‎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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 1: Preparing your Weblate Profile
10+
11+
1. Head to https://translate.nordgedanken.de and register either via Github or email
12+
2. After register check if you got a email to verify your account and click the link (if there is none head to step 1.4)
13+
3. Log into weblate
14+
4. Head to https://translate.nordgedanken.de/accounts/profile/ and select the languages you know and maybe another language you know too.
15+
6. Head to https://translate.nordgedanken.de/accounts/profile/#subscriptions and select Riot Web as Project
16+
17+
## How to check if your language already is being translated
18+
19+
Go to https://translate.nordgedanken.de/projects/riot-web/ and in all 3 sub projects if your language is listed.
20+
If it is listed go to Step 2a if not go to Step 2b
21+
22+
## Step 2a: Helping on existing languages.
23+
24+
1. Head to one of the projects listed https://translate.nordgedanken.de/projects/riot-web/
25+
2. Click on the ``translate`` button on the right side of your language
26+
3. Fill in the translations in the writeable field. You will see the original English string and the String of your second language above.
27+
28+
Head to the explanations under Steb 2b
29+
30+
## Step 2b: Adding a new language
31+
32+
1. Go to one of the projects listed https://translate.nordgedanken.de/projects/riot-web/
33+
2. Click the ``Start new language`` button at the bottom
34+
3. Select our language
35+
4. Start translating like in 2a.3
36+
5. Repeat these steps for the other projects which are listed at the link of step 2b.1
37+
6. Add your language to the array at the [config example](../../blob/develop/config.sample.json#L14)
38+
39+
### What means the green button under the text field?
40+
41+
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.
42+
43+
### What means the yellow button under the text field?
44+
45+
The yellow button has to be used if you are unsure about the translation but you have a rough idea. It ads a new suggestion to the string which can than be reviewed by others.
46+
47+
### What are "%(something)s"?
48+
49+
These things are variables that are filled inside the code. They can be room names, usernames or similiar. If you find one use it for changing the word order but do not delete it as thing are missing if you do so.
50+
51+
### "I want to come back to this string. How?"
52+
53+
You can use inside the translation field "Review needed" checkbox. It will be shown as Strings that need to be reviewed.
54+
55+
### Further reading
56+
57+
The official Doc provides some more in-deepth explanation on how to do translations and talks about do and don't's. You can find it at: https://docs.weblate.org/en/latest/user/translating.html

‎electron_app/src/electron-main.js‎

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ const checkSquirrelHooks = require('./squirrelhooks');
2222
if (checkSquirrelHooks()) return;
2323

2424
const electron = require('electron');
25-
const url = require('url');
2625

2726
const tray = require('./tray');
2827
const vectorMenu = require('./vectormenu');
28+
const webContentsHandler = require('./webcontents-handler');
2929

3030
const windowStateKeeper = require('electron-window-state');
3131

@@ -39,12 +39,6 @@ try {
3939
// Continue with the defaults (ie. an empty config)
4040
}
4141

42-
const PERMITTED_URL_SCHEMES = [
43-
'http:',
44-
'https:',
45-
'mailto:',
46-
];
47-
4842
const UPDATE_POLL_INTERVAL_MS = 60 * 60 * 1000;
4943
const INITIAL_UPDATE_DELAY_MS = 30 * 1000;
5044

@@ -181,6 +175,24 @@ electron.ipcMain.on('setBadgeCount', function(ev, count) {
181175
}
182176
});
183177

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

186198
const shouldQuit = electron.app.makeSingleInstance((commandLine, workingDirectory) => {
@@ -252,15 +264,7 @@ electron.app.on('ready', () => {
252264
}
253265
});
254266

255-
mainWindow.webContents.on('new-window', onWindowOrNavigate);
256-
mainWindow.webContents.on('will-navigate', onWindowOrNavigate);
257-
258-
mainWindow.webContents.on('context-menu', function(ev, params) {
259-
if (params.linkURL) {
260-
onLinkContextMenu(ev, params);
261-
}
262-
});
263-
267+
webContentsHandler(mainWindow.webContents);
264268
mainWindowState.manage(mainWindow);
265269
});
266270

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
const {clipboard, nativeImage, Menu, MenuItem, shell} = require('electron');
2+
const url = require('url');
3+
4+
const PERMITTED_URL_SCHEMES = [
5+
'http:',
6+
'https:',
7+
'mailto:',
8+
];
9+
10+
function safeOpenURL(target) {
11+
// openExternal passes the target to open/start/xdg-open,
12+
// so put fairly stringent limits on what can be opened
13+
// (for instance, open /bin/sh does indeed open a terminal
14+
// with a shell, albeit with no arguments)
15+
const parsedUrl = url.parse(target);
16+
if (PERMITTED_URL_SCHEMES.indexOf(parsedUrl.protocol) > -1) {
17+
// explicitly use the URL re-assembled by the url library,
18+
// so we know the url parser has understood all the parts
19+
// of the input string
20+
const newTarget = url.format(parsedUrl);
21+
shell.openExternal(newTarget);
22+
}
23+
}
24+
25+
function onWindowOrNavigate(ev, target) {
26+
// always prevent the default: if something goes wrong,
27+
// we don't want to end up opening it in the electron
28+
// app, as we could end up opening any sort of random
29+
// url in a window that has node scripting access.
30+
ev.preventDefault();
31+
safeOpenURL(target);
32+
}
33+
34+
function onLinkContextMenu(ev, params) {
35+
const url = params.linkURL || params.srcURL;
36+
37+
const popupMenu = new Menu();
38+
popupMenu.append(new MenuItem({
39+
label: url,
40+
click() {
41+
safeOpenURL(url);
42+
},
43+
}));
44+
45+
if (params.mediaType && params.mediaType === 'image' && !url.startsWith('file://')) {
46+
popupMenu.append(new MenuItem({
47+
label: 'Copy Image',
48+
click() {
49+
if (url.startsWith('data:')) {
50+
clipboard.writeImage(nativeImage.createFromDataURL(url));
51+
} else {
52+
ev.sender.copyImageAt(params.x, params.y);
53+
}
54+
},
55+
}));
56+
}
57+
58+
popupMenu.append(new MenuItem({
59+
label: 'Copy Link Address',
60+
click() {
61+
clipboard.writeText(url);
62+
},
63+
}));
64+
popupMenu.popup();
65+
ev.preventDefault();
66+
}
67+
68+
function _CutCopyPasteSelectContextMenus(params) {
69+
return [{
70+
role: 'cut',
71+
enabled: params.editFlags.canCut,
72+
}, {
73+
role: 'copy',
74+
enabled: params.editFlags.canCopy,
75+
}, {
76+
role: 'paste',
77+
enabled: params.editFlags.canPaste,
78+
}, {
79+
role: 'pasteandmatchstyle',
80+
enabled: params.editFlags.canPaste,
81+
}, {
82+
role: 'selectall',
83+
enabled: params.editFlags.canSelectAll,
84+
}];
85+
}
86+
87+
function onSelectedContextMenu(ev, params) {
88+
const items = _CutCopyPasteSelectContextMenus(params);
89+
const popupMenu = Menu.buildFromTemplate(items);
90+
91+
popupMenu.popup();
92+
ev.preventDefault();
93+
}
94+
95+
function onEditableContextMenu(ev, params) {
96+
const items = [
97+
{ role: 'undo' },
98+
{ role: 'redo', enabled: params.editFlags.canRedo },
99+
{ type: 'separator' },
100+
].concat(_CutCopyPasteSelectContextMenus(params));
101+
102+
const popupMenu = Menu.buildFromTemplate(items);
103+
104+
popupMenu.popup();
105+
ev.preventDefault();
106+
}
107+
108+
109+
module.exports = (webContents) => {
110+
webContents.on('new-window', onWindowOrNavigate);
111+
webContents.on('will-navigate', onWindowOrNavigate);
112+
113+
webContents.on('context-menu', function(ev, params) {
114+
if (params.linkURL || params.srcURL) {
115+
onLinkContextMenu(ev, params);
116+
} else if (params.selectionText) {
117+
onSelectedContextMenu(ev, params);
118+
} else if (params.isEditable) {
119+
onEditableContextMenu(ev, params);
120+
}
121+
});
122+
};

‎karma.conf.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ webpack_config.module.noParse.push(/sinon\/pkg\/sinon\.js$/);
4747
webpack_config.resolve.alias['sinon'] = 'sinon/pkg/sinon.js';
4848

4949
webpack_config.resolve.root = [
50-
path.resolve('./src'),
5150
path.resolve('./test'),
5251
];
5352

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
],
159159
"linux": {
160160
"target": "deb",
161+
"category": "Network;InstantMessaging;Chat",
161162
"maintainer": "support@riot.im",
162163
"desktop": {
163164
"StartupWMClass": "riot-web"

0 commit comments

Comments
 (0)