mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-22 09:37:17 +00:00
Add local dir
This commit is contained in:
parent
c8570973b2
commit
98ca95749c
3 changed files with 32 additions and 0 deletions
|
|
@ -2,12 +2,27 @@ type Teardown = (() => void) | { dispose: () => void };
|
|||
|
||||
export default class Disposable {
|
||||
_teardowns: Teardown[] = [];
|
||||
disposed: boolean;
|
||||
|
||||
constructor() {
|
||||
this.disposed = false;
|
||||
}
|
||||
|
||||
add(...teardowns: Teardown[]): void {
|
||||
if (this.disposed) {
|
||||
throw new Error(
|
||||
"Attempted to add a new teardown to a disposed disposable."
|
||||
);
|
||||
}
|
||||
this._teardowns.push(...teardowns);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
if (this.disposed) {
|
||||
throw new Error(
|
||||
"Attempted to dispose disposable which is already disposed."
|
||||
);
|
||||
}
|
||||
this._teardowns.forEach(teardown => {
|
||||
if (typeof teardown === "function") {
|
||||
teardown();
|
||||
|
|
@ -15,5 +30,6 @@ export default class Disposable {
|
|||
teardown.dispose();
|
||||
}
|
||||
});
|
||||
this.disposed = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,12 @@ export function initializePresets(presetOptions: any): Dispatchable {
|
|||
};
|
||||
}
|
||||
|
||||
export function appendPresetFileList(presets: FileList[]): Dispatchable {
|
||||
return async dispatch => {
|
||||
dispatch({ type: GOT_BUTTERCHURN_PRESETS, presets });
|
||||
};
|
||||
}
|
||||
|
||||
export function selectNextPreset(): Dispatchable {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
|
|
|
|||
|
|
@ -161,6 +161,16 @@ class PresetOverlay extends React.Component<Props, State> {
|
|||
}
|
||||
};
|
||||
|
||||
async loadLocalDir() {
|
||||
const fileReferences = await promptForFileReferences({ directory: true });
|
||||
if (this._disposable.disposed) {
|
||||
return;
|
||||
}
|
||||
// TODO: Technically there is a race condition here, since the component
|
||||
// could get unmounted before the promise resolves.
|
||||
this.props.loadPresets(fileReferences);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { height, width } = this.props;
|
||||
if (this.props.presetKeys == null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue