Skip to content

Commit

Permalink
Fix: 色が反映されないバグを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Mar 8, 2023
1 parent 18c3f89 commit c742e8c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src-electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const createMainWindow = async () => {
params.append("dirname", __dirname)
params.append("muted", (store.get("muted", false) as boolean).toString())
params.append("url", url)
if (isDevelopment) {
if (isDevelopment || store.get("__open_devtools", false)) {
win.webContents.openDevTools({ mode: "detach" })
}
win.loadURL(`${url}?${params.toString()}`)
Expand Down
11 changes: 8 additions & 3 deletions src/inject/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { contextBridge, ipcRenderer } from "electron"
import style from "./style.scss"
import colorsStyle from "./colors.scss"
import loginStyle from "./loginStyle.css"
import colorsStyle from "./colors.scss?inline"
import loginStyle from "./loginStyle.scss?inline"

import type { CafeMusicInfo } from "./window"
import { NowPlayingInfo, Playlist, UpdateAvailable } from "^/type/common"
Expand Down Expand Up @@ -195,7 +195,12 @@ ipcRenderer.on("set-cyalume-settings", (_event, settings: CyalumeSettings) => {
document.body.setAttribute("data-kcd-cyalume-dim", settings.dim.toString())
})
window.addEventListener("message", (event) => {
if (!["http://localhost:5173", "app://."].includes(event.origin)) {
if (
![
"http://localhost:5173", // Development mode
"null", // Production mode, app:// origin is "null"
].includes(event.origin)
) {
return
}
const [type] = event.data
Expand Down
File renamed without changes.
24 changes: 12 additions & 12 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ const router = createRouter({
],
})

createApp({
mounted() {
if (window.parent !== window) {
window.parent.postMessage(["get-settings"], "*")
}
},
})
.use(router)
.mount("#app")

if (typeof window.electron !== "undefined") {
window.electron.receive("set-colors", (colors: [string, string][]) => {
for (const [key, value] of colors) {
Expand Down Expand Up @@ -85,6 +75,16 @@ const onMessage = (event: MessageEvent) => {
}
}

window.addEventListener("DOMContentLoaded", () => {
const setupMessages = () => {
window.addEventListener("message", onMessage)
})
console.log("Loaded, sending get-settings")
window.parent.postMessage(["get-settings"], "*")
}

if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", setupMessages)
} else {
setupMessages()
}

createApp({}).use(router).mount("#app")

0 comments on commit c742e8c

Please sign in to comment.