代码拉取完成,页面将自动刷新
同步操作将从 Chiroc/mouse-finger 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
const electron = require('electron');
const {app, BrowserWindow, globalShortcut, Menu, Tray, ipcMain} = electron;
const mouse = require('./main-process/mouse').mouse;
const {MouseKeys, MouseKeysLabel_ZHCN} = require('./main-process/include/mouseMetrics');
let win = null;
let tray = null;
const appPath = app.getAppPath();
let _ = {
init() {
app.on('ready', () => {
this.createWindow();
this.createMenusAndTray();
mouse.registerEvent();
this.registerShortcut();
this.registerEvent();
});
app.on('window-all-closed', () => {
win = null;
tray = null;
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (win === null) {
this.createWindow();
}
});
},
registerEvent() {
ipcMain.on('params-updated', (event, arg) => {
this.updateTray(arg);
});
},
/**
* 注册系统全局快捷键
*/
registerShortcut() {
// 切换左右键及指针。同时会切换为对应的点击键(左手指针为右键点击,右手指针为左手点击)。
globalShortcut.register('Ctrl+`', () => {
if (mouse.getParams().pointerMode === MouseKeys.LEFT) {
mouse.setAsRightCursor();
mouse.setAsLeftClick();
} else {
mouse.setAsLeftCursor();
mouse.setAsRightClick();
}
win.webContents.send('shortcut-event', mouse.getParams());
this.updateTray();
});
// 只切换左右单击键。
globalShortcut.register('Ctrl+Alt+`', () => {
if (mouse.getMouseState()) {
mouse.setAsRightClick();
} else {
mouse.setAsLeftClick();
}
win.webContents.send('shortcut-event', mouse.getParams());
this.updateTray();
});
// 开启和暂停自动点击操作
globalShortcut.register('Alt+F1', () => {
mouse.togglePaused();
win.webContents.send('shortcut-event', mouse.getParams());
this.updateTray();
});
},
createWindow() {
win = new BrowserWindow({
title: 'Mouse Settings',
icon: appPath + '/assets/logo.png',
autoHideMenuBar: true,
width: 350,
height: 490,
frame: true,
resizable: false,
closable: true
});
win.setMenu(null);
win.loadFile(appPath + '/sections/index.html');
win.hide();
win.on('closed', () => {
win = null;
});
win.on('hide', () => {
this.createMenusAndTray();
});
win.on('minimize', () => {
win.hide();
});
// 隐藏/显示程序
globalShortcut.register('Ctrl+Alt+0', () => {
this.toggleWin();
});
},
createMenusAndTray() {
if (tray) {
return;
}
tray = new Tray(appPath + '/assets/mouse.png');
const contextMenu = Menu.buildFromTemplate([{
label: '设置(Settings)',
type: 'normal',
icon: appPath + '/assets/settings.png',
click() {
win.show();
}
}, {
label: '退出(Exit)',
type: 'normal',
icon: appPath + '/assets/exit.png',
click() {
app.quit();
}
}]);
tray.setToolTip('Mouse Finger');
// tray.setTitle('Mouse Finger');
tray.setContextMenu(contextMenu);
tray.on('double-click', () => {
this.toggleWin();
});
_.updateTray();
},
/**
* 更新系统托盘图标和提示信息
* @param {object} [params]
*/
updateTray(params) {
if (!params) {
params = mouse.getParams();
}
tray.setImage(appPath + `/assets/mouse-${params.mouseKey}-${params.isPaused ? 'manual' : 'auto'}.png`);
tray.setToolTip(`${MouseKeysLabel_ZHCN[params.pointerMode]}手指针|${MouseKeysLabel_ZHCN[params.mouseKey]}键点击|${params.isPaused ? '手动' : '自动'}点击`);
},
toggleWin() {
win.isVisible() ? win.hide() : win.show();
}
};
_.init();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。