Skip to content

Commit ba75928

Browse files
committed
Merge branch 'main' into releases/0.0.18
2 parents 8cb9ea7 + 4f07cd4 commit ba75928

File tree

18 files changed

+304
-96
lines changed

18 files changed

+304
-96
lines changed

app/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Vite timestamp
2+
vite.config.ts.timestamp-*.mjs

app/common/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export enum MainChannels {
5151
ANLYTICS_PREF_SET = 'analytics-pref-set',
5252
SEND_ANALYTICS = 'send-analytics',
5353
GET_USER_SETTINGS = 'get-user-settings',
54+
UPDATE_USER_SETTINGS = 'update-user-settings',
5455

5556
// Ast
5657
GET_TEMPLATE_NODE_AST = 'get-template-node-ast',

app/common/ide.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export enum IdeType {
2+
VS_CODE = 'VSCode',
3+
CURSOR = 'Cursor',
4+
}
5+
6+
export class IDE {
7+
static readonly VS_CODE = new IDE('VSCode', IdeType.VS_CODE, 'vscode');
8+
static readonly CURSOR = new IDE('Cursor', IdeType.CURSOR, 'cursor');
9+
10+
private constructor(
11+
public readonly displayName: string,
12+
public readonly type: IdeType,
13+
public readonly command: string,
14+
) {}
15+
16+
toString() {
17+
return this.displayName;
18+
}
19+
20+
static fromType(type: IdeType): IDE {
21+
switch (type) {
22+
case IdeType.VS_CODE:
23+
return IDE.VS_CODE;
24+
case IdeType.CURSOR:
25+
return IDE.CURSOR;
26+
default:
27+
throw new Error(`Unknown IDE type: ${type}`);
28+
}
29+
}
30+
31+
static getAll(): IDE[] {
32+
return [IDE.VS_CODE, IDE.CURSOR];
33+
}
34+
}

app/common/models/settings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import { IdeType } from '../ide';
2+
13
export interface UserSettings {
24
id?: string;
35
enableAnalytics?: boolean;
6+
ideType?: IdeType;
47
}

app/electron/main/code/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { shell } from 'electron';
2+
import { readUserSettings } from '../storage';
23
import { formatContent, readFile, writeFile } from './files';
4+
import { IDE, IdeType } from '/common/ide';
35
import { CodeDiff } from '/common/models/code';
46
import { TemplateNode } from '/common/models/element/templateNode';
57

@@ -66,11 +68,17 @@ export async function writeCode(codeDiffs: CodeDiff[]): Promise<boolean> {
6668
return success;
6769
}
6870

69-
export function openInVsCode(templateNode: TemplateNode) {
71+
function getIdeFromUserSettings(): IDE {
72+
const userSettings = readUserSettings();
73+
return IDE.fromType(userSettings.ideType || IdeType.VS_CODE);
74+
}
75+
76+
export function openInIde(templateNode: TemplateNode) {
77+
const ide = getIdeFromUserSettings();
7078
const filePath = templateNode.path;
7179
const startTag = templateNode.startTag;
7280
const endTag = templateNode.endTag || startTag;
73-
let command = `vscode://file/${filePath}`;
81+
let command = `${ide.command}://file/${filePath}`;
7482

7583
if (startTag && endTag) {
7684
const startRow = startTag.start.line;

app/electron/main/events/code.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ipcMain } from 'electron';
2-
import { openInVsCode, readCodeBlock, readCodeBlocks, writeCode } from '../code/';
2+
import { openInIde, readCodeBlock, readCodeBlocks, writeCode } from '../code/';
33
import { getCodeDiffs } from '../code/diff';
44
import { getTemplateNodeChild } from '../code/templateNode';
55
import { MainChannels } from '/common/constants';
@@ -9,7 +9,7 @@ import { TemplateNode } from '/common/models/element/templateNode';
99
export function listenForCodeMessages() {
1010
ipcMain.handle(MainChannels.VIEW_SOURCE_CODE, (e: Electron.IpcMainInvokeEvent, args) => {
1111
const templateNode = args as TemplateNode;
12-
openInVsCode(templateNode);
12+
openInIde(templateNode);
1313
});
1414

1515
ipcMain.handle(MainChannels.GET_CODE_BLOCK, (e: Electron.IpcMainInvokeEvent, args) => {

app/electron/main/events/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
import { ipcMain } from 'electron';
2-
import { readUserSettings } from '../storage';
31
import { listenForAnalyticsMessages } from './analytics';
42
import { listenForCodeMessages } from './code';
3+
import { listenForSettingMessages } from './settings';
54
import { listenForTunnelMessages } from './tunnel';
6-
import { MainChannels } from '/common/constants';
75

86
export function listenForIpcMessages() {
97
listenForTunnelMessages();
108
listenForAnalyticsMessages();
119
listenForCodeMessages();
1210
listenForSettingMessages();
1311
}
14-
15-
function listenForSettingMessages() {
16-
ipcMain.handle(MainChannels.GET_USER_SETTINGS, (e: Electron.IpcMainInvokeEvent) => {
17-
return readUserSettings();
18-
});
19-
}

app/electron/main/events/settings.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ipcMain } from 'electron';
2+
import { readUserSettings, updateUserSettings } from '../storage';
3+
import { MainChannels } from '/common/constants';
4+
5+
export function listenForSettingMessages() {
6+
ipcMain.handle(MainChannels.GET_USER_SETTINGS, (e: Electron.IpcMainInvokeEvent) => {
7+
return readUserSettings();
8+
});
9+
10+
ipcMain.handle(MainChannels.UPDATE_USER_SETTINGS, (e: Electron.IpcMainInvokeEvent, args) => {
11+
updateUserSettings(args);
12+
});
13+
}

app/electron/main/storage/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import { UserSettings } from '/common/models/settings';
55
const path = app.getPath('userData');
66
const settingsPath = `${path}/user-settings.json`;
77

8+
export function updateUserSettings(settings: UserSettings) {
9+
const userSettings = readUserSettings();
10+
writeUserSettings({ ...userSettings, ...settings });
11+
}
12+
813
export function writeUserSettings(settings: UserSettings) {
914
const userData = JSON.stringify(settings);
1015
writeFileSync(settingsPath, userData);

app/src/assets/cursor.svg

Lines changed: 41 additions & 0 deletions
Loading

app/src/assets/vscode.svg

Lines changed: 46 additions & 0 deletions
Loading

app/src/components/Announcement/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function Announcement() {
110110
className="text-text flex flex-row items-center"
111111
onClick={() => window.open(Links.GITHUB, '_blank')}
112112
>
113-
<GitHubLogoIcon className="mr-2" /> Star Github Repo
113+
<GitHubLogoIcon className="mr-2" /> Star GitHub Repo
114114
</Button>
115115
<Button
116116
variant="link"

app/src/lib/editor/engine/code/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class CodeManager {
1515
private astManager: AstManager,
1616
) {}
1717

18-
viewSource(templateNode?: TemplateNode) {
18+
viewSource(templateNode?: TemplateNode): void {
1919
if (!templateNode) {
2020
console.error('No template node found.');
2121
return;

app/src/lib/editor/engine/styles/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ElementStyleImpl implements ElementStyle {
4444
}
4545

4646
export const ELEMENT_STYLES: ElementStyle[] = [
47-
// Position & Dimenions
47+
// Position & Dimensions
4848
new ElementStyleImpl(
4949
'width',
5050
'',

app/src/routes/project/TopBar/ModeToggle.tsx renamed to app/src/routes/project/TopBar/ModeToggle/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip
44
import { EditorMode } from '@/lib/models';
55
import { observer } from 'mobx-react-lite';
66
import { useEffect, useState } from 'react';
7-
import { useEditorEngine } from '..';
7+
import { useEditorEngine } from '../..';
88
import { capitalizeFirstLetter } from '/common/helpers';
99
import { Hotkey } from '/common/hotkeys';
1010

0 commit comments

Comments
 (0)