mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
The instance-editing hook looked up the board of an edit without a catch, and the service worker registration had none. Thanks to xet7 !
147 lines
6.4 KiB
JavaScript
147 lines
6.4 KiB
JavaScript
// Fix dynamic-import chunk loading when Wekan runs under a sub-path (ROOT_URL includes a pathname,
|
|
// e.g. https://example.com/wekan). Rspack's runtime builds every chunk URL as
|
|
// __webpack_public_path__ + chunkName, and the chunk name ALREADY includes the "build-chunks/"
|
|
// prefix (its runtime does `u = e => "build-chunks/" + e + "." + hash + ".js"`). The default
|
|
// public path is "/", so at the site root chunks correctly resolve to "/build-chunks/<chunk>".
|
|
// Under a sub-path we must prefix that sub-path — but must NOT re-add "build-chunks/" ourselves,
|
|
// or the URL becomes "/wekan/build-chunks/build-chunks/<chunk>" and 404s (issue #6445, which broke
|
|
// the lazy-loaded language chunks). So set the public path to "<sub-path>/" and let rspack append
|
|
// "build-chunks/" itself. Done here at module evaluation time, before any import() expression runs
|
|
// (those are deferred to Meteor.startup callbacks).
|
|
/* global __webpack_public_path__:writable */
|
|
try {
|
|
const _cfg = typeof window !== 'undefined' && window.__meteor_runtime_config__;
|
|
const _rootUrl = _cfg && _cfg.ROOT_URL;
|
|
if (_rootUrl) {
|
|
const _rootPath = new URL(_rootUrl).pathname.replace(/\/+$/, '');
|
|
if (_rootPath && _rootPath !== '/') {
|
|
__webpack_public_path__ = _rootPath + '/';
|
|
}
|
|
}
|
|
} catch (_) {}
|
|
|
|
// Expose Meteor on window. Under the Meteor 3.5 + rspack build, bare `Meteor`
|
|
// references in app code are rewritten by rspack's ProvidePlugin into per-module
|
|
// imports, so `Meteor` is NOT placed on the browser `window` the way the classic
|
|
// Meteor linker did. Re-expose it so the browser console and the Playwright e2e
|
|
// tests (which call Meteor.loginWithToken / Meteor.userId / Meteor.subscribe etc.
|
|
// via page.evaluate in window scope) can reach it. This matches the long-standing
|
|
// classic-Meteor behaviour where `Meteor` is a global.
|
|
if (typeof window !== 'undefined') {
|
|
window.Meteor = Meteor;
|
|
}
|
|
|
|
// #6752: a ROOT_URL left at the snap's 127.0.0.1 default made every
|
|
// copied link point at 127.0.0.1. When the browser reached WeKan through
|
|
// another address, build absolute links from that address instead
|
|
// (models/lib/browserRootUrl.js says when, and why only then).
|
|
try {
|
|
const { browserRootUrl } = require('/models/lib/browserRootUrl');
|
|
const rootUrl = browserRootUrl(Meteor.absoluteUrl.defaultOptions.rootUrl, window.location.href);
|
|
if (rootUrl) Meteor.absoluteUrl.defaultOptions.rootUrl = rootUrl;
|
|
} catch (_) {}
|
|
|
|
// Fix bug in jam:offline 0.4.1: s?.message.includes() crashes when s.message is
|
|
// undefined (e.g. during WebSocket reconnect errors that don't carry a .message).
|
|
// Wrap _debug so the optional chain is complete: s?.message?.includes().
|
|
(function patchJamOfflineDebug() {
|
|
const patched = Meteor._debug;
|
|
Meteor._debug = function (m, s) {
|
|
try {
|
|
return patched.call(this, m, s);
|
|
} catch (e) {
|
|
// jam:offline's override threw — fall back to the bare console log.
|
|
if (typeof console !== 'undefined') {
|
|
console.log(m, s);
|
|
}
|
|
}
|
|
};
|
|
})();
|
|
|
|
// PWA — use Meteor.absoluteUrl so the path is correct under sub-URL deployments
|
|
if ('serviceWorker' in navigator) {
|
|
window.addEventListener('load', function() {
|
|
const swPath = new URL('pwa-service-worker.js', Meteor.absoluteUrl()).pathname;
|
|
navigator.serviceWorker.register(swPath).catch(error => {
|
|
// No service worker (a private window, an old browser): the app works without the offline cache.
|
|
if (process.env.DEBUG === 'true') console.warn('service worker registration failed:', error);
|
|
});
|
|
});
|
|
}
|
|
|
|
// Import Blaze helpers (replaces removed raix:handlebar-helpers package)
|
|
import '/client/config/blazeHelpers';
|
|
|
|
// Import board converter for on-demand conversion
|
|
import '/client/lib/boardConverter';
|
|
import '/client/features/boardConversion';
|
|
import { Utils } from '/client/lib/utils';
|
|
|
|
// Import migration manager and progress UI - COMMENTED OUT
|
|
// import '/client/lib/attachmentMigrationManager';
|
|
// import '/client/components/settings/migrationProgress';
|
|
|
|
// Custom head tags
|
|
|
|
// Accounts may already have resumed a legacy localStorage session before the
|
|
// application module loads. Move its credentials to memory without a second
|
|
// login: that login rebuilds subscriptions and can discard the current profile
|
|
// (#6677). Keep the poller's token in sync and let the native endpoint validate
|
|
// the token when creating the HttpOnly cookie. An in-flight initial login still
|
|
// finishes through Accounts' normal callback.
|
|
const { installAccountsCookiePaths } = require('/imports/lib/accountsCookiePaths');
|
|
installAccountsCookiePaths(Accounts, Meteor.absoluteUrl(), (...args) => fetch(...args));
|
|
|
|
const legacyResumeToken = Accounts._storedLoginToken();
|
|
const legacyUserId = Accounts._storedUserId();
|
|
const legacyTokenExpires = Accounts._storedLoginTokenExpires();
|
|
// Remove the old persistent copy; subsequent Accounts writes go to memory.
|
|
if (legacyResumeToken) Accounts._unstoreLoginToken();
|
|
Accounts.config({ clientStorage: 'none', useHttpOnlyCookies: true });
|
|
if (legacyResumeToken) {
|
|
Accounts._storeLoginToken(legacyUserId, legacyResumeToken, legacyTokenExpires);
|
|
Accounts._setHttpOnlyCookie(legacyResumeToken, legacyTokenExpires);
|
|
} else {
|
|
Accounts.loginWithCookie();
|
|
}
|
|
|
|
// Subscribe to per-user small publications
|
|
Meteor.startup(() => {
|
|
Tracker.autorun(() => {
|
|
if (Meteor.userId()) {
|
|
Meteor.subscribe('userDesktopDragHandles');
|
|
Meteor.subscribe('userBoardView');
|
|
}
|
|
});
|
|
|
|
// LOGOUT_IDLE_MINUTES: report the user's activity while signed in, if the
|
|
// limit is set (models/lib/idleLogout.js).
|
|
const { createIdleActivityReporter } = require('/client/lib/idleActivity');
|
|
const idleReporter = createIdleActivityReporter({
|
|
target: document,
|
|
touch: () => Meteor.call('touchActivity', () => {}),
|
|
});
|
|
let idleCheckedFor = null;
|
|
Tracker.autorun(() => {
|
|
const userId = Meteor.userId();
|
|
if (!userId) {
|
|
idleCheckedFor = null;
|
|
idleReporter.stop();
|
|
return;
|
|
}
|
|
if (idleCheckedFor === userId) return;
|
|
idleCheckedFor = userId;
|
|
Meteor.call('getIdleLogout', (error, result) => {
|
|
if (!error && result && result.enabled && Meteor.userId() === userId) idleReporter.start();
|
|
});
|
|
});
|
|
|
|
// Initialize mobile mode on startup for iOS devices
|
|
// This ensures mobile mode is applied correctly on page load
|
|
Tracker.afterFlush(() => {
|
|
if (typeof Utils !== 'undefined' && Utils.initializeUserSettings) {
|
|
Utils.initializeUserSettings();
|
|
}
|
|
});
|
|
});
|