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
16 changes: 7 additions & 9 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@nextcloud/capabilities": "^1.1.0",
"@nextcloud/event-bus": "^3.1.0",
"@nextcloud/l10n": "^2.2.0",
"@nextcloud/vue": "^8.0.0-beta.10",
"@nextcloud/vue": "^8.0.1",
"core-js": "^3.33.2",
"electron-squirrel-startup": "^1.0.0",
"floating-vue": "^1.0.0-beta.19",
Expand Down
199 changes: 199 additions & 0 deletions src/patchers/OC/OcDialogsAdapter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<!--
- @copyright Copyright (c) 2023 Grigorii Shartsev <[email protected]>
-
- @author Grigorii Shartsev <[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>
<div>
<NcDialog v-for="dialog in dialogs"
:key="dialog.id"
:name="dialog.name"
:message="dialog.message"
:buttons="dialog.buttons"
@update:open="deleteDialog(dialog.id)" />
</div>
</template>

<script>
import { translate as t } from '@nextcloud/l10n'
import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js'

const Buttons = {
OK_BUTTONS: (callback) => [
{
label: t('talk_desktop', 'Ok'),
callback: () => callback(),
},
],
YES_NO_BUTTONS: (callback) => [
{
label: t('talk_desktop', 'No'),
callback: () => callback(false),
},
{
label: t('talk_desktop', 'Yes'),
type: 'primary',
callback: () => callback(true),
},
],
}

// Maps server Dialogs constants to Buttons
const OcDialogButtonsENUM = {
70: 'YES_NO_BUTTONS',
71: 'OK_BUTTONS',
}

export default {
name: 'OcDialogsAdapter',

expose: ['info', 'alert', 'confirm', 'confirmDestructive', 'prompt'],

components: {
NcDialog,
},

data() {
return {
dialogs: {},
}
},

methods: {
addDialog(dialogProps) {
const id = Math.random().toString(36).slice(2, 7)
this.$set(this.dialogs, id, {
id,
...dialogProps,
})
},

deleteDialog(id) {
this.$delete(this.dialogs, id)
},

/**
* displays info dialog
* @param {string} text content of dialog
* @param {string} title dialog title
* @param {Function} callback which will be triggered when user presses OK
* @param {boolean} [modal] make the dialog modal
*/
info(text, title, callback, modal) {
// TODO: currently not used in Talk, but should be implemented
// this.message(text, title, 'info', Dialogs.OK_BUTTON, callback, modal)
console.warn('OC.dialogs.info is not implemented in Talk Desktop')
},

/**
* displays alert dialog
* @param {string} text content of dialog
* @param {string} title dialog title
* @param {Function} callback which will be triggered when user presses OK
* @param {boolean} [modal] make the dialog modal
*/
alert(text, title, callback, modal) {
return new Promise((resolve) => {
this.addDialog({
name: title,
message: text,
canClose: !modal,
buttons: Buttons.OK_BUTTONS((result) => {
callback(result)
resolve(result)
}),
})
})
},

/**
* displays confirmation dialog
* @param {string} text content of dialog
* @param {string} title dialog title
* @param {Function} callback which will be triggered when user presses OK (true or false would be passed to callback respectively)
* @param {boolean} [modal] make the dialog modal
* @return {Promise}
*/
confirm(text, title, callback, modal) {
return new Promise((resolve) => {
this.addDialog({
name: title,
message: text,
canClose: !modal,
buttons: Buttons.YES_NO_BUTTONS((result) => {
callback(result)
resolve(result)
}),
})
})
},

/**
* displays confirmation dialog
* @param {string} text content of dialog
* @param {string} title dialog title
* @param {(number|{type: number, confirm: string, cancel: string, confirmClasses: string})} buttons text content of buttons
* @param {Function} callback which will be triggered when user presses OK (true or false would be passed to callback respectively)
* @param {boolean} [modal] make the dialog modal
* @return {Promise}
*/
confirmDestructive(text, title, buttons, callback, modal) {
return new Promise((resolve) => {
const theButtons = (typeof buttons === 'object' && buttons.type === 70)
? (callback) => [{
label: buttons.cancel || t('talk_desktop', 'No'),
callback: () => callback?.(false),
},
{
label: buttons.confirm || t('talk_desktop', 'Yes'),
callback: () => callback?.(true),
type: 'error',
// classes: buttons.confirmClasses,
}]
: Buttons[OcDialogButtonsENUM[buttons]]

this.addDialog({
name: title,
message: text,
canClose: !modal,
buttons: theButtons((result) => {
callback(result)
resolve(result)
}),
})
})
},

/**
* displays prompt dialog
* @param {string} text content of dialog
* @param {string} title dialog title
* @param {Function} callback which will be triggered when user presses OK (true or false would be passed to callback respectively)
* @param {boolean} [modal] make the dialog modal
* @param {string} name name of the input field
* @param {boolean} password whether the input should be a password input
* @return {Promise}
*/
prompt(text, title, callback, modal, name, password) {
// TODO: currently not used in Talk, but should be implemented
console.warn('OC.dialogs.prompt is not implemented in Talk Desktop')
},
},
}
</script>
40 changes: 40 additions & 0 deletions src/patchers/OC/dialogs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* @copyright Copyright (c) 2023 Grigorii Shartsev <[email protected]>
*
* @author Grigorii Shartsev <[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/>.
*/

import Vue from 'vue'

let ocDialogsAdapter = null

document.addEventListener('DOMContentLoaded', async () => {
const { default: OcDialogsAdapter } = await import('./OcDialogsAdapter.vue')

const container = document.body.appendChild(document.createElement('oc-dialog-wrapper'))

ocDialogsAdapter = new Vue(OcDialogsAdapter).$mount(container)
})

export const dialogs = {
YES_NO_BUTTONS: 70,
OK_BUTTONS: 71,
alert: (...args) => ocDialogsAdapter.alert(...args),
confirm: (...args) => ocDialogsAdapter.confirm(...args),
confirmDestructive: (...args) => ocDialogsAdapter.confirmDestructive(...args),
}
13 changes: 2 additions & 11 deletions src/patchers/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import { loadState } from '@nextcloud/initial-state'
import { appData } from '../app/AppData.js'
import { dialogs } from './OC/dialogs.js'

export const OC = {
// Constant from: https://github.com/nextcloud/server/blob/master/core/src/OC/constants.js
Expand Down Expand Up @@ -53,17 +54,7 @@ export const OC = {
modRewriteWorking: false,
},

dialogs: {
confirm(text, title, callback) {
callback(confirm(text))
},
confirmDestructive(text, title, options, callback) {
callback(confirm(text))
},
filepicker() {
alert('Unfortunately, Share from Nextcloud is not supported by Nextcloud Talk Preview')
},
},
dialogs,

theme: {
get productName() {
Expand Down