Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Armaldio committed Jan 10, 2025
1 parent 161a960 commit 0b2d3f8
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 29 deletions.
2 changes: 2 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,5 @@ Filesystem plugin: overwrite parameter + better sentences/descriptions

Convert dektop app to web app + node backend
Communication via rest api (for now) or websocket

yin: test c3p need manual exporting instead of automated because of bundled addons
37 changes: 23 additions & 14 deletions assets/electron/template/app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,28 @@ if (config.enableSteamSupport) {
* @param {BrowserWindow} mainWindow
* @returns {Promise<number>}
*/
const createAppServer = (mainWindow) => {
const createAppServer = (mainWindow, serveStatic = true) => {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
// @ts-expect-error import.meta
const dir = app.isPackaged ? join(import.meta.dirname, './app') : './src/app'

const server = createServer((req, res) => {
return serve(req, res, {
maxAge: 0,
public: dir,
rewrites: [
{
source: 'sw.js',
destination: 'index.html'
}
]
const server = createServer()

if (serveStatic) {
server.on('request', (req, res) => {
return serve(req, res, {
maxAge: 0,
public: dir,
rewrites: [
{
source: 'sw.js',
destination: 'index.html'
}
]
})
})
})
}

const wss = new WebSocketServer({ server })
wss.on('connection', function connection(ws) {
Expand Down Expand Up @@ -315,18 +319,21 @@ const createWindow = async () => {

if (argUrl) {
console.log('argUrl', argUrl)
const port = await createAppServer(mainWindow)
const port = await createAppServer(mainWindow, false)

console.log('port', port)

await mainWindow?.loadURL(argUrl)
console.log('URL loaded')
} else {
const port = await createAppServer(mainWindow)

console.log('port', port)

await mainWindow?.loadURL(`http://localhost:${port}`)
}

return mainWindow
}

const registerHandlers = async () => {
Expand All @@ -339,7 +346,9 @@ const registerHandlers = async () => {
app.whenReady().then(async () => {
await registerHandlers()

await createWindow()
const mainWindow = await createWindow()

mainWindow.show()

app.on('activate', async () => {
if (BrowserWindow.getAllWindows().length === 0) {
Expand Down
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ exec "${process.execPath}" "$@"
output: {
type: 'string',
short: 'o'
},
inspect: {
type: 'boolean'
}
}
} satisfies ParseArgsConfig
Expand All @@ -222,6 +225,8 @@ exec "${process.execPath}" "$@"

createWindow()

delete values['inspect']

// exit if values are passed
if (Object.keys(values).length > 0) {
logger().info('Processing graph...')
Expand Down
3 changes: 2 additions & 1 deletion src/main/handler-func.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const checkParams = (definitionParams: InputsDefinition, elementParams: Record<s
// remove from expected
expected = expected.filter((x) => x !== param)
} else {
throw new Error('Unexpected param "' + param + '"')
// throw new Error('Unexpected param "' + param + '"')
console.warn('Unexpected param "' + param + '"')
}
}

Expand Down
47 changes: 42 additions & 5 deletions src/shared/libs/plugin-construct/assets/script.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Page } from 'playwright'
import { join } from 'node:path'
import { join, extname } from 'node:path'
import { readdir } from 'node:fs/promises'

const registerInstallButtonListener = (page: Page, log: typeof console.log) => {
// as soon as it appear, without blocking flow
Expand Down Expand Up @@ -71,7 +72,7 @@ const registerMissingAddonErrorListener = (page: Page, log: typeof console.log)
timeout: 0
})
.then(async () => {
throw new Error("Missing addon. You should bundle addons with your project")
throw new Error('Missing addon. You should bundle addons with your project')
})
.catch(async () => {
log('webglErrorButton.click() failed')
Expand All @@ -85,7 +86,8 @@ export const script = async (
username: string | undefined,
password: string | undefined,
version: string | undefined,
downloadDir: string
downloadDir: string,
// addonsFolder: string | undefined
) => {
let url = 'https://editor.construct.net/'
if (version) {
Expand All @@ -99,6 +101,42 @@ export const script = async (
await page.getByText('No thanks, not now').click()
log('Clicked No thanks button')

// if (addonsFolder) {
// const _files = await readdir(addonsFolder)
// const addonFiles = _files
// .filter((x) => extname(x) === '.c3addon')
// .map((x) => join(addonsFolder, x))
// console.log('addonFiles', addonFiles)

// await page.pause()
// await page.getByRole('button', { name: 'Menu' }).click();
// await page.mouse.move(30, 150)
// await page.mouse.move(150, 100)
// await page.mouse.click(150, 100);

// const [fileChooserAddons] = await Promise.all([
// page.waitForEvent('filechooser'),
// await page.getByRole('button', { name: 'Install new addon...' }).click()
// ])

// await fileChooserAddons.setFiles(addonFiles)

// // await page.pause()
// // if (addonFiles.length > 0) {
// // for (let i = 0; i < addonFiles.length - 1; i += 1) {
// // const [fileChooser] = await Promise.all([
// // page.waitForEvent('filechooser'),
// // page.keyboard.press('ControlOrMeta+O')
// // ])

// // await fileChooser.setFiles(addonFiles[i])
// // log('Set addon files', addonFiles[i])

// // await page.pause()
// // }
// // }
// }

const [fileChooser] = await Promise.all([
page.waitForEvent('filechooser'),
page.keyboard.press('ControlOrMeta+O')
Expand Down Expand Up @@ -193,10 +231,9 @@ export const script = async (
.click()
log('"Web" clicked')


await page.locator('#exportSelectPlatformDialog').getByRole('button', { name: 'Next' }).click()

await page.getByLabel('Offline support').uncheck();
await page.getByLabel('Offline support').uncheck()
log('Disabled offline support')

await page.locator('#exportStandardOptionsDialog').getByRole('button', { name: 'Next' }).click()
Expand Down
31 changes: 22 additions & 9 deletions src/shared/libs/plugin-construct/export-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,21 @@ export const sharedParams = {
}
},
value: 120,
label: 'Tiemout'
}
label: 'Timeout'
},
// addonsFolder: {
// description: 'Folder containing addons to import in the editor',
// required: false,
// control: {
// type: 'path',
// options: {
// buttonLabel: 'Addons folder',
// properties: ['openDirectory']
// }
// },
// value: '',
// label: 'Addons folder'
// }
} satisfies InputsDefinition

type Inputs = ParamsToInput<typeof sharedParams>
Expand All @@ -81,6 +94,8 @@ export const exportc3p = async <ACTION extends Action>(
) => {
const newInputs = inputs as Inputs

// const { addonsFolder } = newInputs

const playwright = await import('playwright')
const { join } = await import('node:path')

Expand Down Expand Up @@ -115,11 +130,7 @@ export const exportc3p = async <ACTION extends Action>(

log('newInputs', newInputs)

// must run in firefox because otherwise
// the local file system access api of chrome take precedence
// https://github.com/microsoft/playwright/issues/18267
const browserInstance = playwright[browserName]
// const { firefox } = playwright;

const version = newInputs.version
const headless = newInputs.headless
Expand Down Expand Up @@ -160,17 +171,19 @@ export const exportc3p = async <ACTION extends Action>(
newInputs.username,
newInputs.password,
version,
downloadDir
downloadDir,
// addonsFolder,
)

log('setting output result to ', result)

setOutput('folder', result)
} catch (e) {
log('no result, crashed')
log('error, no result, crashed', e)
throw new Error('ConstructExport failed: ' + e.message)
} finally {
await browser.close()
await context.browser().close()
await context.close()
}
}

Expand Down

0 comments on commit 0b2d3f8

Please sign in to comment.