Skip to content

Commit

Permalink
Stabilized waitTillWebwindowLoaded()
Browse files Browse the repository at this point in the history
Added some mechanisms to reduce the likelihood of errors in getWebElements.
  • Loading branch information
Dev-iL committed Jul 25, 2018
1 parent b8f70c5 commit 38c49bd
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions mlapptools.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function fontWeight(uiElement, weight)
% to the provided uifigure control.
% Get a handle to the webwindow
win = mlapptools.getWebWindow(uiElement);
mlapptools.waitTillWebwindowLoaded(win);
mlapptools.waitTillWebwindowLoaded(win, ancestor(uiElement, 'matlab.ui.Figure') );

% Find which element of the DOM we want to edit
switch uiElement.Type
Expand Down Expand Up @@ -592,8 +592,12 @@ function unlockUIFig(hUIFig)
end % getWidgetIDFromDijit

function to = getTimeout(hFig)
to = getappdata(hFig, mlapptools.TAG_TIMEOUT);
if isempty(to), to = mlapptools.QUERY_TIMEOUT; end
if isempty(hFig) || ~isa(hFig, 'matlab.ui.Figure')
to = mlapptools.QUERY_TIMEOUT;
else
to = getappdata(hFig, mlapptools.TAG_TIMEOUT);
if isempty(to), to = mlapptools.QUERY_TIMEOUT; end
end
end % getTimeout

function tf = isUIFigure(hList)
Expand Down Expand Up @@ -698,11 +702,14 @@ function waitTillFigureLoaded(hFig)

function waitTillWebwindowLoaded(hWebwindow, hFig)
% A blocking method that ensures a certain webwindow has fully loaded.
if nargin < 2
hFig = mlapptools.figFromWebwindow(hWebwindow);
try
if nargin < 2
hFig = mlapptools.figFromWebwindow(hWebwindow);
end
to = mlapptools.getTimeout(hFig);
catch % possible workaround for R2017a:
to = mlapptools.getTimeout([]);
end

to = mlapptools.getTimeout(hFig);
tic
while (toc < to) && ~jsondecode(hWebwindow.executeJS(...
'this.hasOwnProperty("require") && require !== undefined && typeof(require) === "function"'))
Expand Down

0 comments on commit 38c49bd

Please sign in to comment.