Skip to content

Commit

Permalink
fix: Electron Forge breaks because of incorrect export (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
going-confetti authored Aug 27, 2024
1 parent e9421c0 commit 0ecc24d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
20 changes: 19 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
RECORDINGS_PATH,
SCRIPTS_PATH,
} from './constants/workspace'
import { sendToast, getFilePathFromName } from './utils/electron'
import { sendToast } from './utils/electron'
import invariant from 'tiny-invariant'
import { INVALID_FILENAME_CHARS } from './constants/files'
import { generateFileNameWithTimestamp } from './utils/file'
Expand Down Expand Up @@ -397,3 +397,21 @@ const launchProxyAndAttachEmitter = (
},
})
}

function getFilePathFromName(name: string) {
invariant(process, 'Only use this function in the main process')

switch (name.split('.').pop()) {
case 'har':
return path.join(RECORDINGS_PATH, name)

case 'json':
return path.join(GENERATORS_PATH, name)

case 'js':
return path.join(SCRIPTS_PATH, name)

default:
throw new Error('Invalid file type')
}
}
25 changes: 0 additions & 25 deletions src/utils/electron.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { AddToastPayload } from '@/types/toast'
import { platform, arch } from 'os'
import { WebContents } from 'electron'
import path from 'path'
import invariant from 'tiny-invariant'
import {
GENERATORS_PATH,
RECORDINGS_PATH,
SCRIPTS_PATH,
} from '../constants/workspace'

type Platform = 'linux' | 'mac' | 'win'
type Arch = 'arm64' | 'x86_64'
Expand Down Expand Up @@ -50,21 +43,3 @@ export function getArch(): Arch {
export function sendToast(webContents: WebContents, toast: AddToastPayload) {
webContents.send('ui:toast', toast)
}

export function getFilePathFromName(name: string) {
invariant(process, 'Only use this function in the main process')

switch (name.split('.').pop()) {
case 'har':
return path.join(RECORDINGS_PATH, name)

case 'json':
return path.join(GENERATORS_PATH, name)

case 'js':
return path.join(SCRIPTS_PATH, name)

default:
throw new Error('Invalid file type')
}
}

0 comments on commit 0ecc24d

Please sign in to comment.