提交 81009cd4 authored 作者: 蔡芬's avatar 蔡芬

1

上级 a5b147f0
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
"cropperjs": "^1.5.12", "cropperjs": "^1.5.12",
"electron-icon-builder": "^2.0.1", "electron-icon-builder": "^2.0.1",
"element-ui": "^2.15.6", "element-ui": "^2.15.6",
"icns": "^0.1.0",
"js-cookie": "^3.0.1", "js-cookie": "^3.0.1",
"node-machine-id": "^1.1.12", "node-machine-id": "^1.1.12",
"pbkdf2": "3.1.1", "pbkdf2": "3.1.1",
......
import { ipcMain, dialog, Menu, BrowserWindow } from 'electron' import { ipcMain, dialog, Menu, BrowserWindow, app} from 'electron'
import { saveJson } from '@/libs/utils/backfunction.js'; import { saveJson } from '@/libs/utils/backfunction.js';
const fs = require('fs');
const { exec, execSync } = require('child_process'); const { exec, execSync } = require('child_process');
const nativeImage = require('electron').nativeImage;
class IpcEvents { class IpcEvents {
create (appManager) { create (appManager) {
...@@ -38,25 +40,46 @@ class IpcEvents { ...@@ -38,25 +40,46 @@ class IpcEvents {
// 显示右键菜单 // 显示右键菜单
ipcMain.on('show-context-menu', (event) => { ipcMain.on('show-context-menu', (event) => {
const template = [ let currentMode = this.store.get("currentMode");
let template = [
{ {
label: '编辑', label: '简约模式',
click: () => { event.sender.send('context-menu-command', 'edit') } str:'modeJianYue',
click: () => {
event.sender.send('context-menu-command', 'modeJianYue');
this.store.set("currentMode", "modeJianYue");
}
},
{
label: '极简模式',
str:'modeJiJian',
click: () => {
event.sender.send('context-menu-command', 'modeJiJian');
this.store.set("currentMode", "modeJiJian");
}
},
{
label: 'U学模式',
str:'modeUXue',
click: () => {
event.sender.send('context-menu-command', 'modeUXue');
this.store.set("currentMode", "modeUXue");
}
} }
] ]
template = template.filter(v => v.str != currentMode)
const menu = Menu.buildFromTemplate(template) const menu = Menu.buildFromTemplate(template)
menu.popup(BrowserWindow.fromWebContents(event.sender)) menu.popup(BrowserWindow.fromWebContents(event.sender))
}); });
ipcMain.on("setMainWindow0", (e, data) => { ipcMain.on("setMainWindow0", (e, data) => {
console.log('data',data)
this.windowManager.mainWindow.win.setPosition((data.width-1000)/2,(data.height-40)) this.windowManager.mainWindow.win.setPosition((data.width-1000)/2,(data.height-40))
}) })
ipcMain.on("getApps", (e, data) => { ipcMain.on("getApps", (e, data) => {
let apps = this.store.get("apps"); let apps = this.store.get("apps");
console.log(1) // console.log(apps)
console.log(apps) this.store.set("currentMode", "modeJianYue");
this.windowManager.mainWindow.win.webContents.send("appsList", apps) this.windowManager.mainWindow.win.webContents.send("appsList", apps)
}) })
...@@ -64,6 +87,74 @@ class IpcEvents { ...@@ -64,6 +87,74 @@ class IpcEvents {
exec(data.execCommand); exec(data.execCommand);
}) })
ipcMain.on("getBase64", (e, {imagePath,index}) => {
try {
const imageBase64 = fs.readFileSync(imagePath, 'base64');
let src = `data:image/png;base64,${imageBase64}`;
e.sender.send("base64Info", {url:src,index});
} catch (error) {
}
})
ipcMain.on("getfrontApp", (e, data) => {
console.log('获取前台应用程序')
exec('osascript -e \'tell application "System Events" to get name of application processes whose frontmost is true\'', (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
console.log(stdout.trim());
if( stdout.trim() == app.getName()) {
console.log("点击了当前")
e.sender.send("sendMsg", "点击了当前");
}
});
})
ipcMain.on("getLinuxApp", (e, data) => {
// 获取应用程序的图标
// const appPath = '/usr/share/applications/firefox.desktop'; // 替换为您要获取图标的应用程序的.desktop文件路径
const appPath = data; // 替换为您要获取图标的应用程序的.desktop文件路径
const appData = fs.readFileSync(appPath, 'utf-8');
const iconMatch = appData.match(/Icon=(.*)/);
const iconFile = iconMatch ? iconMatch[1] : null;
let iconFullPath = iconFile ? path.join('/usr/share/icons/hicolor/48x48/apps', iconFile) : null; // 替换为您的系统上的图标目录
try {
var res = execSync(`base64 -w 0 ${iconFullPath}`
, { encoding: 'utf8' });
if(res) iconFullPath = res;
} catch (error) {
console.error(error)
}
e.sender.send("linuxAppIcon", iconFullPath);
})
ipcMain.on("isFullScreen", (e, data) => {
// 1. 判断当前应用是否全屏:
// ```javascript
// const { BrowserWindow } = require('electron');
// const win = BrowserWindow.getFocusedWindow();
// const isFullScreen = win.isFullScreen();
// console.log(`Is full screen: ${isFullScreen}`);
// ```
})
ipcMain.on("isAlwaysOnTop", (e, data) => {
// 2. 判断当前应用是否位于最顶层:
// ```javascript
// const { BrowserWindow } = require('electron');
// const win = BrowserWindow.getFocusedWindow();
// const isAlwaysOnTop = win.isAlwaysOnTop();
// console.log(`Is always on top: ${isAlwaysOnTop}`);
// ```
})
} }
} }
......
...@@ -203,9 +203,23 @@ class MainWindow { ...@@ -203,9 +203,23 @@ class MainWindow {
const nameLine = lines.find(line => line.startsWith('Name=')); const nameLine = lines.find(line => line.startsWith('Name='));
const name = nameLine ? nameLine.substr(5) : path.basename(file, '.desktop'); const name = nameLine ? nameLine.substr(5) : path.basename(file, '.desktop');
const iconLine = lines.find(line => line.startsWith('Icon=')); const iconLine = lines.find(line => line.startsWith('Icon='));
const icon = iconLine ? iconLine.substr(5) : null; let icon = iconLine ? iconLine.substr(5) : null;
const execLine = lines.find(line => line.startsWith('Exec=')); const execLine = lines.find(line => line.startsWith('Exec='));
const execCommand = execLine ? execLine.substr(5) : null; const execCommand = execLine ? execLine.substr(5) : null;
icon = `/usr/share/icons/hicolor/48x48/apps/${icon}`
// 2. 打开应用程序的.desktop文件,并查找“Icon=”行。这一行包含应用程序的图标文件的路径。
// 3. 使用以下代码来将图标文件转换为base64编码:
// ```
// base64 -w 0 /usr/share/icons/hicolor/48x48/apps/${icon}
// ```
// try {
// var res = execSync(`base64 -w 0 /usr/share/icons/hicolor/48x48/apps/${icon}.png`
// , { encoding: 'utf8' });
// if(res) icon = res;
// } catch (error) {
// console.error(error)
// }
return { return {
name, name,
icon, icon,
...@@ -215,7 +229,7 @@ class MainWindow { ...@@ -215,7 +229,7 @@ class MainWindow {
store.set('apps', apps); store.set('apps', apps);
// console.log(apps) // console.log(apps)
this.win.webContents.send("appsList", newarr) this.win.webContents.send("appsList", apps)
// updateContextMenu(); // updateContextMenu();
}); });
} }
...@@ -237,13 +251,26 @@ class MainWindow { ...@@ -237,13 +251,26 @@ class MainWindow {
let fileNameShort = fileName.split('.')[0]; let fileNameShort = fileName.split('.')[0];
let icon = ''; let icon = '';
try { try {
// AppIcon.icns
var res = execSync(`ls /System/Applications/'${fileName}'/Contents/Resources/*.icns` var res = execSync(`ls /System/Applications/'${fileName}'/Contents/Resources/*.icns`
, { encoding: 'utf8' }); , { encoding: 'utf8' });
} catch (e) { } catch (e) {
console.log("Errors:", e); console.log("Errors:", e);
} }
icon = res && res.trim().split('\n') || ''; icon = res && res.trim().split('\n') || [];
icon = icon[icon.length-1]; icon = icon.length > 0 ? icon[0] : '';
// console.log('icon', icon)
// 将.icns文件转为.png文件
let fileRes = '';
try {
if(icon) {
fileRes = execSync(`sips -s format png '${icon}' --out /Users/lianda/Desktop/working/file/'${fileNameShort}'.png`);
}
if(fileRes) icon = `/Users/lianda/Desktop/working/file/${fileNameShort}.png`;
} catch (error) {
console.log("Errors2:", error);
}
let execCommand = `open '${file}'` let execCommand = `open '${file}'`
return { return {
name: fileNameShort, name: fileNameShort,
......
...@@ -2,18 +2,18 @@ ...@@ -2,18 +2,18 @@
<div id="app" ref="appcontainer" class="container"> <div id="app" ref="appcontainer" class="container">
<div class="left_main"> <div class="left_main">
<img src="~@/assets/WechatIMG17.jpeg" alt="" class="left_img"> <img src="~@/assets/WechatIMG17.jpeg" alt="" class="left_img">
<span class="left_name">许昌市第十六中学</span> <span class="left_name" @click="getFrontApp">许昌市第十六中学</span>
</div> </div>
<div class="group1_wrap first"> <div v-if="mode=='modeJianYue'" class="group1_wrap first">
<div v-for="(appItem, appIndex) in group1" <div v-for="(appItem, appIndex) in group1"
v-show="appIndex < 14" v-show="appIndex < 14"
class="app_item" class="app_item"
@click="tapApp(appItem)"> @click="tapApp(appItem)">
<img :src="appItem.icon" alt="" class="img"> <img :src="appItem.icon" alt="" class="img" v-if="appItem.icon && appItem.icon.indexOf('.png') == -1">
<span class="app_name">{{ appItem.name }}</span> <span class="app_name">{{ appItem.name }}</span>
</div> </div>
</div> </div>
<div class="group1_wrap"> <div v-if="mode=='modeJianYue'" class="group1_wrap">
<div v-for="(appItem, appIndex) in group2" <div v-for="(appItem, appIndex) in group2"
v-show="appIndex < 14" v-show="appIndex < 14"
class="app_item" class="app_item"
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<span class="app_name">{{ appItem.name }}</span> <span class="app_name">{{ appItem.name }}</span>
</div> </div>
</div> </div>
<div class="group1_wrap"> <div v-if="mode=='modeJianYue'" class="group1_wrap">
<div v-for="(appItem, appIndex) in group3" <div v-for="(appItem, appIndex) in group3"
v-show="appIndex < 14" v-show="appIndex < 14"
class="app_item" class="app_item"
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
<span class="app_name">{{ appItem.name }}</span> <span class="app_name">{{ appItem.name }}</span>
</div> </div>
</div> </div>
<div class="group1_wrap"> <div v-if="mode=='modeJianYue'" class="group1_wrap">
<div v-for="(appItem, appIndex) in group4" <div v-for="(appItem, appIndex) in group4"
v-show="appIndex < 14" v-show="appIndex < 14"
class="app_item" class="app_item"
...@@ -47,37 +47,89 @@ export default { ...@@ -47,37 +47,89 @@ export default {
data() { data() {
return { return {
appList:[], appList:[],
group1:[], mode:'modeJianYue',
group2:[], // group1:[],
group3:[], // group2:[],
group4:[], // group3:[],
// group4:[],
}; };
}, },
computed: {
group1() {
return this.appList.length > 8 && this.appList.slice(0,9) || [];
},
group2() {
return this.appList.length > 10 && this.appList.slice(9,11) || [];
},
group3() {
return this.appList.length > 12 && this.appList.slice(11,13) || [];
},
group4() {
return this.appList.length > 14 && this.appList.slice(13,15) || [];
},
},
created() { created() {
}, },
mounted() { mounted() {
const screen = this.$electron.remote.screen; const screen = this.$electron.remote.screen;
const {width,height} = screen.getPrimaryDisplay().workAreaSize;//获取到屏幕的宽度和高度 const {width,height} = screen.getPrimaryDisplay().workAreaSize;//获取到屏幕的宽度和高度
console.log('宽高',width,height); console.log('宽高',width,height);
this.listener();
let ipcRenderer = this.$electron && this.$electron.ipcRenderer || {}; let ipcRenderer = this.$electron && this.$electron.ipcRenderer || {};
ipcRenderer.send("setMainWindow0",{width,height}); ipcRenderer.send("setMainWindow0",{width,height});
ipcRenderer.send("getApps") ipcRenderer.send("getApps");
ipcRenderer.on("base64Info", (event, {url,index}) => {
// 获取到base64
url = url.replace(/[\r\n]/g, '');
this.appList[index].icon = url;
});
ipcRenderer.on("appsList", (event, list) => { ipcRenderer.on("appsList", (event, list) => {
console.log('获取到app列表', list) // console.log('获取到app列表', list)
// 获取到app列表
this.appList = list; this.appList = list;
if(list) { this.appList.forEach((item, index) => {
if(list.length > 8) this.group1 = list.slice(0,9); item.icon && ipcRenderer.send("getBase64", {'imagePath':item.icon,index});
if(list.length > 10) this.group2 = list.slice(9,11); });
if(list.length > 12) this.group3 = list.slice(11,13);
if(list.length > 14) this.group4 = list.slice(13,15);
}
}); });
}, },
methods: { methods: {
listener() {
window.addEventListener('contextmenu', (e) => {
e.preventDefault();
if(e.target.parentElement && e.target.parentElement.classList.contains("app_item")
|| e.target.classList.contains("app_item")) {
// console.log('app_item')
return;
}
if(e.target.parentElement && e.target.parentElement.classList.contains("left_main")
|| e.target.classList.contains("left_main")) {
// console.log('left_main')
return;
}
let ipcRenderer = this.$electron && this.$electron.ipcRenderer || {};
ipcRenderer.send("show-context-menu");
});
let ipcRenderer = this.$electron && this.$electron.ipcRenderer || {};
ipcRenderer.on("context-menu-command",(event, mode) => {
console.log('context-menu-command', mode)
let modeObj = {
modeJianYue:'modeJianYue',
modeJiJian:'modeJiJian',
modeUXue:'modeUXue',
};
this.mode = modeObj[mode];
console.log(this.mode)
});
},
tapApp(item) { tapApp(item) {
console.log(item) console.log(item)
let ipcRenderer = this.$electron && this.$electron.ipcRenderer || {}; let ipcRenderer = this.$electron && this.$electron.ipcRenderer || {};
ipcRenderer.send("openApp",item); ipcRenderer.send("openApp",item);
},
getFrontApp() {
let ipcRenderer = this.$electron && this.$electron.ipcRenderer || {};
ipcRenderer.send("getfrontApp");
} }
}, },
} }
...@@ -110,9 +162,9 @@ body { ...@@ -110,9 +162,9 @@ body {
flex: 1; flex: 1;
height: 40px; height: 40px;
&.first { &.first {
margin-left: 2px;
border-top-left-radius: 0; border-top-left-radius: 0;
border-bottom-left-radius: 0; border-bottom-left-radius: 0;
margin-left: 0;
} }
} }
.app_item { .app_item {
...@@ -150,14 +202,14 @@ body { ...@@ -150,14 +202,14 @@ body {
flex-shrink: 0; flex-shrink: 0;
padding: 0 20px; padding: 0 20px;
background-color: hsl(0, 0%, 25%); background-color: hsl(0, 0%, 25%);
&::after { // &::after {
position: absolute; // position: absolute;
content: ""; // content: "";
right: 10px; // right: 10px;
border-right: 1px solid #e4e4e4; // border-right: 1px solid #e4e4e4;
width: 1px; // width: 1px;
height: 100%; // height: 100%;
} // }
} }
.left_img { .left_img {
width: 35px; width: 35px;
......
...@@ -6835,6 +6835,11 @@ human-signals@^2.1.0: ...@@ -6835,6 +6835,11 @@ human-signals@^2.1.0:
resolved "https://registry.npmmirror.com/human-signals/download/human-signals-2.1.0.tgz" resolved "https://registry.npmmirror.com/human-signals/download/human-signals-2.1.0.tgz"
integrity sha1-3JH8ukLk0G5Kuu0zs+ejwC9RTqA= integrity sha1-3JH8ukLk0G5Kuu0zs+ejwC9RTqA=
icns@^0.1.0:
version "0.1.0"
resolved "https://registry.npmmirror.com/icns/-/icns-0.1.0.tgz#e4de94b9a67ef316917b3142d92a2f69a5fc0fab"
integrity sha512-Xax7k3EdDVgwhY71TgJK616YuKRFKHJyLeYrp7sg4CaHrs+8Tq4M2YtsKPSUNXTH3wVn66YyWsDQ2jzy+H/AUA==
icon-gen@^2.0.0: icon-gen@^2.0.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.npmmirror.com/icon-gen/-/icon-gen-2.1.0.tgz" resolved "https://registry.npmmirror.com/icon-gen/-/icon-gen-2.1.0.tgz"
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论