Skip to content

Commit

Permalink
fix(app): 修改app加载文件以及油猴插件路径问题
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Jun 4, 2022
1 parent 8ad21bf commit cbf6930
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"scripts": {
"dev:core": "gulp -f ./scripts/dev-core.js",
"build:core": "pnpm lint && gulp -f ./scripts/build-core.js",
"build:core": "pnpm lint && pnpm build && gulp -f ./scripts/build-core.js",
"build:app": "pnpm lint && pnpm build && gulp -f ./scripts/build-app.js",
"build": "pnpm lint && gulp -f ./scripts/tsc.js",
"lint": "eslint ./packages --ext .ts,.tsx,.js,.jsx,.vue --fix",
Expand Down Expand Up @@ -64,4 +64,4 @@
"path": "./node_modules/cz-conventional-changelog"
}
}
}
}
3 changes: 1 addition & 2 deletions packages/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { globalListenerRegister } from './src/tasks/global.listener';
import { task } from './src/utils';
import { handleError } from './src/tasks/error.handler';
import { updater } from './src/tasks/updater';
import path from 'path';
import { startupServer } from './src/tasks/startup.server';

/** 获取单进程锁 */
Expand Down Expand Up @@ -40,7 +39,7 @@ function bootstrap() {
task('注册app事件监听器', () => globalListenerRegister(window));

if (app.isPackaged) {
await window.loadFile(path.resolve('./public/index.html'));
await window.loadFile('./public/index.html');
} else {
await window.loadURL('http://localhost:3000');
}
Expand Down
6 changes: 3 additions & 3 deletions packages/app/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@ocsjs/app",
"version": "1.3.5",
"version": "1.4.0",
"description": "app package of ocs",
"main": "./lib/index.js",
"types": "./lib/types.d.ts",
"scripts": {
"dev": "tsc && chcp 65001 && electron .",
"pack": "electron-builder --config ./electron.builder.json --dir",
"dist": "electron-builder --config ./electron.builder.json"
"pack": "tsc && electron-builder --config ./electron.builder.json --dir",
"dist": "tsc && electron-builder --config ./electron.builder.json"
},
"devDependencies": {
"@types/adm-zip": "^0.4.34",
Expand Down
3 changes: 2 additions & 1 deletion packages/app/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

const { LoggerCore } = require('./lib/src/logger.core');
const { ScriptWorker } = require('./lib/src/worker/index');
const path = require('path');

const worker = new ScriptWorker();
const worker = new ScriptWorker(path.resolve('./resources/app/extensions/Tampermonkey'));

worker.on('screenshot', (screenshots) => {
process.send({ action: 'screenshot', data: screenshots });
Expand Down
7 changes: 4 additions & 3 deletions packages/app/src/worker/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BrowserContext, Page } from 'playwright';
import { launchScripts, LaunchScriptsOptions } from '@ocsjs/scripts';
import EventEmitter from 'events';
import path from 'path';
import { Instance as Chalk } from 'chalk';
import { LoggerCore } from '../logger.core';
import { ScriptWorkerAction, ScriptWorkerActions } from './types';
Expand All @@ -16,15 +15,16 @@ export class ScriptWorker extends EventEmitter {
page?: Page
logger?: LoggerCore
/** 拓展路径 */
extensionPath: string = path.resolve('./extensions/Tampermonkey')
extensionPath: string
/**
* 可关闭的页面
* 在启动程序完成后会处理多余的可关闭页面
*/
closeablePages: string[] = ['tampermonkey.net/index.php']

constructor() {
constructor(extensionPath: string) {
super();
this.extensionPath = extensionPath;
process.on('unhandledRejection', (e) => this.error('未处理的错误!', e));
process.on('uncaughtException', (e) => this.error('未处理的错误!', e));
}
Expand All @@ -40,6 +40,7 @@ export class ScriptWorker extends EventEmitter {
enableLogger: true
})
async launch(options: LaunchScriptsOptions) {
this.debug('加载油猴:', this.extensionPath);
/** 加载油猴 */
options.launchOptions.args =
[`--disable-extensions-except=${this.extensionPath}`, `--load-extension="${this.extensionPath}"`];
Expand Down
12 changes: 11 additions & 1 deletion packages/app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,15 @@
"skipLibCheck": true,
"outDir": "./lib",
"declaration": true
}
},
"include": [
"**/*.ts",
],
"exclude": [
"node_modules",
"dist",
"extensions",
"**/*.spec.ts",
"**/*.d.ts",
]
}
3 changes: 1 addition & 2 deletions packages/common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"declaration": true
},
"compileOnSave": true
}
}
4 changes: 4 additions & 0 deletions packages/core/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const bannerContent = `

// https://vitejs.dev/config/
export default defineConfig({

build: {
rollupOptions: {
external: '@ocsjs/common'
},
/** 取消css代码分离 */
cssCodeSplit: false,
/** 输出路径 */
Expand Down
4 changes: 2 additions & 2 deletions packages/web/src/route/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import { config } from '../config';

/**
Expand All @@ -8,7 +8,7 @@ import { config } from '../config';
export const routes: RouteRecordRaw[] = Reflect.ownKeys(config.routes).map((key) => Reflect.get(config.routes, key));

export const router = createRouter({
history: createWebHistory(),
history: createWebHashHistory(),
routes
});

Expand Down
3 changes: 2 additions & 1 deletion packages/web/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const store = reactive<AppStore & {
win: {
size: number
},
userScripts: StoreUserScript[]
userScripts: StoreUserScript[],
expandedKeys: string[]
}>(defaultsDeep(s.store, {
name: 'ocs',
version: '0.0.1',
Expand Down
2 changes: 0 additions & 2 deletions packages/web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@
"include": [
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue"
]
}

0 comments on commit cbf6930

Please sign in to comment.