Thanks to visit codestin.com
Credit goes to github.com

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
Binary file modified Songs.db
Binary file not shown.
12 changes: 10 additions & 2 deletions app/main/main.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
const { app, BrowserWindow } = require('electron')
const path = require('path');
const database = require('../../db/database')
const { setupIpcHandlers } = require("./mainIpcHandlers.js")
const { setupIpcHandlers, sendConfig } = require("./mainIpcHandlers.js")
const { createMainWindow } = require("./windowManager/mainWindow.js");




async function setup_app(){

db = database.ConnectDatabase()
const win = createMainWindow()

await database.Config(db)

//win.hide()

setupIpcHandlers(db)
var path_to_index = path.join(__dirname,"../renderer/mainWindow/pages/mainWindow.html")
win.loadFile(path_to_index)
Expand All @@ -21,6 +23,12 @@ async function setup_app(){
console.log("CLOSED")
})

win.on("ready-to-show",()=>{
win.show()

})



}

Expand Down
24 changes: 24 additions & 0 deletions app/main/mainIpcHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@ const { ipcMain, screen, dialog } = require('electron')
const database = require('../../db/database')
const displayWind = require("./windowManager/displayWindow")
const fs = require("fs")
const path = require('path')


const configFilePath = path.join(process.cwd(),"config.json")

function getConfig(win){

var data = fs.readFileSync(configFilePath,"utf-8")
return data

}

function setupIpcHandlers(db){


ipcMain.on("getSongsPreview",(Event,categoryName)=>{
database.getSongsPreview(Event,categoryName,db)
console.debug("getSongsPreview: IPC")
Expand Down Expand Up @@ -61,6 +72,19 @@ function setupIpcHandlers(db){
database.createSong(Event,values,db)
console.debug("createSong: IPC")
})

ipcMain.on("saveConfig",(Event,values)=>{
if (Object.keys(values).length == 0){
return
}
fs.writeFileSync(configFilePath,JSON.stringify(values))

Event.returnValue = true
})
ipcMain.on("getConfig",(Event)=>{

Event.returnValue = getConfig()
})

}

Expand Down
5 changes: 3 additions & 2 deletions app/main/preloads/mainWindowPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ contextBridge.exposeInMainWorld("electronAPI", {
writeToDisplayWindow: (id,data)=> ipcRenderer.sendSync("writeToDisplayWindow",id,data),
getAllDisplays: ()=> ipcRenderer.sendSync("getAllDisplays"),
openFileDialog: (properties) => ipcRenderer.sendSync("openFileDialog",properties),
createSong: (values)=> ipcRenderer.sendSync("createSong",values)

createSong: (values)=> ipcRenderer.sendSync("createSong",values),
saveConfig: (values)=> ipcRenderer.sendSync("saveConfig",values),
getConfig: ()=> ipcRenderer.sendSync("getConfig")
})
7 changes: 6 additions & 1 deletion app/main/windowManager/mainWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ function createMainWindow(){
autoHideMenuBar: true,
webPreferences: {
preload: path.join(__dirname, '../preloads/mainWindowPreload.js')
}
},
show: false

})
win.maximize()
win.show()

var path_to_loading = path.join(__dirname,"../../renderer/mainWindow/pages/loading.html")
win.loadFile(path_to_loading)

return win
}

Expand Down
46 changes: 26 additions & 20 deletions app/renderer/mainWindow/dom/editor/editorEventHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,30 @@ function handleZwrotkaTextAddButtonEvent(event){
}


function setupEditorEventHandlers(){
document.getElementById("editorSaveButton").addEventListener("click",editorSaveButton_click_event)
document.getElementById("editorCreateButton").addEventListener("click",editorCreateButton_click_event)
document.getElementById("returnIndexButton").addEventListener("click",handleReturnIndexButtonClickEvent)
document.getElementById("txtFileLoadButton").addEventListener("click",handleTxtFileLoadButtonClickEvent)
document.getElementById("jsonFileLoadButton").addEventListener("click",handleJsonFileLoadButtonClickEvent)
document.getElementById("undoButton").addEventListener("click",handleUndoButtonClickEvent)
document.getElementById("redoButton").addEventListener("click",handleRedoButtonClickEvent)
document.getElementById("addZwrotka").addEventListener("click",handleZwrotkaTextAddButtonEvent)
document.getElementById("addRefren").addEventListener("click",handleRefrenTextAddButtonEvent)

document.getElementById("textEditingArea").addEventListener("paste", function(e) {
// cancel paste
e.preventDefault();

// get text representation of clipboard
var text = (e.originalEvent || e).clipboardData.getData('text');

// insert text manually
document.execCommand("insertHTML", false, text.replace(/\n/g,'<br>'));
});
}

export {
setupEditorEventHandlers
}

