Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge pull request #60 from ACC-Hymns/staging #185

Merged
merged 10 commits into from
Jul 8, 2024
4 changes: 1 addition & 3 deletions ios/App/App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
<array/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down
15 changes: 0 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "acchymnal",
"version": "3.0.0",
"version": "3.0.1",
"private": true,
"scripts": {
"postinstall": "patch-package",
Expand Down
10 changes: 5 additions & 5 deletions public/books/HG/summary.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": {
"short": "HG",
"medium": "Higher Ground",
"long": "Higher Ground"
"medium": "Camp Book",
"long": "Camp Book"
},
"primaryColor": "#FBBC13",
"secondaryColor": "#BD772A",
"primaryColor": "#FFD35D",
"secondaryColor": "#DB8223",
"fileExtension": "pdf",
"addOn": false,
"addOn": true,
"indexAvailable": true
}
73 changes: 72 additions & 1 deletion src/scripts/book_import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Directory, Encoding, Filesystem } from "@capacitor/filesystem";
import type { DownloadFileResult, FileInfo } from "@capacitor/filesystem";
import { Capacitor } from "@capacitor/core";
import { Network } from "@capacitor/network";
import { useCapacitorPreferences } from "@/composables/preferences";
import router from "@/router";

async function getBookUrls() {
const book_sources_raw = await Preferences.get({ key: "bookSources" });
Expand Down Expand Up @@ -297,6 +299,75 @@ async function collect_signatures(start: BookSignature) {
return hashes;
}

const book_sources = useCapacitorPreferences<BookDataSummary[]>("bookSources", []);
async function handle_missing_book(book_short: string) {
if(book_sources.value.length == 0) {
book_sources.value = await loadBookSources();
}

await addImportedBookByCode(book_short)
async function addImportedBookByCode(short_book_name: string) {
if (short_book_name in known_references) {
const to_import = book_sources.value.find(b => b.id == short_book_name);
if(to_import == undefined)
return;

// Check for duplicate url
if (to_import.status == BookSourceType.IMPORTED || to_import.status == BookSourceType.DOWNLOADED) {
return;
} else {
if (await addImportedURL(to_import, false)) {
router.go(0);
}
}
}
}

async function addImportedURL(input_book: BookDataSummary, show_on_success: boolean = true): Promise<boolean> {
let book = book_sources.value.find(b => b.id == input_book.id);
if(book == undefined)
return false;

let connection = (await Network.getStatus()).connected
if(connection) {
if(Capacitor.getPlatform() !== 'web')
await download_import_summary(book);
}
else {
return false;
}

let resp: Response | null = null;
try {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), 2000);
resp = await fetch(book.src + "/summary.json", {
method: "HEAD",
signal: controller.signal,
});
clearTimeout(id);
} catch (e: any) {
if (e.name == "TypeError") {
return false;
}
if (e.name != "AbortError") {
throw e;
}
}

if (resp == null || !resp.ok || resp.status != 200) {
return false;
}

if (book.status != BookSourceType.IMPORTED) {
book.status = BookSourceType.IMPORTED;
return true;
} else {
return false;
}
}
}

async function generate_force_update_package() {
let update_packages: UpdatePackage[] = [];
let local_hashes: BookSignature[] = await (await fetch(import.meta.env.BASE_URL + `book_signatures.json`)).json();
Expand Down Expand Up @@ -614,4 +685,4 @@ async function getBookIndex(book_short_name: string): Promise<BookIndex | null>
return null;
}

