Skip to content

Commit

Permalink
Add functionality to open zip archive, public file on Google Drive.
Browse files Browse the repository at this point in the history
  • Loading branch information
okaxaki committed Dec 17, 2023
1 parent b8163d7 commit 4f59df7
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 99 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
node-version: 18
- run: npm ci
- run: npm run build
env:
VITE_GD_API_KEY: ${{ secrets.GD_API_KEY }}
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
Expand Down
9 changes: 5 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "m3disp",
"private": true,
"version": "0.11.2",
"version": "0.12.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -16,7 +16,6 @@
"@mui/icons-material": "^5.14.19",
"@mui/material": "^5.14.20",
"@types/sha1": "^1.1.5",
"fflate": "^0.8.1",
"libkss-js": "^2.2.0",
"md5": "^2.3.0",
"mgsc-js": "^2.0.0",
Expand All @@ -33,6 +32,7 @@
"@types/react-beautiful-dnd": "^13.1.4",
"@types/react-dom": "^18.0.11",
"@vitejs/plugin-react": "^4.2.1",
"fflate": "^0.8.1",
"typescript": "^5.3.3",
"vite": "^5.0.7"
}
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/AppProgressContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const defaultContextData: AppProgresssContextData = {
export const AppProgressContext = createContext(defaultContextData);

export function AppProgressContextProvider(props: PropsWithChildren) {
const [state, setState] = useState(defaultContextData);

const setTitle = (value: string | null) => {
setState((oldState) => ({ ...oldState, title: value }));
};
Expand All @@ -27,8 +29,6 @@ export function AppProgressContextProvider(props: PropsWithChildren) {
setState((oldState) => ({ ...oldState, progress: value, rev: oldState.rev + 1 }));
};

const [state, setState] = useState(defaultContextData);

return (
<AppProgressContext.Provider value={{ ...state, setProgress, setTitle }}>
{props.children}
Expand Down
4 changes: 2 additions & 2 deletions src/contexts/FileDropContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Box, useTheme } from "@mui/material";
import { PropsWithChildren, useContext, useRef, useState } from "react";
import { FileDrop } from "react-file-drop";
import { BinaryDataStorage } from "../utils/binary-data-storage";
import { loadFilesFromFileList } from "../utils/load-urls";
import { createEntriesFromFileList } from "../utils/loader";
import { PlayerContext } from "./PlayerContext";

export function useFileDrop(playOnDrop: boolean, clearOnDrop: boolean = false) {
Expand Down Expand Up @@ -35,7 +35,7 @@ export function useFileDrop(playOnDrop: boolean, clearOnDrop: boolean = false) {
};

const loadFiles = async (storage: BinaryDataStorage, files: FileList, insertionIndex: number) => {
const entries = await loadFilesFromFileList(storage, files);
const entries = await createEntriesFromFileList(storage, files);
context.reducer.addEntries(entries, insertionIndex);
if (playOnDrop) {
context.reducer.play(insertionIndex);
Expand Down
19 changes: 18 additions & 1 deletion src/contexts/PlayerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AudioPlayerState } from "webaudio-stream-player";
import { KSSChannelMask } from "../kss/kss-device";
import { KSSPlayer } from "../kss/kss-player";
import { BinaryDataStorage } from "../utils/binary-data-storage";
import { loadEntriesFromUrl } from "../utils/load-urls";
import { loadEntriesFromFileList, loadEntriesFromUrl } from "../utils/loader";
import { isIOS, isSafari } from "../utils/platform-detect";
import { unmuteAudio } from "../utils/unmute";
import AppGlobal from "./AppGlobal";
Expand Down Expand Up @@ -163,9 +163,14 @@ export function PlayerContextProvider(props: React.PropsWithChildren) {
const [initialized, setInitialized] = useState(false);

useEffect(() => {
console.log('attach');
console.log(window.opener);
window.addEventListener("message", onWindowMessage, false);
state.player.addEventListener("statechange", onPlayerStateChange);
initialize();
return () => {
console.log('detach');
window.removeEventListener("message", onWindowMessage, false);
state.player.removeEventListener("statechange", onPlayerStateChange);
};
}, []);
Expand Down Expand Up @@ -232,6 +237,18 @@ export function PlayerContextProvider(props: React.PropsWithChildren) {
}
};

const onWindowMessage = async (ev: MessageEvent) => {
console.log(ev);
if (ev.data instanceof Uint8Array && ev.data.length <= 65536) {
reducer.clearEntries();
const file = new File([ev.data], 'external.mgs');
const entries = await loadEntriesFromFileList(state.storage, [new File([ev.data], file.name)]);
reducer.addEntries(entries, 0);
reducer.resume();
reducer.play(0);
}
};

return (
<PlayerContext.Provider
value={{
Expand Down
Loading

0 comments on commit 4f59df7

Please sign in to comment.