Skip to content

Commit

Permalink
Merge branch 'main' into releases/0.0.18
Browse files Browse the repository at this point in the history
  • Loading branch information
Kitenite committed Sep 1, 2024
2 parents 8cb9ea7 + 4f07cd4 commit ba75928
Show file tree
Hide file tree
Showing 18 changed files with 304 additions and 96 deletions.
2 changes: 2 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Vite timestamp
vite.config.ts.timestamp-*.mjs
1 change: 1 addition & 0 deletions app/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export enum MainChannels {
ANLYTICS_PREF_SET = 'analytics-pref-set',
SEND_ANALYTICS = 'send-analytics',
GET_USER_SETTINGS = 'get-user-settings',
UPDATE_USER_SETTINGS = 'update-user-settings',

// Ast
GET_TEMPLATE_NODE_AST = 'get-template-node-ast',
Expand Down
34 changes: 34 additions & 0 deletions app/common/ide.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export enum IdeType {
VS_CODE = 'VSCode',
CURSOR = 'Cursor',
}

export class IDE {
static readonly VS_CODE = new IDE('VSCode', IdeType.VS_CODE, 'vscode');
static readonly CURSOR = new IDE('Cursor', IdeType.CURSOR, 'cursor');

private constructor(
public readonly displayName: string,
public readonly type: IdeType,
public readonly command: string,
) {}

toString() {
return this.displayName;
}

static fromType(type: IdeType): IDE {
switch (type) {
case IdeType.VS_CODE:
return IDE.VS_CODE;
case IdeType.CURSOR:
return IDE.CURSOR;
default:
throw new Error(`Unknown IDE type: ${type}`);
}
}

static getAll(): IDE[] {
return [IDE.VS_CODE, IDE.CURSOR];
}
}
3 changes: 3 additions & 0 deletions app/common/models/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { IdeType } from '../ide';

export interface UserSettings {
id?: string;
enableAnalytics?: boolean;
ideType?: IdeType;
}
12 changes: 10 additions & 2 deletions app/electron/main/code/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { shell } from 'electron';
import { readUserSettings } from '../storage';
import { formatContent, readFile, writeFile } from './files';
import { IDE, IdeType } from '/common/ide';
import { CodeDiff } from '/common/models/code';
import { TemplateNode } from '/common/models/element/templateNode';

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

export function openInVsCode(templateNode: TemplateNode) {
function getIdeFromUserSettings(): IDE {
const userSettings = readUserSettings();
return IDE.fromType(userSettings.ideType || IdeType.VS_CODE);
}

export function openInIde(templateNode: TemplateNode) {
const ide = getIdeFromUserSettings();
const filePath = templateNode.path;
const startTag = templateNode.startTag;
const endTag = templateNode.endTag || startTag;
let command = `vscode://file/${filePath}`;
let command = `${ide.command}://file/${filePath}`;

if (startTag && endTag) {
const startRow = startTag.start.line;
Expand Down
4 changes: 2 additions & 2 deletions app/electron/main/events/code.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ipcMain } from 'electron';
import { openInVsCode, readCodeBlock, readCodeBlocks, writeCode } from '../code/';
import { openInIde, readCodeBlock, readCodeBlocks, writeCode } from '../code/';
import { getCodeDiffs } from '../code/diff';
import { getTemplateNodeChild } from '../code/templateNode';
import { MainChannels } from '/common/constants';
Expand All @@ -9,7 +9,7 @@ import { TemplateNode } from '/common/models/element/templateNode';
export function listenForCodeMessages() {
ipcMain.handle(MainChannels.VIEW_SOURCE_CODE, (e: Electron.IpcMainInvokeEvent, args) => {
const templateNode = args as TemplateNode;
openInVsCode(templateNode);
openInIde(templateNode);
});

ipcMain.handle(MainChannels.GET_CODE_BLOCK, (e: Electron.IpcMainInvokeEvent, args) => {
Expand Down
10 changes: 1 addition & 9 deletions app/electron/main/events/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import { ipcMain } from 'electron';
import { readUserSettings } from '../storage';
import { listenForAnalyticsMessages } from './analytics';
import { listenForCodeMessages } from './code';
import { listenForSettingMessages } from './settings';
import { listenForTunnelMessages } from './tunnel';
import { MainChannels } from '/common/constants';

export function listenForIpcMessages() {
listenForTunnelMessages();
listenForAnalyticsMessages();
listenForCodeMessages();
listenForSettingMessages();
}

function listenForSettingMessages() {
ipcMain.handle(MainChannels.GET_USER_SETTINGS, (e: Electron.IpcMainInvokeEvent) => {
return readUserSettings();
});
}
13 changes: 13 additions & 0 deletions app/electron/main/events/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ipcMain } from 'electron';
import { readUserSettings, updateUserSettings } from '../storage';
import { MainChannels } from '/common/constants';

export function listenForSettingMessages() {
ipcMain.handle(MainChannels.GET_USER_SETTINGS, (e: Electron.IpcMainInvokeEvent) => {
return readUserSettings();
});

ipcMain.handle(MainChannels.UPDATE_USER_SETTINGS, (e: Electron.IpcMainInvokeEvent, args) => {
updateUserSettings(args);
});
}
5 changes: 5 additions & 0 deletions app/electron/main/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { UserSettings } from '/common/models/settings';
const path = app.getPath('userData');
const settingsPath = `${path}/user-settings.json`;

export function updateUserSettings(settings: UserSettings) {
const userSettings = readUserSettings();
writeUserSettings({ ...userSettings, ...settings });
}

export function writeUserSettings(settings: UserSettings) {
const userData = JSON.stringify(settings);
writeFileSync(settingsPath, userData);
Expand Down
41 changes: 41 additions & 0 deletions app/src/assets/cursor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions app/src/assets/vscode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/components/Announcement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function Announcement() {
className="text-text flex flex-row items-center"
onClick={() => window.open(Links.GITHUB, '_blank')}
>
<GitHubLogoIcon className="mr-2" /> Star Github Repo
<GitHubLogoIcon className="mr-2" /> Star GitHub Repo
</Button>
<Button
variant="link"
Expand Down
2 changes: 1 addition & 1 deletion app/src/lib/editor/engine/code/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class CodeManager {
private astManager: AstManager,
) {}

viewSource(templateNode?: TemplateNode) {
viewSource(templateNode?: TemplateNode): void {
if (!templateNode) {
console.error('No template node found.');
return;
Expand Down
2 changes: 1 addition & 1 deletion app/src/lib/editor/engine/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ElementStyleImpl implements ElementStyle {
}

export const ELEMENT_STYLES: ElementStyle[] = [
// Position & Dimenions
// Position & Dimensions
new ElementStyleImpl(
'width',
'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip
import { EditorMode } from '@/lib/models';
import { observer } from 'mobx-react-lite';
import { useEffect, useState } from 'react';
import { useEditorEngine } from '..';
import { useEditorEngine } from '../..';
import { capitalizeFirstLetter } from '/common/helpers';
import { Hotkey } from '/common/hotkeys';

Expand Down
Loading

0 comments on commit ba75928

Please sign in to comment.