Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Electron Settings - for Auto Launch #920

Merged
merged 6 commits into from May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/BasePlatform.js
Expand Up @@ -75,7 +75,7 @@ export default class BasePlatform {
* Returns a promise that resolves to a string representing
* the current version of the application.
*/
getAppVersion() {
getAppVersion(): Promise<string> {
throw new Error("getAppVersion not implemented!");
}

Expand All @@ -84,10 +84,12 @@ export default class BasePlatform {
* with getUserMedia, return a string explaining why not.
* Otherwise, return null.
*/
screenCaptureErrorString() {
screenCaptureErrorString(): string {
return "Not implemented";
}

isElectron(): boolean { return false; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels a bit weird to pollute BasePlatform with knowledge of electron - could we not just check the type of PlatformPeg to see if it's a VectorBasePlatform or not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do you mean? I can't do PlatformPeg.get() instanceof ElectronPlatform from the react-sdk side of things. How about a generic getFlags() method on BasePlatform and descendants that would have a prop of isElectron = true on Electron Platform, no idea what else it'd be useful for but it seems like the most generic way of solving this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or since now they have getHumanReadableName could do it based off of that but that feels dirty

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it could also just be a property and then accessed as PlatformPeg.get().isElectron
that way no other classes have to implement it but is also weird, I guess its all weird with the current settings architecture

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i must be missing how instanceof works - why wouldn't it work from the react-sdk side?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would I import ElectronPlatform from riot-web into react-sdk so I can refer to it in an instanceof? Am I missing something obvious :/?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only by violating the layering (which already happens in a bunch of places, sadly). for now, stick with the isElectron() method.


/**
* Restarts the application, without neccessarily reloading
* any application code
Expand Down
41 changes: 41 additions & 0 deletions src/components/structures/UserSettings.js
Expand Up @@ -217,6 +217,13 @@ module.exports = React.createClass({

this._localSettings = UserSettingsStore.getLocalSettings();

if (PlatformPeg.get().isElectron()) {
const {ipcRenderer} = require('electron');

ipcRenderer.on('settings', this._electronSettings);
ipcRenderer.send('settings_get');
}

this.setState({
language: languageHandler.getCurrentLanguage(),
});
Expand All @@ -239,6 +246,15 @@ module.exports = React.createClass({
if (cli) {
cli.removeListener("RoomMember.membership", this._onInviteStateChange);
}

if (PlatformPeg.get().isElectron()) {
const {ipcRenderer} = require('electron');
ipcRenderer.removeListener('settings', this._electronSettings);
}
},

_electronSettings: function(ev, settings) {
this.setState({ electron_settings: settings });
},

_refreshFromServer: function() {
Expand Down Expand Up @@ -843,6 +859,29 @@ module.exports = React.createClass({
</div>;
},

_renderElectronSettings: function() {
const settings = this.state.electron_settings;
if (!settings) return;

const {ipcRenderer} = require('electron');

return <div>
<h3>{ _t('Desktop specific') }</h3>
<div className="mx_UserSettings_section">
<div className="mx_UserSettings_toggle">
<input type="checkbox"
name="auto-launch"
defaultChecked={settings['auto-launch']}
onChange={(e) => {
ipcRenderer.send('settings_set', 'auto-launch', e.target.checked);
}}
/>
<label htmlFor="auto-launch">{_t('Start automatically after system login')}</label>
</div>
</div>
</div>;
},

_showSpoiler: function(event) {
const target = event.target;
target.innerHTML = target.getAttribute('data-spoiler');
Expand Down Expand Up @@ -1045,6 +1084,8 @@ module.exports = React.createClass({
{this._renderBulkOptions()}
{this._renderBugReport()}

{PlatformPeg.get().isElectron() && this._renderElectronSettings()}

{this._renderAnalyticsControl()}

<h3>{ _t("Advanced") }</h3>
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/strings/en_EN.json
Expand Up @@ -674,6 +674,9 @@
"%(oneUser)schanged their avatar %(repeats)s times": "%(oneUser)schanged their avatar %(repeats)s times",
"%(severalUsers)schanged their avatar": "%(severalUsers)schanged their avatar",
"%(oneUser)schanged their avatar": "%(oneUser)schanged their avatar",
"Please select the destination room for this message": "Please select the destination room for this message",
"Start automatically after system login": "Start automatically after system login",
"Desktop specific": "Desktop specific",
"Analytics": "Analytics",
"Opt out of analytics": "Opt out of analytics",
"Riot collects anonymous analytics to allow us to improve the application.": "Riot collects anonymous analytics to allow us to improve the application.",
Expand Down