mirror of
https://github.com/lux-tel/session-desktop.git
synced 2026-10-30 20:33:24 +00:00
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import useUpdate from 'react-use/lib/useUpdate';
|
|
import { getAppDispatch } from '../../../../state/dispatch';
|
|
import { tr } from '../../../../localization/localeTools';
|
|
import { Storage } from '../../../../util/storage';
|
|
import { updateConfirmModal } from '../../../../state/ducks/modalDialog';
|
|
import { SessionButtonColor } from '../../../basic/SessionButton';
|
|
import type { ReleaseChannels } from '../../../../updater/types';
|
|
|
|
/**
|
|
* Hook to get and set the release updates channel
|
|
*/
|
|
export const useReleaseChannel = (): {
|
|
releaseChannel: ReleaseChannels;
|
|
setReleaseChannel: (channel: ReleaseChannels) => void;
|
|
} => {
|
|
const releaseChannel = Storage.get('releaseChannel') as ReleaseChannels;
|
|
const dispatch = getAppDispatch();
|
|
const forceUpdate = useUpdate();
|
|
|
|
return {
|
|
releaseChannel,
|
|
setReleaseChannel: (channel: ReleaseChannels) => {
|
|
window.log.debug(
|
|
`[debugMenu] useReleaseChannel Setting release channel to ${channel}. It was ${Storage.get('releaseChannel') || 'not set'}`
|
|
);
|
|
dispatch(
|
|
updateConfirmModal({
|
|
title: tr('warning'),
|
|
i18nMessage: { token: 'settingsRestartDescription' },
|
|
okTheme: SessionButtonColor.Danger,
|
|
okText: tr('restart'),
|
|
onClickOk: async () => {
|
|
try {
|
|
await Storage.put('releaseChannel', channel);
|
|
} catch (error) {
|
|
window.log.warn(
|
|
`[debugMenu] useReleaseChannel Something went wrong when setting the release channel to ${channel}. It was ${Storage.get('releaseChannel') || 'not set'}:`,
|
|
error && error.stack ? error.stack : error
|
|
);
|
|
} finally {
|
|
window.restart();
|
|
}
|
|
},
|
|
onClickCancel: () => {
|
|
dispatch(updateConfirmModal(null));
|
|
forceUpdate();
|
|
},
|
|
})
|
|
);
|
|
},
|
|
};
|
|
};
|