Files
sspm/src/main.js
T
2024-10-21 10:00:30 -05:00

96 lines
2.0 KiB
JavaScript

// const { app, BrowserWindow, ipcMain } = require('electron');
// const { fromUrl } = require('id3js');
// const path = require('node:path');
import { app, BrowserWindow, ipcMain } from 'electron';
import { fromPath } from 'id3js';
import path from 'node:path';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { readdir, promises } from 'fs';
let win;
const createWindow = () => {
const filename = fileURLToPath(import.meta.url);
win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(dirname(filename), 'preload.js'),
contextIsolation: true
}
});
win.loadFile('src/index.html');
// enable(win.webContents);
};
app.whenReady().then(() => {
// ipcMain.handle('getAudioInfo', function(event, url) {
// let info;
// fromUrl(url).then(function(tags) {
// info = tags;
// }).catch(function(reason) {
// console.log(reason);
// });
// return info;
// });
createWindow();
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0)
createWindow();
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin')
app.quit();
});
ipcMain.handle('readMusicLibrary', function(event, path) {
let files = promises.readdir(path)
.then(function(files) {
if (files) {
return files;
} else {
return -1;
}
})
.catch(err => {
console.log(err);
});
return files;
});
ipcMain.handle('getAudioInfo', function(event, url) {
let id3tags = fromPath(url).then(function(tags) {
return tags;
}).catch(function(reason) {
console.log(reason);
})
return id3tags;
});
// function getAudioInfo(url) {
// let info;
// fromUrl(url).then((tags) => {
// info = tags;
// });
// return info;
// }
// ipcMain.on('A', (event, args) => {
// });