diff --git a/src/main/services/AppUpdater.ts b/src/main/services/AppUpdater.ts index 203a0d5f1c..4c71a05556 100644 --- a/src/main/services/AppUpdater.ts +++ b/src/main/services/AppUpdater.ts @@ -64,6 +64,30 @@ export default class AppUpdater { this.autoUpdater = autoUpdater } + private async _getIpCountry() { + try { + // add timeout using AbortController + const controller = new AbortController() + const timeoutId = setTimeout(() => controller.abort(), 5000) + + const ipinfo = await fetch('https://ipinfo.io/json', { + signal: controller.signal, + headers: { + 'User-Agent': + 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36', + 'Accept-Language': 'en-US,en;q=0.9' + } + }) + + clearTimeout(timeoutId) + const data = await ipinfo.json() + return data.country || 'CN' + } catch (error) { + logger.error('Failed to get ipinfo:', error) + return 'CN' + } + } + public setAutoUpdate(isActive: boolean) { autoUpdater.autoDownload = isActive autoUpdater.autoInstallOnAppQuit = isActive @@ -82,6 +106,12 @@ export default class AppUpdater { } } + const ipCountry = await this._getIpCountry() + logger.info('ipCountry', ipCountry) + if (ipCountry !== 'CN') { + this.autoUpdater.setFeedURL(FeedUrl.EARLY_ACCESS) + } + try { const update = await this.autoUpdater.checkForUpdates() if (update?.isUpdateAvailable && !this.autoUpdater.autoDownload) {