Skip to content

Commit

Permalink
refactor(core): Make AJAX cron script work without jQuery
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Jun 28, 2024
1 parent 8ec5360 commit 4d6a21a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion core/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function handle(Event $event): void {

// If installed and background job is set to ajax, add dedicated script
if ($this->config->getAppValue('core', 'backgroundjobs_mode', 'ajax') == 'ajax') {
Util::addScript('core', 'backgroundjobs');
Util::addScript('core', 'ajax-cron');
}
}
}
Expand Down
13 changes: 0 additions & 13 deletions core/js/backgroundjobs.js

This file was deleted.

1 change: 0 additions & 1 deletion core/js/public/publicpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ window.addEventListener('DOMContentLoaded', function () {
$('#remote_address').focus();
});


$(document).mouseup(function(e) {
var toggle = $('#body-public').find('.header-right .menutoggle');
var container = toggle.next('.popovermenu');
Expand Down
18 changes: 18 additions & 0 deletions core/src/ajax-cron.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { getRootUrl } from '@nextcloud/router'
import logger from './logger'

window.addEventListener('DOMContentLoaded', async () => {
// When the page is loaded send GET to the cron endpoint to trigger background jobs
try {
logger.debug('Running web cron')
await window.fetch(`${getRootUrl()}/cron.php`)
logger.debug('Web cron successfull')
} catch (e) {
logger.debug('Running web cron failed', { error: e })
}
})
1 change: 1 addition & 0 deletions webpack.modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
init: path.join(__dirname, 'apps/comments/src', 'init.ts'),
},
core: {
'ajax-cron': path.join(__dirname, 'core/src', 'ajax-cron.ts'),
files_client: path.join(__dirname, 'core/src', 'files/client.js'),
files_fileinfo: path.join(__dirname, 'core/src', 'files/fileinfo.js'),
install: path.join(__dirname, 'core/src', 'install.js'),
Expand Down

0 comments on commit 4d6a21a

Please sign in to comment.