Skip to content

Commit

Permalink
fix: error on xml open dialog cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
rzuppur committed Oct 21, 2022
1 parent c88baf2 commit 14e0ac8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function handleFileOpen(event: IpcMainInvokeEvent) {
filters: [{name: 'XML Files', extensions: ['xml']}],
});
if (canceled) {
return;
return { xml: null, path: '', cancelled: true };
} else {
const path = filePaths[0];
const fileContents = await promises.readFile(path, 'utf-8');
Expand Down
2 changes: 1 addition & 1 deletion packages/preload/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {Collection} from '../../renderer/src/model';
export {versions} from './versions';
const {ipcRenderer} = require('electron');

export function openXML(): Promise<{xml: Collection; path: string}> {
export function openXML(): Promise<{xml: Collection; path: string, cancelled?: boolean}> {
return ipcRenderer.invoke('dialog:openFile');
}

Expand Down
22 changes: 13 additions & 9 deletions packages/renderer/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ const getTracks = (list: (Playlist | Folder)[]): string[] => {
const actionOpenXML = async () => {
collectionLoading.value = true;
const {xml: collection, path} = await openXML();
if (collection) {
try {
try {
const {xml: collection, path, cancelled} = await openXML();
if (cancelled) {
resetCollection();
return;
}
if (collection) {
collectionVersion.value = collection.DJ_PLAYLISTS.PRODUCT[0].$.Version;
collectionTracks.value = collection.DJ_PLAYLISTS.COLLECTION[0].TRACK.map(t => t.$);
Expand Down Expand Up @@ -101,14 +105,14 @@ const actionOpenXML = async () => {
collectionLoaded.value = true;
errorText.value = '';
collectionFilePath.value = path;
} catch (e) {
console.error(e);
toast('' + e);
errorText.value = 'Error reading the file, make sure you followed the instructions above.';
} else {
errorText.value = 'Something went wrong';
resetCollection();
}
} else {
errorText.value = 'Something went wrong';
} catch (e) {
console.error(e);
toast('' + e);
errorText.value = 'Error reading the file, make sure you followed the instructions above.';
resetCollection();
}
};
Expand Down

0 comments on commit 14e0ac8

Please sign in to comment.