Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ransome1 committed Jan 19, 2025
1 parent 3202288 commit 5cbbbc6
Show file tree
Hide file tree
Showing 9 changed files with 1,736 additions and 1,432 deletions.
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ The following versions of sleek are provided with security updates.

## Reporting a Vulnerability

If you find a vulnerability in sleek, please send as much detail as possible to [email protected].
If you find a vulnerability in sleek, please open an issue and provide as much detail as possible.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
"type": "module",
"scripts": {
"format": "prettier --write .",
"lint": "eslint ./src/renderer --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
"lint": "eslint ./src/ --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
"typecheck:node": "tsc --noEmit -p tsconfig.node.json --composite false",
"typecheck:web": "tsc --noEmit -p tsconfig.web.json --composite false",
"typecheck": "yarn typecheck:node && yarn typecheck:web",
"start": "electron-vite preview",
"dev": "yarn lint && electron-vite dev",
"dev": "electron-vite dev",
"build": "yarn peggy && electron-vite build",
"postinstall": "electron-builder install-app-deps",
"build:unpack": "yarn build && electron-builder --dir",
Expand Down
19 changes: 9 additions & 10 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import macIcon from '../../resources/icon.icns?asset'
import windowsIcon from '../../resources/icon.ico?asset'
import linuxIcon from '../../resources/icon.png?asset'
import './modules/IpcMain.js'
let startTime;
let startTime
const environment: string | undefined = process.env.NODE_ENV
let mainWindow: BrowserWindow | null = null
const eventListeners: Record<string, any | undefined> = {}
Expand Down Expand Up @@ -129,9 +129,9 @@ const createMainWindow = () => {
})

mainWindow.once('ready-to-show', () => {
const endTime = performance.now();
console.log(`Startup time: ${(endTime - startTime).toFixed(2)} ms`);
});
const endTime = performance.now()
console.log(`Startup time: ${(endTime - startTime).toFixed(2)} ms`)
})

mainWindow
.on('resize', handleResize)
Expand All @@ -141,7 +141,6 @@ const createMainWindow = () => {
.on('maximize', handleMaximize)
.on('unmaximize', handleUnmaximize)


if (!app.isPackaged && process.env['ELECTRON_RENDERER_URL']) {
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
} else {
Expand Down Expand Up @@ -180,7 +179,7 @@ const createMainWindow = () => {
console.error('Error reading the CSS file:', error)
}
})
}
}

