Unverified Commit e1d9273e authored by stephen scott tucker's avatar stephen scott tucker Committed by GitHub
Browse files

Gets info about latest version from GitHub API rather than openfnirs.org (#92)

* Gets info about latest version from GitHub API rather than openfnirs.org

* Version++
parent f43d8e43
Loading
Loading
Loading
Loading
+25 −18
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ if (strcmp(cfg.GetValue('Check For Updates'),'on'))
    
    % If it has been a week since Homer checked for an update
    if (datetime - GetLastCheckForUpdates() > duration(168,0,0))
        
        url = 'https://openfnirs.org/software/homer/homer3/';        
        [s, status] = urlread(url,'timeout',4);
        if (~status)
@@ -18,40 +19,46 @@ if (strcmp(cfg.GetValue('Check For Updates'),'on'))

        SetLastCheckForUpdates();
        
        % Open a hidden web browser
        % Open a hidden web browser and poll openfnirs.org
        % If user has a web browser open MATLAB will unfortunately just
        % open the page there
        wb = com.mathworks.mde.webbrowser.WebBrowser.createBrowser;
        wb.setCurrentLocation(url);
        setCurrentLocation(wb, url);
        p = getParentRecursive(wb);
        p.setVisible(0);
        
        version = regexp(s, 'id="version">(.*?)<\/', 'tokens');
        desc = regexp(s, 'id="description">(.*?)<\/', 'tokens');
        try  % Version description might not exist
            updateTxt = [version{1}{1},': ', desc{1}{1}];
        catch
            updateTxt = version{1}{1};
        end
        web_vrnum = str2cell(version{1}{1},'.');
        % Get latest release info from GitHub API
        release_info = webread('https://api.github.com/repos/BUNPC/Homer3/releases/latest');
        
        tag = release_info.tag_name;
        update_body_text = release_info.body;
        dest = release_info.html_url;
        
        latest_vrnum = tag;
        latest_vrnum(isletter(latest_vrnum)) = [];
        latest_vrnum = transpose(split(latest_vrnum, '.'));
        
        this_vrnum = getVernum();
        promptFlag = compareVernum(web_vrnum, this_vrnum);  % If fetched vernum is greater
        
        promptFlag = compareVernum(latest_vrnum, this_vrnum);  % If fetched vernum is greater
        if (promptFlag)
            choice = questdlg(sprintf(['An update for Homer3 is available:\n',...
                updateTxt,...
            choice = questdlg(sprintf([sprintf('An update for Homer3 is available: %s\n', tag),...
                update_body_text,...
                '\nWould you like to download it?']),...
                'Update Available',...
                'Yes','Remind me later','Don''t show this again',...
                'Remind me later');
            if strcmp(choice, 'Yes')
                web('https://github.com/BUNPC/Homer3/releases');
                close(wb);
                web(dest);
                return;
            elseif strcmp(choice, 'Don''t show this again')
                web('https://github.com/BUNPC/Homer3');
                cfg.SetValue('Check For Updates', 'off');
            end
            
        end
        
        pause(1);  % To ensure <script> is run
        pause(1);  % To ensure <script> is run on openfnirs.org
        close(wb);
        
    end
+1 −1
Original line number Diff line number Diff line
@@ -30,6 +30,6 @@ function [vrnnum] = getVernum_Homer3()

vrnnum{1} = '1';   % Major version #
vrnnum{2} = '33';  % Major sub-version #
vrnnum{3} = '0';   % Minor version #
vrnnum{3} = '1';   % Minor version #
vrnnum{4} = '0';   % Minor sub-version # or patch #: 'p1', 'p2', etc