Skip to content

Commit

Permalink
Merge pull request #36450 from nextcloud/fix/clipboard-copy
Browse files Browse the repository at this point in the history
Drop vue-clipboard2 in favour of native Clipboard API to fix copy to clipboard
  • Loading branch information
szaimen authored Feb 2, 2023
2 parents db30974 + edcf675 commit 6f3c4f2
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 52 deletions.
2 changes: 1 addition & 1 deletion apps/files_sharing/src/components/SharingEntryInternal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default {
methods: {
async copyLink() {
try {
await this.$copyText(this.internalLink)
await navigator.clipboard.writeText(this.internalLink)
showSuccess(t('files_sharing', 'Link copied'))
// focus and show the tooltip (note: cannot set ref on NcActionLink)
this.$refs.shareEntrySimple.$refs.actionsComponent.$el.focus()
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/src/components/SharingEntryLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ export default {
},
async copyLink() {
try {
await this.$copyText(this.shareLink)
await navigator.clipboard.writeText(this.shareLink)
showSuccess(t('files_sharing', 'Link copied'))
// focus and show the tooltip
this.$refs.copyButton.$el.focus()
Expand Down
2 changes: 0 additions & 2 deletions apps/files_sharing/src/files_sharing_tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/

import Vue from 'vue'
import VueClipboard from 'vue-clipboard2'
import { translate as t, translatePlural as n } from '@nextcloud/l10n'

import SharingTab from './views/SharingTab.vue'
Expand All @@ -45,7 +44,6 @@ Object.assign(window.OCA.Sharing, { ShareTabSections: new TabSections() })

Vue.prototype.t = t
Vue.prototype.n = n
Vue.use(VueClipboard)

// Init Sharing tab component
const View = Vue.extend(SharingTab)
Expand Down
48 changes: 29 additions & 19 deletions apps/settings/src/components/AuthTokenSetupDialogue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@
class="monospaced"
readonly="readonly"
@focus="selectInput">

<a ref="clipboardButton"
<NcButton type="tertiary"
:title="copyTooltipOptions"
:aria-label="copyTooltipOptions"
v-clipboard:copy="appPassword"
v-clipboard:success="onCopyPassword"
v-clipboard:error="onCopyPasswordFailed"
class="icon icon-clippy"
@mouseover="hoveringCopyButton = true"
@mouseleave="hoveringCopyButton = false" />
@click="copyPassword">
<template #icon>
<Check v-if="copied" :size="20" />
<ContentCopy v-else :size="20" />
</template>
</NcButton>
<NcButton @click="reset">
{{ t('settings', 'Done') }}
</NcButton>
Expand All @@ -85,14 +84,20 @@
import QR from '@chenfengyuan/vue-qrcode'
import { confirmPassword } from '@nextcloud/password-confirmation'
import '@nextcloud/password-confirmation/dist/style.css'
import { showError } from '@nextcloud/dialogs'
import { getRootUrl } from '@nextcloud/router'
import NcButton from '@nextcloud/vue/dist/Components/NcButton'
import Check from 'vue-material-design-icons/Check.vue'
import ContentCopy from 'vue-material-design-icons/ContentCopy.vue'
export default {
name: 'AuthTokenSetupDialogue',
components: {
QR,
Check,
ContentCopy,
NcButton,
QR,
},
props: {
add: {
Expand All @@ -107,15 +112,14 @@ export default {
deviceName: '',
appPassword: '',
loginName: '',
passwordCopied: false,
copied: false,
showQR: false,
qrUrl: '',
hoveringCopyButton: false,
}
},
computed: {
copyTooltipOptions() {
if (this.passwordCopied) {
if (this.copied) {
return t('settings', 'Copied!')
}
return t('settings', 'Copy')
Expand Down Expand Up @@ -150,13 +154,19 @@ export default {
this.reset()
})
},
onCopyPassword() {
this.passwordCopied = true
this.$refs.clipboardButton.blur()
setTimeout(() => { this.passwordCopied = false }, 3000)
},
onCopyPasswordFailed() {
OC.Notification.showTemporary(t('settings', 'Could not copy app password. Please copy it manually.'))
async copyPassword() {
try {
await navigator.clipboard.writeText(this.appPassword)
this.copied = true
} catch (e) {
this.copied = false
console.error(e)
showError(t('settings', 'Could not copy app password. Please copy it manually.'))
} finally {
setTimeout(() => {
this.copied = false
}, 4000)
}
},
reset() {
this.adding = false
Expand Down
2 changes: 0 additions & 2 deletions apps/settings/src/main-personal-security.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@

import { loadState } from '@nextcloud/initial-state'
import Vue from 'vue'
import VueClipboard from 'vue-clipboard2'
import VTooltip from 'v-tooltip'

import AuthTokenSection from './components/AuthTokenSection'

// eslint-disable-next-line camelcase
__webpack_nonce__ = btoa(OC.requestToken)

Vue.use(VueClipboard)
Vue.use(VTooltip, { defaultHtml: false })
Vue.prototype.t = t

Expand Down
4 changes: 2 additions & 2 deletions dist/core-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-common.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files_sharing-files_sharing_tab.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_sharing-files_sharing_tab.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/settings-vue-settings-personal-security.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/settings-vue-settings-personal-security.js.map

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
"v-tooltip": "^2.1.3",
"vue": "^2.7.14",
"vue-click-outside": "^1.1.0",
"vue-clipboard2": "^0.3.3",
"vue-cropperjs": "^4.2.0",
"vue-infinite-loading": "^2.4.5",
"vue-localstorage": "^0.6.2",
Expand Down

0 comments on commit 6f3c4f2

Please sign in to comment.