Skip to content

Commit

Permalink
Automatically open dev tools in local and staging environments
Browse files Browse the repository at this point in the history
  • Loading branch information
micahflee committed Jun 12, 2024
1 parent 2e28763 commit 6b8fab3
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ if (!isSingleInstance) {
log.initialize();
log.info('User data folder is at:', app.getPath('userData'))

const semiphemeralEnv = process.env.SEMIPHEMERAL_ENV;

async function createWindow() {
// Run database migrations
await runPrismaMigrations();
Expand All @@ -42,7 +44,7 @@ async function createWindow() {
}

// Create the browser window
const browserWindow = new BrowserWindow({
const win = new BrowserWindow({
show: false,
width: 1024,
height: 768,
Expand All @@ -53,15 +55,14 @@ async function createWindow() {
},
})

browserWindow.on('ready-to-show', () => {
browserWindow?.show()
win.on('ready-to-show', () => {
win?.show()
})

// IPC events

ipcMain.handle('getApiUrl', async (_) => {
// Get SEMIPHEMERAL_ENV from the environment
const semiphemeralEnv = process.env.SEMIPHEMERAL_ENV
if (semiphemeralEnv == "local") {
return "http://localhost:8080/api/v1"
} else if (semiphemeralEnv == "staging") {
Expand Down Expand Up @@ -93,9 +94,15 @@ async function createWindow() {
? 'http://localhost:5173'
: new URL('../dist/renderer/index.html', `file://${__dirname}`).toString()

await browserWindow.loadURL(pageUrl)
await win.loadURL(pageUrl)

// If we're in local or staging, pre-open developer tools
if (semiphemeralEnv == "local" || semiphemeralEnv == "staging") {
win.webContents.openDevTools();
win.setSize(1600, 768);
}

return browserWindow
return win
}

app.on('second-instance', () => {
Expand Down

0 comments on commit 6b8fab3

Please sign in to comment.