diff --git a/SpotifyLyricWindow/common/api/user_api/user_auth.py b/SpotifyLyricWindow/common/api/user_api/user_auth.py index a50cffc..394fed1 100644 --- a/SpotifyLyricWindow/common/api/user_api/user_auth.py +++ b/SpotifyLyricWindow/common/api/user_api/user_auth.py @@ -28,6 +28,7 @@ def __new__(cls, *args, **kwargs): def __init__(self): if not self._is_init: + self.is_listen = False self.user_token_info = None self.client_token_info = None self.state = None @@ -90,6 +91,7 @@ def get_user_auth_url(self) -> str: return auth_code.url def receive_user_auth_code(self) -> str: + self.is_listen = True receive_address = ('127.0.0.1', 8888) server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind(receive_address) @@ -110,8 +112,10 @@ def receive_user_auth_code(self) -> str: client.send(html_content) client.recv(1024) # 确保发回html页面提示用户关闭 self.auth_code = auth_code + self.is_listen = False return auth_code else: + self.is_listen = False raise Exception("验证失败") def get_user_access_token(self): diff --git a/SpotifyLyricWindow/view/lyric_window/lyric_window.py b/SpotifyLyricWindow/view/lyric_window/lyric_window.py index 4e5df53..f06e23c 100644 --- a/SpotifyLyricWindow/view/lyric_window/lyric_window.py +++ b/SpotifyLyricWindow/view/lyric_window/lyric_window.py @@ -287,7 +287,8 @@ def user_auth_button_event(self, *_): self.text_show_signal.emit(1, "请根据页面完成授权", 0) self.text_show_signal.emit(2, "ヾ(≧ ▽ ≦)ゝ", 0) try: - self.spotify_auth.auth.receive_user_auth_code() + if not self.spotify_auth.auth.is_listen: + self.spotify_auth.auth.receive_user_auth_code() except OSError: self.account_button.setEnabled(True) raise UserError("端口8888被占用,请检查端口占用")