@@ -1029,12 +1029,19 @@ def js_dumps(self, obj_name):
10291029 return self .loop .run_until_complete (self .page .js_dumps (obj_name ))
10301030
10311031 def maximize (self ):
1032- if self .get_window ()[1 ].window_state .value == "maximized" :
1033- return
1034- elif self .get_window ()[1 ].window_state .value == "minimized" :
1035- self .loop .run_until_complete (self .page .maximize ())
1036- time .sleep (0.044 )
1037- return self .loop .run_until_complete (self .page .maximize ())
1032+ try :
1033+ if self .get_window ()[1 ].window_state .value == "maximized" :
1034+ return
1035+ elif self .get_window ()[1 ].window_state .value == "minimized" :
1036+ self .loop .run_until_complete (self .page .maximize ())
1037+ time .sleep (0.044 )
1038+ return self .loop .run_until_complete (self .page .maximize ())
1039+ except Exception :
1040+ with suppress (Exception ):
1041+ width = self .evaluate ("screen.availWidth;" )
1042+ height = self .evaluate ("screen.availHeight;" )
1043+ self .__set_window_rect (0 , 0 , width , height )
1044+ return
10381045
10391046 def minimize (self ):
10401047 if self .get_window ()[1 ].window_state .value != "minimized" :
@@ -1725,18 +1732,18 @@ def gui_click_x_y(self, x, y, timeframe=0.25):
17251732 win_x = window_rect ["x" ]
17261733 win_y = window_rect ["y" ]
17271734 scr_width = pyautogui .size ().width
1728- self .maximize ()
1729- self .__add_light_pause ()
1730- win_width = self .get_window_size ()["width" ]
1735+ win_width = self .evaluate ("screen.availWidth;" )
17311736 width_ratio = round (float (scr_width ) / float (win_width ), 2 )
17321737 width_ratio += 0.01
17331738 if width_ratio < 0.45 or width_ratio > 2.55 :
17341739 width_ratio = 1.01
17351740 sb_config ._saved_width_ratio = width_ratio
1736- self .minimize ()
1737- self .__add_light_pause ()
1738- self .__set_window_rect (win_x , win_y , width , height )
1739- self .__add_light_pause ()
1741+ with suppress (Exception ):
1742+ self .get_window () # If this fails, skip the rest
1743+ self .minimize ()
1744+ self .__add_light_pause ()
1745+ self .__set_window_rect (win_x , win_y , width , height )
1746+ self .__add_light_pause ()
17401747 x = x * (width_ratio + 0.03 )
17411748 y = y * (width_ratio - 0.03 )
17421749 self .bring_active_window_to_front ()
@@ -2021,18 +2028,18 @@ def gui_drag_drop_points(self, x1, y1, x2, y2, timeframe=0.35):
20212028 win_x = window_rect ["x" ]
20222029 win_y = window_rect ["y" ]
20232030 scr_width = pyautogui .size ().width
2024- self .maximize ()
2025- self .__add_light_pause ()
2026- win_width = self .get_window_size ()["width" ]
2031+ win_width = self .evaluate ("screen.availWidth;" )
20272032 width_ratio = round (float (scr_width ) / float (win_width ), 2 )
20282033 width_ratio += 0.01
20292034 if width_ratio < 0.45 or width_ratio > 2.55 :
20302035 width_ratio = 1.01
20312036 sb_config ._saved_width_ratio = width_ratio
2032- self .minimize ()
2033- self .__add_light_pause ()
2034- self .__set_window_rect (win_x , win_y , width , height )
2035- self .__add_light_pause ()
2037+ with suppress (Exception ):
2038+ self .get_window () # If this fails, skip the rest
2039+ self .minimize ()
2040+ self .__add_light_pause ()
2041+ self .__set_window_rect (win_x , win_y , width , height )
2042+ self .__add_light_pause ()
20362043 x1 = x1 * width_ratio
20372044 y1 = y1 * (width_ratio - 0.02 )
20382045 x2 = x2 * width_ratio
@@ -2114,15 +2121,14 @@ def gui_hover_x_y(self, x, y, timeframe=0.25):
21142121 width_ratio = sb_config ._saved_width_ratio
21152122 else :
21162123 scr_width = pyautogui .size ().width
2117- self .maximize ()
2118- self .__add_light_pause ()
2119- win_width = self .get_window_size ()["width" ]
2124+ win_width = self .evaluate ("screen.availWidth;" )
21202125 width_ratio = round (float (scr_width ) / float (win_width ), 2 )
21212126 width_ratio += 0.01
21222127 if width_ratio < 0.45 or width_ratio > 2.55 :
21232128 width_ratio = 1.01
21242129 sb_config ._saved_width_ratio = width_ratio
2125- self .__set_window_rect (win_x , win_y , width , height )
2130+ with suppress (Exception ):
2131+ self .__set_window_rect (win_x , win_y , width , height )
21262132 self .__add_light_pause ()
21272133 self .bring_active_window_to_front ()
21282134 elif (
0 commit comments