1 Star 0 Fork 2

下一站、浪漫/FreeScreenRecorder

forked from 云加/FreeScreenRecorder 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.js 3.66 KB
一键复制 编辑 原始数据 按行查看 历史
plter 提交于 2017-03-25 21:42 . 实现直接保存到文件的功能
const electron = require('electron');
const ipcMain = electron.ipcMain;
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
const Config = require("./src/Config");
const path = require('path');
const globalShortcut = electron.globalShortcut;
//additions
require("./src/main/DialogsImplements");
class Main {
constructor() {
this.addListeners();
}
createWindow() {
// Create the browser window.
this.mainWindow = new BrowserWindow({width: 380, height: 280});
// and load the index.html of the app.
this.mainWindow.loadURL("file://" + path.join(Config.getRenderersDir(), "index", "index.html"));
// Open the DevTools.
// this.mainWindow.webContents.openDevTools();
// Emitted when the window is closed.
this.mainWindow.on('closed', () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
this.mainWindow = null;
});
}
createTray() {
this.tray = new electron.Tray(path.join(Config.getImagesDir(), "icon_16.png"));
const contextMenu = electron.Menu.buildFromTemplate([
{
label: '退出',
accelerator: "CmdOrCtrl+Q",
click: (item, focusedWindow) => {
app.quit();
}
}
]);
this.tray.setToolTip('This is my application.');
this.tray.setContextMenu(contextMenu);
}
addListeners() {
app.on('ready', () => {
this.createTray();
this.createWindow();
this.registerGlobalShortcuts();
});
app.on('window-all-closed', function () {
// On OS X it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
// if (process.platform !== 'darwin') {
app.quit();
// }
});
app.on('activate', function () {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (this.mainWindow === null) {
this.createWindow();
}
});
app.on('will-quit', () => {
this.unregisterAllGlobalShortcuts();
});
ipcMain.on("stopped", event => {
this.tray.setImage(path.join(Config.getImagesDir(), "icon_16.png"));
event.returnValue = 1;
});
ipcMain.on("paused", event => {
this.tray.setImage(path.join(Config.getImagesDir(), "icon_paused_16.png"));
event.returnValue = 1;
});
ipcMain.on("recording", event => {
this.tray.setImage(path.join(Config.getImagesDir(), "icon_recording_16.png"));
event.returnValue = 1;
});
}
registerGlobalShortcuts() {
//Start or stop button
globalShortcut.register("CommandOrControl+8", () => {
this.sendStartOrStopButtonClickedEvent();
});
//Pause or resume button
globalShortcut.register("CommandOrControl+9", () => {
this.sendPauseOrResumeButtonClickedEvent();
});
}
sendPauseOrResumeButtonClickedEvent() {
this.mainWindow.webContents.send("pauseOrResume");
}
sendStartOrStopButtonClickedEvent() {
this.mainWindow.webContents.send("startOrStop");
}
unregisterAllGlobalShortcuts() {
globalShortcut.unregisterAll();
}
}
new Main();
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/QQ921782392/FreeScreenRecorder.git
git@gitee.com:QQ921782392/FreeScreenRecorder.git
QQ921782392
FreeScreenRecorder
FreeScreenRecorder
master

搜索帮助