Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #33

Merged
merged 4 commits into from
Apr 19, 2024
Merged

Dev #33

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
244 changes: 129 additions & 115 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
"@types/chrome": "^0.0.266",
"@types/node": "^20.12.7",
"@types/wicg-file-system-access": "^2023.10.5",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/parser": "^7.7.0",
"cross-zip": "^4.0.1",
"eslint": "^8.57.0",
"monaco-editor": "^0.47.0",
"rollup": "^4.14.1",
"rollup": "^4.14.3",
"rollup-plugin-css-only": "^4.5.2",
"stylelint": "^16.3.1",
"stylelint-config-standard": "^36.0.0",
Expand Down
4 changes: 2 additions & 2 deletions src/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { IState } from './popup/store/types';
import type {
IRequest,
IResponse,
RequestEvents,
REQUEST,
} from './transport';

export const getURL = (path: string) => {
Expand All @@ -13,7 +13,7 @@ export const to = (url: string) => {
return chrome.tabs.create({ url });
};

export const sendRequest = async (type: RequestEvents, state: IState): Promise<void> => {
export const sendRequest = async (type: REQUEST, state: IState): Promise<void> => {
const [tab] = await chrome.tabs.query({
active: true,
currentWindow: true,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/module/downloadFiles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Directory } from './tree/Directory';
import type { Directory } from './Directory';
import type { IState } from '../popup/store/types';
import { getMetaFileValue } from '../assets/pkg';
import { duplicateErrorMessage, getRootDir } from './fs';
Expand Down
2 changes: 1 addition & 1 deletion src/module/fs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IPage } from '../types';
import { Directory } from './tree/Directory';
import { Directory } from './Directory';

export const getRootDir = async () => {
try {
Expand Down
10 changes: 5 additions & 5 deletions src/module/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import {
RequestEvents,
ResponseEvents,
REQUEST,
RESPONSE,
addRequestListener,
dispatchResponce,
} from '../transport';
import { downloadFiles } from './downloadFiles';

addRequestListener((req) => {
switch (req?.type) {
case RequestEvents.onmout: {
case REQUEST.READY: {
return dispatchResponce({
type: ResponseEvents.content_loaded,
type: RESPONSE.LOADED,
});
}

case RequestEvents.download: {
case REQUEST.DOWNLOAD: {
return downloadFiles(req.state);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/popup/store/appModule.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { TMoudule } from './types';
import {
type IResponse,
RequestEvents,
ResponseEvents,
REQUEST,
RESPONSE,
} from '../../../src/transport';
import { onMessage, sendRequest } from '../../../src/chrome';

Expand All @@ -17,11 +17,11 @@ export const appModule: TMoudule = (store) => {
});

store.on('@ready', (state) => {
sendRequest(RequestEvents.onmout, state);
sendRequest(REQUEST.READY, state);
});

store.on('download/file', (state) => {
sendRequest(RequestEvents.download, state);
sendRequest(REQUEST.DOWNLOAD, state);
});

store.on('toggle/includePageId', (_, includePageId) => {
Expand All @@ -38,7 +38,7 @@ export const appModule: TMoudule = (store) => {

onMessage<IResponse>((res) => {
switch (res?.type) {
case ResponseEvents.content_loaded: {
case RESPONSE.LOADED: {
return store.set({ isEnable: true });
}
}
Expand Down
28 changes: 15 additions & 13 deletions src/transport.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
import type { IState } from './popup/store/types';

export const CUSTOM_EVENT_REQUEST = '>_request::velo-filesystem';
export const CUSTOM_EVENT_RESPONSE = '<_response::velo-filesystem';
export const enum CUSTOM_EVENT {
REQUEST = '>_request::velo-filesystem',
RESPONSE = '<_response::velo-filesystem',
}

export const enum RequestEvents {
onmout = '>_onmout',
download = '>_download',
export const enum REQUEST {
READY = '>_ready',
DOWNLOAD = '>_download',
}

export const enum ResponseEvents {
content_loaded = '<_content_loaded',
export const enum RESPONSE {
LOADED = '<_loaded',
}

export interface IRequest {
readonly type: RequestEvents;
readonly type: REQUEST;
readonly state: IState;
}

export interface IResponse {
readonly type: ResponseEvents;
readonly type: RESPONSE;
}

type TDispatcer<T> = (detail: T) => boolean;
type TListener<T> = (callback: (detail: T) => void) => void

export const dispatchResponce: TDispatcer<IResponse> = (detail) =>
dispatchEvent(
new CustomEvent<IResponse>(CUSTOM_EVENT_RESPONSE, { detail }),
new CustomEvent<IResponse>(CUSTOM_EVENT.RESPONSE, { detail }),
);

export const dispatchRequest: TDispatcer<IRequest> = (detail) =>
dispatchEvent(
new CustomEvent<IRequest>(CUSTOM_EVENT_REQUEST, { detail }),
new CustomEvent<IRequest>(CUSTOM_EVENT.REQUEST, { detail }),
);

export const addResponseListener: TListener<IResponse> = (callback) =>
addEventListener(CUSTOM_EVENT_RESPONSE, (event) => callback(event.detail));
addEventListener(CUSTOM_EVENT.RESPONSE, (event) => callback(event.detail));


export const addRequestListener: TListener<IRequest> = (callback) =>
addEventListener(CUSTOM_EVENT_REQUEST, (event) => callback(event.detail));
addEventListener(CUSTOM_EVENT.REQUEST, (event) => callback(event.detail));
7 changes: 3 additions & 4 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import type monaco from 'monaco-editor';
import type {
IRequest,
IResponse,
CUSTOM_EVENT_REQUEST,
CUSTOM_EVENT_RESPONSE,
CUSTOM_EVENT,
} from './transport';

interface IPage {
Expand All @@ -28,7 +27,7 @@ declare global {
}

interface WindowEventMap {
readonly [CUSTOM_EVENT_REQUEST]: CustomEvent<IRequest>;
readonly [CUSTOM_EVENT_RESPONSE]: CustomEvent<IResponse>;
readonly [CUSTOM_EVENT.REQUEST]: CustomEvent<IRequest>;
readonly [CUSTOM_EVENT.RESPONSE]: CustomEvent<IResponse>;
}
}
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"DOM"
],
},
"ts-node": {
"esm": true,
"transpileOnly": true
},
"include": [
"src/**/*",
"tests/**/*"
Expand Down