export { generate_force_update_package, download_update_package, getBookFromId, getBookDataSummaryFromName, getBookDataSummary, loadBookSources, download_book, getBookUrls, fetchBookSummary, getAllBookMetaData, getAllSongMetaData, getSongMetaData, getBookIndex, checkForUpdates, delete_import_summary, download_import_summary };
export { handle_missing_book, generate_force_update_package, download_update_package, getBookFromId, getBookDataSummaryFromName, getBookDataSummary, loadBookSources, download_book, getBookUrls, fetchBookSummary, getAllBookMetaData, getAllSongMetaData, getSongMetaData, getBookIndex, checkForUpdates, delete_import_summary, download_import_summary };
3 changes: 2 additions & 1 deletion src/scripts/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const prepackaged_books = ["ZH", "GH", "JH", "HG"];
const prepackaged_books = ["ZH", "GH", "JH"];
const prepackaged_book_urls: string[] = prepackaged_books.map(book_name => import.meta.env.BASE_URL + "books/" + book_name);

const branch: string = import.meta.env.VITE_GIT_BRANCH;
Expand All @@ -12,6 +12,7 @@ const branch: string = import.meta.env.VITE_GIT_BRANCH;
// }

const public_references = {
HG: `https://raw.githubusercontent.com/ACC-Hymns/acchymns-web/${branch}/public/books/HG`,
CH: `https://raw.githubusercontent.com/ACC-Hymns/acchymns-web/${branch}/public/books/CH`,
HSZ: `https://raw.githubusercontent.com/ACC-Hymns/acchymns-web/${branch}/public/books/HSZ`,
HZ: `https://raw.githubusercontent.com/ACC-Hymns/acchymns-web/${branch}/public/books/HZ`,
Expand Down
2 changes: 1 addition & 1 deletion src/views/SettingsAboutChangelogView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const { back } = useNavigator();
<ul style="margin-top: 5px">
<li class="change">Added Zion's Harp</li>
<li class="change">Added Gospel Hymns</li>
<li class="change">Added Higher Ground</li>
<li class="change">Added Camp Book</li>
<li class="change">Added Junior Hymnal</li>
<li class="change">Added Search Page</li>
<li class="change">Added Bookmarks Page</li>
Expand Down
5 changes: 4 additions & 1 deletion src/views/SongDisplayView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import SongContainer from "@/components/SongContainer.vue";
import { bass_note_icons, treble_note_icons } from "@/composables/notes";
import { onMounted, ref, computed, onUnmounted } from "vue";
import { getSongMetaData, getAllBookMetaData } from "@/scripts/book_import";
import { getSongMetaData, getAllBookMetaData, handle_missing_book } from "@/scripts/book_import";
import { animate, pause_path, play_path } from "@/scripts/morph";
import { useRouter } from "vue-router";
import type { BookSummary, SongReference } from "@/scripts/types";
Expand Down Expand Up @@ -235,6 +235,9 @@ onMounted(async () => {
audio_source.value?.load();
}
})
} else {
console.log("book doesn't exist")
await handle_missing_book(props.book);
}

previous_orientation = (await ScreenOrientation.orientation()).type;
Expand Down
10 changes: 9 additions & 1 deletion src/views/SongSelectionView.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<script setup lang="ts">
import { nextTick, onMounted, ref } from "vue";
import { getAllBookMetaData, getSongMetaData } from "@/scripts/book_import";
import { download_import_summary, getAllBookMetaData, getSongMetaData, handle_missing_book } from "@/scripts/book_import";
import { RouterLink, useRouter, useRoute, onBeforeRouteLeave } from "vue-router";
import { useLocalStorage, useSessionStorage } from "@vueuse/core";
import { saveScrollPosition, restoreScrollPosition, saveGroupOpened, getGroupOpened, removeGroupOpened, removeScrollPosition } from "@/router/scroll";
import { known_references } from "@/scripts/constants";
import { useCapacitorPreferences } from "@/composables/preferences";
import { BookSourceType, type BookDataSummary } from "@/scripts/types";
import { Capacitor } from "@capacitor/core";
import { Network } from "@capacitor/network";
import { Toast } from "@capacitor/toast";

const props = defineProps<{
book: string;
Expand Down Expand Up @@ -36,6 +42,8 @@ onMounted(async () => {
const songs = await getSongMetaData(props.book);

if (songs == null) {
await handle_missing_book(props.book);

error_active.value = true;
return;
}
Expand Down
Loading