mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
@@ -4,7 +4,6 @@ import { net, protocol, session } from 'electron';
|
||||
import cookieParser from 'set-cookie-parser';
|
||||
|
||||
import { logger } from './logger';
|
||||
import { isOfflineModeEnabled } from './utils';
|
||||
|
||||
protocol.registerSchemesAsPrivileged([
|
||||
{
|
||||
@@ -141,36 +140,6 @@ export function registerProtocol() {
|
||||
session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
|
||||
const url = new URL(details.url);
|
||||
const pathname = url.pathname;
|
||||
const protocol = url.protocol;
|
||||
const origin = url.origin;
|
||||
|
||||
// offline whitelist
|
||||
// 1. do not block non-api request for http://localhost || file:// (local dev assets)
|
||||
// 2. do not block devtools
|
||||
// 3. block all other requests
|
||||
const blocked = (() => {
|
||||
if (!isOfflineModeEnabled()) {
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
(protocol === 'file:' || origin.startsWith('http://localhost')) &&
|
||||
!isNetworkResource(pathname)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if ('devtools:' === protocol) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})();
|
||||
|
||||
if (blocked) {
|
||||
logger.debug('blocked request', details.url);
|
||||
callback({
|
||||
cancel: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
// session cookies are set to file:// on production
|
||||
|
||||
@@ -3,7 +3,6 @@ import { autoUpdater as defaultAutoUpdater } from 'electron-updater';
|
||||
|
||||
import { buildType } from '../config';
|
||||
import { logger } from '../logger';
|
||||
import { isOfflineModeEnabled } from '../utils';
|
||||
import { AFFiNEUpdateProvider } from './affine-update-provider';
|
||||
import { updaterSubjects } from './event';
|
||||
import { WindowsUpdater } from './windows-updater';
|
||||
@@ -55,7 +54,7 @@ export const setConfig = (newConfig: Partial<UpdaterConfig> = {}): void => {
|
||||
};
|
||||
|
||||
export const checkForUpdates = async () => {
|
||||
if (disabled || checkingUpdate || isOfflineModeEnabled()) {
|
||||
if (disabled || checkingUpdate) {
|
||||
return;
|
||||
}
|
||||
checkingUpdate = true;
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import type { CookiesSetDetails } from 'electron';
|
||||
|
||||
import { logger } from './logger';
|
||||
import { globalStateStorage } from './shared-storage/storage';
|
||||
|
||||
export function parseCookie(
|
||||
cookieString: string,
|
||||
url: string
|
||||
@@ -55,16 +52,3 @@ export function parseCookie(
|
||||
|
||||
return details;
|
||||
}
|
||||
|
||||
export const isOfflineModeEnabled = () => {
|
||||
try {
|
||||
return (
|
||||
// todo(pengx17): better abstraction for syncing flags with electron
|
||||
// packages/common/infra/src/modules/feature-flag/entities/flags.ts
|
||||
globalStateStorage.get('affine-flag:enable_offline_mode') ?? false
|
||||
);
|
||||
} catch (error) {
|
||||
logger.error('Failed to get offline mode flag', error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user