How To - Auto switch theme for mobile - one bug

I’ve figured out how to get the themes to switch for mobile devices. I like SuiteR for mobile and Suite7 for desktop. The issue is switching back once the user logs out of their phone. Not sure if it’s a cache issue yet or not.
Here’s what I have so far.

This applies to SuiteCRM 7.3.1

  1. in include\MVC\SugarApplication.php on about line 408 replace
 $theme = $GLOBALS['current_user']->getPreference('user_theme');

with

// load the user's default theme // overide if mobile
		if(preg_match("/(iPhone|Mobile|android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]))
		{
			$theme='SuiteR';
		}else{
        $theme = $GLOBALS['current_user']->getPreference('user_theme');
		}

This part works fine for switching the theme.
The problem I’m having is switching back.
I figure it should be in \modules\Users\Logout.php around line 52 which is

$current_user->setPreference('lastTheme',$theme);

I tried

$current_user->setPreference('lastTheme','Suite7');
$current_user->setPreference('user_theme','Suite7');

Then did a quick rebuild, clear browser cache, etc but the SuiteR theme stays when the user logs in on a desktop.
Any thoughts on how to fix the code to switch back to Suite7 or the default theme??

I think I found the issue with switching themes. In include\MVC\SugarApplication.php around line 447 (after changing the code above) when I commented out the line

$GLOBALS['current_user']->setPreference('user_theme', $theme, 0, 'global');

the mobile theme (SuiteR) displays on my iphone then when I log out and log in on my desktop the default theme (Suite7) returns as desired.

If you are trying to do this too, try it out and let me know your thoughts.