Skip to content

Commit

Permalink
remove sendTo
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Mar 6, 2024
1 parent dc63b2e commit 0831ebe
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/src/ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async function main (): Promise<void> {
await app.whenReady()
registerGlobalShortcut()
setMenu()
ipc()
ipc(() => mainWindow)

ipcMain.on('flash', () => {
mainWindow && mainWindow.flashFrame(true)
Expand Down
13 changes: 9 additions & 4 deletions app/src/ts/main/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ipcMain, SaveDialogOptions, dialog, app, RelaunchOptions, OpenDialogOptions } from 'electron'
import { ipcMain, SaveDialogOptions, dialog, app, RelaunchOptions, OpenDialogOptions, type BrowserWindow } from 'electron'
import { getProxyAgent } from 'mishiro-core/util/proxy'
import got from 'got'
// import onManifestQuery from './on-manifest-query'
Expand Down Expand Up @@ -40,7 +40,7 @@ function registerIpcConfig (configurer: Configurer): void {
})
}

export default function ipc (): void {
export default function ipc (getMainWindow: () => (BrowserWindow | null)): void {
if (initialized) return

// let manifestData: any = {}
Expand All @@ -67,8 +67,13 @@ export default function ipc (): void {
// event.sender.send('readManifest', masterHash, resVer)
// })

ipcMain.on('openScoreWindow', function () {
openScoreWindow()
ipcMain.handle('openScoreWindow', function () {
openScoreWindow(() => {
const mainWindow = getMainWindow()
if (mainWindow) {
mainWindow.webContents.send('liveEnd')
}
})
})

ipcMain.handle('showSaveDialog', (_event, options: SaveDialogOptions) => {
Expand Down
5 changes: 4 additions & 1 deletion app/src/ts/main/open-score-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { error } from './log'

let win: BrowserWindow | null = null

export default function openScoreWindow (): void {
export default function openScoreWindow (onClose?: () => void): void {
if (win !== null) {
return
}
Expand Down Expand Up @@ -45,6 +45,9 @@ export default function openScoreWindow (): void {
}

win.on('close', () => {
if (typeof onClose === 'function') {
onClose()
}
win = null
})
}
1 change: 0 additions & 1 deletion app/src/ts/renderer/ipc-back.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ ipcRenderer.on('port', e => {
})

function invokeBackWindow<T> (name: string, args: any[] = []): Promise<T> {
console.log('invokeBackWindow: ', name, args)
return new Promise((resolve, reject) => {
if (!backWindowPort) {
reject(new Error('back window is not ready'))
Expand Down
2 changes: 1 addition & 1 deletion app/src/ts/renderer/modal-score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class extends mixins(modalMixin) {
this.event.$emit('gameStart')
this.event.$emit('pauseBgm')

ipcRenderer.send('openScoreWindow')
await ipcRenderer.invoke('openScoreWindow')

this.visible = false
// ipcRenderer.send(
Expand Down
4 changes: 0 additions & 4 deletions app/src/ts/renderer/scoreviewer/score-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ interface Option {

class ScoreViewer {
public static main (): void {
window.addEventListener('beforeunload', () => {
ipcRenderer.sendTo(ipcRenderer.sendSync('mainWindowId'), 'liveEnd', null, false)
})

const song = ipcRenderer.sendSync('getSong')
if (!song) return

Expand Down

0 comments on commit 0831ebe

Please sign in to comment.