mirror of
https://github.com/yeongpin/cursor-free-vip.git
synced 2025-08-03 04:57:36 +08:00
[Windows] Fix for Custom Chrome Installations
This commit fixes that error when you had an custom chrome installation. For example: D:\Chromium or something. Now it uses windows PATH to start chrome and if there's no PATH installation script would check default location. Here's demo for current bug: https://youtu.be/O8lPblnBIGQ
This commit is contained in:
parent
ea44218a8a
commit
3c12561997
@ -33,6 +33,8 @@ a = Analysis(
|
|||||||
('new_tempemail.py', '.'),
|
('new_tempemail.py', '.'),
|
||||||
('quit_cursor.py', '.'),
|
('quit_cursor.py', '.'),
|
||||||
('cursor_register_manual.py', '.'),
|
('cursor_register_manual.py', '.'),
|
||||||
|
('oauth_auth.py', '.'),
|
||||||
|
('utils.py', '.'),
|
||||||
('.env', '.'),
|
('.env', '.'),
|
||||||
('block_domain.txt', '.')
|
('block_domain.txt', '.')
|
||||||
],
|
],
|
||||||
@ -42,7 +44,9 @@ a = Analysis(
|
|||||||
'new_signup',
|
'new_signup',
|
||||||
'new_tempemail',
|
'new_tempemail',
|
||||||
'quit_cursor',
|
'quit_cursor',
|
||||||
'cursor_register_manual'
|
'cursor_register_manual',
|
||||||
|
'oauth_auth',
|
||||||
|
'utils'
|
||||||
],
|
],
|
||||||
hookspath=[],
|
hookspath=[],
|
||||||
hooksconfig={},
|
hooksconfig={},
|
||||||
|
@ -10,6 +10,8 @@ from cursor_auth import CursorAuth
|
|||||||
from utils import get_random_wait_time, get_default_chrome_path
|
from utils import get_random_wait_time, get_default_chrome_path
|
||||||
from config import get_config
|
from config import get_config
|
||||||
import platform
|
import platform
|
||||||
|
import subprocess
|
||||||
|
import shutil
|
||||||
|
|
||||||
# Initialize colorama
|
# Initialize colorama
|
||||||
init()
|
init()
|
||||||
@ -149,11 +151,20 @@ class OAuthHandler:
|
|||||||
# co.auto_port()
|
# co.auto_port()
|
||||||
|
|
||||||
print(f"{Fore.CYAN}{EMOJI['INFO']} {self.translator.get('oauth.starting_browser', path=chrome_path) if self.translator else f'Starting browser at: {chrome_path}'}{Style.RESET_ALL}")
|
print(f"{Fore.CYAN}{EMOJI['INFO']} {self.translator.get('oauth.starting_browser', path=chrome_path) if self.translator else f'Starting browser at: {chrome_path}'}{Style.RESET_ALL}")
|
||||||
|
try:
|
||||||
self.browser = ChromiumPage(co)
|
self.browser = ChromiumPage(co)
|
||||||
|
|
||||||
# Verify browser launched successfully
|
# Verify browser launched successfully
|
||||||
if not self.browser:
|
if not self.browser:
|
||||||
raise Exception("Failed to initialize browser instance")
|
raise Exception("Failed to initialize browser instance")
|
||||||
|
except Exception as browser_error:
|
||||||
|
print(f"{Fore.RED}{EMOJI['ERROR']} Подробная ошибка запуска браузера: {str(browser_error)}{Style.RESET_ALL}")
|
||||||
|
# Выведем, какие пути проверялись
|
||||||
|
print(f"{Fore.YELLOW}{EMOJI['INFO']} Пути поиска Chrome:{Style.RESET_ALL}")
|
||||||
|
for path in [chrome_path] + self._get_all_possible_browser_paths():
|
||||||
|
exists = os.path.exists(path) if path else False
|
||||||
|
status = f"{Fore.GREEN}Существует{Style.RESET_ALL}" if exists else f"{Fore.RED}Не найден{Style.RESET_ALL}"
|
||||||
|
print(f" - {path}: {status}")
|
||||||
|
raise browser_error
|
||||||
|
|
||||||
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('oauth.browser_setup_completed') if self.translator else 'Browser setup completed successfully'}{Style.RESET_ALL}")
|
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} {self.translator.get('oauth.browser_setup_completed') if self.translator else 'Browser setup completed successfully'}{Style.RESET_ALL}")
|
||||||
return True
|
return True
|
||||||
@ -166,6 +177,15 @@ class OAuthHandler:
|
|||||||
print(f"{Fore.YELLOW}{EMOJI['INFO']} {self.translator.get('oauth.make_sure_chrome_chromium_is_properly_installed') if self.translator else 'Make sure Chrome/Chromium is properly installed'}{Style.RESET_ALL}")
|
print(f"{Fore.YELLOW}{EMOJI['INFO']} {self.translator.get('oauth.make_sure_chrome_chromium_is_properly_installed') if self.translator else 'Make sure Chrome/Chromium is properly installed'}{Style.RESET_ALL}")
|
||||||
if platform_name == 'linux':
|
if platform_name == 'linux':
|
||||||
print(f"{Fore.YELLOW}{EMOJI['INFO']} {self.translator.get('oauth.try_install_chromium') if self.translator else 'Try: sudo apt install chromium-browser'}{Style.RESET_ALL}")
|
print(f"{Fore.YELLOW}{EMOJI['INFO']} {self.translator.get('oauth.try_install_chromium') if self.translator else 'Try: sudo apt install chromium-browser'}{Style.RESET_ALL}")
|
||||||
|
# Добавим проверку PATH
|
||||||
|
if os.name == 'nt': # Windows
|
||||||
|
print(f"{Fore.YELLOW}{EMOJI['INFO']} Проверьте, что Chrome/Chromium добавлен в PATH и доступен по команде 'chrome'{Style.RESET_ALL}")
|
||||||
|
# Попробуем запустить chrome напрямую, чтобы увидеть ошибку
|
||||||
|
try:
|
||||||
|
subprocess.run('where chrome', shell=True, check=True)
|
||||||
|
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} Chrome найден в PATH{Style.RESET_ALL}")
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
print(f"{Fore.RED}{EMOJI['ERROR']} Chrome не найден в PATH{Style.RESET_ALL}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _kill_browser_processes(self):
|
def _kill_browser_processes(self):
|
||||||
@ -229,6 +249,24 @@ class OAuthHandler:
|
|||||||
if chrome_path and os.path.exists(chrome_path):
|
if chrome_path and os.path.exists(chrome_path):
|
||||||
return chrome_path
|
return chrome_path
|
||||||
|
|
||||||
|
# Trying to find through which/where
|
||||||
|
try:
|
||||||
|
if os.name == 'nt': # Windows
|
||||||
|
result = subprocess.run('where chrome', shell=True, capture_output=True, text=True)
|
||||||
|
if result.returncode == 0 and result.stdout.strip():
|
||||||
|
path = result.stdout.strip().split('\n')[0].strip()
|
||||||
|
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} Chrome found in PATH: {path}{Style.RESET_ALL}")
|
||||||
|
return path
|
||||||
|
else: # Linux/Mac
|
||||||
|
result = subprocess.run('which google-chrome || which chrome || which chromium-browser || which chromium',
|
||||||
|
shell=True, capture_output=True, text=True)
|
||||||
|
if result.returncode == 0 and result.stdout.strip():
|
||||||
|
path = result.stdout.strip()
|
||||||
|
print(f"{Fore.GREEN}{EMOJI['SUCCESS']} Browser found in PATH: {path}{Style.RESET_ALL}")
|
||||||
|
return path
|
||||||
|
except Exception as which_error:
|
||||||
|
print(f"{Fore.YELLOW}{EMOJI['INFO']} Ошибка при поиске через PATH: {str(which_error)}{Style.RESET_ALL}")
|
||||||
|
|
||||||
print(f"{Fore.YELLOW}{EMOJI['INFO']} {self.translator.get('oauth.searching_for_alternative_browser_installations') if self.translator else 'Searching for alternative browser installations...'}{Style.RESET_ALL}")
|
print(f"{Fore.YELLOW}{EMOJI['INFO']} {self.translator.get('oauth.searching_for_alternative_browser_installations') if self.translator else 'Searching for alternative browser installations...'}{Style.RESET_ALL}")
|
||||||
|
|
||||||
# Platform-specific paths
|
# Platform-specific paths
|
||||||
@ -237,9 +275,22 @@ class OAuthHandler:
|
|||||||
r'C:\Program Files\Google\Chrome\Application\chrome.exe',
|
r'C:\Program Files\Google\Chrome\Application\chrome.exe',
|
||||||
r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe',
|
r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe',
|
||||||
r'C:\Program Files\Chromium\Application\chrome.exe',
|
r'C:\Program Files\Chromium\Application\chrome.exe',
|
||||||
|
r'C:\Program Files\Google\Chrome\chrome.exe', # Дополнительный путь
|
||||||
|
r'C:\Program Files (x86)\Google\Chrome\chrome.exe', # Дополнительный путь
|
||||||
os.path.expandvars(r'%ProgramFiles%\Google\Chrome\Application\chrome.exe'),
|
os.path.expandvars(r'%ProgramFiles%\Google\Chrome\Application\chrome.exe'),
|
||||||
os.path.expandvars(r'%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe')
|
os.path.expandvars(r'%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe'),
|
||||||
|
os.path.expandvars(r'%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe'), # Дополнительный путь
|
||||||
|
os.path.expandvars(r'%USERPROFILE%\AppData\Local\Google\Chrome\Application\chrome.exe'), # Дополнительный путь
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Добавим проверку всех дисков
|
||||||
|
for drive in 'CDEFGHIJKLMNOPQRSTUVWXYZ':
|
||||||
|
chrome_path = f"{drive}:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
|
||||||
|
if os.path.exists(chrome_path):
|
||||||
|
return chrome_path
|
||||||
|
chrome_path = f"{drive}:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
|
||||||
|
if os.path.exists(chrome_path):
|
||||||
|
return chrome_path
|
||||||
elif sys.platform == 'darwin': # macOS
|
elif sys.platform == 'darwin': # macOS
|
||||||
alt_paths = [
|
alt_paths = [
|
||||||
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
||||||
@ -830,7 +881,7 @@ class OAuthHandler:
|
|||||||
missing.append("email")
|
missing.append("email")
|
||||||
if not token:
|
if not token:
|
||||||
missing.append("token")
|
missing.append("token")
|
||||||
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('oauth.missing_authentication_data', data=', '.join(missing)) if self.translator else f'Missing authentication data: {", ".join(missing)}'}{Style.RESET_ALL}")
|
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('oauth.missing_authentication_data', data=', '.join(missing)) if self.translator else 'Missing authentication data: ' + ', '.join(missing)}{Style.RESET_ALL}")
|
||||||
return False, None
|
return False, None
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -879,6 +930,46 @@ class OAuthHandler:
|
|||||||
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('oauth.failed_to_delete_account', error=str(e)) if self.translator else f'Failed to delete account: {str(e)}'}{Style.RESET_ALL}")
|
print(f"{Fore.RED}{EMOJI['ERROR']} {self.translator.get('oauth.failed_to_delete_account', error=str(e)) if self.translator else f'Failed to delete account: {str(e)}'}{Style.RESET_ALL}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _get_all_possible_browser_paths(self):
|
||||||
|
"""Получить все возможные пути к браузерам для отладки"""
|
||||||
|
if os.name == 'nt': # Windows
|
||||||
|
paths = [
|
||||||
|
r'C:\Program Files\Google\Chrome\Application\chrome.exe',
|
||||||
|
r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe',
|
||||||
|
r'C:\Program Files\Chromium\Application\chrome.exe',
|
||||||
|
os.path.expandvars(r'%ProgramFiles%\Google\Chrome\Application\chrome.exe'),
|
||||||
|
os.path.expandvars(r'%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe')
|
||||||
|
]
|
||||||
|
|
||||||
|
# Добавить путь из which, если доступен
|
||||||
|
chrome_path = None
|
||||||
|
try:
|
||||||
|
chrome_path = shutil.which("chrome")
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if chrome_path:
|
||||||
|
paths.append(chrome_path)
|
||||||
|
|
||||||
|
return paths
|
||||||
|
|
||||||
|
elif sys.platform == 'darwin': # macOS
|
||||||
|
return [
|
||||||
|
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
||||||
|
'/Applications/Chromium.app/Contents/MacOS/Chromium',
|
||||||
|
'~/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
||||||
|
'~/Applications/Chromium.app/Contents/MacOS/Chromium'
|
||||||
|
]
|
||||||
|
else: # Linux
|
||||||
|
return [
|
||||||
|
'/usr/bin/google-chrome',
|
||||||
|
'/usr/bin/chromium-browser',
|
||||||
|
'/usr/bin/chromium',
|
||||||
|
'/snap/bin/chromium',
|
||||||
|
'/usr/local/bin/chrome',
|
||||||
|
'/usr/local/bin/chromium'
|
||||||
|
]
|
||||||
|
|
||||||
def main(auth_type, translator=None):
|
def main(auth_type, translator=None):
|
||||||
"""Main function to handle OAuth authentication
|
"""Main function to handle OAuth authentication
|
||||||
|
|
||||||
|
9
utils.py
9
utils.py
@ -13,6 +13,15 @@ def get_user_documents_path():
|
|||||||
def get_default_chrome_path():
|
def get_default_chrome_path():
|
||||||
"""Get default Chrome path"""
|
"""Get default Chrome path"""
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
|
# Trying to find chrome in PATH
|
||||||
|
try:
|
||||||
|
import shutil
|
||||||
|
chrome_in_path = shutil.which("chrome")
|
||||||
|
if chrome_in_path:
|
||||||
|
return chrome_in_path
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
# Going to default path
|
||||||
return r"C:\Program Files\Google\Chrome\Application\chrome.exe"
|
return r"C:\Program Files\Google\Chrome\Application\chrome.exe"
|
||||||
elif sys.platform == "darwin":
|
elif sys.platform == "darwin":
|
||||||
return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
|
return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user