Skip to content

Commit

Permalink
✨ Improved transitions
Browse files Browse the repository at this point in the history
- Better export
- Audio will not start if error
- Fixed VideoPsalm issue
- Open Cache folder button
- Fixed capitalize with special chars first
- Fixed output paint freeze
- New version
  • Loading branch information
vassbo committed Jun 28, 2024
1 parent 7711870 commit 66bf6aa
Show file tree
Hide file tree
Showing 27 changed files with 244 additions and 101 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "freeshow",
"version": "1.1.8",
"version": "1.1.9",
"private": true,
"main": "build/electron/index.js",
"description": "Show song lyrics and more for free!",
Expand Down
1 change: 1 addition & 0 deletions public/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@
"delete_shows_not_indexed": "Delete shows in 'Shows' folder that are not indexed",
"delete_thumbnail_cache": "Delete thumbnail cache",
"open_log_file": "Open log file",
"open_cache_folder": "Open cache folder",
"refresh_all_shows": "Get all shows in 'Shows' folder",
"start_timer": "Start timer",
"stop_timers": "Stop active timers",
Expand Down
40 changes: 34 additions & 6 deletions src/electron/data/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import fs from "fs"
import { join } from "path"
import { EXPORT, MAIN, STARTUP } from "../../types/Channels"
import { isProd, toApp } from "../index"
import { dataFolderNames, doesPathExist, getDataFolder, openSystemFolder, selectFolderDialog } from "../utils/files"
import { dataFolderNames, doesPathExist, getDataFolder, openSystemFolder, parseShow, readFile, selectFolderDialog } from "../utils/files"
import { exportOptions } from "../utils/windowOptions"
import { Message } from "../../types/Socket"
import { getAllShows } from "../utils/responses"

