Skip to content

Commit

Permalink
✨ 支持插件分离,增加开发者工具功能
Browse files Browse the repository at this point in the history
  • Loading branch information
muwoo committed Jan 4, 2022
1 parent c69be6c commit 19cd77b
Show file tree
Hide file tree
Showing 29 changed files with 13,717 additions and 15 deletions.
23 changes: 23 additions & 0 deletions detach/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.DS_Store
node_modules
/dist


# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
24 changes: 24 additions & 0 deletions detach/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# detach

## Project setup
```
npm install
```

### Compiles and hot-reloads for development
```
npm run serve
```

### Compiles and minifies for production
```
npm run build
```

### Lints and fixes files
```
npm run lint
```

### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).
3 changes: 3 additions & 0 deletions detach/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ["@vue/cli-plugin-babel/preset"],
};
13,240 changes: 13,240 additions & 0 deletions detach/package-lock.json

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions detach/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "detach",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.5",
"lodash.throttle": "^4.1.1",
"vue": "^3.0.0",
"vue-router": "^4.0.0-0",
"vuex": "^4.0.0-0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-plugin-typescript": "~4.5.0",
"@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/compiler-sfc": "^3.0.0",
"@vue/eslint-config-prettier": "^6.0.0",
"@vue/eslint-config-typescript": "^7.0.0",
"eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vue": "^7.0.0",
"prettier": "^2.2.1",
"typescript": "~4.1.5"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/vue3-essential",
"eslint:recommended",
"@vue/typescript/recommended",
"@vue/prettier",
"@vue/prettier/@typescript-eslint"
],
"parserOptions": {
"ecmaVersion": 2020
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
Binary file added detach/public/favicon.ico
Binary file not shown.
17 changes: 17 additions & 0 deletions detach/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
150 changes: 150 additions & 0 deletions detach/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<template>
<div :class="[platform, 'detach']">
<div class="info">
<img :src="plugInfo.logo" />
<input
autofocus
@input="changeValue"
v-if="showInput"
:value="plugInfo.subInput?.value"
:placeholder="plugInfo.subInput?.placeholder"
/>
<span v-else>{{ plugInfo.pluginName }}</span>
</div>
<div class="handle">
<div class="devtool" @click="openDevTool" title="开发者工具"></div>
</div>
</div>
</template>

<script setup>
import throttle from "lodash.throttle";
import { ref } from "vue";
const { ipcRenderer } = window.require("electron");
const platform = ref(window.process.platform);
const plugInfo = ref({});
const showInput = ref(false);
window.initDetach = (pluginInfo) => {
plugInfo.value = pluginInfo;
showInput.value =
pluginInfo.subInput &&
(!!pluginInfo.subInput.value || !!pluginInfo.subInput.placeholder);
console.log(showInput.value);
};
const changeValue = throttle((e) => {
ipcRenderer.send("msg-trigger", {
type: "detachInputChange",
data: {
text: e.target.value,
},
});
}, 500);
const openDevTool = () => {
ipcRenderer.send("msg-trigger", { type: "openPluginDevTools" });
};
Object.assign(window, {
setSubInputValue: ({ value }) => {
plugInfo.value.subInput.value = value;
},
setSubInput: (placeholder) => {
plugInfo.value.subInput.placeholder = placeholder;
},
removeSubInput: () => {
plugInfo.value.subInput = null;
},
});
</script>

<style>
html, body {
margin: 0;
padding: 0;
font-family: system-ui, "PingFang SC", "Helvetica Neue", "Microsoft Yahei", sans-serif;
user-select: none;
overflow: hidden;
}
.detach {
width: 100%;
height: 56px;
display: flex;
align-items: center;
background: #eee;
}
.detach {
flex: 1;
display: flex;
align-items: center;
font-size: 18px;
padding-left: 10px;
font-weight: 500;
box-sizing: border-box;
justify-content: space-between;
}
.detach.darwin {
padding-left: 80px;
-webkit-app-region: drag;
}
.detach.win32 {
-webkit-app-region: drag;
}
.detach img {
width: 36px;
height: 36px;
margin-right: 10px;
}
.detach input {
background-color: #FFFFFF;
color: #333333;
width: 360px;
height: 36px;
line-height: 36px;
border-radius: 4px;
font-size: 14px;
border: none;
padding: 0 10px;
outline: none;
-webkit-app-region: no-drag;
}
.detach input::-webkit-input-placeholder {
color: #aaa;
user-select: none;
}
.detach .info {
display: flex;
align-items: center;
}
.handle {
display: flex;
-webkit-app-region: no-drag;
}
.handle > div {
width: 36px;
height: 36px;
border-radius: 18px;
cursor: pointer;
margin-right: 6px;
}
.handle > div:hover {
background-color: #dee2e6;
}
.detach .devtool {
background: center / 18px no-repeat url("./assets/devtool.svg");
}
</style>
1 change: 1 addition & 0 deletions detach/src/assets/devtool.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions detach/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createApp } from "vue";
import App from "./App.vue";

createApp(App).mount("#app");
6 changes: 6 additions & 0 deletions detach/src/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable */
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
39 changes: 39 additions & 0 deletions detach/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"types": [
"webpack-env"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
13 changes: 13 additions & 0 deletions detach/vue.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const path = require("path");

module.exports = {
css: { // 配置css模块
loaderOptions: { // 向预处理器 Loader 传递配置选项
less: { // 配置less(其他样式解析用法一致)
javascriptEnabled: true, // 设置为true
},
},
},
outputDir: path.join(__dirname, "../public/detach"),
publicPath: process.env.NODE_ENV === "production" ? "" : "/",
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rubick",
"version": "2.0.1-beta.10",
"version": "2.0.1-beta.11",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
Expand Down
1 change: 1 addition & 0 deletions public/detach/css/app.9d15d34b.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added public/detach/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions public/detach/img/devtool.87e078f5.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions public/detach/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="favicon.ico"><title>detach</title><link href="css/app.9d15d34b.css" rel="preload" as="style"><link href="js/app.a7b22972.js" rel="preload" as="script"><link href="js/chunk-vendors.c073804a.js" rel="preload" as="script"><link href="css/app.9d15d34b.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but detach doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="js/chunk-vendors.c073804a.js"></script><script src="js/app.a7b22972.js"></script></body></html>
2 changes: 2 additions & 0 deletions public/detach/js/app.a7b22972.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 19cd77b

Please sign in to comment.