-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44259 from nextcloud/feat/app-discover-app-links
feat(settings): Allow app discover section links to open app routes or the appstore page
- Loading branch information
Showing
19 changed files
with
150 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
apps/settings/src/components/AppStoreDiscover/AppLink.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<!-- | ||
- @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de> | ||
- | ||
- @author Ferdinand Thiessen <[email protected]> | ||
- | ||
- @license AGPL-3.0-or-later | ||
- | ||
- This program is free software: you can redistribute it and/or modify | ||
- it under the terms of the GNU Affero General Public License as | ||
- published by the Free Software Foundation, either version 3 of the | ||
- License, or (at your option) any later version. | ||
- | ||
- This program is distributed in the hope that it will be useful, | ||
- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
- GNU Affero General Public License for more details. | ||
- | ||
- You should have received a copy of the GNU Affero General Public License | ||
- along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
- | ||
--> | ||
<template> | ||
<a v-if="linkProps" v-bind="linkProps"> | ||
<slot /> | ||
</a> | ||
<RouterLink v-else-if="routerProps" v-bind="routerProps"> | ||
<slot /> | ||
</RouterLink> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import type { RouterLinkProps } from 'vue-router/types/router.js' | ||
|
||
import { loadState } from '@nextcloud/initial-state' | ||
import { generateUrl } from '@nextcloud/router' | ||
import { defineComponent } from 'vue' | ||
import { RouterLink } from 'vue-router' | ||
|
||
const knownRoutes = Object.fromEntries( | ||
Object.entries( | ||
loadState<Record<string, { app?: string, href: string }>>('core', 'apps'), | ||
).map(([k, v]) => [v.app ?? k, v.href]), | ||
) | ||
|
||
/** | ||
* This component either shows a native link to the installed app or external size - or a router link to the appstore page of the app if not installed | ||
*/ | ||
export default defineComponent({ | ||
name: 'AppLink', | ||
|
||
components: { RouterLink }, | ||
|
||
props: { | ||
href: { | ||
type: String, | ||
required: true, | ||
}, | ||
}, | ||
|
||
data() { | ||
return { | ||
routerProps: undefined as RouterLinkProps|undefined, | ||
linkProps: undefined as Record<string, string>|undefined, | ||
} | ||
}, | ||
|
||
watch: { | ||
href: { | ||
immediate: true, | ||
handler() { | ||
const match = this.href.match(/^app:\/\/([^/]+)(\/.+)?$/) | ||
this.routerProps = undefined | ||
this.linkProps = undefined | ||
|
||
// not an app url | ||
if (match === null) { | ||
this.linkProps = { | ||
href: this.href, | ||
target: '_blank', | ||
rel: 'noreferrer noopener', | ||
} | ||
return | ||
} | ||
|
||
const appId = match[1] | ||
// Check if specific route was requested | ||
if (match[2]) { | ||
// we do no know anything about app internal path so we only allow generic app paths | ||
this.linkProps = { | ||
href: generateUrl(`/apps/${appId}${match[2]}`), | ||
} | ||
return | ||
} | ||
|
||
// If we know any route for that app we open it | ||
if (appId in knownRoutes) { | ||
this.linkProps = { | ||
href: knownRoutes[appId], | ||
} | ||
return | ||
} | ||
|
||
// Fallback to show the app store entry | ||
this.routerProps = { | ||
to: { | ||
name: 'apps-details', | ||
params: { | ||
category: this.$route.params?.category ?? 'discover', | ||
id: appId, | ||
}, | ||
}, | ||
} | ||
}, | ||
}, | ||
}, | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.