Skip to content

Commit

Permalink
Work around file/folder dialogs not working on NC 27.1.0 and 27.1.1
Browse files Browse the repository at this point in the history
In the mentioned NC versions, the legacy filepicker API doesn't work
without passing the dialog type (choose/copy/move/copy-and-move)
explicitly while the "choose" has previously been the default type.
This is supposed to get fixed in NC 27.1.2. In the meantime, we may
pass the type "choose" explicitly.

All the access to the OC filepicker API now happens through our own
wrapper class. This should make our life easier if the deprecated
legacy API gets removed for good at some point.

refs owncloud#1091
  • Loading branch information
paulijar committed Sep 27, 2023
1 parent c453851 commit 5fdc64f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 36 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
[#1071](https://github.com/owncloud/music/issues/1071)
- Scanning breaking if any out-of-bounds numeric value gets scanned from any audio file
[#1073](https://github.com/owncloud/music/issues/1073)
- File and folder selection dialogs not working on NC 27.1.0 and 27.1.1 (workaround for a NC bug which should get fixed in NC 27.1.2)
[#1091](https://github.com/owncloud/music/issues/1091)

## 1.8.4 - 2023-06-06
### Added
Expand Down
26 changes: 2 additions & 24 deletions js/app/controllers/views/settingsviewcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,8 @@ angular.module('Music').controller('SettingsViewController', [
_.each(unsubFuncs, function(func) { func(); });
});

function folderPicker(title, callback, path = '') {
// The filepicker interface wants to get the initial path without a trailing slash
if (path.endsWith('/')) {
path = path.slice(0, -1);
}

OC.dialogs.filepicker(
title,
function (selectedPath) {
if (!selectedPath.endsWith('/')) {
selectedPath = selectedPath + '/';
}
callback(selectedPath);
},
false, // multiselect
'httpd/unix-directory',
true, // modal
undefined, // type (only on NC, use default)
path // initial folder, only on NC16+
);
}

$scope.selectPath = function() {
folderPicker(
OCA.Music.Dialogs.folderPicker(
gettextCatalog.getString('Path to your music collection'),
function (path) {
if ($scope.settings.path !== path) {
Expand Down Expand Up @@ -93,7 +71,7 @@ angular.module('Music').controller('SettingsViewController', [
};

$scope.selectExcludedPath = function(index) {
folderPicker(
OCA.Music.Dialogs.folderPicker(
gettextCatalog.getString('Path to exclude from your music collection'),
function (path) {
$scope.settings.excludedPaths[index] = path;
Expand Down
16 changes: 4 additions & 12 deletions js/app/services/playlistfileservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,14 @@ function($rootScope : MusicRootScope, $q : ng.IQService, libraryService : Librar
}

function showFolderPicker(caption : string, onSelectedCallback : CallableFunction) : void {
OC.dialogs.filepicker(
caption,
(datapath : string, _returnType : any) => onSelectedCallback(datapath), // arg _returnType is passed by NC but not by OC
false, // <! multiselect
'httpd/unix-directory',
true // <! modal
);
OCA.Music.Dialogs.folderPicker(caption, onSelectedCallback);
}

function showPlaylistFilePicker(caption : string, onSelectedCallback : CallableFunction) : void {
OC.dialogs.filepicker(
OCA.Music.Dialogs.filePicker(
caption,
(datapath : string, _returnType : any) => onSelectedCallback(datapath), // arg _returnType is passed by NC but not by OC
false, // <! multiselect
['audio/mpegurl', 'audio/x-scpls'],
true // <! modal
onSelectedCallback,
['audio/mpegurl', 'audio/x-scpls']
);
}

Expand Down
50 changes: 50 additions & 0 deletions js/shared/dialogs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* ownCloud - Music app
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Pauli Järvinen <pauli.jarvinen@gmail.com>
* @copyright Pauli Järvinen 2023
*/

OCA.Music = OCA.Music || {};

/** @namespace
*
* Wrapper for dialogs provided by the host cloud. Provide a bit more concise interface
* and hide any differences between the supported cloud versions.
*/
OCA.Music.Dialogs = class {

static filePicker(title : string, callback : CallableFunction, mimetype : string|string[], path : string|undefined = undefined) {
// The filepicker interface wants to get the initial path without a trailing slash
if (path?.endsWith('/')) {
path = path.slice(0, -1);
}

OC.dialogs.filepicker(
title,
(datapath : string, _returnType : any) => callback(datapath), // arg _returnType is passed by NC but not by OC
false, // multiselect
mimetype,
true, // modal
OC.dialogs.FILEPICKER_TYPE_CHOOSE, // type (only on NC)
path // initial folder, only on NC16+
);
}

static folderPicker(title : string, callback : CallableFunction, path = '') {
OCA.Music.Dialogs.filePicker(
title,
(selectedPath : string) => {
if (!selectedPath.endsWith('/')) {
selectedPath = selectedPath + '/';
}
callback(selectedPath);
},
'httpd/unix-directory',
path // initial folder, only on NC16+
);
}
};

0 comments on commit 5fdc64f

Please sign in to comment.