Skip to content

Commit

Permalink
general improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Armaldio committed Aug 16, 2024
1 parent ae90dfa commit 6e5f56b
Show file tree
Hide file tree
Showing 48 changed files with 847 additions and 885 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Tests:
- Disable step
- View logs in realtime
- editor full width (no sidebar)
- ask feedback on the editor (pause, confirm, etc.)
ask feedback on the editor (pause, confirm, etc.) @done(24-08-07 07:36)
- env

- export Electron ne fonctionne pas
Expand Down
108 changes: 63 additions & 45 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,55 +1,73 @@
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import globals from 'globals'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import js from '@eslint/js'
import { FlatCompat } from '@eslint/eslintrc'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [{
ignores: ["**/node_modules", "**/dist", "**/out", "**/.gitignore"],
}, ...compat.extends(
"plugin:vue/vue3-recommended",
"eslint:recommended",
"@vue/eslint-config-typescript/recommended",
"@vue/eslint-config-prettier",
), {
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
})

export default [
{
ignores: ['**/node_modules', '**/dist', '**/out', '**/.gitignore']
},
...compat.extends(
'plugin:vue/vue3-recommended',
'eslint:recommended',
'@vue/eslint-config-typescript/recommended',
'@vue/eslint-config-prettier'
),
{
files: ['**/src/**/*.ts', '**/src/**/*.vue'],

rules: {
'no-console': ['error']
}
},
{
languageOptions: {
globals: {
...globals.browser,
...globals.commonjs,
...globals.node,
...vue.environments["setup-compiler-macros"]["setup-compiler-macros"],
},
globals: {
...globals.browser,
...globals.commonjs,
...globals.node
// ...vue.environments["setup-compiler-macros"]["setup-compiler-macros"],
}
},

rules: {
"@typescript-eslint/ban-ts-comment": ["error", {
"ts-ignore": "allow-with-description",
}],
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-ignore': 'allow-with-description'
}
],

"@typescript-eslint/explicit-module-boundary-types": "off",
'@typescript-eslint/explicit-module-boundary-types': 'off',

"@typescript-eslint/no-empty-function": ["error", {
allow: ["arrowFunctions"],
}],
'@typescript-eslint/no-empty-function': [
'error',
{
allow: ['arrowFunctions']
}
],

"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-var-requires": "off",
"vue/require-default-prop": "off",
"vue/multi-word-component-names": "off",
},
}, {
files: ["**/*.js"],
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-var-requires': 'off',
'vue/require-default-prop': 'off',
'vue/multi-word-component-names': 'off'
}
},
{
files: ['**/*.js'],

rules: {
"@typescript-eslint/explicit-function-return-type": "off",
},
}];
'@typescript-eslint/explicit-function-return-type': 'off'
}
}
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"packageManager": "[email protected]",
"scripts": {
"format": "prettier --write .",
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts,.vue --fix",
"lint": "eslint .",
"typecheck:node": "tsc --noEmit -p tsconfig.json --composite false",
"typecheck:web": "vue-tsc --noEmit -p tsconfig.json --composite false",
"typecheck": "npm run typecheck:node && npm run typecheck:web",
Expand Down
64 changes: 32 additions & 32 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { app, shell, BrowserWindow, dialog, autoUpdater } from 'electron'
import { join } from 'path'
import { platform } from 'os'
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
// @ts-expect-error
// @ts-expect-error asset
import icon from '../assets/icon.png?asset'
import { registerIPCHandlers } from './main/handlers'
import { usePlugins } from '@@/plugins'
Expand All @@ -12,20 +12,20 @@ import { Tray, Menu, nativeImage } from 'electron'
import { readFile, writeFile, mkdir } from 'fs/promises'
import { getFinalPlugins } from '@main/utils'
import { SavedFile } from '@@/model'
import { handleActionExecute, handleConditionExecute } from '@main/handler-func'
import { logger } from '@@/logger'
import { handleActionExecute } from '@main/handler-func'
import { useLogger } from '@@/logger'
import * as Sentry from '@sentry/electron/main'
import { assetsPath } from '@main/paths'

// disable asar throughout the app

const isLinux = platform() === 'linux'
let tray

logger.info('app.isPackaged', app.isPackaged)
logger.info('process.env.TEST', process.env.TEST)
logger.info('process.env.WINEHOMEDIR', process.env.WINEHOMEDIR)
logger.info('isLinux', isLinux)
const { logger, setMainWindow } = useLogger()

logger().info('app.isPackaged', app.isPackaged)
logger().info('process.env.TEST', process.env.TEST)
logger().info('process.env.WINEHOMEDIR', process.env.WINEHOMEDIR)
logger().info('isLinux', isLinux)

const isWine = platform() === 'win32' && 'WINEHOMEDIR' in process.env

Expand All @@ -37,9 +37,7 @@ if (app.isPackaged && process.env.TEST !== 'true' && !isWine) {
}

const imagePath = join('./assets', 'icon.png')
let isQuiting = false

console.log('imagePath', imagePath)
// let isQuiting = false

if (!isLinux && process.env.TEST !== 'true' && require('electron-squirrel-startup')) app.quit()

Expand All @@ -61,6 +59,8 @@ function createWindow(): void {
}
})

