Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/timelapse-settings
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/plugins/webSocketClient.ts
meteyou committed Jan 28, 2024
2 parents bfe0ee8 + 65a62cb commit 1ae449e
Showing 11 changed files with 154 additions and 85 deletions.
10 changes: 6 additions & 4 deletions .github/label-actions.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configuration for Label Actions - https://github.com/dessant/label-actions

not on Github:
not an Issue:
issues:
comment: |
Ahoi!
@@ -9,10 +9,12 @@ not on Github:
Many helpful people will not see your message here and you are
unlikely to get a useful response.
We use github to handle bugreports, feature requests and
planning new releases.
We use the Github Issue-Tracker only for development related
topics, like feature requests, bug reports etc. To get help,
please join our Discord-Server or ask in Github Discussions:
Please use our Discord-Server for help: [discord.gg/mainsail](https://discord.gg/mainsail)
- [discord.gg/mainsail](https://discord.gg/mainsail)
- [GitHub Discussions](https://github.com/orgs/mainsail-crew/discussions)
This ticket will be automatically closed.
2 changes: 1 addition & 1 deletion .github/workflows/auto-analyze.yml
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ jobs:

- name: Check package.json was changed
id: changed-file-package-json
uses: tj-actions/changed-files@v23
uses: tj-actions/changed-files@v41
with:
sha: ${{ github.event.pull_request.head.sha }}

2 changes: 1 addition & 1 deletion .github/workflows/check_locale.yml
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ jobs:

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v23
uses: tj-actions/changed-files@v41
with:
sha: ${{ github.event.pull_request.head.sha }}
files: 'src/locales/*.json'
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@
"@codemirror/view": "^6.0.3",
"@jaames/iro": "^5.5.2",
"@lezer/highlight": "^1.0.0",
"@sindarius/gcodeviewer": "^3.2.2",
"@sindarius/gcodeviewer": "^3.7.6",
"@uiw/codemirror-theme-vscode": "^4.19.11",
"axios": "^1.6.0",
"codemirror": "^6.0.1",
@@ -94,7 +94,7 @@
"start-server-and-test": "^2.0.0",
"typescript": "^4.5.5",
"unplugin-vue-components": "^0.22.12",
"vite": "^4.4.12",
"vite": "^4.5.2",
"vite-plugin-checker": "^0.6.0",
"vite-plugin-package-version": "^1.0.2",
"vite-plugin-pwa": "^0.16.4",
7 changes: 6 additions & 1 deletion src/components/panels/ExtruderControlPanel.vue
Original file line number Diff line number Diff line change
@@ -180,7 +180,12 @@ export default class ExtruderControlPanel extends Mixins(BaseMixin, ControlMixin
}
get showFilamentMacros(): boolean {
return this.loadFilamentMacro !== undefined || this.unloadFilamentMacro !== undefined
return (
this.loadFilamentMacro !== undefined ||
this.unloadFilamentMacro !== undefined ||
this.purgeFilamentMacro !== undefined ||
this.cleanNozzleMacro !== undefined
)
}
get showTools(): boolean {
9 changes: 5 additions & 4 deletions src/components/panels/GcodefilesPanel.vue
Original file line number Diff line number Diff line change
@@ -1235,11 +1235,12 @@ export default class GcodefilesPanel extends Mixins(BaseMixin, ControlMixin) {
refreshMetadata(data: FileStateGcodefile[]) {
const items = data.filter((file) => !file.isDirectory && !file.metadataRequested && !file.metadataPulled)
items.forEach((file: FileStateGcodefile) => {
this.$store.dispatch('files/requestMetadata', {
this.$store.dispatch(
'files/requestMetadata',
items.map((file: FileStateGcodefile) => ({
filename: 'gcodes' + this.currentPath + '/' + file.filename,
})
})
}))
)
}
clickRow(item: FileStateGcodefile, force = false) {
2 changes: 1 addition & 1 deletion src/components/panels/Machine/ConfigFilesPanel.vue
Original file line number Diff line number Diff line change
@@ -260,7 +260,7 @@
<img
v-if="dialogImage.item.url"
:src="dialogImage.item.url"
style="max-height: 100%; width: auto"
style="max-height: 100%; width: auto; object-fit: contain"
alt="image" />
<div v-else-if="dialogImage.item.svg" class="fill-width" v-html="dialogImage.item.svg"></div>
</div>
10 changes: 5 additions & 5 deletions src/components/panels/Status/Gcodefiles.vue
Original file line number Diff line number Diff line change
@@ -343,12 +343,12 @@ export default class StatusPanelGcodefiles extends Mixins(BaseMixin, ControlMixi
const requestItems = gcodes.filter(
(file: FileStateGcodefile) => !file.metadataRequested && !file.metadataPulled
)
requestItems.forEach((file: FileStateGcodefile) => {
this.$store.dispatch('files/requestMetadata', {
this.$store.dispatch(
'files/requestMetadata',
requestItems.map((file: FileStateGcodefile) => ({
filename: 'gcodes/' + file.filename,
})
})
}))
)
return gcodes
}
143 changes: 94 additions & 49 deletions src/plugins/webSocketClient.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ export class WebSocketClient {
reconnectInterval = 1000
reconnects = 0
keepAliveTimeout = 1000
messageId: number = 0
timerId: number | null = null
store: Store<RootState> | null = null
waits: Wait[] = []
@@ -25,6 +26,59 @@ export class WebSocketClient {
this.url = url
}

handleMessage(data: any) {
const wait = this.getWaitById(data.id)

// report error messages
if (data.error?.message) {
// only report errors, if not disconnected and no init component
if (data.error?.message !== 'Klippy Disconnected') {
window.console.error(`Response Error: ${data.error.message} (${wait?.action ?? 'no action'})`)
}

if (wait?.id) {
const modulename = wait.action?.split('/')[1] ?? null

if (
modulename &&
wait.action?.startsWith('server/') &&
initableServerComponents.includes(modulename) &&
this.store?.state.socket?.initializationList.length
) {
const component = wait.action.replace('server/', '').split('/')[0]
window.console.error(`init server component ${component} failed`)
this.store?.dispatch('server/addFailedInitComponent', component)
this.store?.dispatch('socket/removeInitComponent', `server/${component}/`)
}

this.removeWaitById(wait.id)
}

return
}

// pass it to socket/onMessage, if no wait exists
if (!wait) {
this.store?.dispatch('socket/onMessage', data)
return
}

// pass result to action
if (wait?.action) {
let result = data.result
if (result === 'ok') result = { result: result }
if (typeof result === 'string') result = { result: result }

const preload = {}
if (wait.actionPayload) Object.assign(preload, wait.actionPayload)
Object.assign(preload, { requestParams: wait.params })
Object.assign(preload, result)
this.store?.dispatch(wait.action, preload)
}

this.removeWaitById(wait.id)
}

async connect() {
this.store?.dispatch('socket/setData', {
isConnecting: true,
@@ -58,56 +112,13 @@ export class WebSocketClient {
if (this.store === null) return

const data = JSON.parse(msg.data)
const wait = this.getWaitById(data.id)

// report error messages
if (data.error?.message) {
// only report errors, if not disconnected and no init component
if (data.error?.message !== 'Klippy Disconnected') {
window.console.error(`Response Error: ${data.error.message} (${wait?.action ?? 'no action'})`)
if (Array.isArray(data)) {
for (const message of data) {
this.handleMessage(message)
}

if (wait?.id) {
const modulename = wait.action?.split('/')[1] ?? null

if (
modulename &&
wait.action?.startsWith('server/') &&
initableServerComponents.includes(modulename) &&
this.store?.state.socket?.initializationList.length
) {
const component = wait.action.replace('server/', '').split('/')[0]
window.console.error(`init server component ${component} failed`)
this.store?.dispatch('server/addFailedInitComponent', component)
this.store?.dispatch('socket/removeInitComponent', `server/${component}/`)
}

this.removeWaitById(wait.id)
}

return
}

// pass it to socket/onMessage, if no wait exists
if (!wait) {
this.store?.dispatch('socket/onMessage', data)
return
} else {
this.handleMessage(data)
}

// pass result to action
if (wait?.action) {
let result = data.result
if (result === 'ok') result = { result: result }
if (typeof result === 'string') result = { result: result }

const preload = {}
if (wait.actionPayload) Object.assign(preload, wait.actionPayload)
Object.assign(preload, { requestParams: wait.params })
Object.assign(preload, result)
this.store?.dispatch(wait.action, preload)
}

this.removeWaitById(wait.id)
}
}

@@ -131,7 +142,7 @@ export class WebSocketClient {
emit(method: string, params: Params, options: emitOptions = {}): void {
if (this.instance?.readyState !== WebSocket.OPEN) return

const id = Math.floor(Math.random() * 10000) + 1
const id = this.messageId++
this.waits.push({
id: id,
params: params,
@@ -151,6 +162,33 @@ export class WebSocketClient {
})
)
}

emitBatch(messages: BatchMessage[]): void {
if (messages.length === 0) return
if (this.instance?.readyState !== WebSocket.OPEN) return

const body = []
for (const { method, params, emitOptions = {} } of messages) {
const id = this.messageId++
this.waits.push({
id: id,
params: params,
action: emitOptions.action ?? null,
actionPayload: emitOptions.actionPayload ?? {},
loading: emitOptions.loading ?? null,
})

if (emitOptions.loading) this.store?.dispatch('socket/addLoading', { name: emitOptions.loading })
body.push({
jsonrpc: '2.0',
method,
params,
id,
})
}

this.instance.send(JSON.stringify(body))
}
}

export function WebSocketPlugin(Vue: typeof _Vue, options: WebSocketPluginOptions): void {
@@ -170,6 +208,13 @@ export interface WebSocketClient {
connect(): void
close(): void
emit(method: string, params: Params, emitOptions: emitOptions): void
emitBatch(messages: BatchMessage[]): void
}

export interface BatchMessage {
method: string
params: Params
emitOptions: emitOptions
}

export interface Wait {
Loading

0 comments on commit 1ae449e

Please sign in to comment.