Skip to content

Commit

Permalink
electron improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Armaldio committed Aug 13, 2024
1 parent ed46bfc commit 26be9b1
Show file tree
Hide file tree
Showing 14 changed files with 459 additions and 605 deletions.
7 changes: 7 additions & 0 deletions .changeset/thick-teachers-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@cyn/app': patch
---

feat(electron): add custom main code support
feat(electron): add "configure" action
feat: improve display strings
15 changes: 7 additions & 8 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,17 @@ https://remixicon.com/

Tests:
- Disable step
- Reorder steps
- View logs in realtime
- editor full width (no sidebar)
- env
- construct 3 validation url: 402.2 instead of **402-2**
- electron prepare app bundle: backspace on input doesn't cancel running evaluation resulting in slowdowns
- manage c3 export error:
- missing addon
- manage c3 export error:
- missing addon
- handle pipeline error gracefully
- restore working ui
- display what happened in dialog
- steam upload stuck
- handle steamworks
- customize electron build
- allow running js for electron
- restore working ui
- display what happened in dialog
- steam upload stuck
- handle steamworks

12 changes: 8 additions & 4 deletions assets/electron/template/app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ import { app, BrowserWindow } from 'electron'
import { join } from 'node:path'
import serve from 'serve-handler'
import { createServer } from 'http'

// if (require('electron-squirrel-startup')) {
// app.quit()
// }
import './custom-main.js'

/**
*
* @returns {Promise<number>}
*/
const createAppServer = () => {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const dir = app.isPackaged ? join(import.meta.dirname, './app') : './src/app'

Expand Down Expand Up @@ -44,7 +42,13 @@ const createWindow = async () => {
await mainWindow.loadURL(`http://localhost:${port}`)
}

const registerHandlers = async () => {
// handlers
}

app.whenReady().then(async () => {
await registerHandlers()

await createWindow()

app.on('activate', async () => {
Expand Down
17 changes: 15 additions & 2 deletions assets/electron/template/app/src/preload.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
// See the Electron documentation for details on how to use preload scripts:
// https://www.electronjs.org/docs/latest/tutorial/process-model#preload-scripts
const { contextBridge, ipcRenderer } = require('electron')

// Expose a limited API to the renderer process
contextBridge.exposeInMainWorld('electronAPI', {
invoke: async (channel, data) => {
try {
return await ipcRenderer.invoke(channel, data)
} catch (error) {
console.error('IPC invocation error:', error)
throw error
}
}
})

console.log('Preload script loaded')
3 changes: 2 additions & 1 deletion src/shared/libs/plugin-construct/export-c3p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export const ID = 'export-construct-project'
export const exportAction = createAction({
id: ID,
name: 'Export .c3p',
displayString: "`Export projet ${params.version ? `r${params.version}` : ''}`",
displayString:
"`Export projet ${fmt.param(params.file, 'primary')} ${params.version ? `r${params.version}` : ''}`",
meta: {},
params: {
file: {
Expand Down
59 changes: 59 additions & 0 deletions src/shared/libs/plugin-electron/configure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { createAction, createActionRunner } from '@cyn/plugin-core'
import { ElectronConfiguration } from './model'

export const props = createAction({
id: 'electron:configure',
description: 'Configure electron',
displayString: "'Configure Electron'",
icon: '',
meta: {},
name: 'Configure Electron',
outputs: {
configuration: {
label: 'Configuration',
value: {} as ElectronConfiguration
}
},
params: {
electronVersion: {
value: '',
label: 'Electron version',
description: 'The version of Electron to use',
required: false,
control: {
type: 'input',
options: {
kind: 'text'
}
}
},
customMainCode: {
required: false,
label: 'Custom main code',
value: '',
control: {
type: 'path',
options: {
filters: [{ name: 'JavaScript', extensions: ['js'] }]
},
label: 'Path to a file containing custom main code'
}
},
enableSteamSupport: {
required: false,
label: 'Enable steam support',
value: false,
control: {
type: 'boolean'
}
}
}
})

export const configureRunner = createActionRunner<typeof props>(async ({ setOutput, inputs }) => {
setOutput('configuration', {
electronVersion: inputs.electronVersion,
steamSupport: inputs.enableSteamSupport,
customMainCode: inputs.customMainCode,
})
})
Loading

0 comments on commit 26be9b1

Please sign in to comment.