Commit 8ed9587b authored by sstucker's avatar sstucker
Browse files

check for update on startup

parent 975ff157
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -14,4 +14,10 @@ SNIRF
% Logging
On

% Last Checked For Update
12-Mar-1998 17:03:23

% Update Refused
0

% END
+1 −1
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ logger = Logger('Homer3');

logger.CurrTime();

if ~exist('groupDirs','var') || isempty(groupDirs)
if nargin==0
    groupDirs = convertToStandardPath(pwd);
end
if nargin<2
+53 −36
Original line number Diff line number Diff line
function checkForHomerUpdates()
    url = 'http://bu.edu/neurophotonics/research/fnirs/homer3';
    
    cfg = ConfigFileClass();
    
    % If it has been a week since Homer checked for an update
    if (datetime - cfg.GetValue('Last Checked For Update') > duration(168,0,0))

        url = 'http://bu.edu/neurophotonics/research/fnirs/homer3';
        promptFlag = 0;
    % Open a hidden web browser to run Google Analytics code
    try
        % Open a hidden web browser 
        [~,h] = web(url);
        p = getParentRecursive(h);
        p.setVisible(0);
        s = urlread(url,'timeout',2);
    catch

        [s,status] = urlread(url,'timeout',4);
        if (~status)
            % App is offline or server could not be reached
        close(h);
            fprintf('Server could not be reached to check for updates.') 
            return
        end

    updateTxt = ''; % Get information about potential update from s
        cfg.SetValue('Last Checked For Update', datetime);

        % Open a hidden web browser 
        wb = com.mathworks.mde.webbrowser.WebBrowser.createBrowser;
        wb.setCurrentLocation(url);
        p = getParentRecursive(wb);
        p.setVisible(0);

%             out = regexp(s, '<a id="version">(.*?)<\/a>', 'match')
        vrnum = getVernum();  % Compare to current version and set promptFlag
%             if (vrnum < updateTxt) & (cfg.GetValue('LatestUpdateRefused') < updateTxt)
%               promptFlag = 1;
@@ -31,13 +39,22 @@ function checkForHomerUpdates()
            switch choice
                case 'Yes'
                    % Open browser to update page
                    close(wb);
                    web(url);    
                case 'Don''t ask again'
                    % Make sure user doesn't get asked about this particular
                    % update again.
                %
                % cfg.SetValue('LatestUpdateRefused',updateTxt); 
                    cfg.SetValue('Update Refused', updateTxt);

            end

        end
    close(h);

        pause(1);
        close(wb);
        cfg.WriteFile();
        cfg.Close();
       
    end
    
end
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
function top = getParentRecursive(obj)
%   Returns topmost parent of a given graphics object using getParent function.
    while (~isempty(obj))
        top = obj;
        obj = obj.getParent();
    end
end