flying-lobster 0.1.2 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 cnijh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 cnijh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
Binary file
Binary file
@@ -0,0 +1,220 @@
1
+ const { app, BrowserWindow, globalShortcut, Tray, Menu, nativeImage, screen, ipcMain } = require('electron');
2
+ const path = require('path');
3
+ const Store = require('electron-store').default || require('electron-store');
4
+
5
+ const store = new Store({
6
+ defaults: {
7
+ windowBounds: null, // will be computed on first launch
8
+ chatUrl: null
9
+ }
10
+ });
11
+
12
+ const AutoLaunch = require('auto-launch');
13
+
14
+ const autoLauncher = new AutoLaunch({
15
+ name: 'Flying Lobster',
16
+ isHidden: true
17
+ });
18
+
19
+ // Enable auto-launch on first run
20
+ autoLauncher.isEnabled().then((isEnabled) => {
21
+ if (!isEnabled) autoLauncher.enable();
22
+ });
23
+
24
+ let win = null;
25
+ let tray = null;
26
+
27
+ function getDefaultBounds() {
28
+ const display = screen.getPrimaryDisplay();
29
+ const { width: screenW, height: screenH } = display.workAreaSize;
30
+ // Wide but short, centered at bottom
31
+ const winW = Math.min(700, screenW - 100);
32
+ const winH = 340;
33
+ const x = Math.round((screenW - winW) / 2);
34
+ const y = screenH - winH - 20; // 20px from bottom
35
+ return { x, y, width: winW, height: winH };
36
+ }
37
+
38
+ function createWindow() {
39
+ // Always use computed defaults on first launch
40
+ let bounds = store.get('windowBounds');
41
+ if (!bounds || !bounds.width) {
42
+ bounds = getDefaultBounds();
43
+ store.set('windowBounds', bounds);
44
+ }
45
+
46
+ win = new BrowserWindow({
47
+ ...bounds,
48
+ minWidth: 400,
49
+ minHeight: 200,
50
+ alwaysOnTop: true,
51
+ visibleOnAllWorkspaces: true,
52
+ fullscreenable: false,
53
+ frame: false,
54
+ transparent: false,
55
+ skipTaskbar: false,
56
+ show: false,
57
+ hasShadow: true,
58
+ roundedCorners: true,
59
+ type: process.platform === 'darwin' ? 'panel' : undefined,
60
+ webPreferences: {
61
+ preload: path.join(__dirname, 'preload.js'),
62
+ contextIsolation: false,
63
+ nodeIntegration: false,
64
+ partition: 'persist:telegram'
65
+ }
66
+ });
67
+
68
+ if (process.platform === 'darwin') {
69
+ win.setAlwaysOnTop(true, 'floating');
70
+ win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
71
+ }
72
+
73
+ const chatUrl = store.get('chatUrl');
74
+ if (chatUrl) {
75
+ win.loadURL(chatUrl);
76
+ } else {
77
+ win.loadURL('https://web.telegram.org/a/');
78
+ }
79
+
80
+ // When page loads, focus the input and scroll to bottom
81
+ win.webContents.on('did-finish-load', () => {
82
+ // Wait for Telegram to render, then focus input and scroll to latest
83
+ setTimeout(() => {
84
+ win.webContents.executeJavaScript(`
85
+ (function() {
86
+ // Scroll chat to bottom
87
+ var msgs = document.querySelector('.messages-container .scrollable');
88
+ if (msgs) msgs.scrollTop = msgs.scrollHeight;
89
+ // Alternative scroll target
90
+ var bubble = document.querySelector('.bubbles-inner');
91
+ if (bubble) bubble.scrollTop = bubble.scrollHeight;
92
+ // Focus the message input
93
+ var input = document.querySelector('[contenteditable="true"]');
94
+ if (input) input.focus();
95
+ var textInput = document.querySelector('.input-message-input');
96
+ if (textInput) textInput.focus();
97
+ })();
98
+ `).catch(() => {});
99
+ }, 2000);
100
+ });
101
+
102
+ // Save chat URL when user navigates to a chat
103
+ win.webContents.on('did-navigate-in-page', (event, url) => {
104
+ if (url.match(/web\.telegram\.org\/a\/#-?\d+/)) {
105
+ store.set('chatUrl', url);
106
+ }
107
+ });
108
+
109
+ const saveBounds = () => {
110
+ if (win && !win.isMinimized() && !win.isMaximized()) {
111
+ store.set('windowBounds', win.getBounds());
112
+ }
113
+ };
114
+ win.on('resize', saveBounds);
115
+ win.on('move', saveBounds);
116
+
117
+ win.on('close', (e) => {
118
+ if (!app.isQuitting) {
119
+ e.preventDefault();
120
+ win.hide();
121
+ }
122
+ });
123
+ }
124
+
125
+ function toggleWindow() {
126
+ if (!win) return;
127
+ if (win.isVisible() && win.isFocused()) {
128
+ win.hide();
129
+ } else {
130
+ win.show();
131
+ win.focus();
132
+ // Re-focus input when showing
133
+ setTimeout(() => {
134
+ win.webContents.executeJavaScript(`
135
+ (function() {
136
+ var input = document.querySelector('[contenteditable="true"]');
137
+ if (input) input.focus();
138
+ var textInput = document.querySelector('.input-message-input');
139
+ if (textInput) textInput.focus();
140
+ })();
141
+ `).catch(() => {});
142
+ }, 200);
143
+ }
144
+ }
145
+
146
+ function resetChat() {
147
+ store.delete('chatUrl');
148
+ if (win) {
149
+ win.loadURL('https://web.telegram.org/a/');
150
+ }
151
+ }
152
+
153
+ function resetPosition() {
154
+ if (win) {
155
+ const bounds = getDefaultBounds();
156
+ win.setBounds(bounds);
157
+ store.set('windowBounds', bounds);
158
+ }
159
+ }
160
+
161
+ function createTray() {
162
+ // On macOS, use title string with emoji for tray (shows as text icon)
163
+ if (process.platform === 'darwin') {
164
+ // Create a tiny transparent image for tray, then set title to emoji
165
+ const emptyIcon = nativeImage.createEmpty();
166
+ tray = new Tray(emptyIcon);
167
+ tray.setTitle('🦞');
168
+ } else {
169
+ const icon = nativeImage.createFromDataURL(
170
+ 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAA' +
171
+ 'mElEQVQ4T2NkoBAwUqifAY8B/xkY/v9nYPj/n4Hh338Ghn//GRj+MTAw/GNgYPjHwMDw' +
172
+ 'F8z+z8Dwl4GB4Q8DA8MfBgaG3wwMDL8YGBh+MjAw/GBgYPjOwMDwjYGB4SsDA8MXBgaG' +
173
+ 'zwwMDJ8YGBg+MjAwfGBgYHjPwMDwjoGB4S0DA8MbBgaG1wwMDK8YGBheAukvAQBNjCYR' +
174
+ 'jE8ZzQAAAABJRU5ErkJggg=='
175
+ );
176
+ tray = new Tray(icon);
177
+ }
178
+ tray.setToolTip('🦞 Flying Lobster');
179
+
180
+ const contextMenu = Menu.buildFromTemplate([
181
+ { label: 'Show/Hide', click: toggleWindow },
182
+ { label: 'Switch Chat', click: resetChat },
183
+ { label: 'Reset Position', click: resetPosition },
184
+ { type: 'separator' },
185
+ { label: 'Quit', click: () => { app.isQuitting = true; app.quit(); } }
186
+ ]);
187
+
188
+ tray.setContextMenu(contextMenu);
189
+ tray.on('click', toggleWindow);
190
+ }
191
+
192
+ app.whenReady().then(() => {
193
+ createWindow();
194
+ createTray();
195
+
196
+ // Handle window drag from preload
197
+ ipcMain.on('window-drag', (event, dx, dy) => {
198
+ if (!win) return;
199
+ const [x, y] = win.getPosition();
200
+ win.setPosition(x + dx, y + dy);
201
+ });
202
+
203
+ const shortcut = process.platform === 'darwin' ? 'CommandOrControl+Shift+M' : 'Ctrl+Shift+M';
204
+ globalShortcut.register(shortcut, toggleWindow);
205
+ });
206
+
207
+ app.on('will-quit', () => {
208
+ globalShortcut.unregisterAll();
209
+ });
210
+
211
+ app.on('window-all-closed', (e) => {
212
+ // Don't quit on window close
213
+ });
214
+
215
+ app.on('activate', () => {
216
+ if (win) {
217
+ win.show();
218
+ win.focus();
219
+ }
220
+ });