if (environment === 'development') {
mainWindow.webContents.openDevTools()
Expand All @@ -204,16 +203,16 @@ const handleBeforeQuit = () => {

const handleOpenFile = (path) => {
try {
if(path) addFile(path, null);
} catch(error) {
if (path) addFile(path, null)
} catch (error) {
console.error(error)
}
};
}

app
.whenReady()
.then(() => {
startTime = performance.now();
startTime = performance.now()
createMainWindow()
eventListeners.handleCreateWindow = handleCreateWindow
eventListeners.handleWindowAllClosed = handleWindowAllClosed
Expand Down
5 changes: 4 additions & 1 deletion src/main/modules/File/File.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ function readFileContent(filePath: string, bookmark: string | null): string | Er

function addFile(filePath: string, bookmark: string | null) {
if (process.mas && !bookmark) {
mainWindow!.webContents.send('responseFromMainProcess', 'The Mac App Store release requires you to open files from within the app')
mainWindow!.webContents.send(
'responseFromMainProcess',
'The Mac App Store release requires you to open files from within the app'
)
throw new Error('The Mac App Store release requires you to open files from within the app')
}

Expand Down
128 changes: 62 additions & 66 deletions src/main/modules/Filters/FilterLang.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/** Provides information pointing to a location within a source. */
export interface Location {
/** Line in the parsed source (1-based). */
readonly line: number;
readonly line: number
/** Column in the parsed source (1-based). */
readonly column: number;
readonly column: number
/** Offset in the parsed source (0-based). */
readonly offset: number;
readonly offset: number
}

/**
Expand All @@ -15,75 +15,71 @@ export interface Location {
* The GrammarLocation class in Peggy is a good example.
*/
export interface GrammarSourceObject {
readonly toString: () => string;
readonly toString: () => string

/**
* If specified, allows the grammar source to be embedded in a larger file
* at some offset.
*/
readonly offset?: undefined | ((loc: Location) => Location);
readonly offset?: undefined | ((loc: Location) => Location)
}

/**
* Most often, you just use a string with the file name.
*/
export type GrammarSource = string | GrammarSourceObject;
export type GrammarSource = string | GrammarSourceObject

/** The `start` and `end` position's of an object within the source. */
export interface LocationRange {
/**
* A string or object that was supplied to the `parse()` call as the
* `grammarSource` option.
*/
readonly source: GrammarSource;
readonly source: GrammarSource
/** Position at the beginning of the expression. */
readonly start: Location;
readonly start: Location
/** Position after the end of the expression. */
readonly end: Location;
readonly end: Location
}

/**
* Expected a literal string, like `"foo"i`.
*/
export interface LiteralExpectation {
readonly type: "literal";
readonly text: string;
readonly ignoreCase: boolean;
readonly type: 'literal'
readonly text: string
readonly ignoreCase: boolean
}

/**
* Range of characters, like `a-z`
*/
export type ClassRange = [
start: string,
end: string,
]
export type ClassRange = [start: string, end: string]

export interface ClassParts extends Array<string | ClassRange> {
}
export interface ClassParts extends Array<string | ClassRange> {}

/**
* Expected a class, such as `[^acd-gz]i`
*/
export interface ClassExpectation {
readonly type: "class";
readonly parts: ClassParts;
readonly inverted: boolean;
readonly ignoreCase: boolean;
readonly type: 'class'
readonly parts: ClassParts
readonly inverted: boolean
readonly ignoreCase: boolean
}

/**
* Expected any character, with `.`
*/
export interface AnyExpectation {
readonly type: "any";
readonly type: 'any'
}

/**
* Expected the end of input.
*/
export interface EndExpectation {
readonly type: "end";
readonly type: 'end'
}

/**
Expand All @@ -92,16 +88,16 @@ export interface EndExpectation {
* function.
*/
export interface OtherExpectation {
readonly type: "other";
readonly description: string;
readonly type: 'other'
readonly description: string
}

export type Expectation =
| AnyExpectation
| ClassExpectation
| EndExpectation
| LiteralExpectation
| OtherExpectation;
| OtherExpectation

/**
* Pass an array of these into `SyntaxError.prototype.format()`
Expand All @@ -110,9 +106,9 @@ export interface SourceText {
/**
* Identifier of an input that was used as a grammarSource in parse().
*/
readonly source: GrammarSource;
readonly source: GrammarSource
/** Source text of the input. */
readonly text: string;
readonly text: string
}

export declare class SyntaxError extends Error {
Expand All @@ -123,87 +119,87 @@ export declare class SyntaxError extends Error {
* @param found Any text that will appear as found in the input instead of
* expected
*/
static buildMessage(expected: Expectation[], found?: string | null | undefined): string;
readonly message: string;
readonly expected: Expectation[];
readonly found: string | null | undefined;
readonly location: LocationRange;
readonly name: string;
static buildMessage(expected: Expectation[], found?: string | null | undefined): string
readonly message: string
readonly expected: Expectation[]
readonly found: string | null | undefined
readonly location: LocationRange
readonly name: string
constructor(
message: string,
expected: Expectation[],
found: string | null,
location: LocationRange,
);
location: LocationRange
)

/**
* With good sources, generates a feature-rich error message pointing to the
* error in the input.
* @param sources List of {source, text} objects that map to the input.
*/
format(sources: SourceText[]): string;
format(sources: SourceText[]): string
}

/**
* Trace execution of the parser.
*/
export interface ParserTracer {
trace: (event: ParserTracerEvent) => void;
trace: (event: ParserTracerEvent) => void
}

export type ParserTracerEvent
= {
readonly type: "rule.enter";
readonly rule: string;
export type ParserTracerEvent =
| {
readonly type: 'rule.enter'
readonly rule: string
readonly location: LocationRange
}
| {
readonly type: "rule.fail";
readonly rule: string;
readonly type: 'rule.fail'
readonly rule: string
readonly location: LocationRange
}
| {
readonly type: "rule.match";
readonly rule: string;
readonly type: 'rule.match'
readonly rule: string
readonly location: LocationRange
/** Return value from the rule. */
readonly result: unknown;
};
readonly result: unknown
}

export type StartRuleNames = "filterQuery";
export interface ParseOptions<T extends StartRuleNames = "filterQuery"> {
export type StartRuleNames = 'filterQuery'
export interface ParseOptions<T extends StartRuleNames = 'filterQuery'> {
/**
* String or object that will be attached to the each `LocationRange` object
* created by the parser. For example, this can be path to the parsed file
* or even the File object.
*/
readonly grammarSource?: GrammarSource;
readonly startRule?: T;
readonly tracer?: ParserTracer;
readonly grammarSource?: GrammarSource
readonly startRule?: T
readonly tracer?: ParserTracer

// Internal use only:
readonly peg$library?: boolean;
readonly peg$library?: boolean
// Internal use only:
peg$currPos?: number;
peg$currPos?: number
// Internal use only:
peg$silentFails?: number;
peg$silentFails?: number
// Internal use only:
peg$maxFailExpected?: Expectation[];
peg$maxFailExpected?: Expectation[]
// Extra application-specific properties
[key: string]: unknown;
[key: string]: unknown
}

export declare const StartRules: StartRuleNames[];
export declare const parse: typeof ParseFunction;
export declare const StartRules: StartRuleNames[]
export declare const parse: typeof ParseFunction

// Overload of ParseFunction for each allowedStartRule

declare function ParseFunction<Options extends ParseOptions<"filterQuery">>(
declare function ParseFunction<Options extends ParseOptions<'filterQuery'>>(
input: string,
options?: Options,
): any;
options?: Options
): any

declare function ParseFunction<Options extends ParseOptions<StartRuleNames>>(
input: string,
options?: Options,
): any;
options?: Options
): any
Loading

0 comments on commit 5cbbbc6

Please sign in to comment.