Skip to content

Commit

Permalink
🐛 fix repeated user verification button usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Mai-icy committed Sep 17, 2024
1 parent 5f857d8 commit bf54feb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions SpotifyLyricWindow/common/api/user_api/user_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion SpotifyLyricWindow/view/lyric_window/lyric_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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被占用,请检查端口占用")
Expand Down

0 comments on commit bf54feb

Please sign in to comment.