Skip to content

Commit cc3583b

Browse files
committed
feat: made editor use MIME types
1 parent 0c2ffbb commit cc3583b

File tree

2 files changed

+70
-22
lines changed

2 files changed

+70
-22
lines changed

src/system/apps/Editor.ts

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,6 @@ interface EditorConfig {
1212
path: string
1313
}
1414

15-
const fileLanguageMap: {
16-
[key: string]: string
17-
} = {
18-
c: 'clike',
19-
cpp: 'clike',
20-
java: 'clike',
21-
cs: 'clike',
22-
ts: 'typescript',
23-
js: 'javascript',
24-
mjs: 'javascript',
25-
cjs: 'javascript',
26-
jsx: 'jsx',
27-
tsx: 'tsx',
28-
html: 'html',
29-
md: 'markdown',
30-
css: 'css',
31-
xml: 'xml',
32-
py: 'python'
33-
}
34-
3515
const Editor: Process = {
3616
config: {
3717
name: 'Editor',
@@ -40,6 +20,8 @@ const Editor: Process = {
4020
targetVer: '1.0.0-indev.0'
4121
},
4222
run: async (process) => {
23+
const MIMETypes = await process.loadLibrary('lib/MIMETypes')
24+
4325
if (Object.keys(process.data).length > 0) {
4426
const win = await process.loadLibrary('lib/WindowManager').then((wm: any) => {
4527
return wm.createWindow({
@@ -153,8 +135,44 @@ const Editor: Process = {
153135
}
154136
})
155137

156-
const fileExtension = data.path.split('.').pop()?.toLowerCase() as string
157-
const language = fileLanguageMap[fileExtension] ?? 'text'
138+
const fileExtension = (data.path.split('.').pop() as string).toLowerCase()
139+
console.log('owo ' + fileExtension, MIMETypes)
140+
const mime = fileExtension in MIMETypes ? MIMETypes[fileExtension].type : 'text/plain'
141+
let language = 'text'
142+
143+
switch (mime) {
144+
case 'text/markdown':
145+
language = 'markdown'
146+
break
147+
case 'text/css':
148+
language = 'css'
149+
break
150+
case 'text/html':
151+
language = 'html'
152+
break
153+
case 'text/javascript':
154+
language = 'javascript'
155+
break
156+
case 'text/jsx':
157+
language = 'jsx'
158+
break
159+
case 'application/x-flow-theme':
160+
case 'application/json':
161+
language = 'clike'
162+
break
163+
case 'text/typescript':
164+
language = 'typescript'
165+
break
166+
case 'text/tsx':
167+
language = 'tsx'
168+
break
169+
case 'application/python':
170+
language = 'python'
171+
break
172+
default:
173+
language = 'text'
174+
break
175+
}
158176

159177
const value = Buffer.from(await fs.readFile(data.path)).toString()
160178
const editor = fullEditor(

src/system/lib/MIMETypes.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,30 @@ const MIMETypes: Library = {
4444
opensWith: ['apps/ImageViewer'],
4545
icon: 'image'
4646
},
47+
cjs: {
48+
type: 'application/javascript',
49+
description: 'CommonJS Module',
50+
opensWith: ['apps/Editor'],
51+
icon: 'code'
52+
},
53+
htm: {
54+
type: 'text/html',
55+
description: 'HTML Document',
56+
opensWith: ['apps/Editor'],
57+
icon: 'code'
58+
},
59+
html: {
60+
type: 'text/html',
61+
description: 'HTML Document',
62+
opensWith: ['apps/Editor'],
63+
icon: 'code'
64+
},
65+
js: {
66+
type: 'text/javascript',
67+
description: 'JavaScript File',
68+
opensWith: ['apps/Editor'],
69+
icon: 'code'
70+
},
4771
lnk: {
4872
type: 'application/x-ms-shortcut',
4973
description: 'Windows Shortcut',
@@ -56,6 +80,12 @@ const MIMETypes: Library = {
5680
opensWith: ['apps/Editor'],
5781
icon: 'markdown'
5882
},
83+
mjs: {
84+
type: 'text/javascript',
85+
description: 'JavaScript Module',
86+
opensWith: ['apps/Editor'],
87+
icon: 'code'
88+
},
5989
mp4: {
6090
type: 'video/mp4',
6191
description: 'MP4 Video',

0 commit comments

Comments
 (0)