Skip to content

Commit f34b9db

Browse files
committed
* Update the JS last update date on upgrade
* Prevent JS errors on some browsers which do not support the Notifications API * Prevent a template error for guests
1 parent 7aa09df commit f34b9db

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

addon-LiveUpdate.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<addon addon_id="LiveUpdate" title="Live Update" version_string="4.1.0" version_id="4010072" url="https://xenresources.com" install_callback_class="LiveUpdate_Install" install_callback_method="installer" uninstall_callback_class="LiveUpdate_Install" uninstall_callback_method="uninstaller">
2+
<addon addon_id="LiveUpdate" title="Live Update" version_string="4.1.0" version_id="4010073" url="https://xenresources.com" install_callback_class="LiveUpdate_Install" install_callback_method="installer" uninstall_callback_class="LiveUpdate_Install" uninstall_callback_method="uninstaller">
33
<admin_navigation/>
44
<admin_permissions/>
55
<admin_style_properties/>

upload/js/liveupdate/min/update.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

upload/js/liveupdate/update.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,22 @@ var LiveUpdate = {};
100100
}
101101
};
102102

103+
LiveUpdate.Notification = null;
104+
103105
LiveUpdate.SetupNotificationAPI = function()
104106
{
105-
if (Notification.permission !== 'denied' && Notification.permission !== 'granted')
107+
if (LiveUpdate.Notification && LiveUpdate.Notification.permission !== 'denied' && LiveUpdate.Notification.permission !== 'granted')
106108
{
107-
Notification.requestPermission(function (permission) {})
109+
LiveUpdate.Notification.requestPermission(function (permission) {})
108110
}
109111
};
110112

111-
LiveUpdate.Notification = null;
112-
113113
LiveUpdate.SendNotification = function(message)
114114
{
115115
if (LiveUpdate.displayOptions.indexOf('notifications_api') === -1
116-
|| Notification.permission !== 'granted'
116+
|| navigator.userAgent.search(/\((iPhone|iPad|iPod);/) !== -1
117+
|| (LiveUpdate.Notification
118+
&& LiveUpdate.Notification.permission !== 'granted')
117119
)
118120
{
119121
return;

upload/library/LiveUpdate/Install.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ public static function installer($previous)
2727
$dw->delete();
2828
}
2929

30-
self::_runQuery("
30+
self::_runQuery('
3131
ALTER TABLE xf_user_option
32-
ADD COLUMN liveupdate_display_option MEDIUMBLOB NULL DEFAULT NULL
33-
");
32+
ADD COLUMN liveupdate_display_option MEDIUMBLOB NULL DEFAULT ?
33+
', json_encode(array('tab_icon', 'notifications_api')));
3434
}
3535
else
3636
{
3737
if ($version < 4010070 || $version < 4010071)
3838
{
39-
self::_runQuery("
39+
self::_runQuery('
4040
ALTER TABLE xf_user_option
41-
CHANGE COLUMN liveupdate_display_option liveupdate_display_option MEDIUMBLOB NULL DEFAULT NULL
42-
");
41+
CHANGE COLUMN liveupdate_display_option liveupdate_display_option MEDIUMBLOB NULL DEFAULT ?
42+
', json_encode(array('tab_icon', 'notifications_api')));
4343

4444

4545
/**
@@ -71,6 +71,11 @@ public static function installer($previous)
7171
WHERE liveupdate_display_option = ''
7272
", json_encode(array()));
7373
}
74+
75+
if ($version < 4010073)
76+
{
77+
self::_updateJsCacheBuster();
78+
}
7479
}
7580
}
7681

@@ -81,6 +86,11 @@ public static function uninstaller()
8186
");
8287
}
8388

89+
protected static function _updateJsCacheBuster($time = null)
90+
{
91+
XenForo_Model::create('XenForo_Model_Option')->updateOption('jsLastUpdate', $time ? $time : time());
92+
}
93+
8494
protected static function _runQuery($sql, $bind = array())
8595
{
8696
$db = self::_getDb();

upload/library/LiveUpdate/Listener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static function helperLiveUpdateOptions($json = false)
2424
$visitor = XenForo_Visitor::getInstance();
2525
if (!$visitor->user_id)
2626
{
27-
return '';
27+
return array();
2828
}
2929

3030
if (!empty($visitor['permissions']['general']['liveUpdateChangeOptions']))

upload/library/LiveUpdate/addon-LiveUpdate.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<addon addon_id="LiveUpdate" title="Live Update" version_string="4.1.0" version_id="4010072" url="https://xenresources.com" install_callback_class="LiveUpdate_Install" install_callback_method="installer" uninstall_callback_class="LiveUpdate_Install" uninstall_callback_method="uninstaller">
2+
<addon addon_id="LiveUpdate" title="Live Update" version_string="4.1.0" version_id="4010073" url="https://xenresources.com" install_callback_class="LiveUpdate_Install" install_callback_method="installer" uninstall_callback_class="LiveUpdate_Install" uninstall_callback_method="uninstaller">
33
<admin_navigation/>
44
<admin_permissions/>
55
<admin_style_properties/>

0 commit comments

Comments
 (0)