Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 59 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@nextcloud/capabilities": "^1.1.0",
"@nextcloud/event-bus": "^3.1.0",
"@nextcloud/l10n": "^2.2.0",
"@nextcloud/router": "^3.0.0",
"@nextcloud/vue": "^8.11.1",
"core-js": "^3.36.1",
"electron-squirrel-startup": "^1.0.0",
Expand Down
60 changes: 27 additions & 33 deletions src/patchers/@nextcloud/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,37 @@

/* eslint-disable jsdoc/require-jsdoc */

import { getRootUrl, generateFilePath as _generateFilePath } from '@desktop-modules--@nextcloud/router'
import {
getRootUrl as _getRootUrl,
getAppRootUrl as _getAppRootUrl,
generateUrl as _generateUrl,
linkTo as _linkTo,
generateRemoteUrl as _generateRemoteUrl,
generateOcsUrl as _generateOcsUrl,
generateFilePath as _generateFilePath,
} from '@desktop-modules--@nextcloud/router'

export { linkTo, getRootUrl, generateUrl } from '@desktop-modules--@nextcloud/router'
// Original @nextcloud/router sometimes relies on window.location which is not correct on desktop
// So, some function must be re-defined or patched

// getBaseUrl added in v3.0.0
// On Talk Desktop same as getRootUrl, because getRootUrl is absolute already
export const getBaseUrl = getRootUrl
// Works as expected originally, does not use location
export const getRootUrl = _getRootUrl

/**
* @param {string} s - String with "{token}" blocks
* @param {{[token: string]: string}} [tokens] - Dict with replacements
* @return {string}
*/
function formattedString(s, tokens = {}) {
return Object.entries(tokens).reduce((acc, [token, replacement]) => acc.replaceAll(`{${token}}`, replacement), s)
}

export function generateOcsUrl(url, params = {}, options = {}) {
// Reason to patch: it uses window.location
const allOptions = { ...options, ocsVersion: 2 }
const version = (allOptions.ocsVersion === 1) ? 1 : 2
return `${getRootUrl()}/ocs/v${version}.php/${formattedString(url, params)}`
}
// Works fine originally with enabled absolute webroot
export const getAppRootUrl = (...args) => window.OCA.Talk.Desktop.runWithAbsoluteWebroot(_getAppRootUrl, ...args)
export const generateUrl = (...args) => window.OCA.Talk.Desktop.runWithAbsoluteWebroot(_generateUrl, ...args)
export const linkTo = (...args) => window.OCA.Talk.Desktop.runWithAbsoluteWebroot(_linkTo, ...args)

const linkToRemoteBase = (service) => getRootUrl() + '/remote.php/' + service
// Original getBaseUrl relies on window.location, create a new one as an absolute version of getRootUrl
export const getBaseUrl = (...args) => window.OCA.Talk.Desktop.runWithAbsoluteWebroot(_getRootUrl, ...args)

export function generateRemoteUrl(service) {
// Reason to patch: it uses window.location
return linkToRemoteBase(service)
}
// Requires changing the default options.baseUrl from original relative getBaseUrl to new absolute getBaseUrl
export const generateRemoteUrl = (service, options = {}) => _generateRemoteUrl(service, { baseURL: getBaseUrl(), ...options })
export const generateOcsUrl = (url, params, options = {}) => _generateOcsUrl(url, params, { baseURL: getBaseUrl(), ...options })

// By default, Talk requests images and sounds as a file from server assets using generateFilePath
// Desktop app should use path to the local file in the bundle
export function generateFilePath(app, type, file) {
/**
* By default, Talk requests images and sounds as a file from server assets using generateFilePath
* Desktop app should use path to the local file in the build
*/

const filename = file.substring(0, file.lastIndexOf('.'))
const ext = file.substring(file.lastIndexOf('.'))

Expand All @@ -77,14 +71,14 @@ export function generateFilePath(app, type, file) {
return requiresByExt[ext]()
}
} else if (app === 'notifications' && ext === '.ogg') {
// For now notifications sounds are just a copy of the notifications app sounds
// For now, notifications' sounds are just a copy of the Notifications app sounds
return require(`../../../sounds/${filename}.ogg`)
}

return _generateFilePath(app, type, file)
return window.OCA.Talk.Desktop.runWithAbsoluteWebroot(() => _generateFilePath(app, type, file))
}

// Copy of original function, but using patched generateFilePath
// Copy of original but using patched generateFilePath
export function imagePath(app, file) {
if (file.indexOf('.') === -1) {
return generateFilePath(app, 'img', file + '.svg')
Expand Down
37 changes: 31 additions & 6 deletions src/shared/globals/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ import { translate, translatePlural } from '@nextcloud/l10n'

import { appData } from '../../app/AppData.js'
import { dialogs } from './OC/dialogs.js'
import { getDesktopMediaSource } from '../../talk/renderer/getDesktopMediaSource.js'

let enabledAbsoluteWebroot = false

/**
* Run a function with an absolute webroot enabled to not rely on window.location
*
* @param {Function} func - the function to run
* @param {...any} args - the arguments to pass to the function
* @return {any} the result of the function's run
*/
function runWithAbsoluteWebroot(func, ...args) {
enabledAbsoluteWebroot = true
const result = func.call(this, ...args)
enabledAbsoluteWebroot = false
return result
}

const getMaybeAbsoluteWebroot = () => enabledAbsoluteWebroot ? appData.serverUrl : new URL(appData.serverUrl).pathname

const OC = {
// Constant from: https://github.com/nextcloud/server/blob/master/core/src/OC/constants.js
Expand All @@ -46,9 +65,7 @@ const OC = {
},

get webroot() {
// Original method returns only path, for example, /nextcloud-webroot
// Desktop needs to have full URL: https://nextcloud.host/nextcloud-webroot
return appData.serverUrl
return getMaybeAbsoluteWebroot()
},

config: {
Expand Down Expand Up @@ -81,7 +98,15 @@ const OC = {
},
}

const OCA = {}
const OCA = {
Talk: {
Desktop: {
getDesktopMediaSource,
runWithAbsoluteWebroot,
enabledAbsoluteWebroot: false,
},
},
}

const OCP = {
Accessibility: {
Expand All @@ -101,10 +126,10 @@ export function initGlobals() {
window.OCP = OCP

Object.defineProperty(window, '_oc_webroot', {
get: () => OC.webroot,
get: () => getMaybeAbsoluteWebroot(),
})

Object.defineProperty(window, '_oc_appswebroots', {
get: () => OC.appswebroots,
get: () => window.OC.appswebroots,
})
}
5 changes: 0 additions & 5 deletions src/talk/renderer/talk.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import './assets/styles.css'
import 'regenerator-runtime' // TODO: Why isn't it added on bundling
import { init, initTalkHashIntegration } from './init.js'
import { setupWebPage } from '../../shared/setupWebPage.js'
import { getDesktopMediaSource } from './getDesktopMediaSource.js'
import { createViewer } from './Viewer/Viewer.js'

// Initially open the welcome page, if not specified
Expand All @@ -46,8 +45,4 @@ await import('@talk/src/main.js')

initTalkHashIntegration(OCA.Talk.instance)

window.OCA.Talk.Desktop = {
getDesktopMediaSource,
}

await import('./notifications/notifications.store.js')