* WIP: Turn on link sharing in released apps with electron-builder Fixes #5136 * Add import.meta.env defaults * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * Add convenience scripts for windows development; fix protocol name for electron; enable share cmd * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * Force release builds * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * Trigger CI * Fix lint * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * CSC_FOR_PULL_REQUEST: true for release build testing * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * Adding :// * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * Back to debug builds * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * Back to debug builds * WIP: origin * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * To revert: Add logs and custom package version for easier testing * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * More messing with env vars * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * Messing with help from deep links docs * Removed alerts * Working on macos * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * Working second window on windows. Cold start not yet working * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * Handle windows cold start * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * Clean up after macos testing * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * Replace tron:package (Forge) with tronb📦dev (Builder) for e2e * Add new env var for web app link * tronb:vite:dev for e2e * Remove app.requestSingleInstanceLock() call * Fix unit test * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * Revert snap changes * Only nightly at first * Remove test app * Update package.json * Update src/main.ts * Remove fetch:wasm:windows * Final line * Clean up * Back to test app for final test * Fix tsc * Back to https://app.dev.zoo.dev from vercel branch deploy --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
156 lines
4.9 KiB
TypeScript
156 lines
4.9 KiB
TypeScript
import { CommandBarOverwriteWarning } from 'components/CommandBarOverwriteWarning'
|
|
import { Command, CommandArgumentOption } from './commandTypes'
|
|
import { codeManager, kclManager } from './singletons'
|
|
import { isDesktop } from './isDesktop'
|
|
import { FILE_EXT } from './constants'
|
|
import { UnitLength_type } from '@kittycad/lib/dist/types/src/models'
|
|
import { reportRejection } from './trap'
|
|
import { IndexLoaderData } from './types'
|
|
import { IS_NIGHTLY_OR_DEBUG } from 'routes/Settings'
|
|
import { copyFileShareLink } from './links'
|
|
|
|
interface OnSubmitProps {
|
|
sampleName: string
|
|
code: string
|
|
sampleUnits?: UnitLength_type
|
|
method: 'overwrite' | 'newFile'
|
|
}
|
|
|
|
interface KclCommandConfig {
|
|
// TODO: find a different approach that doesn't require
|
|
// special props for a single command
|
|
specialPropsForSampleCommand: {
|
|
onSubmit: (p: OnSubmitProps) => Promise<void>
|
|
providedOptions: CommandArgumentOption<string>[]
|
|
}
|
|
projectData: IndexLoaderData
|
|
authToken: string
|
|
settings: {
|
|
defaultUnit: UnitLength_type
|
|
}
|
|
}
|
|
|
|
export function kclCommands(commandProps: KclCommandConfig): Command[] {
|
|
return [
|
|
{
|
|
name: 'format-code',
|
|
displayName: 'Format Code',
|
|
description: 'Nicely formats the KCL code in the editor.',
|
|
needsReview: false,
|
|
groupId: 'code',
|
|
icon: 'code',
|
|
onSubmit: () => {
|
|
kclManager.format().catch(reportRejection)
|
|
},
|
|
},
|
|
{
|
|
name: 'open-kcl-example',
|
|
displayName: 'Open sample',
|
|
description: 'Imports an example KCL program into the editor.',
|
|
needsReview: true,
|
|
icon: 'code',
|
|
reviewMessage: ({ argumentsToSubmit }) =>
|
|
argumentsToSubmit.method === 'newFile'
|
|
? CommandBarOverwriteWarning({
|
|
heading: 'Create a new file, overwrite project units?',
|
|
message: `This will add the sample as a new file to your project, and replace your current project units with the sample's units.`,
|
|
})
|
|
: CommandBarOverwriteWarning({}),
|
|
groupId: 'code',
|
|
onSubmit(data) {
|
|
if (!data?.sample) {
|
|
return
|
|
}
|
|
const pathParts = data.sample.split('/')
|
|
const projectPathPart = pathParts[0]
|
|
const primaryKclFile = pathParts[1]
|
|
const sampleCodeUrl = `https://raw.githubusercontent.com/KittyCAD/kcl-samples/main/${encodeURIComponent(
|
|
projectPathPart
|
|
)}/${encodeURIComponent(primaryKclFile)}`
|
|
|
|
fetch(sampleCodeUrl)
|
|
.then(async (codeResponse): Promise<OnSubmitProps> => {
|
|
if (!codeResponse.ok) {
|
|
console.error(
|
|
'Failed to fetch sample code:',
|
|
codeResponse.statusText
|
|
)
|
|
return Promise.reject(new Error('Failed to fetch sample code'))
|
|
}
|
|
const code = await codeResponse.text()
|
|
return {
|
|
sampleName: data.sample.split('/')[0] + FILE_EXT,
|
|
code,
|
|
method: data.method,
|
|
}
|
|
})
|
|
.then((props) => {
|
|
if (props?.code) {
|
|
commandProps.specialPropsForSampleCommand
|
|
.onSubmit(props)
|
|
.catch(reportError)
|
|
}
|
|
})
|
|
.catch(reportError)
|
|
},
|
|
args: {
|
|
method: {
|
|
inputType: 'options',
|
|
required: true,
|
|
skip: true,
|
|
defaultValue: isDesktop() ? 'newFile' : 'overwrite',
|
|
options() {
|
|
return [
|
|
{
|
|
value: 'overwrite',
|
|
name: 'Overwrite current code',
|
|
isCurrent: !isDesktop(),
|
|
},
|
|
...(isDesktop()
|
|
? [
|
|
{
|
|
value: 'newFile',
|
|
name: 'Create a new file',
|
|
isCurrent: true,
|
|
},
|
|
]
|
|
: []),
|
|
]
|
|
},
|
|
},
|
|
sample: {
|
|
inputType: 'options',
|
|
required: true,
|
|
valueSummary(value) {
|
|
const MAX_LENGTH = 12
|
|
if (typeof value === 'string') {
|
|
return value.length > MAX_LENGTH
|
|
? value.substring(0, MAX_LENGTH) + '...'
|
|
: value
|
|
}
|
|
return value
|
|
},
|
|
options: commandProps.specialPropsForSampleCommand.providedOptions,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: 'share-file-link',
|
|
displayName: 'Share file',
|
|
hide: IS_NIGHTLY_OR_DEBUG ? undefined : 'desktop',
|
|
description: 'Create a link that contains a copy of the current file.',
|
|
groupId: 'code',
|
|
needsReview: false,
|
|
icon: 'link',
|
|
onSubmit: () => {
|
|
copyFileShareLink({
|
|
token: commandProps.authToken,
|
|
code: codeManager.code,
|
|
name: commandProps.projectData.project?.name || '',
|
|
units: commandProps.settings.defaultUnit,
|
|
}).catch(reportRejection)
|
|
},
|
|
},
|
|
]
|
|
}
|