提交 e6dfe828 编写于 作者: 郭维嘉

feat:添加搜索webview

上级 7e4bb158
......@@ -18,6 +18,8 @@ module.exports = () => {
ipcMain.on("token", (e, info) => {
console.log("on token");
const loginNote = createNote("登录成功");
session.defaultSession.cookies
.get({
url: url
......@@ -25,27 +27,20 @@ module.exports = () => {
.then((cookies, err) => {
const userInfo = {};
cookies.forEach(cookie => {
userInfo[cookie.name] = decodeURI(cookie.value);
userInfo[cookie.name] = decodeURIComponent(cookie.value);
});
userInfo.avatar = info.avatar;
userInfo.UserAvatar = decodeURIComponent(info.UserAvatar);
console.log(userInfo);
global.opConfig.set("userInfo", userInfo);
mainWindow.webContents.send("setUserInfo", userInfo);
// ipcRenderer.send("re-register");
win.close();
const note = new Notification({
title: "CSDN通知", // 通知标题
body: "登录成功", // 内容
icon: path.resolve(__static, "./icon.png"),
href: "https://www.csdn.net/"
});
note.show();
loginNote.show();
});
});
ipcMain.on("logout", (e, info) => {
console.log("remove cookie");
const logoutNote = createNote("退出登录");
session.defaultSession.cookies
.get({
url: url
......@@ -55,17 +50,20 @@ module.exports = () => {
session.defaultSession.cookies.remove(url, cookie.name, e => {});
});
mainWindow.webContents.send("setUserInfo", "");
const note = new Notification({
title: "CSDN通知", // 通知标题
icon: path.resolve(__static, "./icon.png"),
body: "退出登录", // 内容
href: "https://www.csdn.net/"
});
note.show();
logoutNote.show();
});
});
};
let createNote = note => {
return new Notification({
title: "CSDN通知", // 通知标题
icon: path.resolve(__static, "./icon.png"),
body: note, // 内容
href: "https://www.csdn.net/"
});
};
let createWindow = () => {
console.log("create window");
session.defaultSession.cookies
......@@ -94,13 +92,14 @@ module.exports = () => {
nodeIntegration: true,
backgroundThrottling: false,
devTools: false,
webviewTag: true,
preload: path.resolve(__dirname, "../common/preload.js")
}
});
// win.loadFile(path.resolve(__dirname, "../../../../send.html"));
// win.loadURL("https://meiyin.xyz");
win.loadURL(
`https://passport.csdn.net/account/login?from=http://test-code.csdn.net/lives`
`https://passport.csdn.net/account/login?from=http://test-code.csdn.net/about/quicker`
);
win.on("closed", () => {
win = undefined;
......@@ -110,20 +109,43 @@ module.exports = () => {
// win.hide();
});
win.webContents.on("did-stop-loading", () => {
// (function observe() {
// const MutationObserver =
// window.MutationObserver ||
// window.WebKitMutationObserver ||
// window.MozMutationObserver;
// const observer = new MutationObserver(() => {
// const isSuccess = document.querySelector('login-success-tip')
// if(!isSuccess) return
// console.log(isSuccess)
// console.log('success')
// });
// const targetEl = document.body;
// observer.observe(targetEl, {
// childList: true,
// subtree: true
// });
// })()
// win.webContents.executeJavaScript(`
// window.onbeforeunload = function() { console.log(44444999) }
// `);
win.webContents.insertCSS(
`
header.navbar { display:none !important; }
#csdn-toolbar, #copyright-box, #app .notes, #app .icon-list, #app .user-service-link { display: none }
#app, #app .container-main { min-width: unset!important; min-height: unset!important; }
#app .main { width: unset }
html, body { overflow: hidden }
#app .main-login { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 999 }
#app .form-control-phone { width: 62%; float: right }
#app .main-process-login { width: 66%; margin-top: 20px }
.login-success-tip { display: none }
.login-success-tip, .quicker_loading { position: fixed; width: 100%; height: 100%; left: 0; top: 0; color: #fff; z-index: 2000; background: #fff }
.login-success-tip::after, .quicker_loading::after { content: '正在同步个人设置…'; color: #666; position: absolute; background: #fff; left: 50%; top: 50%; transform: translate(-50%, -50%); }
`
);
setTimeout(() => {
win.show();
}, 10);
}, 200);
});
};
......
......@@ -29,7 +29,7 @@ module.exports = () => {
backgroundThrottling: false,
contextIsolation: false,
webviewTag: true,
devTools: false,
devTools: true,
nodeIntegration: true, // 在网页中集成Node
// preload: path.resolve(__dirname, '../common/preload.js')
},
......
......@@ -81,14 +81,14 @@
<img
v-if="userInfo"
class="icon-tool"
:src="userInfo.avatar"
:src="userInfo.UserAvatar"
alt=""
/>
<img v-else class="icon-tool" :src="selected.icon" />
</div>
<!-- 用户头像 -->
<div v-else class="logo">
<img v-if="userInfo" :src="userInfo.avatar" alt="" />
<img v-if="userInfo" :src="userInfo.UserAvatar" alt="" />
<img v-else src="./assets/imgs/quicker.png" />
</div>
</div>
......
......@@ -7,14 +7,8 @@
:preload="preload"
></webview>
<!-- 聚合搜索 -->
<webview
v-else-if="isWebview"
id="webview"
:src="webviewPath"
:preload="preload"
disablewebsecurity
allowpopups
></webview>
<search-bowser v-else-if="isWebview" :src="webviewPath" :preload="preload">
</search-bowser>
<!-- 本地插件 -->
<div v-else>
<webview id="webview" :src="templatePath" :preload="preload"></webview>
......@@ -25,14 +19,16 @@
<script>
import path from "path";
import { mapMutations, mapState } from "vuex";
import { remote, ipcRenderer } from "electron";
import { remote, ipcRenderer, shell } from "electron";
import { getWindowHeight } from "../../assets/common/utils";
import searchBowser from "../search-bowser/index.vue";
const currentWindow = remote.getCurrentWindow();
const winId = currentWindow.id;
export default {
name: "index.vue",
components: { searchBowser },
data() {
return {
preload: `File://${path.join(__static, "./preload.js")}`,
......@@ -42,6 +38,7 @@ export default {
},
mounted() {
this.webview = document.querySelector("webview");
// if (!this.webview) return;
this.webview.addEventListener("dom-ready", () => {
this.webview.send("onPluginReady", this.pluginInfo);
this.webview.send("onPluginEnter", this.pluginInfo);
......@@ -149,9 +146,6 @@ export default {
});
return `File://${this.pluginInfo.sourceFile}`;
},
// webviewPath() {
// return "https://so.csdn.net/so/search?q=csdn";
// },
templatePath() {
return `File://${path.join(__static, "./plugins/tpl/index.html")}?code=${
this.pluginInfo.detail.code
......
<template>
<!-- <div class="search_bowser"> -->
<a-tabs size="small" v-model="activeTab" type="editable-card" @edit="onEdit">
<a-tab-pane
v-for="tab in tabs"
:key="tab.key"
:tab="tab.title"
:closable="true"
>
<webview
v-open
:src="tab.src"
:preload="preload"
disablewebsecurity
></webview>
</a-tab-pane>
</a-tabs>
<!-- </div> -->
</template>
<script>
export default {
props: {
src: {
type: String,
default: ""
},
preload: {
type: String,
default: ""
}
},
data() {
const tabs = [{ title: "搜索", key: "111", src: this.src }];
return {
// webview: null,
newTabIndex: 0,
tabs,
activeTab: tabs[0].key
};
},
// mounted() {
// setTimeout(() => {
// this.webview = document.querySelector("webview");
// this.webview.addEventListener("new-window", e => {
// console.log(e);
// const key = `newTab${this.newTabIndex++}`;
// // const title = e.
// this.tabs.push({
// title: "csdn",
// key,
// src: e.url
// });
// this.activeTab = key;
// });
// }, 0);
// },
directives: {
open: {
inserted: (el, binding, vnode) => {
el.addEventListener("new-window", e => {
console.log(e);
const _this = vnode.context;
const key = `newTab${_this.newTabIndex++}`;
const title = el.getTitle()
// const title = e.
_this.tabs.push({
title,
key,
src: e.url
});
_this.activeTab = key;
});
}
}
},
methods: {
onEdit(targetKey, action) {
this[action](targetKey);
},
add() {
const tabs = this.tabs;
const activeTab = `newTab${this.newTabIndex++}`;
tabs.push({
title: "New Tab",
content: "Content of new Tab",
key: activeTab
});
this.tabs = tabs;
this.activeTab = activeTab;
},
remove(targetKey) {
let activeTab = this.activeTab;
let lastIndex;
this.tabs.forEach((pane, i) => {
if (pane.key === targetKey) {
lastIndex = i - 1;
}
});
const tabs = this.tabs.filter(pane => pane.key !== targetKey);
if (tabs.length && activeTab === targetKey) {
if (lastIndex >= 0) {
activeTab = tabs[lastIndex].key;
} else {
activeTab = tabs[0].key;
}
}
this.tabs = tabs;
this.activeTab = activeTab;
}
}
};
</script>
<style lang="less" scoped>
webview {
height: calc(~"100vh - 100px");
width: 100%;
}
.ant-tabs {
/deep/.ant-tabs-bar {
margin: 0;
}
}
</style>
......@@ -2,8 +2,8 @@
<div class="pg-settings">
<div class="dev-detail">
<div class="user-panel">
<template v-if="config.userInfo">
<a-avatar :size="64" :src="config.userInfo.avatar" />
<template v-if="userInfo">
<a-avatar :size="64" :src="userInfo.UserAvatar" />
<div class="username">{{ userInfo.UserNick }}</div>
<a-popconfirm
title="确认退出?"
......@@ -17,7 +17,9 @@
</template>
<template v-else>
<a-avatar @click="login" :size="64" icon="user" />
<a-button @click="login" size="small">登录</a-button>
<a-button @click="login" size="small" :loading="signLoading"
>登录</a-button
>
</template>
</div>
<div class="settings-detail">
......@@ -177,6 +179,7 @@ export default {
return {
currentSelect: [3],
config: { ...opConfig.get() },
signLoading: false,
examples: [
{
title: "快捷键 「 Alt + W」 关键字 「 微信」",
......@@ -204,29 +207,18 @@ export default {
methods: {
...mapMutations("main", ["setUserInfo"]),
login() {
this.signLoading = true;
setTimeout(() => {
this.signLoading = false;
}, 2000);
ipcRenderer.send("login");
},
logout() {
opConfig.set("userInfo", "");
this.config.userInfo = "";
this.setUserInfo('');
this.setUserInfo("");
ipcRenderer.send("logout");
},
// getUserInfo() {
// axios
// .post(
// "http://internalapi.csdn.net/uc/userinfo/userinfo/getdetailbyusername",
// {
// username: this.userInfo.UserName
// }
// )
// .then(res => {
// console.log(res);
// })
// .catch(e => {
// console.log(e);
// });
// },
changeShortCut(e, key) {
let change = false;
if (e.altKey && e.keyCode !== 18) {
......@@ -326,7 +318,11 @@ export default {
.username {
font-size: 14px;
font-weight: bold;
margin: 10px 0 20px;
max-width: 80%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
margin: 10px auto 20px;
}
}
}
......
......@@ -14,6 +14,8 @@ import fs, { stat } from "fs";
import path from "path";
import { execSync } from "child_process";
const opConfig = remote.getGlobal("opConfig");
const state = {
selected: null,
options: [],
......@@ -22,7 +24,7 @@ const state = {
searchValue: "",
devPlugins: mergePlugins(sysFile.getUserPlugins() || []),
subPlaceHolder: "",
userInfo: "",
userInfo: { ...opConfig.get() }.userInfo,
webviewPath: "https://so.csdn.net/so/search?q=csdn",
pluginLoading: true,
pluginInfo: (() => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册