docs-combiner 0.1.15 → 0.1.17

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/dist/main.js CHANGED
@@ -47,6 +47,20 @@ const path = __importStar(require("path"));
47
47
  const fs = __importStar(require("fs"));
48
48
  const http = __importStar(require("http"));
49
49
  const url = __importStar(require("url"));
50
+ let pendingGoogleAuth = null;
51
+ function abortPendingGoogleAuth(reason) {
52
+ const pending = pendingGoogleAuth;
53
+ if (!pending)
54
+ return;
55
+ pendingGoogleAuth = null;
56
+ try {
57
+ pending.server.close();
58
+ }
59
+ catch (_a) {
60
+ /* ignore */
61
+ }
62
+ pending.reject(new Error(reason));
63
+ }
50
64
  function createWindow() {
51
65
  // Try to read theme preference from localStorage file
52
66
  // In Electron, localStorage is stored in a specific location
@@ -133,6 +147,7 @@ electron_1.app.whenReady().then(() => {
133
147
  return true;
134
148
  }));
135
149
  electron_1.ipcMain.handle('start-auth', (event, clientId) => __awaiter(void 0, void 0, void 0, function* () {
150
+ abortPendingGoogleAuth('AUTH_SUPERSEDED');
136
151
  return new Promise((resolve, reject) => {
137
152
  const server = http.createServer((req, res) => __awaiter(void 0, void 0, void 0, function* () {
138
153
  try {
@@ -146,25 +161,54 @@ electron_1.app.whenReady().then(() => {
146
161
  const port = address && typeof address !== 'string' ? address.port : 0;
147
162
  res.writeHead(200, { 'Content-Type': 'text/html' });
148
163
  res.end('<h1>Authentication successful!</h1><p>You can close this window and return to the app.</p><script>window.close();</script>');
149
- server.close();
164
+ pendingGoogleAuth = null;
165
+ try {
166
+ server.close();
167
+ }
168
+ catch (_a) {
169
+ /* ignore */
170
+ }
150
171
  resolve({ code: query.code, redirectUri: `http://127.0.0.1:${port}` });
151
172
  }
152
173
  else if (query.error) {
153
174
  res.writeHead(400, { 'Content-Type': 'text/html' });
154
175
  res.end('Authentication failed.');
155
- server.close();
176
+ pendingGoogleAuth = null;
177
+ try {
178
+ server.close();
179
+ }
180
+ catch (_b) {
181
+ /* ignore */
182
+ }
156
183
  reject(new Error(query.error));
157
184
  }
158
185
  }
159
186
  catch (e) {
160
- server.close();
161
- reject(e);
187
+ pendingGoogleAuth = null;
188
+ try {
189
+ server.close();
190
+ }
191
+ catch (_c) {
192
+ /* ignore */
193
+ }
194
+ reject(e instanceof Error ? e : new Error(String(e)));
162
195
  }
163
196
  }));
197
+ server.on('error', (err) => {
198
+ if ((pendingGoogleAuth === null || pendingGoogleAuth === void 0 ? void 0 : pendingGoogleAuth.server) === server) {
199
+ pendingGoogleAuth = null;
200
+ }
201
+ reject(err);
202
+ });
164
203
  server.listen(0, '127.0.0.1', () => {
165
204
  const address = server.address();
166
205
  if (!address || typeof address === 'string') {
167
- server.close();
206
+ try {
207
+ server.close();
208
+ }
209
+ catch (_a) {
210
+ /* ignore */
211
+ }
168
212
  reject(new Error('Failed to get server port'));
169
213
  return;
170
214
  }
@@ -173,10 +217,25 @@ electron_1.app.whenReady().then(() => {
173
217
  // Google Drive Scope: https://www.googleapis.com/auth/drive (Full Access)
174
218
  // Added prompt=consent to force new refresh token with correct scopes
175
219
  const authUrl = `https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&response_type=code&client_id=${clientId}&redirect_uri=${redirectUri}&prompt=consent`;
220
+ pendingGoogleAuth = { authUrl, server, resolve, reject };
176
221
  electron_1.shell.openExternal(authUrl);
177
222
  });
178
223
  });
179
224
  }));
225
+ electron_1.ipcMain.handle('reopen-pending-auth-browser', () => __awaiter(void 0, void 0, void 0, function* () {
226
+ if (!pendingGoogleAuth) {
227
+ return { ok: false };
228
+ }
229
+ yield electron_1.shell.openExternal(pendingGoogleAuth.authUrl);
230
+ return { ok: true };
231
+ }));
232
+ electron_1.ipcMain.handle('cancel-pending-auth', () => __awaiter(void 0, void 0, void 0, function* () {
233
+ if (!pendingGoogleAuth) {
234
+ return { ok: false };
235
+ }
236
+ abortPendingGoogleAuth('LOGIN_CANCELLED');
237
+ return { ok: true };
238
+ }));
180
239
  electron_1.ipcMain.handle('open-external', (event, url) => __awaiter(void 0, void 0, void 0, function* () {
181
240
  yield electron_1.shell.openExternal(url);
182
241
  }));
package/dist/preload.js CHANGED
@@ -55,6 +55,8 @@ electron_1.contextBridge.exposeInMainWorld('electronAPI', {
55
55
  saveConfig: (config) => electron_1.ipcRenderer.invoke('save-config', config),
56
56
  loadConfig: () => electron_1.ipcRenderer.invoke('load-config'),
57
57
  startAuth: (clientId) => electron_1.ipcRenderer.invoke('start-auth', clientId),
58
+ reopenPendingAuthBrowser: () => electron_1.ipcRenderer.invoke('reopen-pending-auth-browser'),
59
+ cancelPendingAuth: () => electron_1.ipcRenderer.invoke('cancel-pending-auth'),
58
60
  openExternal: (url) => electron_1.ipcRenderer.invoke('open-external', url),
59
61
  log: (level, ...args) => electron_1.ipcRenderer.invoke('log', level, ...args),
60
62
  });