forked from terkelg/ramme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
141 lines (113 loc) · 3.32 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
'use strict';
const path = require('path');
const fs = require('fs');
const electron = require('electron');
const appMenu = require('./menu');
const config = require('./config');
const tray = require('./tray');
const version = require('./version');
const app = electron.app;
const ipcMain = electron.ipcMain;
require('electron-debug')();
const BrowserWindow = electron.BrowserWindow;
let mainWindow;
let isQuitting = false;
const isAlreadyRunning = app.makeSingleInstance(() => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.show();
}
});
if (isAlreadyRunning) {
app.quit();
}
function createMainWindow() {
const lastWindowState = config.get('lastWindowState');
const isDarkMode = config.get('darkMode');
const userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1';
const rammeDesktopIcon = path.join(__dirname, 'static/icon.png');
const maxWidthValue = 3300;
const minWidthValue = 400;
// Create the browser window.
const win = new BrowserWindow({
title: app.getName(),
show: false,
x: lastWindowState.x,
y: lastWindowState.y,
minHeight: 400,
minWidth: minWidthValue,
maxWidth: maxWidthValue,
width: lastWindowState.width,
height: lastWindowState.height,
maximizable: false,
fullscreenable: false,
icon: process.platform === 'linux' && rammeDesktopIcon,
titleBarStyle: 'hidden-inset',
darkTheme: isDarkMode,
backgroundColor: isDarkMode ? '#192633' : '#fff',
autoHideMenuBar: true,
webPreferences: {
preload: path.join(__dirname, 'browser.js'),
nodeIntegration: false
}
});
win.webContents.setUserAgent(userAgent);
win.loadURL(`https://www.instagram.com`);
win.openDevTools({mode: 'detach'});
win.on('close', e => {
if (!isQuitting) {
e.preventDefault();
if (process.platform === 'darwin') {
app.hide();
} else {
win.hide();
}
}
});
win.on('page-title-updated', e => {
e.preventDefault();
tray.create(win);
});
return win;
}
function sendAction(action) {
const win = BrowserWindow.getAllWindows()[0];
if (process.platform === 'darwin') {
win.restore();
}
win.webContents.send(action);
}
app.on('ready', () => {
electron.Menu.setApplicationMenu(appMenu);
mainWindow = createMainWindow();
const page = mainWindow.webContents;
ipcMain.on('back', (event, arg) => {
if (page.canGoBack()) {
page.goBack();
}
});
page.on('did-navigate-in-page', (event, arg) => {
const menuBackBtn = appMenu.items[1].submenu.items[0];
menuBackBtn.enabled = page.canGoBack();
page.send('set-button-state', menuBackBtn.enabled);
});
page.on('dom-ready', () => {
page.insertCSS(fs.readFileSync(path.join(__dirname, 'browser.css'), 'utf8'));
page.insertCSS(fs.readFileSync(path.join(__dirname, 'dark-browser.css'), 'utf8'));
mainWindow.show();
});
page.on('new-window', (e, url) => {
e.preventDefault();
electron.shell.openExternal(url);
});
setTimeout(function() {version.check()}, 8000);
});
app.on('activate', () => {
mainWindow.show();
});
app.on('before-quit', () => {
isQuitting = true;
config.set('lastWindowState', mainWindow.getBounds());
});