Better support for non-production envs

This commit is contained in:
Alexander Zinchuk 2021-06-20 16:50:42 +03:00
parent f329217307
commit 71e90c7b64
4 changed files with 23 additions and 16 deletions

View File

@ -52,6 +52,7 @@ type DispatchProps = Pick<GlobalActions, (
const ANIMATION_LEVEL_OPTIONS = [0, 1, 2]; const ANIMATION_LEVEL_OPTIONS = [0, 1, 2];
const PRODUCTION_HOSTNAME = 'web.telegram.org';
const LEGACY_VERSION_URL = 'https://web.telegram.org/?legacy=1'; const LEGACY_VERSION_URL = 'https://web.telegram.org/?legacy=1';
const WEBK_VERSION_URL = 'https://web.telegram.org/k/'; const WEBK_VERSION_URL = 'https://web.telegram.org/k/';
const PERMANENT_VERSION_KEY = 'kz_version'; const PERMANENT_VERSION_KEY = 'kz_version';
@ -101,6 +102,8 @@ const LeftMainHeader: FC<OwnProps & StateProps & DispatchProps> = ({
}, 0); }, 0);
}, [hasMenu, chatsById]); }, [hasMenu, chatsById]);
const withOtherVersions = window.location.hostname === PRODUCTION_HOSTNAME;
const MainButton: FC<{ onTrigger: () => void; isOpen?: boolean }> = useMemo(() => { const MainButton: FC<{ onTrigger: () => void; isOpen?: boolean }> = useMemo(() => {
return ({ onTrigger, isOpen }) => ( return ({ onTrigger, isOpen }) => (
<Button <Button
@ -229,19 +232,23 @@ const LeftMainHeader: FC<OwnProps & StateProps & DispatchProps> = ({
> >
Report Bug Report Bug
</MenuItem> </MenuItem>
<MenuItem {withOtherVersions && (
icon="char-K" <>
href={WEBK_VERSION_URL} <MenuItem
onClick={handleSwitchToWebK} icon="char-K"
> href={WEBK_VERSION_URL}
Switch to K Version onClick={handleSwitchToWebK}
</MenuItem> >
<MenuItem Switch to K Version
icon="char-W" </MenuItem>
href={LEGACY_VERSION_URL} <MenuItem
> icon="char-W"
Switch to Old Version href={LEGACY_VERSION_URL}
</MenuItem> >
Switch to Old Version
</MenuItem>
</>
)}
</DropdownMenu> </DropdownMenu>
<SearchInput <SearchInput
inputId="telegram-search-input" inputId="telegram-search-input"

View File

@ -1,7 +1,7 @@
export const PAGE_TITLE = 'Telegram'; export const PAGE_TITLE = 'Telegram';
export const INACTIVE_MARKER = ' [Inactive]'; export const INACTIVE_MARKER = ' [Inactive]';
export const APP_NAME = 'Telegram WebZ'; export const APP_NAME = process.env.APP_NAME || 'Telegram WebZ';
export const APP_VERSION = process.env.APP_VERSION || 'dev'; export const APP_VERSION = process.env.APP_VERSION || 'dev';
export const DEBUG = ( export const DEBUG = (

View File

@ -141,7 +141,7 @@ async function focusChatMessage(client: WindowClient, data: { chatId?: number; m
} }
export function handleNotificationClick(e: NotificationEvent) { export function handleNotificationClick(e: NotificationEvent) {
const appUrl = process.env.APP_URL!; const appUrl = self.location.href.replace('serviceWorker.js', '');
e.notification.close(); // Android needs explicit close. e.notification.close(); // Android needs explicit close.
const { data } = e.notification; const { data } = e.notification;
const notifyClients = async () => { const notifyClients = async () => {

View File

@ -103,9 +103,9 @@ module.exports = (env = {}, argv = {}) => {
ignoreOrder: true, ignoreOrder: true,
}), }),
new EnvironmentPlugin({ new EnvironmentPlugin({
APP_NAME: 'Telegram WebZ',
APP_VERSION: 'dev', APP_VERSION: 'dev',
APP_ENV: 'production', APP_ENV: 'production',
APP_URL: 'https://web.telegram.org/z/',
TELEGRAM_T_API_ID: '', TELEGRAM_T_API_ID: '',
TELEGRAM_T_API_HASH: '', TELEGRAM_T_API_HASH: '',
}), }),