Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/BasePlatform.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,29 @@ export default class BasePlatform {
reload() {
throw new Error("reload not implemented!");
}

supportsAutoLaunch(): boolean {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we don't have type annotations anywhere else. We probably should have them, but for now I'd say don't include them as it introduces confusion.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nvm, it is worse than that: we do use it in the scope of electron. I'm not going to block this PR on that :/

return false;
}

// XXX: Surely this should be a setting like any other?
async getAutoLaunchEnabled(): boolean {
return false;
}

async setAutoLaunchEnabled(enabled: boolean): void {
throw new Error("Unimplemented");
}

supportsMinimizeToTray(): boolean {
return false;
}

async getMinimizeToTrayEnabled(): boolean {
return false;
}

async setMinimizeToTrayEnabled(enabled: boolean): void {
throw new Error("Unimplemented");
}
}
28 changes: 25 additions & 3 deletions src/components/views/settings/tabs/PreferencesSettingsTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,39 @@ export default class PreferencesSettingsTab extends React.Component {
this.state = {
autoLaunch: false,
autoLaunchSupported: false,
minimizeToTray: true,
minimizeToTraySupported: false,
};
}

async componentWillMount(): void {
const autoLaunchSupported = await PlatformPeg.get().supportsAutoLaunch();
const platform = PlatformPeg.get();

const autoLaunchSupported = await platform.supportsAutoLaunch();
let autoLaunch = false;

if (autoLaunchSupported) {
autoLaunch = await PlatformPeg.get().getAutoLaunchEnabled();
autoLaunch = await platform.getAutoLaunchEnabled();
}

const minimizeToTraySupported = await platform.supportsMinimizeToTray();
let minimizeToTray = true;

if (minimizeToTraySupported) {
minimizeToTray = await platform.getMinimizeToTrayEnabled();
}

this.setState({autoLaunch, autoLaunchSupported});
this.setState({autoLaunch, autoLaunchSupported, minimizeToTraySupported, minimizeToTray});
}

_onAutoLaunchChange = (checked) => {
PlatformPeg.get().setAutoLaunchEnabled(checked).then(() => this.setState({autoLaunch: checked}));
};

_onMinimizeToTrayChange = (checked) => {
PlatformPeg.get().setMinimizeToTrayEnabled(checked).then(() => this.setState({minimizeToTray: checked}));
};

_onAutocompleteDelayChange = (e) => {
SettingsStore.setValue("autocompleteDelay", null, SettingLevel.DEVICE, e.target.value);
};
Expand All @@ -93,6 +108,12 @@ export default class PreferencesSettingsTab extends React.Component {
onChange={this._onAutoLaunchChange}
label={_t('Start automatically after system login')} />;
}
let minimizeToTrayOption = null;
if (this.state.minimizeToTraySupported) {
minimizeToTrayOption = <LabelledToggleSwitch value={this.state.minimizeToTray}
onChange={this._onMinimizeToTrayChange}
label={_t('Close button should minimize window to tray')} />;
}

return (
<div className="mx_SettingsTab mx_PreferencesSettingsTab">
Expand All @@ -106,6 +127,7 @@ export default class PreferencesSettingsTab extends React.Component {

<span className="mx_SettingsTab_subheading">{_t("Advanced")}</span>
{this._renderGroup(PreferencesSettingsTab.ADVANCED_SETTINGS)}
{minimizeToTrayOption}
{autoLaunchOption}
<Field id={"autocompleteDelay"} label={_t('Autocomplete delay (ms)')} type='number'
value={SettingsStore.getValueAt(SettingLevel.DEVICE, 'autocompleteDelay')}
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@
"Labs": "Labs",
"Notifications": "Notifications",
"Start automatically after system login": "Start automatically after system login",
"Close button should minimize window to tray": "Close button should minimize window to tray",
"Preferences": "Preferences",
"Composer": "Composer",
"Timeline": "Timeline",
Expand Down