setMainWindow(mainWindow)

if (is.dev) {
mainWindow.webContents.openDevTools()
}
Expand All @@ -75,7 +75,7 @@ function createWindow(): void {
mainWindow.hide()
})

mainWindow.on('close', function (event) {
mainWindow.on('close', function () {
app.quit()
})

Expand Down Expand Up @@ -110,9 +110,9 @@ app.whenReady().then(async () => {
})

autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
logger.info('releaseNotes', releaseNotes)
logger.info('releaseName', releaseName)
logger.info('event', event)
logger().info('releaseNotes', releaseNotes)
logger().info('releaseName', releaseName)
logger().info('event', event)
const dialogOpts: Electron.MessageBoxOptions = {
type: 'info',
buttons: ['Restart', 'Later'],
Expand All @@ -127,25 +127,25 @@ app.whenReady().then(async () => {
})

autoUpdater.on('error', (message) => {
logger.info('There was a problem updating the application')
logger.info(message)
logger().info('There was a problem updating the application')
logger().info(message)
})

autoUpdater.on('update-available', () => {
logger.info('Found update')
logger().info('Found update')
})

autoUpdater.on('update-not-available', () => {
logger.info('No update available')
logger().info('No update available')
})

autoUpdater.on('checking-for-update', (info: any) => {
logger.info('checking-for-update', info)
logger().info('checking-for-update', info)
})

logger.info('app ready')
logger().info('app ready')
autoUpdater.checkForUpdates()
logger.info('autoUpdater.getFeedURL()', autoUpdater.getFeedURL())
logger().info('autoUpdater.getFeedURL()', autoUpdater.getFeedURL())

// Set app user model id for windows
electronApp.setAppUserModelId('com.cyn')
Expand Down Expand Up @@ -220,19 +220,19 @@ exec "${process.execPath}" "$@"

const { values } = parseArgs(config)

logger.info('values', values)
logger().info('values', values)

// exit if values are passed
if (Object.keys(values).length > 0) {
logger.info('Processing graph...')
logger().info('Processing graph...')

const { action, project, output } = values

if (action === 'run') {
const rawData = await readFile(project, 'utf8')
const data = JSON.parse(rawData) as SavedFile

logger.info('data', data)
logger().info('data', data)

const { canvas, variables } = data
const { blocks: nodes } = canvas
Expand All @@ -245,22 +245,22 @@ exec "${process.execPath}" "$@"
steps: {},
context: {},
onNodeEnter: (node) => {
logger.info('onNodeEnter', node.uid)
logger().info('onNodeEnter', node.uid)
},
onNodeExit: (node) => {
logger.info('onNodeExit', node.uid)
logger().info('onNodeExit', node.uid)
},
onExecuteItem: (node, params, steps) => {
onExecuteItem: (node, params/* , steps */) => {
/* if (node.type === 'condition') {
return handleConditionExecute(node.origin.nodeId, node.origin.pluginId, params, {
send: (data) => {
logger.info('send', data)
logger().info('send', data)
}
})
} else */ if (node.type === 'action') {
return handleActionExecute(node.origin.nodeId, node.origin.pluginId, params, mainWindow, {
send: (data) => {
logger.info('send', data)
logger().info('send', data)
}
})
} else {
Expand Down Expand Up @@ -296,7 +296,7 @@ exec "${process.execPath}" "$@"
label: 'Exit',
type: 'normal',
click: () => {
isQuiting = true
// isQuiting = true
app.quit()
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/main/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { BrowserWindow } from 'electron'
import { klona } from 'klona'
import { toRaw } from 'vue'

import { RendererPluginDefinition } from '@cyn/plugin-core'
import type { Tagged } from 'type-fest'
import { ILogObjMeta } from 'tslog'
import { useLogger } from '@@/logger'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
type Event<TYPE extends string, DATA> = { type: TYPE; data: DATA }
type EndEvent<DATA> = { type: 'end'; data: DATA }

Expand All @@ -15,6 +17,11 @@ export type IpcDefinition = {
{ message: string; buttons?: { title: string; value: string }[] },
EndEvent<{ answer: string }>
]
'log:message': [
// input
ILogObjMeta,
EndEvent<void>
]
}

export type RendererChannels = keyof IpcDefinition
Expand Down Expand Up @@ -44,6 +51,7 @@ export type ListenerMain<KEY extends RendererChannels> = (
) => Promise<void>

export const usePluginAPI = (browserWindow: BrowserWindow) => {
const { logger } = useLogger()
/**
* Send an order
*/
Expand Down Expand Up @@ -93,8 +101,8 @@ export const usePluginAPI = (browserWindow: BrowserWindow) => {
try {
browserWindow.webContents.send(channel, message)
} catch (e) {
console.error(e)
console.error(channel, message)
logger().error(e)
logger().error(channel, message)
}
})
}
Expand Down
Loading

0 comments on commit 6e5f56b

Please sign in to comment.