-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
185 lines (185 loc) · 6.59 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable @typescript-eslint/no-use-before-define */
/* eslint-disable import/no-dynamic-require */
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable global-require */
var electron_1 = require("electron");
var path = require("path");
var url = require("url");
var electron_updater_1 = require("electron-updater");
var obs_1 = require("./src/worker/obs");
var store_1 = require("./src/app/_helpers/store");
var win = null;
var obs = null;
var args = process.argv.slice(1);
var serve = args.some(function (val) { return val === "--serve"; });
function createWindow() {
var size = electron_1.screen.getPrimaryDisplay().workAreaSize;
var store = new store_1.Store({
configName: "window-state",
defaults: {
windowBounds: {
width: size.width / 2,
height: size.height / 2,
x: undefined,
y: undefined,
isMaximized: false,
},
},
});
var _a = store.get("windowBounds"), width = _a.width, height = _a.height, x = _a.x, y = _a.y, isMaximized = _a.isMaximized;
win = new electron_1.BrowserWindow({
width: width,
height: height,
x: x,
y: y,
icon: path.join(__dirname, "src/assets/icons/favicon.png"),
webPreferences: {
nodeIntegration: true,
webSecurity: false,
enableRemoteModule: true,
allowRunningInsecureContent: !!(serve),
},
frame: false,
backgroundColor: "#1E1E1E",
});
if (isMaximized) {
win.maximize();
}
win.on("resize", function () {
storeWindowState(store);
});
win.on("move", function () {
storeWindowState(store);
});
if (serve) {
require("devtron").install();
win.webContents.openDevTools();
require("electron-reload")(__dirname, {
electron: require(__dirname + "/node_modules/electron"),
});
win.loadURL("http://localhost:4200");
}
else {
win.loadURL(url.format({
pathname: path.join(__dirname, "dist/index.html"),
protocol: "file:",
slashes: true,
}));
}
electron_1.ipcMain.on("obs-action", function (action) {
var data = [];
for (var _i = 1; _i < arguments.length; _i++) {
data[_i - 1] = arguments[_i];
}
switch (action) {
case "initialize":
if (obs) {
obs.shutdown();
obs = undefined;
}
obs = new obs_1.OBS(win);
break;
default:
// eslint-disable-next-line no-console
console.log("unknown event:", action, data);
}
});
electron_1.ipcMain.on("preview-init", function (bounds) {
electron_1.ipcMain.emit("preview-height", obs.setupPreview(win, bounds));
});
electron_1.ipcMain.on("preview-bounds", function (bounds) {
electron_1.ipcMain.emit("preview-height", obs.resizePreview(bounds));
});
electron_1.ipcMain.on("projector-init", function () {
obs.setupProjector(win);
});
electron_1.ipcMain.on("projector-end", function () {
obs.endProjector();
});
electron_1.ipcMain.on("add-slides", function (slides) {
for (var _i = 0, _a = slides; _i < _a.length; _i++) {
var slide = _a[_i];
obs.addFile(slide);
}
});
electron_1.ipcMain.on("transition-to", function (slide) {
obs.transitionTo(slide.id);
});
electron_1.ipcMain.on("transition-to-default-slide", function (slide) {
obs.transitionToDefaultSlide(slide);
});
electron_1.ipcMain.on("update-properties", function (slide) {
obs.updateProperties(slide);
});
electron_1.ipcMain.handle("getVideoFileLength", function (_, filePath) {
if (!obs)
return;
// eslint-disable-next-line consistent-return
return obs.getVideoFileLength(filePath);
});
electron_1.ipcMain.handle("playSource", function (_, slideId) {
if (!obs)
return;
// eslint-disable-next-line consistent-return
return obs.playSource(slideId);
});
electron_1.ipcMain.handle("pauseSource", function (_, slideId) {
if (!obs)
return;
// eslint-disable-next-line consistent-return
return obs.pauseSource(slideId);
});
electron_1.ipcMain.handle("seek", function (_, slideId, position) {
if (!obs)
return;
// eslint-disable-next-line consistent-return
return obs.seek(slideId, position);
});
electron_1.ipcMain.handle("getMediaPosition", function (_, slideId) {
if (!obs)
return;
// eslint-disable-next-line consistent-return
return obs.getMediaPosition(slideId);
});
electron_1.ipcMain.on("clear-slides", function () {
obs.clearSlides();
});
electron_1.ipcMain.on("settings-changed", function () {
obs.updateSettings(win);
});
electron_1.ipcMain.on("shutdown", function () {
obs.shutdown();
});
// Emitted when the window is closed.
win.on("closed", function () {
// Dereference the window object, usually you would store window
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
obs.shutdown();
electron_1.app.quit();
});
electron_updater_1.autoUpdater.checkForUpdatesAndNotify();
return win;
}
try {
electron_1.app.allowRendererProcessReuse = false;
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
// Added 400 ms to fix the black background issue while using transparent window. More detais at https://github.com/electron/electron/issues/15947
electron_1.app.on("ready", function () { return setTimeout(createWindow, 400); });
}
catch (e) {
// Catch Error
// throw e;
}
function storeWindowState(store) {
var _a = win.getBounds(), width = _a.width, height = _a.height, x = _a.x, y = _a.y;
var isMaximized = win.isMaximized();
store.set("windowBounds", {
width: width, height: height, x: x, y: y, isMaximized: isMaximized,
});
}
//# sourceMappingURL=main.js.map