Skip to content

Commit

Permalink
Add terminal metrics (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kitenite authored Dec 2, 2024
1 parent 05b091b commit 243b454
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
21 changes: 20 additions & 1 deletion apps/studio/electron/main/run/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { TemplateNode } from '@onlook/models/element';
import { RunState } from '@onlook/models/run';
import { type FSWatcher, watch } from 'chokidar';
import { mainWindow } from '..';
import { sendAnalytics } from '../analytics';
import { writeFile } from '../code/files';
import { removeIdsFromDirectory } from './cleanup';
import { getValidFiles } from './helpers';
Expand All @@ -30,7 +31,11 @@ class RunManager {

async restart(id: string, folderPath: string, command: string): Promise<boolean> {
await this.stop(id, folderPath);
return await this.start(id, folderPath, command);
const res = await this.start(id, folderPath, command);
sendAnalytics('run restarted', {
success: res,
});
return res;
}

async start(id: string, folderPath: string, command: string): Promise<boolean> {
Expand Down Expand Up @@ -58,6 +63,10 @@ class RunManager {
this.startTerminal(id, folderPath, command);
this.setState(RunState.RUNNING, 'Running...');
this.runningDirs.add(folderPath);

sendAnalytics('run started', {
command,
});
return true;
} catch (error) {
const errorMessage = `Failed to setup: ${error}`;
Expand All @@ -77,6 +86,7 @@ class RunManager {

this.setState(RunState.STOPPED, 'Stopped.');
this.runningDirs.delete(folderPath);
sendAnalytics('run stopped');
return true;
} catch (error) {
const errorMessage = `Failed to stop: ${error}`;
Expand All @@ -96,15 +106,24 @@ class RunManager {
state,
message,
});
if (state === RunState.ERROR) {
sendAnalytics('run error', {
message,
});
}
}

startTerminal(id: string, folderPath: string, command: string) {
terminal.create(id, { cwd: folderPath });
terminal.executeCommand(id, command);
sendAnalytics('terminal started', {
command,
});
}

stopTerminal(id: string) {
terminal.kill(id);
sendAnalytics('terminal stopped');
}

async cleanProjectDir(folderPath: string): Promise<void> {
Expand Down
1 change: 1 addition & 0 deletions apps/studio/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default [
'react/prop-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/no-unused-expressions': 'warn',
},
},
];
3 changes: 2 additions & 1 deletion apps/studio/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import baseConfig from '@onlook/ui/tailwind.config';
import type { Config } from 'tailwindcss';
import colors from 'tailwindcss/colors.js';
import typography from '@tailwindcss/typography';

function flattenColors(colors, prefix = '') {
return Object.keys(colors).reduce((acc, key) => {
Expand Down Expand Up @@ -32,5 +33,5 @@ function exposeColorsAsCssVariables({ addBase }) {
export default {
content: ['./src/**/*.{ts,tsx}', '../../packages/ui/src/**/*.{ts,tsx}'],
presets: [baseConfig],
plugins: [require('@tailwindcss/typography'), exposeColorsAsCssVariables],
plugins: [typography, exposeColorsAsCssVariables],
} satisfies Config;
Binary file modified bun.lockb
Binary file not shown.

0 comments on commit 243b454

Please sign in to comment.