-
Notifications
You must be signed in to change notification settings - Fork 92
feat: add auto start on startup option to user settings #1564
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
base: dev
Are you sure you want to change the base?
Changes from 1 commit
bc6edfa
188de00
eb9cdc4
afd9d08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import { SettingsKey } from '../../../../data/settings-key'; | |
| import { ToastUtils } from '../../../../session/utils'; | ||
| import { PanelRadioButton } from '../../../buttons/panel/PanelRadioButton'; | ||
| import { useHasEnterSendEnabled } from '../../../../state/selectors/settings'; | ||
| import { isLinux } from '../../../../OS'; | ||
|
|
||
| async function toggleStartInTray() { | ||
| try { | ||
|
|
@@ -38,6 +39,19 @@ async function toggleStartInTray() { | |
| } | ||
| } | ||
|
|
||
| async function toggleAutoStart() { | ||
| try { | ||
| const currentSettings = await window.getAutoStartEnabled(); | ||
| const newValue = !currentSettings; | ||
|
|
||
| // make sure to write it here too, as this is the value used on the UI to mark the toggle as true/false | ||
| await window.setSettingValue(SettingsKey.settingsAutoStart, newValue); | ||
| await window.setAutoStartEnabled(newValue); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we make those 2 calls only one, and call one from the other? I feel like we are going to forget at some point. I guess we should keep Not sure if that's possible
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I think we should remove |
||
| } catch (e) { | ||
| window.log.warn('auto start change error:', e); | ||
| } | ||
| } | ||
|
|
||
| function SendWithShiftEnter() { | ||
| const initialSetting = useHasEnterSendEnabled(); | ||
| const selectedWithSettingTrue = 'enterForNewLine'; | ||
|
|
@@ -100,6 +114,11 @@ export function PreferencesSettingsPage(modalState: UserSettingsModalState) { | |
| const closeAction = useUserSettingsCloseAction(modalState); | ||
| const title = useUserSettingsTitle(modalState); | ||
| const isStartInTrayActive = Boolean(window.getSettingValue(SettingsKey.settingsStartInTray)); | ||
|
|
||
| const platformIsLinux = isLinux(); | ||
| const isAutoStartActive = platformIsLinux | ||
| ? false | ||
| : Boolean(window.getSettingValue(SettingsKey.settingsAutoStart)); | ||
| const forceUpdate = useUpdate(); | ||
|
|
||
| return ( | ||
|
|
@@ -144,6 +163,24 @@ export function PreferencesSettingsPage(modalState: UserSettingsModalState) { | |
| active={isStartInTrayActive} | ||
| /> | ||
| </PanelButtonGroup> | ||
| <PanelLabelWithDescription title={{ token: 'settingsStartCategoryDesktop' }} /> | ||
| <PanelButtonGroup> | ||
| <SettingsToggleBasic | ||
| baseDataTestId="auto-start" | ||
| text={{ token: 'launchOnStartDesktop' }} | ||
| subText={{ token: 'launchOnStartDescriptionDesktop' }} | ||
| onClick={async () => { | ||
| await toggleAutoStart(); | ||
| forceUpdate(); | ||
| }} | ||
| active={isAutoStartActive} | ||
| unavailableProps={{ | ||
| unavailable: platformIsLinux, | ||
| modalReasonTitle: { token: 'settingsCannotChangeDesktop' }, | ||
| modalReasonDescription: { token: 'launchOnStartupDisabledDesktop' }, | ||
| }} | ||
| /> | ||
| </PanelButtonGroup> | ||
| <SendWithShiftEnter /> | ||
| </SessionWrapperModal> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1023,6 +1023,60 @@ ipc.on('get-start-in-tray', event => { | |
| } | ||
| }); | ||
|
|
||
| ipc.on('set-auto-start-enabled', (event, newValue) => { | ||
| try { | ||
| userConfig.set('autoStart', newValue); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to set/save this here? the setLoginItemSettings is not enough?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah we can remove |
||
|
|
||
| // Set the login item settings based on the platform | ||
| if (process.platform === 'darwin') { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not use isLinux, isWindows etc?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
| // macOS | ||
| app.setLoginItemSettings({ | ||
| openAtLogin: newValue, | ||
| openAsHidden: false, | ||
| }); | ||
| } else if (process.platform === 'win32') { | ||
| // Windows - For Squirrel-based apps, we need to handle the stub launcher - https://www.electronjs.org/docs/latest/api/app/#appsetloginitemsettingssettings-macos-windows | ||
| const appFolder = path.dirname(process.execPath); | ||
| const ourExeName = path.basename(process.execPath); | ||
| const stubLauncher = path.resolve(appFolder, '..', ourExeName); | ||
|
|
||
| app.setLoginItemSettings({ | ||
| openAtLogin: newValue, | ||
| path: stubLauncher, | ||
| args: [], | ||
| }); | ||
|
Comment on lines
+1057
to
+1065
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you've tested this right?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, works on windows |
||
| } else { | ||
| // Linux and other platforms - basic support | ||
| app.setLoginItemSettings({ | ||
| openAtLogin: newValue, | ||
| }); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't support that right? Maybe throw?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah sorry this was meant to be gone, i included it to test it, can confirm it doesnt do anything on ubuntu |
||
| } | ||
|
|
||
| event.sender.send('set-auto-start-enabled-response', null); | ||
| } catch (e) { | ||
| event.sender.send('set-auto-start-enabled-response', e); | ||
| } | ||
| }); | ||
|
|
||
| ipc.on('get-auto-start-enabled', event => { | ||
| try { | ||
| const configVal = userConfig.get('autoStart'); | ||
|
|
||
| if (configVal !== undefined) { | ||
| event.sender.send('get-auto-start-enabled-response', configVal); | ||
| return; | ||
| } | ||
|
|
||
| const loginSettings = app.getLoginItemSettings(); | ||
| const isEnabled = loginSettings.openAtLogin; | ||
|
|
||
| userConfig.set('autoStart', isEnabled); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment, if |
||
| event.sender.send('get-auto-start-enabled-response', isEnabled); | ||
| } catch (e) { | ||
| event.sender.send('get-auto-start-enabled-response', false); | ||
| } | ||
| }); | ||
|
|
||
| ipcMain.on('update-badge-count', (_event, count) => { | ||
| if (app.isReady()) { | ||
| app.setBadgeCount(isNumber(count) && isFinite(count) && count >= 0 ? count : 0); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid commiting those, we want those to come from crowdin only.
The flow should be