Skip to content

Commit

Permalink
feat: adds Danger Klipper config support (#1446)
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
pedrolamas authored Jun 3, 2024
1 parent b8b1924 commit 0c4f79e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/components/widgets/filesystem/setupMonaco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ async function setupMonaco () {
const app = getVueApp()

monaco.editor.registerCommand('fluidd_open_docs', (_, service: CodeLensSupportedService, hash: string) => {
const serviceKey = service.replace(/-/g, '_')
const serviceKey = (
service === 'klipper'
? app.$store.getters['printer/getKlippyApp']
: service
).toLowerCase().replace(/-/g, '_')

const url = app.$t(`app.file_system.url.${serviceKey}_config`, { hash }).toString()

window.open(url)
Expand Down
9 changes: 8 additions & 1 deletion src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,14 @@ export const Globals = Object.freeze({
{ filename: 'mooncord-webcam.json', service: 'webcamd', link: 'https://github.com/eliteSchwein/mooncord' },
{ prefix: 'mooncord', service: 'MoonCord', link: 'https://github.com/eliteSchwein/mooncord' },
{ filename: 'telegram.conf', service: 'moonraker-telegram-bot', link: 'https://github.com/nlef/moonraker-telegram-bot/wiki/Sample-config' },
{ suffix: '.cfg', service: 'klipper', link: 'https://www.klipper3d.org/Config_Reference.html' }
{
suffix: '.cfg',
service: 'klipper',
link: 'https://www.klipper3d.org/Config_Reference.html',
linkOverride: {
'danger-klipper': 'https://dangerklipper.io/Config_Reference.html'
}
}
],
FILE_DATA_TRANSFER_TYPES: {
files: 'x-fluidd-files',
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ app:
root_disabled: '{root} root is not available. Please check your logs.'
url:
klipper_config: 'https://www.klipper3d.org/Config_Reference.html#%{hash}'
danger_klipper_config: 'https://dangerklipper.io/Config_Reference.html#%{hash}'
moonraker_config: 'https://moonraker.readthedocs.io/en/latest/configuration/#%{hash}'
moonraker_telegram_bot_config: 'https://github.com/nlef/moonraker-telegram-bot/wiki/Sample-config#%{hash}'
crowsnest_config: 'https://crowsnest.mainsail.xyz/configuration/%{hash}-section'
Expand Down
15 changes: 15 additions & 0 deletions src/store/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ export const getters: GetterTree<PrinterState, RootState> = {
return 'Unknown'
},

getKlippyApp: (state) => {
const supportedKlippyApps = [
'Klipper',
'Danger-Klipper'
]

const app = state.printer.info.app

if (supportedKlippyApps.includes(app)) {
return app
}

return 'Klipper'
},

/**
* Returns a string value indicating the state of the printer.
*/
Expand Down
14 changes: 13 additions & 1 deletion src/store/server/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ServerInfo, ServerConfig, ServerState, SystemInfo, ServerSystemSta
import type { RootState } from '../types'
import { Globals } from '@/globals'
import { gte, valid } from 'semver'
import isKeyOf from '@/util/is-key-of'

export const getters: GetterTree<ServerState, RootState> = {
/**
Expand Down Expand Up @@ -66,7 +67,7 @@ export const getters: GetterTree<ServerState, RootState> = {
* Maps configuration files to an object representing a config doc link,
* along with a service name.
*/
getConfigMapByFilename: (state, getters, rootState) => (filename: string) => {
getConfigMapByFilename: (state, getters, rootState, rootGetters) => (filename: string) => {
const configMap = Globals.CONFIG_SERVICE_MAP

// First, see if can find an exact match.
Expand All @@ -82,6 +83,17 @@ export const getters: GetterTree<ServerState, RootState> = {
item = configMap.find(o => o.suffix && filename.endsWith(o.suffix.toLowerCase()))
}

if (
item?.service === 'klipper' &&
item.linkOverride
) {
const app = rootGetters['printer/getKlippyApp'].toLowerCase()

if (isKeyOf(app, item.linkOverride)) {
item.link = item.linkOverride[app]
}
}

if (item) {
const itemService = item?.service
const instanceIds = rootState.server.system_info?.instance_ids
Expand Down

0 comments on commit 0c4f79e

Please sign in to comment.