document.getElementById("editorSaveButton").addEventListener("click",editorSaveButton_click_event)
document.getElementById("editorCreateButton").addEventListener("click",editorCreateButton_click_event)
document.getElementById("returnIndexButton").addEventListener("click",handleReturnIndexButtonClickEvent)
document.getElementById("txtFileLoadButton").addEventListener("click",handleTxtFileLoadButtonClickEvent)
document.getElementById("jsonFileLoadButton").addEventListener("click",handleJsonFileLoadButtonClickEvent)
document.getElementById("undoButton").addEventListener("click",handleUndoButtonClickEvent)
document.getElementById("redoButton").addEventListener("click",handleRedoButtonClickEvent)
document.getElementById("addZwrotka").addEventListener("click",handleZwrotkaTextAddButtonEvent)
document.getElementById("addRefren").addEventListener("click",handleRefrenTextAddButtonEvent)

document.getElementById("textEditingArea").addEventListener("paste", function(e) {
// cancel paste
e.preventDefault();

// get text representation of clipboard
var text = (e.originalEvent || e).clipboardData.getData('text');

// insert text manually
document.execCommand("insertHTML", false, text.replace(/\n/g,'<br>'));
});
31 changes: 15 additions & 16 deletions app/renderer/mainWindow/dom/index/elementConstructors.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {
add_playlistRecord_click_event,
add_playlistRecord_button_click_event,
add_db_record_button_click_event,
add_verseBox_click_event,
add_categoryRecord_click_event,
add_editor_button_click_event
add_categoryRecord_events,
add_playlistRecord_events,
add_dbRecord_events,
add_verseBox_events

} from "./indexEventHandlers.js"

function construct_verse(verse) {
Expand All @@ -15,7 +14,8 @@ function construct_verse(verse) {
p_tag.innerText = verse

box.appendChild(p_tag)
add_verseBox_click_event(box)

add_verseBox_events(box)
return box
}

Expand Down Expand Up @@ -53,15 +53,13 @@ function construct_db_record(element) {
editorButton.classList.add("dbRecordEditorButton")
editorButton.classList.add("dbRecordButton")

add_editor_button_click_event(editorButton)
add_db_record_button_click_event(dbButton)

buttonHolder.appendChild(dbButton)
buttonHolder.appendChild(editorButton)

dbRecord.appendChild(title_p)
dbRecord.appendChild(buttonHolder)

add_dbRecord_events(dbRecord)

return dbRecord
}
Expand All @@ -70,13 +68,15 @@ function construct_category_record(element) {
categoryRecord.classList.add("categoryRecord")

categoryRecord.classList.add("categoryRecord")
categoryRecord.setAttribute("data-category", element["category"])

var title_p = document.createElement("p")

title_p.textContent = element["category"]
title_p.textContent = element["category"].toUpperCase()

categoryRecord.appendChild(title_p)
add_categoryRecord_click_event(categoryRecord)

add_categoryRecord_events(categoryRecord)

return categoryRecord
}
Expand Down Expand Up @@ -130,15 +130,14 @@ function construct_playlist_record(dbRecord) {
playlistRecordButton.classList.add("playlistRecordButton")


add_editor_button_click_event(editorButton)
add_playlistRecord_button_click_event(playlistRecordButton)

buttonHolder.appendChild(editorButton)
buttonHolder.appendChild(playlistRecordButton)
playlistRecord.append(textHolder)
playlistRecord.append(buttonHolder)

add_playlistRecord_click_event(playlistRecord)
playlistRecord.setAttribute("draggable","true")

add_playlistRecord_events(playlistRecord)

return playlistRecord

Expand Down
17 changes: 13 additions & 4 deletions app/renderer/mainWindow/dom/index/elementUpdaters.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,25 @@ function updatePlayView(song){

var ind = 0
console.log(song.chorus)
var mainIndex = Object.keys(song.chorus)[0]
var chorusMainText = song.chorus[mainIndex]
if (Object.keys(song.chorus).length != 0){
var mainIndex = Object.keys(song.chorus)[0]
var chorusMainText = song.chorus[mainIndex]
}
else {
var mainIndex = -1
var chorusMainText = ""
}



console.log(chorusMainText)
song.lyrics.push(" ") // w celu space takera
for (var verse of song.lyrics){
if (String(ind) in song.chorus && song.chorus[String(ind)] != ""){
if (String(ind) in song.chorus && song.chorus[String(ind)] != "" && verse){
var chorusElement = construct_verse(song.chorus[String(ind)])
playview.appendChild(chorusElement)
}
else if (chorusMainText && ind >= mainIndex){
else if (chorusMainText && ind >= mainIndex && verse){
var chorusElement = construct_verse(chorusMainText)
playview.appendChild(chorusElement)
}
Expand Down
Loading