// SHOW: .show, PROJECT: .project, BIBLE: .fsb
const customJSONExtensions: any = {
Expand All @@ -35,6 +36,11 @@ export function startExport(_e: any, msg: Message) {
return
}

if (msg.channel === "ALL_SHOWS") {
exportAllShows(msg.data)
return
}

if (msg.channel !== "GENERATE") return

if (msg.data.type === "pdf") createPDFWindow(msg.data)
Expand All @@ -44,16 +50,16 @@ export function startExport(_e: any, msg: Message) {

// only open once per session
let systemOpened: boolean = false
function doneWritingFile(err: any, exportFolder: string) {
function doneWritingFile(err: any, exportFolder: string, toMain: boolean = true) {
let msg: string = "export.exported"

// open export location in system when completed
if (!err && !systemOpened) {
openSystemFolder(exportFolder)
systemOpened = true
} else msg = err
} else if (err) msg = err

toApp(MAIN, { channel: "ALERT", data: msg })
if (toMain) toApp(MAIN, { channel: "ALERT", data: msg })
}

// ----- PDF -----
Expand Down Expand Up @@ -118,8 +124,8 @@ export function exportJSON(content: any, extension: string, path: string) {
// ----- TXT -----

export function exportTXT(data: any) {
data.shows.forEach((show: any) => {
writeFile(join(data.path, show.name), ".txt", getSlidesText(show), "utf-8", (err: any) => doneWritingFile(err, data.path))
data.shows.forEach((show: any, i: number) => {
writeFile(join(data.path, show.name), ".txt", getSlidesText(show), "utf-8", (err: any) => doneWritingFile(err, data.path, i >= data.shows.length - 1))
})
}

Expand Down Expand Up @@ -168,6 +174,28 @@ function getSlidesText(show: any) {
return text.trim()
}

// ----- ALL SHOWS -----

function exportAllShows(data: any) {
let type = data.type || "txt"

if (type !== "txt") return

let allShows: string[] = getAllShows({ path: data.showsPath })
let shows: any[] = []
for (let i = 0; i < allShows.length; i++) {
const showName: string = allShows[i]
const showFilePath = join(data.showsPath, showName)
// WIP override existing instead of creating new?
const showContent: any = parseShow(readFile(showFilePath))

if (showContent?.[1]) shows.push(showContent[1])
}

if (shows.length) exportTXT({ ...data, shows })
else toApp(MAIN, { channel: "ALERT", data: "Exported 0 shows!" })
}

// ----- PROJECT -----

export function exportProject(data: any) {
Expand Down
2 changes: 1 addition & 1 deletion src/electron/data/thumbnails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function generateThumbnail(data: Thumbnail) {
}

let thumbnailFolderPath: string = ""
function getThumbnailFolderPath() {
export function getThumbnailFolderPath() {
if (thumbnailFolderPath) return thumbnailFolderPath

let p: string = path.join(app.getPath("temp"), "freeshow-cache")
Expand Down
3 changes: 2 additions & 1 deletion src/electron/utils/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { restoreFiles } from "../data/backup"
import { downloadMedia } from "../data/downloadMedia"
import { importShow } from "../data/import"
import { error_log } from "../data/store"
import { getThumbnail, saveImage } from "../data/thumbnails"
import { getThumbnail, getThumbnailFolderPath, saveImage } from "../data/thumbnails"
import { outputWindows } from "../output/output"
import { closeServers, startServers } from "../servers"
import { Message } from "./../../types/Socket"
Expand Down Expand Up @@ -107,6 +107,7 @@ const mainResponses: any = {
DATA_PATH: (): string => getDocumentsFolder(null, ""),
LOG_ERROR: (data: any) => logError(data),
OPEN_LOG: () => openSystemFolder(error_log.path),
OPEN_CACHE: () => openSystemFolder(getThumbnailFolderPath()),
// SHOWS
DELETE_SHOWS: (data: any) => deleteShowsNotIndexed(data),
REFRESH_SHOWS: (data: any) => refreshAllShows(data),
Expand Down
6 changes: 5 additions & 1 deletion src/frontend/components/context/menuClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ const actions: any = {
save: () => save(),
import: () => activePopup.set("import"),
export_more: () => activePopup.set("export"),
settings: () => activePage.set("settings"),
settings: () => {
if (get(activePage) === "stage") settingsTab.set("connection")
else if (get(activePage) === "settings") settingsTab.set("general")
activePage.set("settings")
},
quit: () => {
if (get(saved)) send(MAIN, ["CLOSE"])
else activePopup.set("unsaved")
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/draw/Paint.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
export let settings: any = {}
$: currentOutput = $outputs[getActiveOutputs()[0]]
$: currentOutput = $outputs[getActiveOutputs()[0]] || {}
$: currentLayout = currentOutput.out?.slide ? _show(currentOutput.out.slide.id).layouts([currentOutput.out.slide.layout]).ref()[0] : []
$: currentSlide = currentOutput.out?.slide ? (currentOutput.out.slide.id === "temp" ? { items: currentOutput.out.slide.tempItems } : _show(currentOutput.out.slide.id).slides([currentLayout![currentOutput.out.slide.index!].id]).get()[0]) : null
$: resolution = getResolution(currentSlide?.settings?.resolution, { $outputs, $styles })
Expand Down
1 change: 0 additions & 1 deletion src/frontend/components/drawer/bible/Scripture.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
let chapterId: any = cachedRef?.chapterId ?? "GEN.1"
let activeVerses: string[] = cachedRef?.activeVerses || ["1"]
$: console.log(verses, bibles)
$: if (bookId || chapterId || verses || activeVerses) updateActive()
function updateActive() {
if (!loaded) return
Expand Down
9 changes: 9 additions & 0 deletions src/frontend/components/drawer/bible/scripture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { clone, removeDuplicates } from "../../helpers/array"

const api = "https://api.scripture.api.bible/v1/bibles/"
let tempCache: any = {}
let fetchTimeout: any = null
export async function fetchBible(load: string, active: string, ref: any = { versesList: [], bookId: "GEN", chapterId: "GEN.1" }) {
let versesId: any = null
if (ref.versesList.length) {
Expand All @@ -22,19 +23,27 @@ export async function fetchBible(load: string, active: string, ref: any = { vers
versesText: `${api}${active}/verses/${versesId}`,
}

if (fetchTimeout) clearTimeout(fetchTimeout)
if (tempCache[urls[load]]) return tempCache[urls[load]]

return new Promise((resolve, reject) => {
if (!get(bibleApiKey)) return reject("No API key!")
if (urls[load].includes("null")) return reject("Something went wrong!")

fetchTimeout = setTimeout(() => {
// WIP display error messages...
reject("Timed out!")
}, 10000)

fetch(urls[load], { headers: { "api-key": get(bibleApiKey) } })
.then((response) => response.json())
.then((data) => {
tempCache[urls[load]] = data.data
clearTimeout(fetchTimeout)
resolve(data.data)
})
.catch((e) => {
clearTimeout(fetchTimeout)
reject(e)
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/drawer/live/NDIStreams.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let sources: any[] = []
$: currentOutput = $outputs[getActiveOutputs()[0]]
$: currentOutput = $outputs[getActiveOutputs()[0]] || {}
const receiveNDI: any = {
RECEIVE_LIST: (msg) => {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/drawer/live/Screens.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
receive(MAIN, { GET_SCREENS: (d: any) => (screens = d) }, "GET_SCREENS")
onDestroy(() => destroy(MAIN, "GET_SCREENS"))
$: currentOutput = $outputs[getActiveOutputs()[0]]
$: currentOutput = $outputs[getActiveOutputs()[0]] || {}
$: console.log(screens)
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/drawer/live/Windows.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
if (searchValue.length > 1) fullFilteredWindows = fullFilteredWindows.filter((a) => filter(a.name).includes(searchValue))
}
$: currentOutput = $outputs[getActiveOutputs()[0]]
$: currentOutput = $outputs[getActiveOutputs()[0]] || {}
</script>

{#if fullFilteredWindows.length}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/drawer/media/Media.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
zoomOpened = false
}
$: currentOutput = $outputs[getActiveOutputs()[0]]
$: currentOutput = $outputs[getActiveOutputs()[0]] || {}
// select all
$: if ($selectAllMedia) selectAll()
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/edit/MediaTools.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
updateStore("media", { keys: [mediaId, input.id], value })
// update output filters
let currentOutput: any = $outputs[getActiveOutputs()[0]]
let currentOutput: any = $outputs[getActiveOutputs()[0]] || {}
if (!currentOutput.out?.background || currentOutput.out?.background?.path !== mediaId) return
let bg = currentOutput.out.background
Expand Down
15 changes: 13 additions & 2 deletions src/frontend/components/helpers/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,20 @@ export async function playAudio({ path, name = "", audio = null, stream = null }
}

if (startAt > 0) audio.currentTime = startAt
audio.play()

analyseAudio()
audio.addEventListener("error", (err) => {
console.error("Could not get audio:", err)

playingAudio.update((a) => {
delete a[path]
return a
})
})

audio.addEventListener("canplay", () => {
audio.play()
analyseAudio()
})
}

// if no "path" is provided it will fade out/clear all audio
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/components/helpers/showActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export function nextSlide(e: any, start: boolean = false, end: boolean = false,
if (document.activeElement instanceof window.HTMLElement) document.activeElement.blur()

let outputId = customOutputId || getActiveOutputs()[0]
let currentOutput: any = get(outputs)[outputId]
let currentOutput: any = get(outputs)[outputId] || {}
let slide: null | OutSlide = currentOutput.out?.slide || null

// let layout: SlideData[] = GetLayout(slide ? slide.id : null, slide ? slide.layout : null)
Expand Down Expand Up @@ -264,7 +264,7 @@ export function previousSlide(e: any) {
if (get(outLocked)) return
if (document.activeElement instanceof window.HTMLElement) document.activeElement.blur()

let currentOutput: any = get(outputs)[getActiveOutputs()[0]]
let currentOutput: any = get(outputs)[getActiveOutputs()[0]] || {}
let slide: null | OutSlide = currentOutput.out?.slide || null
// let layout: SlideData[] = GetLayout(slide ? slide.id : null, slide ? slide.layout : null)
let layout: any[] = _show(slide ? slide.id : "active")
Expand Down Expand Up @@ -325,7 +325,7 @@ function getNextEnabled(index: null | number, end: boolean = false): null | numb

index++

let currentOutput: any = get(outputs)[getActiveOutputs()[0]]
let currentOutput: any = get(outputs)[getActiveOutputs()[0]] || {}
let slide: null | OutSlide = currentOutput.out?.slide || null
let layout: any[] = _show(slide ? slide.id : "active")
.layouts(slide ? [slide.layout] : "active")
Expand All @@ -351,7 +351,7 @@ export function randomSlide() {
if (document.activeElement instanceof window.HTMLElement) document.activeElement.blur()

let outputId = getActiveOutputs()[0]
let currentOutput: any = get(outputs)[outputId]
let currentOutput: any = get(outputs)[outputId] || {}
let slide: null | OutSlide = currentOutput.out?.slide || null
let showId = slide?.id || get(activeShow)?.id
if (!showId) return
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/components/inputs/ShowButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
function doubleClick(e: any) {
if (editActive || $outLocked || e.target.closest("input")) return
let currentOutput: any = getActiveOutputs()[0]
let currentOutput: any = getActiveOutputs()[0] || {}
let slide: any = currentOutput.out?.slide || null
if (type === "show" && $showsCache[id] && $showsCache[id].layouts[$showsCache[id].settings.activeLayout].slides.length) {
Expand Down
42 changes: 27 additions & 15 deletions src/frontend/components/main/popups/Export.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { EXPORT } from "../../../../types/Channels"
import type { Project } from "../../../../types/Projects"
import { activePopup, activeProject, activeShow, dataPath, os, projects, selected, showsCache, shows as showsList } from "../../../stores"
import { activePopup, activeProject, activeShow, dataPath, os, projects, selected, showsCache, showsPath } from "../../../stores"
import { newToast } from "../../../utils/common"
import { send } from "../../../utils/request"
import Pdf from "../../export/Pdf.svelte"
Expand Down Expand Up @@ -32,13 +32,12 @@
return $selected.data.map(({ id }) => ({ id, ...$showsCache[id] }))
},
all_shows: () => {
let allShows: any[] = []
console.log($showsCache)
Object.entries($showsCache).forEach(([id, show]) => {
allShows.push({ id, ...show })
})
return allShows
// let allShows: any[] = []
// console.log($showsCache)
// Object.entries($showsCache).forEach(([id, show]) => {
// allShows.push({ id, ...show })
// })
// return allShows
},
}
Expand All @@ -55,14 +54,17 @@
let loading: boolean = false
async function getShowsToExport() {
shows = []
loading = true
if (what.id === "project" && $activeProject) await loadShows($projects[$activeProject].shows.filter(({ type }) => type === undefined || type === "show").map(({ id }) => id))
else if (what.id === "selected_shows") await loadShows($selected.data.map(({ id }) => id))
else if (what.id === "all_shows") {
loading = true
// WIP progress meter & faster loading
await loadShows(Object.keys($showsList))
loading = false
format.id = "txt"
}
loading = false
if (what.id === "all_shows") return
shows = getShows[what.id]()
}
Expand Down Expand Up @@ -104,6 +106,12 @@
return
}
if (what.id === "all_shows") {
loading = true
send(EXPORT, ["ALL_SHOWS"], { type: "txt", path: $dataPath, showsPath: $showsPath })
return
}
if (format.id === "project") {
let project: Project | null = what.id === "project" && $activeProject ? $projects[$activeProject] : null
if (!project) {
Expand All @@ -129,7 +137,11 @@
<p style="white-space: break-spaces;"><T id="export.export_as" /></p>
<Dropdown style="min-width: 200px;" options={whats} value={what.name} on:click={(e) => (what = e.detail)} />
<p style="white-space: break-spaces;"><T id="export.export_as" index={1} />&nbsp;</p>
<Dropdown style="min-width: 200px;" options={formats} value={format.name} on:click={(e) => (format = e.detail)} />
{#if what.id === "all_shows"}
TXT
{:else}
<Dropdown style="min-width: 200px;" options={formats} value={format.name} on:click={(e) => (format = e.detail)} />
{/if}
</div>

<hr />
Expand Down Expand Up @@ -246,7 +258,7 @@
{/if}

{#if loading}
<Center>
<Center padding={10}>
<Loader />
</Center>
{/if}
Expand All @@ -270,7 +282,7 @@
</span>
{/if} -->

<Button style="margin-top: 10px;" disabled={!shows.length} on:click={exportClick} center dark>
<Button style="margin-top: 10px;" disabled={!shows.length && what.id !== "all_shows"} on:click={exportClick} center dark>
<Icon id="export" size={1.2} right />
<T id="export.export" />
{#if shows.length > 1 && format.id !== "project"}
Expand Down
Loading

0 comments on commit 66bf6aa

Please sign in to comment.