diff --git a/.eslintignore b/.eslintignore index 0538e65d3..c4eb0fbcd 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,6 @@ src/lib/rlottie/rlottie-wasm.js src/lib/video-preview/libav* -src/lib/video-preview/polyfill/* +src/lib/video-preview/polyfill src/lib/webp/webp_wasm.js src/lib/fasttextweb/fasttext-wasm.js @@ -17,6 +17,7 @@ jest.config.js src/lib/secret-sauce/ playwright.config.ts -dist/* +dist +public deploy/update_version.js diff --git a/public/get/apple-logo.svg b/public/get/apple-logo.svg new file mode 100644 index 000000000..3f06156a4 --- /dev/null +++ b/public/get/apple-logo.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/public/get/icon-electron-macos.png b/public/get/icon-electron-macos.png new file mode 100644 index 000000000..92dfcdca2 Binary files /dev/null and b/public/get/icon-electron-macos.png differ diff --git a/public/get/index.css b/public/get/index.css new file mode 100644 index 000000000..7917ccf43 --- /dev/null +++ b/public/get/index.css @@ -0,0 +1,137 @@ +body { + display: flex; + align-items: center; + justify-content: center; + + height: 100vh; + margin: 0; + + font-family: 'Arial', sans-serif; + color: #222222; + + background-color: white; + + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +.container { + min-width: 200px; + max-width: 330px; + padding: 40px 40px 16px 40px; + + text-align: center; + + background-color: rgba(255, 255, 255, 0.95); + border-radius: 10px; +} + +.logo-container { + display: flex; + gap: 5px; + align-items: center; + justify-content: center; + + margin-bottom: 20px; +} + +.logo { + width: 90px; + height: 90px; + + background-repeat: no-repeat; + background-position: center; + background-size: cover; +} + +.telegram-logo { + background-image: url('./icon-electron-macos.png'); +} + +.apple-logo { + background-image: url('./apple-logo.svg'); + background-size: auto 80%; +} + +.container h1 { + margin-bottom: 10px; + + font-size: 24px; +} + +.select-model { + margin-top: 36px; + margin-bottom: 16px; + + color: #444444; +} + +.info { + margin-top: 28px; + margin-bottom: 36px; + + line-height: 1.25rem; + color: #444444; +} + +.download-container { + display: flex; + gap: 20px; + align-items: center; + justify-content: center; +} + +.download-block { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + + margin-bottom: 36px; +} + +.caption { + font-size: 14px; + color: #777; +} + +.download-btn { + display: inline-block; + + margin: 10px; + padding: 8px 20px; + + font-size: 16px; + color: #FFF; + text-decoration: none; + + background-color: #007BFF; + border-radius: 5px; + + transition: background-color 150ms; +} + +.download-btn:hover { + background-color: rgba(0, 123, 255, 0.9); +} + +.download-btn.single { + display: block; + + margin: 32px 0; +} + +.footer { + font-size: small; + color: #A9A9A9; +} + +.footer a { + display: inline-block; + + color: #A9A9A9; +} + +a:hover { + text-decoration: none; +} diff --git a/public/get/index.html b/public/get/index.html new file mode 100644 index 000000000..1e9601297 --- /dev/null +++ b/public/get/index.html @@ -0,0 +1,23 @@ + + + + + + Telegram A Desktop + + + + +
+
+ +
+

Telegram A

+ Download + +
+ + diff --git a/public/get/index.js b/public/get/index.js new file mode 100644 index 000000000..0a99da8cc --- /dev/null +++ b/public/get/index.js @@ -0,0 +1,131 @@ +const REPO = 'Ajaxy/telegram-tt'; +const LATEST_RELEASE_API_URL = `https://api.github.com/repos/${REPO}/releases/latest`; +const LATEST_RELEASE_WEB_URL = `https://github.com/${REPO}/releases/latest`; +const WEB_APP_URL = location.pathname.startsWith('/a/') ? '/a/' : '/'; + +const platform = getPlatform(); +const currentPage = location.href.includes('mac.html') + ? 'mac' + : location.href.includes('unsupported.html') + ? 'unsupported' + : 'index'; + +// Request the latest release information from GitHub +const packagesPromise = fetch(LATEST_RELEASE_API_URL) + .then(response => response.json()) + .then(data => { + return data.assets.reduce((acc, { + name, + browser_download_url, + }) => { + if (name.endsWith('.exe')) { + acc['win'] = browser_download_url; + } else if (name.endsWith('.AppImage')) { + acc['linux'] = browser_download_url; + } else if (name.endsWith('.dmg')) { + acc[`mac-${name.includes('arm') ? 'arm' : 'x64'}`] = browser_download_url; + } + + return acc; + }, { + $version: data.name, + }); + }) + .catch((error) => { + console.error('Error:', error); + }); + +(function init() { + if (platform === 'Windows' || platform === 'Linux') { + if (currentPage === 'index') { + setupDownloadButton(); + setupVersion(); + } + } else if (platform === 'macOS') { + if (currentPage !== 'mac') { + redirectToMac(); + } else { + setupVersion(); + } + } else if (currentPage !== 'unsupported') { + redirectToUnsupported(); + } +}()); + +function getPlatform() { + const { + userAgent, + platform, + } = window.navigator; + + const iosPlatforms = ['iPhone', 'iPad', 'iPod']; + if ( + iosPlatforms.indexOf(platform) !== -1 + // For new IPads with M1 chip and IPadOS platform returns "MacIntel" + || (platform === 'MacIntel' && ('maxTouchPoints' in navigator && navigator.maxTouchPoints > 2)) + ) { + return 'iOS'; + } + + const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']; + if (macosPlatforms.indexOf(platform) !== -1) return 'macOS'; + + const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']; + if (windowsPlatforms.indexOf(platform) !== -1) return 'Windows'; + + if (/Android/.test(userAgent)) return 'Android'; + + if (/Linux/.test(platform)) return 'Linux'; + + return undefined; +} + +function setupDownloadButton() { + document.addEventListener('DOMContentLoaded', () => { + const downloadBtn = document.querySelector('.download-btn'); + downloadBtn.innerHTML += ` for ${platform}`; + }); +} + +function setupVersion() { + document.addEventListener('DOMContentLoaded', () => { + packagesPromise.then((packages) => { + const versionEl = document.querySelector('.version'); + versionEl.innerHTML = `v. ${packages.$version} ยท `; + }); + }); +} + +function redirectToMac() { + location.href = './mac.html'; +} + +function redirectToUnsupported() { + location.href = './unsupported.html'; +} + +function redirectToWeb() { + location.href = WEB_APP_URL; +} + +function redirectToFullList() { + location.href = LATEST_RELEASE_WEB_URL; +} + +function downloadDefault() { + if (platform === 'Windows') { + download('win'); + } else if (platform === 'Linux') { + download('linux'); + } else if (platform === 'macOS') { + redirectToMac(); + } else { + redirectToUnsupported(); + } +} + +function download(platform) { + packagesPromise.then((packages) => { + location.href = packages[platform]; + }); +} diff --git a/public/get/mac.html b/public/get/mac.html new file mode 100644 index 000000000..000869a37 --- /dev/null +++ b/public/get/mac.html @@ -0,0 +1,34 @@ + + + + + + Telegram A for Mac + + + + +
+
+ + +
+

Telegram A for your Mac

+
Select your device model
+
+
+ Newer Mac +
M1 and later
+
+
+ Older Mac +
2019 and earlier
+
+
+ +
+ + diff --git a/public/get/unsupported.html b/public/get/unsupported.html new file mode 100644 index 000000000..4f4e9f350 --- /dev/null +++ b/public/get/unsupported.html @@ -0,0 +1,24 @@ + + + + + + Telegram A Desktop + + + + +
+
+ +
+

Telegram A for Desktop

+
Open this page from Mac, PC or Linux
to install Telegram A.
+ Open Web Version + +
+ + diff --git a/src/util/windowEnvironment.ts b/src/util/windowEnvironment.ts index b725a94b9..ff067f4ce 100644 --- a/src/util/windowEnvironment.ts +++ b/src/util/windowEnvironment.ts @@ -11,26 +11,25 @@ export * from './environmentWebp'; export function getPlatform() { const { userAgent, platform } = window.navigator; - const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']; - const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']; + const iosPlatforms = ['iPhone', 'iPad', 'iPod']; - let os: 'macOS' | 'iOS' | 'Windows' | 'Android' | 'Linux' | undefined; - - if (iosPlatforms.indexOf(platform) !== -1 + if ( + iosPlatforms.indexOf(platform) !== -1 // For new IPads with M1 chip and IPadOS platform returns "MacIntel" - || (platform === 'MacIntel' && ('maxTouchPoints' in navigator && navigator.maxTouchPoints > 2))) { - os = 'iOS'; - } else if (macosPlatforms.indexOf(platform) !== -1) { - os = 'macOS'; - } else if (windowsPlatforms.indexOf(platform) !== -1) { - os = 'Windows'; - } else if (/Android/.test(userAgent)) { - os = 'Android'; - } else if (/Linux/.test(platform)) { - os = 'Linux'; - } + || (platform === 'MacIntel' && ('maxTouchPoints' in navigator && navigator.maxTouchPoints > 2)) + ) return 'iOS'; - return os; + const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K']; + if (macosPlatforms.indexOf(platform) !== -1) return 'macOS'; + + const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']; + if (windowsPlatforms.indexOf(platform) !== -1) return 'Windows'; + + if (/Android/.test(userAgent)) return 'Android'; + + if (/Linux/.test(platform)) return 'Linux'; + + return undefined; } export const IS_PRODUCTION_HOST = window.location.host === PRODUCTION_HOSTNAME;