mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-23 04:42:24 +03:00
feat(mobile): ios oauth & magic-link login (#8581)
Co-authored-by: EYHN <cneyhn@gmail.com>
This commit is contained in:
parent
d6ec4cc597
commit
06dda70319
@ -1,4 +1,3 @@
|
||||
import type { Component } from './components/component';
|
||||
import type { Entity } from './components/entity';
|
||||
import type { Scope } from './components/scope';
|
||||
import type { Service } from './components/service';
|
||||
@ -408,8 +407,6 @@ class FrameworkEditor {
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* override(OriginClass, NewClass, [dependencies, ...])
|
||||
* or
|
||||
* override(Identifier, Class, [dependencies, ...])
|
||||
* or
|
||||
* override(Identifier, Instance)
|
||||
@ -418,10 +415,10 @@ class FrameworkEditor {
|
||||
* ```
|
||||
*/
|
||||
override = <
|
||||
Arg1 extends GeneralIdentifier<any>,
|
||||
Arg2 extends Type<Trait> | ComponentFactory<Trait> | Trait | null,
|
||||
Arg1 extends Identifier<any>,
|
||||
Arg2 extends Type<Trait> | ComponentFactory<Trait> | Trait,
|
||||
Arg3 extends Deps,
|
||||
Trait extends Component = IdentifierType<Arg1>,
|
||||
Trait = IdentifierType<Arg1>,
|
||||
Deps = Arg2 extends Type<Trait>
|
||||
? TypesToDeps<ConstructorParameters<Arg2>>
|
||||
: [],
|
||||
|
@ -55,7 +55,7 @@ export abstract class FrameworkProvider {
|
||||
getOptional = <T>(
|
||||
identifier: GeneralIdentifier<T>,
|
||||
options?: ResolveOptions
|
||||
): T | null => {
|
||||
): T | undefined => {
|
||||
return this.getRaw(parseIdentifier(identifier), {
|
||||
...options,
|
||||
optional: true,
|
||||
|
@ -23,7 +23,7 @@ export function useService<T extends Service>(
|
||||
): T {
|
||||
const stack = useContext(FrameworkStackContext);
|
||||
|
||||
let service: T | null = null;
|
||||
let service: T | undefined = undefined;
|
||||
|
||||
for (let i = stack.length - 1; i >= 0; i--) {
|
||||
service = stack[i].getOptional(identifier, {
|
||||
@ -87,10 +87,10 @@ export function useServices<
|
||||
|
||||
export function useServiceOptional<T extends Service>(
|
||||
identifier: Type<T>
|
||||
): T | null {
|
||||
): T | undefined {
|
||||
const stack = useContext(FrameworkStackContext);
|
||||
|
||||
let service: T | null = null;
|
||||
let service: T | undefined = undefined;
|
||||
|
||||
for (let i = stack.length - 1; i >= 0; i--) {
|
||||
service = stack[i].getOptional(identifier, {
|
||||
|
@ -116,7 +116,7 @@ export const useResetUserPassword = () => {
|
||||
setResetPasswordLink('');
|
||||
resetPassword({
|
||||
userId: id,
|
||||
callbackUrl: '/auth/changePassword?isClient=false',
|
||||
callbackUrl: '/auth/changePassword',
|
||||
})
|
||||
.then(res => {
|
||||
setResetPasswordLink(res.createChangePasswordUrl);
|
||||
|
@ -9,6 +9,10 @@ import { configureAppTabsHeaderModule } from '@affine/core/modules/app-tabs-head
|
||||
import { I18nProvider } from '@affine/core/modules/i18n';
|
||||
import { configureElectronStateStorageImpls } from '@affine/core/modules/storage';
|
||||
import { CustomThemeModifier } from '@affine/core/modules/theme-editor';
|
||||
import {
|
||||
ClientSchemaProvider,
|
||||
PopupWindowProvider,
|
||||
} from '@affine/core/modules/url';
|
||||
import { configureSqliteUserspaceStorageProvider } from '@affine/core/modules/userspace';
|
||||
import { configureDesktopWorkbenchModule } from '@affine/core/modules/workbench';
|
||||
import {
|
||||
@ -16,6 +20,7 @@ import {
|
||||
configureSqliteWorkspaceEngineStorageProvider,
|
||||
} from '@affine/core/modules/workspace-engine';
|
||||
import createEmotionCache from '@affine/core/utils/create-emotion-cache';
|
||||
import { apis, appInfo } from '@affine/electron-api';
|
||||
import { CacheProvider } from '@emotion/react';
|
||||
import {
|
||||
Framework,
|
||||
@ -58,6 +63,18 @@ configureSqliteWorkspaceEngineStorageProvider(framework);
|
||||
configureSqliteUserspaceStorageProvider(framework);
|
||||
configureDesktopWorkbenchModule(framework);
|
||||
configureAppTabsHeaderModule(framework);
|
||||
framework.impl(PopupWindowProvider, {
|
||||
open: (url: string) => {
|
||||
apis?.ui.openExternal(url).catch(e => {
|
||||
console.error('Failed to open external URL', e);
|
||||
});
|
||||
},
|
||||
});
|
||||
framework.impl(ClientSchemaProvider, {
|
||||
getClientSchema() {
|
||||
return appInfo?.schema;
|
||||
},
|
||||
});
|
||||
const frameworkProvider = framework.provider();
|
||||
|
||||
// setup application lifecycle events, and emit application start event
|
||||
|
@ -7,28 +7,32 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
2FAD9763203C412B000D30F8 /* config.xml in Resources */ = {isa = PBXBuildFile; fileRef = 2FAD9762203C412B000D30F8 /* config.xml */; };
|
||||
50379B232058CBB4000EE86E /* capacitor.config.json in Resources */ = {isa = PBXBuildFile; fileRef = 50379B222058CBB4000EE86E /* capacitor.config.json */; };
|
||||
504EC3081FED79650016851F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504EC3071FED79650016851F /* AppDelegate.swift */; };
|
||||
504EC30D1FED79650016851F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 504EC30B1FED79650016851F /* Main.storyboard */; };
|
||||
504EC30F1FED79650016851F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 504EC30E1FED79650016851F /* Assets.xcassets */; };
|
||||
50B271D11FEDC1A000F3C39B /* public in Resources */ = {isa = PBXBuildFile; fileRef = 50B271D01FEDC1A000F3C39B /* public */; };
|
||||
9D90BE252CCB9876006677DB /* CookieManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D90BE172CCB9876006677DB /* CookieManager.swift */; };
|
||||
9D90BE262CCB9876006677DB /* CookiePlugin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D90BE182CCB9876006677DB /* CookiePlugin.swift */; };
|
||||
9D90BE272CCB9876006677DB /* AFFiNEViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D90BE1B2CCB9876006677DB /* AFFiNEViewController.swift */; };
|
||||
9D90BE282CCB9876006677DB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D90BE1C2CCB9876006677DB /* AppDelegate.swift */; };
|
||||
9D90BE292CCB9876006677DB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9D90BE1D2CCB9876006677DB /* Assets.xcassets */; };
|
||||
9D90BE2A2CCB9876006677DB /* capacitor.config.json in Resources */ = {isa = PBXBuildFile; fileRef = 9D90BE1E2CCB9876006677DB /* capacitor.config.json */; };
|
||||
9D90BE2B2CCB9876006677DB /* config.xml in Resources */ = {isa = PBXBuildFile; fileRef = 9D90BE1F2CCB9876006677DB /* config.xml */; };
|
||||
9D90BE2D2CCB9876006677DB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9D90BE222CCB9876006677DB /* Main.storyboard */; };
|
||||
9D90BE2E2CCB9876006677DB /* public in Resources */ = {isa = PBXBuildFile; fileRef = 9D90BE232CCB9876006677DB /* public */; };
|
||||
C4C413792CBE705D00337889 /* Pods_App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF277DCFFFF123FFC6DF26C7 /* Pods_App.framework */; };
|
||||
E9D409712CCA317C00B06598 /* AFFiNEViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E9D409702CCA317C00B06598 /* AFFiNEViewController.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
2FAD9762203C412B000D30F8 /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = config.xml; sourceTree = "<group>"; };
|
||||
50379B222058CBB4000EE86E /* capacitor.config.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = capacitor.config.json; sourceTree = "<group>"; };
|
||||
504EC3041FED79650016851F /* App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = App.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
504EC3071FED79650016851F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
504EC30C1FED79650016851F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
504EC30E1FED79650016851F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
504EC3131FED79650016851F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
50B271D01FEDC1A000F3C39B /* public */ = {isa = PBXFileReference; lastKnownFileType = folder; path = public; sourceTree = "<group>"; };
|
||||
9D90BE172CCB9876006677DB /* CookieManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CookieManager.swift; sourceTree = "<group>"; };
|
||||
9D90BE182CCB9876006677DB /* CookiePlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CookiePlugin.swift; sourceTree = "<group>"; };
|
||||
9D90BE1B2CCB9876006677DB /* AFFiNEViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AFFiNEViewController.swift; sourceTree = "<group>"; };
|
||||
9D90BE1C2CCB9876006677DB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
9D90BE1D2CCB9876006677DB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
9D90BE1E2CCB9876006677DB /* capacitor.config.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = capacitor.config.json; sourceTree = "<group>"; };
|
||||
9D90BE1F2CCB9876006677DB /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = config.xml; sourceTree = "<group>"; };
|
||||
9D90BE202CCB9876006677DB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
9D90BE212CCB9876006677DB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
|
||||
9D90BE232CCB9876006677DB /* public */ = {isa = PBXFileReference; lastKnownFileType = folder; path = public; sourceTree = "<group>"; };
|
||||
AF277DCFFFF123FFC6DF26C7 /* Pods_App.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_App.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
AF51FD2D460BCFE21FA515B2 /* Pods-App.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App.release.xcconfig"; path = "Pods/Target Support Files/Pods-App/Pods-App.release.xcconfig"; sourceTree = "<group>"; };
|
||||
E9D409702CCA317C00B06598 /* AFFiNEViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AFFiNEViewController.swift; sourceTree = "<group>"; };
|
||||
FC68EB0AF532CFC21C3344DD /* Pods-App.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App.debug.xcconfig"; path = "Pods/Target Support Files/Pods-App/Pods-App.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
@ -55,7 +59,7 @@
|
||||
504EC2FB1FED79650016851F = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
504EC3061FED79650016851F /* App */,
|
||||
9D90BE242CCB9876006677DB /* App */,
|
||||
504EC3051FED79650016851F /* Products */,
|
||||
7F8756D8B27F46E3366F6CEA /* Pods */,
|
||||
27E2DDA53C4D2A4D1A88CE4A /* Frameworks */,
|
||||
@ -72,21 +76,6 @@
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
504EC3061FED79650016851F /* App */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
50379B222058CBB4000EE86E /* capacitor.config.json */,
|
||||
504EC3071FED79650016851F /* AppDelegate.swift */,
|
||||
504EC30B1FED79650016851F /* Main.storyboard */,
|
||||
504EC30E1FED79650016851F /* Assets.xcassets */,
|
||||
504EC3131FED79650016851F /* Info.plist */,
|
||||
2FAD9762203C412B000D30F8 /* config.xml */,
|
||||
50B271D01FEDC1A000F3C39B /* public */,
|
||||
E9D409702CCA317C00B06598 /* AFFiNEViewController.swift */,
|
||||
);
|
||||
path = App;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
7F8756D8B27F46E3366F6CEA /* Pods */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -96,6 +85,39 @@
|
||||
name = Pods;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9D90BE192CCB9876006677DB /* Cookie */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9D90BE172CCB9876006677DB /* CookieManager.swift */,
|
||||
9D90BE182CCB9876006677DB /* CookiePlugin.swift */,
|
||||
);
|
||||
path = Cookie;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9D90BE1A2CCB9876006677DB /* plugins */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9D90BE192CCB9876006677DB /* Cookie */,
|
||||
);
|
||||
path = plugins;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
9D90BE242CCB9876006677DB /* App */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
9D90BE1A2CCB9876006677DB /* plugins */,
|
||||
9D90BE1B2CCB9876006677DB /* AFFiNEViewController.swift */,
|
||||
9D90BE1C2CCB9876006677DB /* AppDelegate.swift */,
|
||||
9D90BE1D2CCB9876006677DB /* Assets.xcassets */,
|
||||
9D90BE1E2CCB9876006677DB /* capacitor.config.json */,
|
||||
9D90BE1F2CCB9876006677DB /* config.xml */,
|
||||
9D90BE202CCB9876006677DB /* Info.plist */,
|
||||
9D90BE222CCB9876006677DB /* Main.storyboard */,
|
||||
9D90BE232CCB9876006677DB /* public */,
|
||||
);
|
||||
path = App;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
@ -130,7 +152,7 @@
|
||||
TargetAttributes = {
|
||||
504EC3031FED79650016851F = {
|
||||
CreatedOnToolsVersion = 9.2;
|
||||
LastSwiftMigration = 1100;
|
||||
LastSwiftMigration = 1600;
|
||||
};
|
||||
};
|
||||
};
|
||||
@ -157,11 +179,11 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
50B271D11FEDC1A000F3C39B /* public in Resources */,
|
||||
504EC30F1FED79650016851F /* Assets.xcassets in Resources */,
|
||||
50379B232058CBB4000EE86E /* capacitor.config.json in Resources */,
|
||||
504EC30D1FED79650016851F /* Main.storyboard in Resources */,
|
||||
2FAD9763203C412B000D30F8 /* config.xml in Resources */,
|
||||
9D90BE292CCB9876006677DB /* Assets.xcassets in Resources */,
|
||||
9D90BE2A2CCB9876006677DB /* capacitor.config.json in Resources */,
|
||||
9D90BE2B2CCB9876006677DB /* config.xml in Resources */,
|
||||
9D90BE2D2CCB9876006677DB /* Main.storyboard in Resources */,
|
||||
9D90BE2E2CCB9876006677DB /* public in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -208,18 +230,20 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
504EC3081FED79650016851F /* AppDelegate.swift in Sources */,
|
||||
E9D409712CCA317C00B06598 /* AFFiNEViewController.swift in Sources */,
|
||||
9D90BE252CCB9876006677DB /* CookieManager.swift in Sources */,
|
||||
9D90BE262CCB9876006677DB /* CookiePlugin.swift in Sources */,
|
||||
9D90BE272CCB9876006677DB /* AFFiNEViewController.swift in Sources */,
|
||||
9D90BE282CCB9876006677DB /* AppDelegate.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXVariantGroup section */
|
||||
504EC30B1FED79650016851F /* Main.storyboard */ = {
|
||||
9D90BE222CCB9876006677DB /* Main.storyboard */ = {
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
504EC30C1FED79650016851F /* Base */,
|
||||
9D90BE212CCB9876006677DB /* Base */,
|
||||
);
|
||||
name = Main.storyboard;
|
||||
sourceTree = "<group>";
|
||||
|
@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1600"
|
||||
version = "1.7">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES"
|
||||
buildArchitectures = "Automatic">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "504EC3031FED79650016851F"
|
||||
BuildableName = "App.app"
|
||||
BlueprintName = "App"
|
||||
ReferencedContainer = "container:App.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
shouldAutocreateTestPlan = "YES">
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "504EC3031FED79650016851F"
|
||||
BuildableName = "App.app"
|
||||
BlueprintName = "App"
|
||||
ReferencedContainer = "container:App.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "504EC3031FED79650016851F"
|
||||
BuildableName = "App.app"
|
||||
BlueprintName = "App"
|
||||
ReferencedContainer = "container:App.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
@ -8,4 +8,8 @@ class AFFiNEViewController: CAPBridgeViewController {
|
||||
webView?.allowsBackForwardNavigationGestures = true
|
||||
}
|
||||
|
||||
override func capacitorDidLoad() {
|
||||
bridge?.registerPluginInstance(CookiePlugin())
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>en</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
@ -20,8 +18,23 @@
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>$(MARKETING_VERSION)</string>
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>None</string>
|
||||
<key>CFBundleURLName</key>
|
||||
<string>affine</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>affine</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>10</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UILaunchScreen</key>
|
||||
|
@ -0,0 +1,30 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
public class CookieManager: NSObject {
|
||||
public func getCookies(_ urlString: String) -> [String: String] {
|
||||
var cookiesMap: [String: String] = [:]
|
||||
let jar = HTTPCookieStorage.shared
|
||||
guard let url = getServerUrl(urlString) else { return [:] }
|
||||
if let cookies = jar.cookies(for: url) {
|
||||
for cookie in cookies {
|
||||
cookiesMap[cookie.name] = cookie.value
|
||||
}
|
||||
}
|
||||
return cookiesMap
|
||||
}
|
||||
|
||||
private func isUrlSanitized(_ urlString: String) -> Bool {
|
||||
return urlString.hasPrefix("http://") || urlString.hasPrefix("https://")
|
||||
}
|
||||
|
||||
public func getServerUrl(_ urlString: String) -> URL? {
|
||||
let validUrlString = (isUrlSanitized(urlString)) ? urlString : "http://\(urlString)"
|
||||
|
||||
guard let url = URL(string: validUrlString) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
import Foundation
|
||||
import Capacitor
|
||||
|
||||
@objc(CookiePlugin)
|
||||
public class CookiePlugin: CAPPlugin, CAPBridgedPlugin {
|
||||
public let identifier = "CookiePlugin"
|
||||
public let jsName = "Cookie"
|
||||
public let pluginMethods: [CAPPluginMethod] = [
|
||||
CAPPluginMethod(name: "getCookies", returnType: CAPPluginReturnPromise)
|
||||
]
|
||||
|
||||
let cookieManager = CookieManager()
|
||||
|
||||
@objc public func getCookies(_ call: CAPPluginCall) {
|
||||
guard let url = call.getString("url") else {
|
||||
return call.resolve([:])
|
||||
}
|
||||
|
||||
call.resolve(cookieManager.getCookies(url))
|
||||
}
|
||||
}
|
@ -11,7 +11,8 @@ install! 'cocoapods', :disable_input_output_paths => true
|
||||
def capacitor_pods
|
||||
pod 'Capacitor', :path => '../../../../../node_modules/@capacitor/ios'
|
||||
pod 'CapacitorCordova', :path => '../../../../../node_modules/@capacitor/ios'
|
||||
|
||||
pod 'CapacitorApp', :path => '../../../../../node_modules/@capacitor/app'
|
||||
pod 'CapacitorBrowser', :path => '../../../../../node_modules/@capacitor/browser'
|
||||
end
|
||||
|
||||
target 'App' do
|
||||
|
@ -1,22 +1,34 @@
|
||||
PODS:
|
||||
- Capacitor (6.1.2):
|
||||
- CapacitorCordova
|
||||
- CapacitorApp (6.0.1):
|
||||
- Capacitor
|
||||
- CapacitorBrowser (6.0.3):
|
||||
- Capacitor
|
||||
- CapacitorCordova (6.1.2)
|
||||
|
||||
DEPENDENCIES:
|
||||
- "Capacitor (from `../../../../../node_modules/@capacitor/ios`)"
|
||||
- "CapacitorApp (from `../../../../../node_modules/@capacitor/app`)"
|
||||
- "CapacitorBrowser (from `../../../../../node_modules/@capacitor/browser`)"
|
||||
- "CapacitorCordova (from `../../../../../node_modules/@capacitor/ios`)"
|
||||
|
||||
EXTERNAL SOURCES:
|
||||
Capacitor:
|
||||
:path: "../../../../../node_modules/@capacitor/ios"
|
||||
CapacitorApp:
|
||||
:path: "../../../../../node_modules/@capacitor/app"
|
||||
CapacitorBrowser:
|
||||
:path: "../../../../../node_modules/@capacitor/browser"
|
||||
CapacitorCordova:
|
||||
:path: "../../../../../node_modules/@capacitor/ios"
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
Capacitor: 679f9673fdf30597493a6362a5d5bf233d46abc2
|
||||
CapacitorApp: 0bc633b4eae40a1f32cd2834788fad3bc42da6a1
|
||||
CapacitorBrowser: aab1ed943b01c0365c4810538a8b3477e2d9f72e
|
||||
CapacitorCordova: f48c89f96c319101cd2f0ce8a2b7449b5fb8b3dd
|
||||
|
||||
PODFILE CHECKSUM: 54b94ef731578bd3a2af3619f2a5a0589e32dea5
|
||||
PODFILE CHECKSUM: 0f32d90fb8184cf478f85b78b1c00db1059ac3aa
|
||||
|
||||
COCOAPODS: 1.15.2
|
||||
|
@ -7,6 +7,17 @@ const config: CapacitorConfig = {
|
||||
ios: {
|
||||
path: '.',
|
||||
},
|
||||
server: {
|
||||
// url: 'http://localhost:8080',
|
||||
},
|
||||
plugins: {
|
||||
CapacitorCookies: {
|
||||
enabled: true,
|
||||
},
|
||||
CapacitorHttp: {
|
||||
enabled: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
|
@ -15,6 +15,8 @@
|
||||
"@affine/i18n": "workspace:*",
|
||||
"@blocksuite/affine": "0.17.19",
|
||||
"@blocksuite/icons": "^2.1.67",
|
||||
"@capacitor/app": "^6.0.1",
|
||||
"@capacitor/browser": "^6.0.3",
|
||||
"@capacitor/core": "^6.1.2",
|
||||
"@capacitor/ios": "^6.1.2",
|
||||
"@sentry/react": "^8.0.0",
|
||||
|
@ -4,14 +4,21 @@ import { Telemetry } from '@affine/core/components/telemetry';
|
||||
import { configureMobileModules } from '@affine/core/mobile/modules';
|
||||
import { router } from '@affine/core/mobile/router';
|
||||
import { configureCommonModules } from '@affine/core/modules';
|
||||
import { AuthService, WebSocketAuthProvider } from '@affine/core/modules/cloud';
|
||||
import { I18nProvider } from '@affine/core/modules/i18n';
|
||||
import { configureLocalStorageStateStorageImpls } from '@affine/core/modules/storage';
|
||||
import {
|
||||
ClientSchemaProvider,
|
||||
PopupWindowProvider,
|
||||
} from '@affine/core/modules/url';
|
||||
import { configureIndexedDBUserspaceStorageProvider } from '@affine/core/modules/userspace';
|
||||
import { configureBrowserWorkbenchModule } from '@affine/core/modules/workbench';
|
||||
import {
|
||||
configureBrowserWorkspaceFlavours,
|
||||
configureIndexedDBWorkspaceEngineStorageProvider,
|
||||
} from '@affine/core/modules/workspace-engine';
|
||||
import { App as CapacitorApp } from '@capacitor/app';
|
||||
import { Browser } from '@capacitor/browser';
|
||||
import {
|
||||
Framework,
|
||||
FrameworkRoot,
|
||||
@ -21,6 +28,9 @@ import {
|
||||
import { Suspense } from 'react';
|
||||
import { RouterProvider } from 'react-router-dom';
|
||||
|
||||
import { configureFetchProvider } from './fetch';
|
||||
import { Cookie } from './plugins/cookie';
|
||||
|
||||
const future = {
|
||||
v7_startTransition: true,
|
||||
} as const;
|
||||
@ -33,6 +43,31 @@ configureBrowserWorkspaceFlavours(framework);
|
||||
configureIndexedDBWorkspaceEngineStorageProvider(framework);
|
||||
configureIndexedDBUserspaceStorageProvider(framework);
|
||||
configureMobileModules(framework);
|
||||
framework.impl(PopupWindowProvider, {
|
||||
open: (url: string) => {
|
||||
Browser.open({
|
||||
url,
|
||||
presentationStyle: 'popover',
|
||||
}).catch(console.error);
|
||||
},
|
||||
});
|
||||
framework.impl(ClientSchemaProvider, {
|
||||
getClientSchema() {
|
||||
return 'affine';
|
||||
},
|
||||
});
|
||||
configureFetchProvider(framework);
|
||||
framework.impl(WebSocketAuthProvider, {
|
||||
getAuthToken: async url => {
|
||||
const cookies = await Cookie.getCookies({
|
||||
url,
|
||||
});
|
||||
return {
|
||||
userId: cookies['affine_user_id'],
|
||||
token: cookies['affine_session'],
|
||||
};
|
||||
},
|
||||
});
|
||||
const frameworkProvider = framework.provider();
|
||||
|
||||
// setup application lifecycle events, and emit application start event
|
||||
@ -41,6 +76,38 @@ window.addEventListener('focus', () => {
|
||||
});
|
||||
frameworkProvider.get(LifecycleService).applicationStart();
|
||||
|
||||
CapacitorApp.addListener('appUrlOpen', ({ url }) => {
|
||||
// try to close browser if it's open
|
||||
Browser.close().catch(e => console.error('Failed to close browser', e));
|
||||
|
||||
const urlObj = new URL(url);
|
||||
|
||||
if (urlObj.hostname === 'authentication') {
|
||||
const method = urlObj.searchParams.get('method');
|
||||
const payload = JSON.parse(urlObj.searchParams.get('payload') ?? 'false');
|
||||
|
||||
if (
|
||||
!method ||
|
||||
(method !== 'magic-link' && method !== 'oauth') ||
|
||||
!payload
|
||||
) {
|
||||
console.error('Invalid authentication url', url);
|
||||
return;
|
||||
}
|
||||
|
||||
const authService = frameworkProvider.get(AuthService);
|
||||
if (method === 'oauth') {
|
||||
authService
|
||||
.signInOauth(payload.code, payload.state, payload.provider)
|
||||
.catch(console.error);
|
||||
} else if (method === 'magic-link') {
|
||||
authService
|
||||
.signInMagicLink(payload.email, payload.token)
|
||||
.catch(console.error);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export function App() {
|
||||
return (
|
||||
<Suspense>
|
||||
|
194
packages/frontend/apps/ios/src/fetch.ts
Normal file
194
packages/frontend/apps/ios/src/fetch.ts
Normal file
@ -0,0 +1,194 @@
|
||||
/**
|
||||
* this file is modified from part of https://github.com/ionic-team/capacitor/blob/74c3e9447e1e32e73f818d252eb12f453d849e8d/ios/Capacitor/Capacitor/assets/native-bridge.js#L466
|
||||
*
|
||||
* for support arraybuffer response type
|
||||
*/
|
||||
import { FetchProvider } from '@affine/core/modules/cloud/provider/fetch';
|
||||
import { CapacitorHttp } from '@capacitor/core';
|
||||
import type { Framework } from '@toeverything/infra';
|
||||
|
||||
const readFileAsBase64 = (file: File) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onloadend = () => {
|
||||
const data = reader.result;
|
||||
if (data === null) {
|
||||
reject(new Error('Failed to read file'));
|
||||
} else {
|
||||
resolve(btoa(data as string));
|
||||
}
|
||||
};
|
||||
reader.onerror = reject;
|
||||
reader.readAsBinaryString(file);
|
||||
});
|
||||
const convertFormData = async (formData: FormData) => {
|
||||
const newFormData = [];
|
||||
// @ts-expect-error FormData.entries
|
||||
for (const pair of formData.entries()) {
|
||||
const [key, value] = pair;
|
||||
if (value instanceof File) {
|
||||
const base64File = await readFileAsBase64(value);
|
||||
newFormData.push({
|
||||
key,
|
||||
value: base64File,
|
||||
type: 'base64File',
|
||||
contentType: value.type,
|
||||
fileName: value.name,
|
||||
});
|
||||
} else {
|
||||
newFormData.push({ key, value, type: 'string' });
|
||||
}
|
||||
}
|
||||
return newFormData;
|
||||
};
|
||||
const convertBody = async (body: unknown, contentType: string) => {
|
||||
if (body instanceof ReadableStream || body instanceof Uint8Array) {
|
||||
let encodedData;
|
||||
if (body instanceof ReadableStream) {
|
||||
const reader = body.getReader();
|
||||
const chunks = [];
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
chunks.push(value);
|
||||
}
|
||||
const concatenated = new Uint8Array(
|
||||
chunks.reduce((acc, chunk) => acc + chunk.length, 0)
|
||||
);
|
||||
let position = 0;
|
||||
for (const chunk of chunks) {
|
||||
concatenated.set(chunk, position);
|
||||
position += chunk.length;
|
||||
}
|
||||
encodedData = concatenated;
|
||||
} else {
|
||||
encodedData = body;
|
||||
}
|
||||
let data = new TextDecoder().decode(encodedData);
|
||||
let type;
|
||||
if (contentType === 'application/json') {
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
type = 'json';
|
||||
} else if (contentType === 'multipart/form-data') {
|
||||
type = 'formData';
|
||||
} else if (
|
||||
contentType === null || contentType === void 0
|
||||
? void 0
|
||||
: contentType.startsWith('image')
|
||||
) {
|
||||
type = 'image';
|
||||
} else if (contentType === 'application/octet-stream') {
|
||||
type = 'binary';
|
||||
} else {
|
||||
type = 'text';
|
||||
}
|
||||
return {
|
||||
data,
|
||||
type,
|
||||
headers: { 'Content-Type': contentType || 'application/octet-stream' },
|
||||
};
|
||||
} else if (body instanceof URLSearchParams) {
|
||||
return {
|
||||
data: body.toString(),
|
||||
type: 'text',
|
||||
};
|
||||
} else if (body instanceof FormData) {
|
||||
const formData = await convertFormData(body);
|
||||
return {
|
||||
data: formData,
|
||||
type: 'formData',
|
||||
};
|
||||
} else if (body instanceof File) {
|
||||
const fileData = await readFileAsBase64(body);
|
||||
return {
|
||||
data: fileData,
|
||||
type: 'file',
|
||||
headers: { 'Content-Type': body.type },
|
||||
};
|
||||
}
|
||||
return { data: body, type: 'json' };
|
||||
};
|
||||
function base64ToUint8Array(base64: string) {
|
||||
const binaryString = atob(base64);
|
||||
const binaryArray = binaryString.split('').map(function (char) {
|
||||
return char.charCodeAt(0);
|
||||
});
|
||||
return new Uint8Array(binaryArray);
|
||||
}
|
||||
export function configureFetchProvider(framework: Framework) {
|
||||
framework.override(FetchProvider, {
|
||||
fetch: async (input, init) => {
|
||||
const request = new Request(input, init);
|
||||
const { method } = request;
|
||||
const tag = `CapacitorHttp fetch ${Date.now()} ${input}`;
|
||||
console.time(tag);
|
||||
try {
|
||||
const { body } = request;
|
||||
// @ts-expect-error Headers.entries
|
||||
const optionHeaders = Object.fromEntries(request.headers.entries());
|
||||
const {
|
||||
data: requestData,
|
||||
type,
|
||||
headers,
|
||||
} = await convertBody(
|
||||
(init === null || init === void 0 ? void 0 : init.body) ||
|
||||
body ||
|
||||
undefined,
|
||||
optionHeaders['Content-Type'] || optionHeaders['content-type']
|
||||
);
|
||||
const nativeResponse = await CapacitorHttp.request({
|
||||
url: request.url,
|
||||
method: method,
|
||||
data: requestData,
|
||||
dataType: type as any,
|
||||
responseType:
|
||||
(optionHeaders['Accept'] || optionHeaders['accept']) ===
|
||||
'application/octet-stream'
|
||||
? 'arraybuffer'
|
||||
: undefined,
|
||||
headers: Object.assign(Object.assign({}, headers), optionHeaders),
|
||||
});
|
||||
const contentType =
|
||||
nativeResponse.headers['Content-Type'] ||
|
||||
nativeResponse.headers['content-type'];
|
||||
let data = (
|
||||
contentType === null || contentType === void 0
|
||||
? void 0
|
||||
: contentType.startsWith('application/json')
|
||||
)
|
||||
? JSON.stringify(nativeResponse.data)
|
||||
: contentType === 'application/octet-stream'
|
||||
? base64ToUint8Array(nativeResponse.data)
|
||||
: nativeResponse.data;
|
||||
|
||||
// use null data for 204 No Content HTTP response
|
||||
if (nativeResponse.status === 204) {
|
||||
data = null;
|
||||
}
|
||||
// intercept & parse response before returning
|
||||
const response = new Response(data, {
|
||||
headers: nativeResponse.headers,
|
||||
status: nativeResponse.status,
|
||||
});
|
||||
/*
|
||||
* copy url to response, `cordova-plugin-ionic` uses this url from the response
|
||||
* we need `Object.defineProperty` because url is an inherited getter on the Response
|
||||
* see: https://stackoverflow.com/a/57382543
|
||||
* */
|
||||
Object.defineProperty(response, 'url', {
|
||||
value: nativeResponse.url,
|
||||
});
|
||||
console.timeEnd(tag);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.timeEnd(tag);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
@ -18,6 +18,15 @@ import { App } from './app';
|
||||
|
||||
function main() {
|
||||
if (BUILD_CONFIG.debug || window.SENTRY_RELEASE) {
|
||||
// workaround for Capacitor HttpPlugin
|
||||
// capacitor-http-plugin will replace window.XMLHttpRequest with its own implementation
|
||||
// but XMLHttpRequest.prototype is not defined which is used by sentry
|
||||
// see: https://github.com/ionic-team/capacitor/blob/74c3e9447e1e32e73f818d252eb12f453d849e8d/core/native-bridge.ts#L581
|
||||
if ('CapacitorWebXMLHttpRequest' in window) {
|
||||
window.XMLHttpRequest.prototype = (
|
||||
window.CapacitorWebXMLHttpRequest as any
|
||||
).prototype;
|
||||
}
|
||||
// https://docs.sentry.io/platforms/javascript/guides/react/#configure
|
||||
init({
|
||||
dsn: process.env.SENTRY_DSN,
|
||||
|
@ -0,0 +1,6 @@
|
||||
export interface CookiePlugin {
|
||||
/**
|
||||
* Returns the screen's current orientation.
|
||||
*/
|
||||
getCookies(options: { url: string }): Promise<Record<string, string>>;
|
||||
}
|
8
packages/frontend/apps/ios/src/plugins/cookie/index.ts
Normal file
8
packages/frontend/apps/ios/src/plugins/cookie/index.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { registerPlugin } from '@capacitor/core';
|
||||
|
||||
import type { CookiePlugin } from './definitions';
|
||||
|
||||
const Cookie = registerPlugin<CookiePlugin>('Cookie');
|
||||
|
||||
export * from './definitions';
|
||||
export { Cookie };
|
@ -6,6 +6,7 @@ import { router } from '@affine/core/mobile/router';
|
||||
import { configureCommonModules } from '@affine/core/modules';
|
||||
import { I18nProvider } from '@affine/core/modules/i18n';
|
||||
import { configureLocalStorageStateStorageImpls } from '@affine/core/modules/storage';
|
||||
import { PopupWindowProvider } from '@affine/core/modules/url';
|
||||
import { configureIndexedDBUserspaceStorageProvider } from '@affine/core/modules/userspace';
|
||||
import { configureBrowserWorkbenchModule } from '@affine/core/modules/workbench';
|
||||
import {
|
||||
@ -33,6 +34,25 @@ configureBrowserWorkspaceFlavours(framework);
|
||||
configureIndexedDBWorkspaceEngineStorageProvider(framework);
|
||||
configureIndexedDBUserspaceStorageProvider(framework);
|
||||
configureMobileModules(framework);
|
||||
framework.impl(PopupWindowProvider, {
|
||||
open: (target: string) => {
|
||||
const targetUrl = new URL(target);
|
||||
|
||||
let url: string;
|
||||
// safe to open directly if in the same origin
|
||||
if (targetUrl.origin === location.origin) {
|
||||
url = target;
|
||||
} else {
|
||||
const redirectProxy = location.origin + '/redirect-proxy';
|
||||
const search = new URLSearchParams({
|
||||
redirect_uri: target,
|
||||
});
|
||||
|
||||
url = `${redirectProxy}?${search.toString()}`;
|
||||
}
|
||||
window.open(url, '_blank', 'noreferrer noopener');
|
||||
},
|
||||
});
|
||||
const frameworkProvider = framework.provider();
|
||||
|
||||
// setup application lifecycle events, and emit application start event
|
||||
|
@ -7,6 +7,7 @@ import { configureCommonModules } from '@affine/core/modules';
|
||||
import { I18nProvider } from '@affine/core/modules/i18n';
|
||||
import { configureLocalStorageStateStorageImpls } from '@affine/core/modules/storage';
|
||||
import { CustomThemeModifier } from '@affine/core/modules/theme-editor';
|
||||
import { PopupWindowProvider } from '@affine/core/modules/url';
|
||||
import { configureIndexedDBUserspaceStorageProvider } from '@affine/core/modules/userspace';
|
||||
import { configureBrowserWorkbenchModule } from '@affine/core/modules/workbench';
|
||||
import {
|
||||
@ -37,6 +38,25 @@ configureLocalStorageStateStorageImpls(framework);
|
||||
configureBrowserWorkspaceFlavours(framework);
|
||||
configureIndexedDBWorkspaceEngineStorageProvider(framework);
|
||||
configureIndexedDBUserspaceStorageProvider(framework);
|
||||
framework.impl(PopupWindowProvider, {
|
||||
open: (target: string) => {
|
||||
const targetUrl = new URL(target);
|
||||
|
||||
let url: string;
|
||||
// safe to open directly if in the same origin
|
||||
if (targetUrl.origin === location.origin) {
|
||||
url = target;
|
||||
} else {
|
||||
const redirectProxy = location.origin + '/redirect-proxy';
|
||||
const search = new URLSearchParams({
|
||||
redirect_uri: target,
|
||||
});
|
||||
|
||||
url = `${redirectProxy}?${search.toString()}`;
|
||||
}
|
||||
window.open(url, '_blank', 'noreferrer noopener');
|
||||
},
|
||||
});
|
||||
const frameworkProvider = framework.provider();
|
||||
|
||||
// setup application lifecycle events, and emit application start event
|
||||
|
@ -18,6 +18,8 @@
|
||||
"@affine/track": "workspace:*",
|
||||
"@blocksuite/affine": "0.17.19",
|
||||
"@blocksuite/icons": "2.1.69",
|
||||
"@capacitor/app": "^6.0.1",
|
||||
"@capacitor/browser": "^6.0.3",
|
||||
"@dnd-kit/core": "^6.1.0",
|
||||
"@dnd-kit/modifiers": "^7.0.0",
|
||||
"@dnd-kit/sortable": "^8.0.0",
|
||||
|
@ -4,15 +4,17 @@ import { ContactWithUsIcon, NewIcon } from '@blocksuite/icons/rc';
|
||||
import type { createStore } from 'jotai';
|
||||
|
||||
import { openSettingModalAtom } from '../components/atoms';
|
||||
import { popupWindow } from '../utils';
|
||||
import type { UrlService } from '../modules/url';
|
||||
import { registerAffineCommand } from './registry';
|
||||
|
||||
export function registerAffineHelpCommands({
|
||||
t,
|
||||
store,
|
||||
urlService,
|
||||
}: {
|
||||
t: ReturnType<typeof useI18n>;
|
||||
store: ReturnType<typeof createStore>;
|
||||
urlService: UrlService;
|
||||
}) {
|
||||
const unsubs: Array<() => void> = [];
|
||||
unsubs.push(
|
||||
@ -23,7 +25,7 @@ export function registerAffineHelpCommands({
|
||||
label: t['com.affine.cmdk.affine.whats-new'](),
|
||||
run() {
|
||||
track.$.cmdk.help.openChangelog();
|
||||
popupWindow(BUILD_CONFIG.changelogUrl);
|
||||
urlService.openPopupWindow(BUILD_CONFIG.changelogUrl);
|
||||
},
|
||||
})
|
||||
);
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { Skeleton } from '@affine/component';
|
||||
import { Button } from '@affine/component/ui/button';
|
||||
import { popupWindow } from '@affine/core/utils';
|
||||
import { appInfo } from '@affine/electron-api';
|
||||
import { UrlService } from '@affine/core/modules/url';
|
||||
import { OAuthProviderType } from '@affine/graphql';
|
||||
import { GithubIcon, GoogleDuotoneIcon } from '@blocksuite/icons/rc';
|
||||
import { useLiveData, useService } from '@toeverything/infra';
|
||||
@ -31,10 +30,12 @@ const OAuthProviderMap: Record<
|
||||
|
||||
export function OAuth({ redirectUrl }: { redirectUrl?: string }) {
|
||||
const serverConfig = useService(ServerConfigService).serverConfig;
|
||||
const urlService = useService(UrlService);
|
||||
const oauth = useLiveData(serverConfig.features$.map(r => r?.oauth));
|
||||
const oauthProviders = useLiveData(
|
||||
serverConfig.config$.map(r => r?.oauthProviders)
|
||||
);
|
||||
const schema = urlService.getClientSchema();
|
||||
|
||||
if (!oauth) {
|
||||
return <Skeleton height={50} />;
|
||||
@ -45,6 +46,10 @@ export function OAuth({ redirectUrl }: { redirectUrl?: string }) {
|
||||
key={provider}
|
||||
provider={provider}
|
||||
redirectUrl={redirectUrl}
|
||||
schema={schema}
|
||||
popupWindow={url => {
|
||||
urlService.openPopupWindow(url);
|
||||
}}
|
||||
/>
|
||||
));
|
||||
}
|
||||
@ -52,9 +57,13 @@ export function OAuth({ redirectUrl }: { redirectUrl?: string }) {
|
||||
function OAuthProvider({
|
||||
provider,
|
||||
redirectUrl,
|
||||
schema,
|
||||
popupWindow,
|
||||
}: {
|
||||
provider: OAuthProviderType;
|
||||
redirectUrl?: string;
|
||||
schema?: string;
|
||||
popupWindow: (url: string) => void;
|
||||
}) {
|
||||
const { icon } = OAuthProviderMap[provider];
|
||||
|
||||
@ -67,17 +76,18 @@ function OAuthProvider({
|
||||
params.set('redirect_uri', redirectUrl);
|
||||
}
|
||||
|
||||
if (BUILD_CONFIG.isElectron && appInfo) {
|
||||
params.set('client', appInfo.schema);
|
||||
if (schema) {
|
||||
params.set('client', schema);
|
||||
}
|
||||
|
||||
// TODO: Android app scheme not implemented
|
||||
// if (BUILD_CONFIG.isAndroid) {}
|
||||
|
||||
const oauthUrl =
|
||||
(BUILD_CONFIG.isElectron || BUILD_CONFIG.isIOS || BUILD_CONFIG.isAndroid
|
||||
? BUILD_CONFIG.serverUrlPrefix
|
||||
: '') + `/oauth/login?${params.toString()}`;
|
||||
BUILD_CONFIG.serverUrlPrefix + `/oauth/login?${params.toString()}`;
|
||||
|
||||
popupWindow(oauthUrl);
|
||||
}, [provider, redirectUrl]);
|
||||
}, [popupWindow, provider, redirectUrl, schema]);
|
||||
|
||||
return (
|
||||
<Button
|
||||
|
@ -121,9 +121,7 @@ const useSendEmail = (emailType: AuthPanelProps<'sendEmail'>['emailType']) => {
|
||||
// TODO(@eyhn): add error handler
|
||||
return trigger({
|
||||
email,
|
||||
callbackUrl: `/auth/${callbackUrl}?isClient=${
|
||||
BUILD_CONFIG.isElectron ? 'true' : 'false'
|
||||
}`,
|
||||
callbackUrl: `/auth/${callbackUrl}`,
|
||||
});
|
||||
},
|
||||
[
|
||||
|
@ -1,12 +1,13 @@
|
||||
import { useDocMetaHelper } from '@affine/core/components/hooks/use-block-suite-page-meta';
|
||||
import { useDocCollectionPage } from '@affine/core/components/hooks/use-block-suite-workspace-page';
|
||||
import { FetchService } from '@affine/core/modules/cloud';
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import type { ListHistoryQuery } from '@affine/graphql';
|
||||
import { listHistoryQuery, recoverDocMutation } from '@affine/graphql';
|
||||
import { i18nTime } from '@affine/i18n';
|
||||
import { assertEquals } from '@blocksuite/affine/global/utils';
|
||||
import { DocCollection } from '@blocksuite/affine/store';
|
||||
import { getAFFiNEWorkspaceSchema } from '@toeverything/infra';
|
||||
import { getAFFiNEWorkspaceSchema, useService } from '@toeverything/infra';
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import useSWRImmutable from 'swr/immutable';
|
||||
import {
|
||||
@ -99,10 +100,13 @@ const snapshotFetcher = async (
|
||||
const docCollectionMap = new Map<string, DocCollection>();
|
||||
|
||||
// assume the workspace is a cloud workspace since the history feature is only enabled for cloud workspace
|
||||
const getOrCreateShellWorkspace = (workspaceId: string) => {
|
||||
const getOrCreateShellWorkspace = (
|
||||
workspaceId: string,
|
||||
fetchService: FetchService
|
||||
) => {
|
||||
let docCollection = docCollectionMap.get(workspaceId);
|
||||
if (!docCollection) {
|
||||
const blobStorage = new CloudBlobStorage(workspaceId);
|
||||
const blobStorage = new CloudBlobStorage(workspaceId, fetchService);
|
||||
docCollection = new DocCollection({
|
||||
id: workspaceId,
|
||||
blobSources: {
|
||||
@ -139,13 +143,17 @@ export const useSnapshotPage = (
|
||||
pageDocId: string,
|
||||
ts?: string
|
||||
) => {
|
||||
const fetchService = useService(FetchService);
|
||||
const snapshot = usePageHistory(docCollection.id, pageDocId, ts);
|
||||
const page = useMemo(() => {
|
||||
if (!ts) {
|
||||
return;
|
||||
}
|
||||
const pageId = pageDocId + '-' + ts;
|
||||
const historyShellWorkspace = getOrCreateShellWorkspace(docCollection.id);
|
||||
const historyShellWorkspace = getOrCreateShellWorkspace(
|
||||
docCollection.id,
|
||||
fetchService
|
||||
);
|
||||
let page = historyShellWorkspace.getDoc(pageId);
|
||||
if (!page && snapshot) {
|
||||
page = historyShellWorkspace.createDoc({
|
||||
@ -159,15 +167,18 @@ export const useSnapshotPage = (
|
||||
}); // must load before applyUpdate
|
||||
}
|
||||
return page ?? undefined;
|
||||
}, [pageDocId, snapshot, ts, docCollection]);
|
||||
}, [ts, pageDocId, docCollection.id, fetchService, snapshot]);
|
||||
|
||||
useEffect(() => {
|
||||
const historyShellWorkspace = getOrCreateShellWorkspace(docCollection.id);
|
||||
const historyShellWorkspace = getOrCreateShellWorkspace(
|
||||
docCollection.id,
|
||||
fetchService
|
||||
);
|
||||
// apply the rootdoc's update to the current workspace
|
||||
// this makes sure the page reference links are not deleted ones in the preview
|
||||
const update = encodeStateAsUpdate(docCollection.doc);
|
||||
applyUpdate(historyShellWorkspace.doc, update);
|
||||
}, [docCollection]);
|
||||
}, [docCollection, fetchService]);
|
||||
|
||||
return page;
|
||||
};
|
||||
|
@ -5,20 +5,22 @@ import {
|
||||
SettingWrapper,
|
||||
} from '@affine/component/setting-components';
|
||||
import { useAppUpdater } from '@affine/core/components/hooks/use-app-updater';
|
||||
import { UrlService } from '@affine/core/modules/url';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import { mixpanel } from '@affine/track';
|
||||
import { ArrowRightSmallIcon, OpenInNewIcon } from '@blocksuite/icons/rc';
|
||||
import { useService } from '@toeverything/infra';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { useAppSettingHelper } from '../../../../../components/hooks/affine/use-app-setting-helper';
|
||||
import { appIconMap, appNames } from '../../../../../desktop/pages/open-app';
|
||||
import { popupWindow } from '../../../../../utils';
|
||||
import { relatedLinks } from './config';
|
||||
import * as styles from './style.css';
|
||||
import { UpdateCheckSection } from './update-check-section';
|
||||
|
||||
export const AboutAffine = () => {
|
||||
const t = useI18n();
|
||||
const urlService = useService(UrlService);
|
||||
const { appSettings, updateSettings } = useAppSettingHelper();
|
||||
const { toggleAutoCheck, toggleAutoDownload } = useAppUpdater();
|
||||
const channel = BUILD_CONFIG.appBuildType;
|
||||
@ -100,7 +102,7 @@ export const AboutAffine = () => {
|
||||
desc={t['com.affine.aboutAFFiNE.changelog.description']()}
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => {
|
||||
popupWindow(BUILD_CONFIG.changelogUrl);
|
||||
urlService.openPopupWindow(BUILD_CONFIG.changelogUrl);
|
||||
}}
|
||||
>
|
||||
<ArrowRightSmallIcon />
|
||||
@ -144,7 +146,7 @@ export const AboutAffine = () => {
|
||||
<div
|
||||
className={styles.communityItem}
|
||||
onClick={() => {
|
||||
popupWindow(link);
|
||||
urlService.openPopupWindow(link);
|
||||
}}
|
||||
key={title}
|
||||
>
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Button } from '@affine/component';
|
||||
import { SettingRow } from '@affine/component/setting-components';
|
||||
import { ThemeEditorService } from '@affine/core/modules/theme-editor';
|
||||
import { popupWindow } from '@affine/core/utils';
|
||||
import { UrlService } from '@affine/core/modules/url';
|
||||
import { apis } from '@affine/electron-api';
|
||||
import { DeleteIcon } from '@blocksuite/icons/rc';
|
||||
import { useLiveData, useService } from '@toeverything/infra';
|
||||
@ -11,14 +11,15 @@ import { useCallback } from 'react';
|
||||
export const ThemeEditorSetting = () => {
|
||||
const themeEditor = useService(ThemeEditorService);
|
||||
const modified = useLiveData(themeEditor.modified$);
|
||||
const urlService = useService(UrlService);
|
||||
|
||||
const open = useCallback(() => {
|
||||
if (BUILD_CONFIG.isElectron) {
|
||||
apis?.ui.openThemeEditor().catch(console.error);
|
||||
} else {
|
||||
popupWindow('/theme-editor');
|
||||
} else if (BUILD_CONFIG.isMobileWeb || BUILD_CONFIG.isWeb) {
|
||||
urlService.openPopupWindow(location.origin + '/theme-editor');
|
||||
}
|
||||
}, []);
|
||||
}, [urlService]);
|
||||
|
||||
return (
|
||||
<SettingRow
|
||||
|
@ -14,6 +14,7 @@ import {
|
||||
InvoicesService,
|
||||
SubscriptionService,
|
||||
} from '@affine/core/modules/cloud';
|
||||
import { UrlService } from '@affine/core/modules/url';
|
||||
import type { InvoicesQuery } from '@affine/graphql';
|
||||
import {
|
||||
createCustomerPortalMutation,
|
||||
@ -32,7 +33,6 @@ import { useSetAtom } from 'jotai';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import { useMutation } from '../../../../../components/hooks/use-mutation';
|
||||
import { popupWindow } from '../../../../../utils';
|
||||
import {
|
||||
openSettingModalAtom,
|
||||
type PlansScrollAnchor,
|
||||
@ -456,15 +456,16 @@ const PaymentMethodUpdater = () => {
|
||||
const { isMutating, trigger } = useMutation({
|
||||
mutation: createCustomerPortalMutation,
|
||||
});
|
||||
const urlService = useService(UrlService);
|
||||
const t = useI18n();
|
||||
|
||||
const update = useAsyncCallback(async () => {
|
||||
await trigger(null, {
|
||||
onSuccess: data => {
|
||||
popupWindow(data.createCustomerPortal);
|
||||
urlService.openPopupWindow(data.createCustomerPortal);
|
||||
},
|
||||
});
|
||||
}, [trigger]);
|
||||
}, [trigger, urlService]);
|
||||
|
||||
return (
|
||||
<Button onClick={update} loading={isMutating} disabled={isMutating}>
|
||||
@ -575,12 +576,13 @@ const InvoiceLine = ({
|
||||
invoice: NonNullable<InvoicesQuery['currentUser']>['invoices'][0];
|
||||
}) => {
|
||||
const t = useI18n();
|
||||
const urlService = useService(UrlService);
|
||||
|
||||
const open = useCallback(() => {
|
||||
if (invoice.link) {
|
||||
popupWindow(invoice.link);
|
||||
urlService.openPopupWindow(invoice.link);
|
||||
}
|
||||
}, [invoice.link]);
|
||||
}, [invoice.link, urlService]);
|
||||
|
||||
const planText =
|
||||
invoice.plan === SubscriptionPlan.AI
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
||||
import { SubscriptionService } from '@affine/core/modules/cloud';
|
||||
import { popupWindow } from '@affine/core/utils';
|
||||
import { UrlService } from '@affine/core/modules/url';
|
||||
import type { CreateCheckoutSessionInput } from '@affine/graphql';
|
||||
import { useService } from '@toeverything/infra';
|
||||
import { nanoid } from 'nanoid';
|
||||
@ -32,6 +32,7 @@ export const CheckoutSlot = ({
|
||||
const [idempotencyKey, setIdempotencyKey] = useState(nanoid());
|
||||
const [isMutating, setMutating] = useState(false);
|
||||
const [isOpenedExternalWindow, setOpenedExternalWindow] = useState(false);
|
||||
const urlService = useService(UrlService);
|
||||
|
||||
const subscriptionService = useService(SubscriptionService);
|
||||
|
||||
@ -63,7 +64,7 @@ export const CheckoutSlot = ({
|
||||
idempotencyKey,
|
||||
...checkoutOptions,
|
||||
});
|
||||
popupWindow(session);
|
||||
urlService.openPopupWindow(session);
|
||||
setOpenedExternalWindow(true);
|
||||
setIdempotencyKey(nanoid());
|
||||
onCheckoutSuccess?.();
|
||||
@ -79,6 +80,7 @@ export const CheckoutSlot = ({
|
||||
onCheckoutError,
|
||||
onCheckoutSuccess,
|
||||
subscriptionService,
|
||||
urlService,
|
||||
]);
|
||||
|
||||
return <Renderer onClick={subscribe} loading={isMutating} />;
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { UrlService } from '@affine/core/modules/url';
|
||||
import type { UpdateMeta } from '@affine/electron-api';
|
||||
import { apis, events } from '@affine/electron-api';
|
||||
import { track } from '@affine/track';
|
||||
import { appSettingAtom } from '@toeverything/infra';
|
||||
import { appSettingAtom, useService } from '@toeverything/infra';
|
||||
import { atom, useAtom, useAtomValue } from 'jotai';
|
||||
import { atomWithObservable, atomWithStorage } from 'jotai/utils';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
import { popupWindow } from '../../utils';
|
||||
import { useAsyncCallback } from './affine-async-hooks';
|
||||
|
||||
function rpcToObservable<
|
||||
@ -104,6 +104,7 @@ const currentChangelogUnreadAtom = atom(
|
||||
export const useAppUpdater = () => {
|
||||
const [appQuitting, setAppQuitting] = useState(false);
|
||||
const updateReady = useAtomValue(updateReadyAtom);
|
||||
const urlService = useService(UrlService);
|
||||
const [setting, setSetting] = useAtom(appSettingAtom);
|
||||
const downloadProgress = useAtomValue(downloadProgressAtom);
|
||||
const [changelogUnread, setChangelogUnread] = useAtom(
|
||||
@ -177,9 +178,9 @@ export const useAppUpdater = () => {
|
||||
|
||||
const openChangelog = useAsyncCallback(async () => {
|
||||
track.$.navigationPanel.bottomButtons.openChangelog();
|
||||
popupWindow(BUILD_CONFIG.changelogUrl);
|
||||
urlService.openPopupWindow(BUILD_CONFIG.changelogUrl);
|
||||
await setChangelogUnread(true);
|
||||
}, [setChangelogUnread]);
|
||||
}, [setChangelogUnread, urlService]);
|
||||
|
||||
const dismissChangelog = useAsyncCallback(async () => {
|
||||
track.$.navigationPanel.bottomButtons.dismissChangelog();
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { AppSidebarService } from '@affine/core/modules/app-sidebar';
|
||||
import { I18nService } from '@affine/core/modules/i18n';
|
||||
import { UrlService } from '@affine/core/modules/url';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import type { AffineEditorContainer } from '@blocksuite/affine/presets';
|
||||
import { useService, WorkspaceService } from '@toeverything/infra';
|
||||
@ -66,6 +67,7 @@ export function useRegisterWorkspaceCommands() {
|
||||
const t = useI18n();
|
||||
const theme = useTheme();
|
||||
const currentWorkspace = useService(WorkspaceService).workspace;
|
||||
const urlService = useService(UrlService);
|
||||
const pageHelper = usePageHelper(currentWorkspace.docCollection);
|
||||
const navigationHelper = useNavigateHelper();
|
||||
const [editor] = useActiveBlocksuiteEditor();
|
||||
@ -162,10 +164,11 @@ export function useRegisterWorkspaceCommands() {
|
||||
const unsub = registerAffineHelpCommands({
|
||||
store,
|
||||
t,
|
||||
urlService,
|
||||
});
|
||||
|
||||
return () => {
|
||||
unsub();
|
||||
};
|
||||
}, [store, t]);
|
||||
}, [store, t, urlService]);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Tooltip } from '@affine/component/ui/tooltip';
|
||||
import { popupWindow } from '@affine/core/utils';
|
||||
import { UrlService } from '@affine/core/modules/url';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import { CloseIcon, NewIcon } from '@blocksuite/icons/rc';
|
||||
import {
|
||||
@ -34,8 +34,9 @@ const showList = BUILD_CONFIG.isElectron
|
||||
: DEFAULT_SHOW_LIST;
|
||||
|
||||
export const HelpIsland = () => {
|
||||
const { globalContextService } = useServices({
|
||||
const { globalContextService, urlService } = useServices({
|
||||
GlobalContextService,
|
||||
UrlService,
|
||||
});
|
||||
const docId = useLiveData(globalContextService.globalContext.docId.$);
|
||||
const docMode = useLiveData(globalContextService.globalContext.docMode.$);
|
||||
@ -79,7 +80,7 @@ export const HelpIsland = () => {
|
||||
<StyledIconWrapper
|
||||
data-testid="right-bottom-change-log-icon"
|
||||
onClick={() => {
|
||||
popupWindow(BUILD_CONFIG.changelogUrl);
|
||||
urlService.openPopupWindow(BUILD_CONFIG.changelogUrl);
|
||||
}}
|
||||
>
|
||||
<NewIcon />
|
||||
|
@ -7,7 +7,7 @@ import { useNavigateHelper } from '@affine/core/components/hooks/use-navigate-he
|
||||
import { PageDetailEditor } from '@affine/core/components/page-detail-editor';
|
||||
import { SharePageNotFoundError } from '@affine/core/components/share-page-not-found-error';
|
||||
import { AppContainer, MainContainer } from '@affine/core/components/workspace';
|
||||
import { AuthService } from '@affine/core/modules/cloud';
|
||||
import { AuthService, FetchService } from '@affine/core/modules/cloud';
|
||||
import {
|
||||
type Editor,
|
||||
type EditorSelector,
|
||||
@ -147,6 +147,7 @@ const SharePageInner = ({
|
||||
templateSnapshotUrl?: string;
|
||||
}) => {
|
||||
const workspacesService = useService(WorkspacesService);
|
||||
const fetchService = useService(FetchService);
|
||||
|
||||
const [workspace, setWorkspace] = useState<Workspace | null>(null);
|
||||
const [page, setPage] = useState<Doc | null>(null);
|
||||
@ -181,7 +182,7 @@ const SharePageInner = ({
|
||||
return EmptyBlobStorage;
|
||||
},
|
||||
getRemoteBlobStorages() {
|
||||
return [new CloudBlobStorage(workspaceId)];
|
||||
return [new CloudBlobStorage(workspaceId, fetchService)];
|
||||
},
|
||||
}
|
||||
);
|
||||
@ -220,6 +221,7 @@ const SharePageInner = ({
|
||||
selector,
|
||||
workspaceBinary,
|
||||
docBinary,
|
||||
fetchService,
|
||||
]);
|
||||
|
||||
const pageTitle = useLiveData(page?.title$);
|
||||
|
@ -85,6 +85,10 @@ export const topLevelRoutes = [
|
||||
path: '/redirect-proxy',
|
||||
lazy: () => import('@affine/core/desktop/pages/redirect'),
|
||||
},
|
||||
{
|
||||
path: '/open-app/:action',
|
||||
lazy: () => import('@affine/core/desktop/pages/open-app'),
|
||||
},
|
||||
{
|
||||
path: '*',
|
||||
lazy: () => import('./pages/404'),
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Tooltip } from '@affine/component';
|
||||
import { useCatchEventCallback } from '@affine/core/components/hooks/use-catch-event-hook';
|
||||
import { popupWindow } from '@affine/core/utils';
|
||||
import { UrlService } from '@affine/core/modules/url';
|
||||
import { Unreachable } from '@affine/env/constant';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import {
|
||||
@ -9,6 +9,7 @@ import {
|
||||
NewIcon,
|
||||
ResetIcon,
|
||||
} from '@blocksuite/icons/rc';
|
||||
import { useService } from '@toeverything/infra';
|
||||
import clsx from 'clsx';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
|
||||
@ -186,6 +187,7 @@ export function AppUpdaterButton({
|
||||
className,
|
||||
style,
|
||||
}: AddPageButtonProps) {
|
||||
const urlService = useService(UrlService);
|
||||
const handleClick = useCallback(() => {
|
||||
if (updateReady) {
|
||||
onQuitAndInstall();
|
||||
@ -197,7 +199,7 @@ export function AppUpdaterButton({
|
||||
onDownloadUpdate();
|
||||
}
|
||||
} else {
|
||||
popupWindow(
|
||||
urlService.openPopupWindow(
|
||||
`https://github.com/toeverything/AFFiNE/releases/tag/v${updateAvailable.version}`
|
||||
);
|
||||
}
|
||||
@ -213,6 +215,7 @@ export function AppUpdaterButton({
|
||||
onQuitAndInstall,
|
||||
autoDownload,
|
||||
onDownloadUpdate,
|
||||
urlService,
|
||||
onOpenChangelog,
|
||||
]);
|
||||
|
||||
|
@ -6,6 +6,7 @@ export {
|
||||
isNetworkError,
|
||||
NetworkError,
|
||||
} from './error';
|
||||
export { WebSocketAuthProvider } from './provider/websocket-auth';
|
||||
export { AccountChanged, AuthService } from './services/auth';
|
||||
export { FetchService } from './services/fetch';
|
||||
export { GraphQLService } from './services/graphql';
|
||||
@ -26,6 +27,7 @@ import {
|
||||
WorkspaceScope,
|
||||
} from '@toeverything/infra';
|
||||
|
||||
import { UrlService } from '../url';
|
||||
import { CloudDocMeta } from './entities/cloud-doc-meta';
|
||||
import { Invoices } from './entities/invoices';
|
||||
import { ServerConfig } from './entities/server-config';
|
||||
@ -35,6 +37,8 @@ import { SubscriptionPrices } from './entities/subscription-prices';
|
||||
import { UserCopilotQuota } from './entities/user-copilot-quota';
|
||||
import { UserFeature } from './entities/user-feature';
|
||||
import { UserQuota } from './entities/user-quota';
|
||||
import { DefaultFetchProvider, FetchProvider } from './provider/fetch';
|
||||
import { WebSocketAuthProvider } from './provider/websocket-auth';
|
||||
import { AuthService } from './services/auth';
|
||||
import { CloudDocMetaService } from './services/cloud-doc-meta';
|
||||
import { FetchService } from './services/fetch';
|
||||
@ -57,17 +61,25 @@ import { UserQuotaStore } from './stores/user-quota';
|
||||
|
||||
export function configureCloudModule(framework: Framework) {
|
||||
framework
|
||||
.service(FetchService)
|
||||
.service(FetchService, [FetchProvider])
|
||||
.impl(FetchProvider, DefaultFetchProvider)
|
||||
.service(GraphQLService, [FetchService])
|
||||
.service(WebSocketService, [AuthService])
|
||||
.service(
|
||||
WebSocketService,
|
||||
f =>
|
||||
new WebSocketService(
|
||||
f.get(AuthService),
|
||||
f.getOptional(WebSocketAuthProvider)
|
||||
)
|
||||
)
|
||||
.service(ServerConfigService)
|
||||
.entity(ServerConfig, [ServerConfigStore])
|
||||
.store(ServerConfigStore, [GraphQLService])
|
||||
.service(AuthService, [FetchService, AuthStore])
|
||||
.service(AuthService, [FetchService, AuthStore, UrlService])
|
||||
.store(AuthStore, [FetchService, GraphQLService, GlobalState])
|
||||
.entity(AuthSession, [AuthStore])
|
||||
.service(SubscriptionService, [SubscriptionStore])
|
||||
.store(SubscriptionStore, [GraphQLService, GlobalCache])
|
||||
.store(SubscriptionStore, [GraphQLService, GlobalCache, UrlService])
|
||||
.entity(Subscription, [AuthService, ServerConfigService, SubscriptionStore])
|
||||
.entity(SubscriptionPrices, [ServerConfigService, SubscriptionStore])
|
||||
.service(UserQuotaService)
|
||||
|
16
packages/frontend/core/src/modules/cloud/provider/fetch.ts
Normal file
16
packages/frontend/core/src/modules/cloud/provider/fetch.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { createIdentifier } from '@toeverything/infra';
|
||||
|
||||
import type { FetchInit } from '../services/fetch';
|
||||
|
||||
export interface FetchProvider {
|
||||
/**
|
||||
* standard fetch, in ios&android, we can use native fetch to implement this
|
||||
*/
|
||||
fetch: (input: string | URL, init?: FetchInit) => Promise<Response>;
|
||||
}
|
||||
|
||||
export const FetchProvider = createIdentifier<FetchProvider>('FetchProvider');
|
||||
|
||||
export const DefaultFetchProvider = {
|
||||
fetch: globalThis.fetch.bind(globalThis),
|
||||
};
|
@ -0,0 +1,22 @@
|
||||
import { createIdentifier } from '@toeverything/infra';
|
||||
|
||||
export interface WebSocketAuthProvider {
|
||||
/**
|
||||
* Returns the token and userId for WebSocket authentication
|
||||
*
|
||||
* Useful when cookies are not available for WebSocket connections
|
||||
*
|
||||
* @param url - The URL of the WebSocket endpoint
|
||||
*/
|
||||
getAuthToken: (url: string) => Promise<
|
||||
| {
|
||||
token?: string;
|
||||
userId?: string;
|
||||
}
|
||||
| undefined
|
||||
>;
|
||||
}
|
||||
|
||||
export const WebSocketAuthProvider = createIdentifier<WebSocketAuthProvider>(
|
||||
'WebSocketAuthProvider'
|
||||
);
|
@ -1,6 +1,6 @@
|
||||
import { notify } from '@affine/component';
|
||||
import { AIProvider } from '@affine/core/blocksuite/presets/ai';
|
||||
import { apis, appInfo, events } from '@affine/electron-api';
|
||||
import { apis, events } from '@affine/electron-api';
|
||||
import type { OAuthProviderType } from '@affine/graphql';
|
||||
import { I18n } from '@affine/i18n';
|
||||
import { track } from '@affine/track';
|
||||
@ -13,6 +13,7 @@ import {
|
||||
} from '@toeverything/infra';
|
||||
import { distinctUntilChanged, map, skip } from 'rxjs';
|
||||
|
||||
import type { UrlService } from '../../url';
|
||||
import { type AuthAccountInfo, AuthSession } from '../entities/session';
|
||||
import type { AuthStore } from '../stores/auth';
|
||||
import type { FetchService } from './fetch';
|
||||
@ -44,7 +45,8 @@ export class AuthService extends Service {
|
||||
|
||||
constructor(
|
||||
private readonly fetchService: FetchService,
|
||||
private readonly store: AuthStore
|
||||
private readonly store: AuthStore,
|
||||
private readonly urlService: UrlService
|
||||
) {
|
||||
super();
|
||||
|
||||
@ -117,14 +119,14 @@ export class AuthService extends Service {
|
||||
) {
|
||||
track.$.$.auth.signIn({ method: 'magic-link' });
|
||||
try {
|
||||
const scheme = this.urlService.getClientSchema();
|
||||
const magicLinkUrlParams = new URLSearchParams();
|
||||
if (redirectUrl) {
|
||||
magicLinkUrlParams.set('redirect_uri', redirectUrl);
|
||||
}
|
||||
magicLinkUrlParams.set(
|
||||
'client',
|
||||
BUILD_CONFIG.isElectron && appInfo ? appInfo.schema : 'web'
|
||||
);
|
||||
if (scheme) {
|
||||
magicLinkUrlParams.set('client', scheme);
|
||||
}
|
||||
await this.fetchService.fetch('/api/auth/sign-in', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
|
@ -3,6 +3,7 @@ import { UserFriendlyError } from '@affine/graphql';
|
||||
import { fromPromise, Service } from '@toeverything/infra';
|
||||
|
||||
import { BackendError, NetworkError } from '../error';
|
||||
import type { FetchProvider } from '../provider/fetch';
|
||||
|
||||
export function getAffineCloudBaseUrl(): string {
|
||||
if (BUILD_CONFIG.isElectron || BUILD_CONFIG.isIOS || BUILD_CONFIG.isAndroid) {
|
||||
@ -17,6 +18,9 @@ const logger = new DebugLogger('affine:fetch');
|
||||
export type FetchInit = RequestInit & { timeout?: number };
|
||||
|
||||
export class FetchService extends Service {
|
||||
constructor(private readonly fetchProvider: FetchProvider) {
|
||||
super();
|
||||
}
|
||||
rxFetch = (
|
||||
input: string,
|
||||
init?: RequestInit & {
|
||||
@ -50,13 +54,15 @@ export class FetchService extends Service {
|
||||
abortController.abort('timeout');
|
||||
}, timeout);
|
||||
|
||||
const res = await fetch(new URL(input, getAffineCloudBaseUrl()), {
|
||||
...init,
|
||||
signal: abortController.signal,
|
||||
}).catch(err => {
|
||||
logger.debug('network error', err);
|
||||
throw new NetworkError(err);
|
||||
});
|
||||
const res = await this.fetchProvider
|
||||
.fetch(new URL(input, getAffineCloudBaseUrl()), {
|
||||
...init,
|
||||
signal: abortController.signal,
|
||||
})
|
||||
.catch(err => {
|
||||
logger.debug('network error', err);
|
||||
throw new NetworkError(err);
|
||||
});
|
||||
clearTimeout(timeoutId);
|
||||
if (res.status === 504) {
|
||||
const error = new Error('Gateway Timeout');
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { ApplicationStarted, OnEvent, Service } from '@toeverything/infra';
|
||||
import { Manager } from 'socket.io-client';
|
||||
|
||||
import type { WebSocketAuthProvider } from '../provider/websocket-auth';
|
||||
import { getAffineCloudBaseUrl } from '../services/fetch';
|
||||
import type { AuthService } from './auth';
|
||||
import { AccountChanged } from './auth';
|
||||
@ -13,10 +14,26 @@ export class WebSocketService extends Service {
|
||||
transports: ['websocket'],
|
||||
secure: location.protocol === 'https:',
|
||||
});
|
||||
socket = this.ioManager.socket('/');
|
||||
socket = this.ioManager.socket('/', {
|
||||
auth: this.webSocketAuthProvider
|
||||
? cb => {
|
||||
this.webSocketAuthProvider
|
||||
?.getAuthToken(`${getAffineCloudBaseUrl()}/`)
|
||||
.then(v => {
|
||||
cb(v ?? {});
|
||||
})
|
||||
.catch(e => {
|
||||
console.error('Failed to get auth token for websocket', e);
|
||||
});
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
refCount = 0;
|
||||
|
||||
constructor(private readonly authService: AuthService) {
|
||||
constructor(
|
||||
private readonly authService: AuthService,
|
||||
private readonly webSocketAuthProvider?: WebSocketAuthProvider
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { appInfo } from '@affine/electron-api';
|
||||
import type {
|
||||
CreateCheckoutSessionInput,
|
||||
SubscriptionRecurring,
|
||||
@ -15,6 +14,7 @@ import {
|
||||
import type { GlobalCache } from '@toeverything/infra';
|
||||
import { Store } from '@toeverything/infra';
|
||||
|
||||
import type { UrlService } from '../../url';
|
||||
import type { SubscriptionType } from '../entities/subscription';
|
||||
import { getAffineCloudBaseUrl } from '../services/fetch';
|
||||
import type { GraphQLService } from '../services/graphql';
|
||||
@ -22,14 +22,15 @@ import type { GraphQLService } from '../services/graphql';
|
||||
const SUBSCRIPTION_CACHE_KEY = 'subscription:';
|
||||
|
||||
const getDefaultSubscriptionSuccessCallbackLink = (
|
||||
plan: SubscriptionPlan | null
|
||||
plan: SubscriptionPlan | null,
|
||||
schema?: string
|
||||
) => {
|
||||
const path =
|
||||
plan === SubscriptionPlan.AI ? '/ai-upgrade-success' : '/upgrade-success';
|
||||
const urlString = getAffineCloudBaseUrl() + path;
|
||||
const url = new URL(urlString);
|
||||
if (BUILD_CONFIG.isElectron && appInfo) {
|
||||
url.searchParams.set('schema', appInfo.schema);
|
||||
if (schema) {
|
||||
url.searchParams.set('schema', schema);
|
||||
}
|
||||
return url.toString();
|
||||
};
|
||||
@ -37,7 +38,8 @@ const getDefaultSubscriptionSuccessCallbackLink = (
|
||||
export class SubscriptionStore extends Store {
|
||||
constructor(
|
||||
private readonly gqlService: GraphQLService,
|
||||
private readonly globalCache: GlobalCache
|
||||
private readonly globalCache: GlobalCache,
|
||||
private readonly urlService: UrlService
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@ -129,7 +131,10 @@ export class SubscriptionStore extends Store {
|
||||
...input,
|
||||
successCallbackLink:
|
||||
input.successCallbackLink ||
|
||||
getDefaultSubscriptionSuccessCallbackLink(input.plan),
|
||||
getDefaultSubscriptionSuccessCallbackLink(
|
||||
input.plan,
|
||||
this.urlService.getClientSchema()
|
||||
),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
@ -28,6 +28,7 @@ import { configureSystemFontFamilyModule } from './system-font-family';
|
||||
import { configureTagModule } from './tag';
|
||||
import { configureTelemetryModule } from './telemetry';
|
||||
import { configureThemeEditorModule } from './theme-editor';
|
||||
import { configureUrlModule } from './url';
|
||||
import { configureUserspaceModule } from './userspace';
|
||||
|
||||
export function configureCommonModules(framework: Framework) {
|
||||
@ -61,4 +62,5 @@ export function configureCommonModules(framework: Framework) {
|
||||
configureDocInfoModule(framework);
|
||||
configureAppSidebarModule(framework);
|
||||
configureJournalModule(framework);
|
||||
configureUrlModule(framework);
|
||||
}
|
||||
|
20
packages/frontend/core/src/modules/url/index.ts
Normal file
20
packages/frontend/core/src/modules/url/index.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import type { Framework } from '@toeverything/infra';
|
||||
|
||||
import { ClientSchemaProvider } from './providers/client-schema';
|
||||
import { PopupWindowProvider } from './providers/popup-window';
|
||||
import { UrlService } from './services/url';
|
||||
|
||||
export { ClientSchemaProvider } from './providers/client-schema';
|
||||
export { PopupWindowProvider } from './providers/popup-window';
|
||||
export { UrlService } from './services/url';
|
||||
|
||||
export const configureUrlModule = (container: Framework) => {
|
||||
container.service(
|
||||
UrlService,
|
||||
f =>
|
||||
new UrlService(
|
||||
f.getOptional(PopupWindowProvider),
|
||||
f.getOptional(ClientSchemaProvider)
|
||||
)
|
||||
);
|
||||
};
|
@ -0,0 +1,12 @@
|
||||
import { createIdentifier } from '@toeverything/infra';
|
||||
|
||||
export interface ClientSchemaProvider {
|
||||
/**
|
||||
* Get the client schema in the current environment, used for the user to complete the authentication process in the browser and redirect back to the app.
|
||||
*/
|
||||
getClientSchema(): string | undefined;
|
||||
}
|
||||
|
||||
export const ClientSchemaProvider = createIdentifier<ClientSchemaProvider>(
|
||||
'ClientSchemaProvider'
|
||||
);
|
@ -0,0 +1,13 @@
|
||||
import { createIdentifier } from '@toeverything/infra';
|
||||
|
||||
export interface PopupWindowProvider {
|
||||
/**
|
||||
* open a popup window, provide different implementations in different environments.
|
||||
* e.g. in electron, use system default browser to open a popup window.
|
||||
*/
|
||||
open(url: string): void;
|
||||
}
|
||||
|
||||
export const PopupWindowProvider = createIdentifier<PopupWindowProvider>(
|
||||
'PopupWindowProvider'
|
||||
);
|
31
packages/frontend/core/src/modules/url/services/url.ts
Normal file
31
packages/frontend/core/src/modules/url/services/url.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { Service } from '@toeverything/infra';
|
||||
|
||||
import type { ClientSchemaProvider } from '../providers/client-schema';
|
||||
import type { PopupWindowProvider } from '../providers/popup-window';
|
||||
|
||||
export class UrlService extends Service {
|
||||
constructor(
|
||||
// those providers are optional, because they are not always available in some environments
|
||||
private readonly popupWindowProvider?: PopupWindowProvider,
|
||||
private readonly clientSchemaProvider?: ClientSchemaProvider
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
getClientSchema() {
|
||||
return this.clientSchemaProvider?.getClientSchema();
|
||||
}
|
||||
|
||||
/**
|
||||
* open a popup window, provide different implementations in different environments.
|
||||
* e.g. in electron, use system default browser to open a popup window.
|
||||
*
|
||||
* @param url only full url with http/https protocol is supported
|
||||
*/
|
||||
openPopupWindow(url: string) {
|
||||
if (!url.startsWith('http')) {
|
||||
throw new Error('only full url with http/https protocol is supported');
|
||||
}
|
||||
this.popupWindowProvider?.open(url);
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
import { popupWindow } from '@affine/core/utils';
|
||||
import { apis } from '@affine/electron-api';
|
||||
import { createIdentifier } from '@toeverything/infra';
|
||||
import { parsePath, type To } from 'history';
|
||||
@ -20,7 +19,7 @@ export const BrowserWorkbenchNewTabHandler: WorkbenchNewTabHandler = ({
|
||||
const link =
|
||||
basename +
|
||||
(typeof to === 'string' ? to : `${to.pathname}${to.search}${to.hash}`);
|
||||
popupWindow(link);
|
||||
window.open(link, '_blank');
|
||||
};
|
||||
|
||||
export const DesktopWorkbenchNewTabHandler: WorkbenchNewTabHandler = ({
|
||||
|
@ -32,6 +32,7 @@ import { applyUpdate, encodeStateAsUpdate } from 'yjs';
|
||||
|
||||
import type {
|
||||
AuthService,
|
||||
FetchService,
|
||||
GraphQLService,
|
||||
WebSocketService,
|
||||
} from '../../cloud';
|
||||
@ -59,7 +60,8 @@ export class CloudWorkspaceFlavourProviderService
|
||||
private readonly authService: AuthService,
|
||||
private readonly storageProvider: WorkspaceEngineStorageProvider,
|
||||
private readonly graphqlService: GraphQLService,
|
||||
private readonly webSocketService: WebSocketService
|
||||
private readonly webSocketService: WebSocketService,
|
||||
private readonly fetchService: FetchService
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@ -200,7 +202,7 @@ export class CloudWorkspaceFlavourProviderService
|
||||
// get information from both cloud and local storage
|
||||
|
||||
// we use affine 'static' storage here, which use http protocol, no need to websocket.
|
||||
const cloudStorage = new CloudStaticDocStorage(id);
|
||||
const cloudStorage = new CloudStaticDocStorage(id, this.fetchService);
|
||||
const docStorage = this.storageProvider.getDocStorage(id);
|
||||
// download root doc
|
||||
const localData = await docStorage.doc.get(id);
|
||||
@ -235,7 +237,7 @@ export class CloudWorkspaceFlavourProviderService
|
||||
return localBlob;
|
||||
}
|
||||
|
||||
const cloudBlob = new CloudBlobStorage(id);
|
||||
const cloudBlob = new CloudBlobStorage(id, this.fetchService);
|
||||
return await cloudBlob.get(blob);
|
||||
}
|
||||
getEngineProvider(workspaceId: string): WorkspaceEngineProvider {
|
||||
@ -255,8 +257,11 @@ export class CloudWorkspaceFlavourProviderService
|
||||
getLocalBlobStorage: () => {
|
||||
return this.storageProvider.getBlobStorage(workspaceId);
|
||||
},
|
||||
getRemoteBlobStorages() {
|
||||
return [new CloudBlobStorage(workspaceId), new StaticBlobStorage()];
|
||||
getRemoteBlobStorages: () => {
|
||||
return [
|
||||
new CloudBlobStorage(workspaceId, this.fetchService),
|
||||
new StaticBlobStorage(),
|
||||
];
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { FetchService } from '@affine/core/modules/cloud';
|
||||
import {
|
||||
deleteBlobMutation,
|
||||
fetcher,
|
||||
getBaseUrl,
|
||||
listBlobsQuery,
|
||||
setBlobMutation,
|
||||
UserFriendlyError,
|
||||
@ -12,7 +12,10 @@ import { BlobStorageOverCapacity } from '@toeverything/infra';
|
||||
import { bufferToBlob } from '../../utils/buffer-to-blob';
|
||||
|
||||
export class CloudBlobStorage implements BlobStorage {
|
||||
constructor(private readonly workspaceId: string) {}
|
||||
constructor(
|
||||
private readonly workspaceId: string,
|
||||
private readonly fetchService: FetchService
|
||||
) {}
|
||||
|
||||
name = 'cloud';
|
||||
readonly = false;
|
||||
@ -22,15 +25,23 @@ export class CloudBlobStorage implements BlobStorage {
|
||||
? key
|
||||
: `/api/workspaces/${this.workspaceId}/blobs/${key}`;
|
||||
|
||||
return fetch(getBaseUrl() + suffix, { cache: 'default' }).then(
|
||||
async res => {
|
||||
return this.fetchService
|
||||
.fetch(suffix, {
|
||||
cache: 'default',
|
||||
headers: {
|
||||
Accept: 'application/octet-stream', // this is necessary for ios native fetch to return arraybuffer
|
||||
},
|
||||
})
|
||||
.then(async res => {
|
||||
if (!res.ok) {
|
||||
// status not in the range 200-299
|
||||
return null;
|
||||
}
|
||||
return bufferToBlob(await res.arrayBuffer());
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch(() => {
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
async set(key: string, value: Blob) {
|
||||
|
@ -1,15 +1,23 @@
|
||||
import type { FetchService } from '@affine/core/modules/cloud';
|
||||
|
||||
export class CloudStaticDocStorage {
|
||||
name = 'cloud-static';
|
||||
constructor(private readonly workspaceId: string) {}
|
||||
constructor(
|
||||
private readonly workspaceId: string,
|
||||
private readonly fetchService: FetchService
|
||||
) {}
|
||||
|
||||
async pull(
|
||||
docId: string
|
||||
): Promise<{ data: Uint8Array; state?: Uint8Array | undefined } | null> {
|
||||
const response = await fetch(
|
||||
const response = await this.fetchService.fetch(
|
||||
`/api/workspaces/${this.workspaceId}/docs/${docId}`,
|
||||
{
|
||||
priority: 'high',
|
||||
} as any
|
||||
headers: {
|
||||
Accept: 'application/octet-stream', // this is necessary for ios native fetch to return arraybuffer
|
||||
},
|
||||
}
|
||||
);
|
||||
if (response.ok) {
|
||||
const arrayBuffer = await response.arrayBuffer();
|
||||
|
@ -1,5 +1,6 @@
|
||||
import {
|
||||
AuthService,
|
||||
FetchService,
|
||||
GraphQLService,
|
||||
WebSocketService,
|
||||
} from '@affine/core/modules/cloud';
|
||||
@ -33,6 +34,7 @@ export function configureBrowserWorkspaceFlavours(framework: Framework) {
|
||||
WorkspaceEngineStorageProvider,
|
||||
GraphQLService,
|
||||
WebSocketService,
|
||||
FetchService,
|
||||
])
|
||||
.impl(WorkspaceFlavourProvider('CLOUD'), p =>
|
||||
p.get(CloudWorkspaceFlavourProviderService)
|
||||
|
@ -1,8 +1,6 @@
|
||||
export * from './create-emotion-cache';
|
||||
export * from './event';
|
||||
export * from './extract-emoji-icon';
|
||||
export * from './popup';
|
||||
export * from './string2color';
|
||||
export * from './toast';
|
||||
export * from './unflatten-object';
|
||||
export * from './url';
|
||||
|
@ -1,41 +0,0 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { apis } from '@affine/electron-api';
|
||||
|
||||
const logger = new DebugLogger('popup');
|
||||
|
||||
const origin =
|
||||
BUILD_CONFIG.isElectron || BUILD_CONFIG.isIOS || BUILD_CONFIG.isAndroid
|
||||
? BUILD_CONFIG.serverUrlPrefix
|
||||
: location.origin;
|
||||
|
||||
/**
|
||||
* @deprecated need to be refactored as [UrlService] dependencies on [ServerConfigService]
|
||||
*/
|
||||
export function popupWindow(target: string) {
|
||||
const isFullUrl = /^https?:\/\//.test(target);
|
||||
|
||||
const redirectProxy = origin + '/redirect-proxy';
|
||||
target = isFullUrl ? target : origin + target;
|
||||
|
||||
const targetUrl = new URL(target);
|
||||
|
||||
let url: string;
|
||||
// safe to open directly if in the same origin
|
||||
if (targetUrl.origin === origin) {
|
||||
url = target;
|
||||
} else {
|
||||
const search = new URLSearchParams({
|
||||
redirect_uri: target,
|
||||
});
|
||||
|
||||
url = `${redirectProxy}?${search.toString()}`;
|
||||
}
|
||||
|
||||
if (BUILD_CONFIG.isElectron) {
|
||||
apis?.ui.openExternal(url).catch(e => {
|
||||
logger.error('Failed to open external URL', e);
|
||||
});
|
||||
} else {
|
||||
window.open(url, '_blank', `noreferrer noopener`);
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
import { appInfo } from '@affine/electron-api';
|
||||
|
||||
interface AppUrlOptions {
|
||||
desktop?: boolean | string;
|
||||
openInHiddenWindow?: boolean;
|
||||
redirectFromWeb?: boolean;
|
||||
}
|
||||
|
||||
export function buildAppUrl(path: string, opts: AppUrlOptions = {}) {
|
||||
// TODO(@EYHN): should use server base url
|
||||
const webBase = BUILD_CONFIG.serverUrlPrefix;
|
||||
// TODO(@pengx17): how could we know the corresponding app schema in web environment
|
||||
if (opts.desktop && appInfo?.schema) {
|
||||
const urlCtor = new URL(path, webBase);
|
||||
|
||||
if (opts.openInHiddenWindow) {
|
||||
urlCtor.searchParams.set('hidden', 'true');
|
||||
}
|
||||
|
||||
const url = `${appInfo.schema}://${urlCtor.pathname}${urlCtor.search}`;
|
||||
|
||||
if (opts.redirectFromWeb) {
|
||||
const redirect_uri = new URL('/open-app/url', webBase);
|
||||
redirect_uri.searchParams.set('url', url);
|
||||
|
||||
return redirect_uri.toString();
|
||||
}
|
||||
|
||||
return url;
|
||||
} else {
|
||||
return new URL(path, webBase).toString();
|
||||
}
|
||||
}
|
@ -52,6 +52,9 @@ const buildFlags = process.argv.includes('--static')
|
||||
{
|
||||
value: 'mobile',
|
||||
},
|
||||
{
|
||||
value: 'ios',
|
||||
},
|
||||
],
|
||||
initialValue: 'web',
|
||||
}),
|
||||
|
22
yarn.lock
22
yarn.lock
@ -391,6 +391,8 @@ __metadata:
|
||||
"@affine/track": "workspace:*"
|
||||
"@blocksuite/affine": "npm:0.17.19"
|
||||
"@blocksuite/icons": "npm:2.1.69"
|
||||
"@capacitor/app": "npm:^6.0.1"
|
||||
"@capacitor/browser": "npm:^6.0.3"
|
||||
"@dnd-kit/core": "npm:^6.1.0"
|
||||
"@dnd-kit/modifiers": "npm:^7.0.0"
|
||||
"@dnd-kit/sortable": "npm:^8.0.0"
|
||||
@ -598,6 +600,8 @@ __metadata:
|
||||
"@affine/i18n": "workspace:*"
|
||||
"@blocksuite/affine": "npm:0.17.19"
|
||||
"@blocksuite/icons": "npm:^2.1.67"
|
||||
"@capacitor/app": "npm:^6.0.1"
|
||||
"@capacitor/browser": "npm:^6.0.3"
|
||||
"@capacitor/cli": "npm:^6.1.2"
|
||||
"@capacitor/core": "npm:^6.1.2"
|
||||
"@capacitor/ios": "npm:^6.1.2"
|
||||
@ -2910,6 +2914,24 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@capacitor/app@npm:^6.0.1":
|
||||
version: 6.0.1
|
||||
resolution: "@capacitor/app@npm:6.0.1"
|
||||
peerDependencies:
|
||||
"@capacitor/core": ^6.0.0
|
||||
checksum: 10/3e8bc85c3a43728c003c80511dde913872b1263dbc27931b1168f52442b8d95f35e5a6a85423d6ac61253a5e4b2198bbb7b899cae9f5e343edfed24010399ade
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@capacitor/browser@npm:^6.0.3":
|
||||
version: 6.0.3
|
||||
resolution: "@capacitor/browser@npm:6.0.3"
|
||||
peerDependencies:
|
||||
"@capacitor/core": ^6.0.0
|
||||
checksum: 10/e19e66c12b5c3a05e0c4a93715c0bec760781ddeb215a93da0a9ee3e9e4ede2f2893d399ffb8d7b5ded6ac70651ab482689ff57e5e0d067cd4398cc3247c4f81
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@capacitor/cli@npm:^6.1.2":
|
||||
version: 6.1.2
|
||||
resolution: "@capacitor/cli@npm:6.1.2"
|
||||
|
Loading…
Reference in New Issue
Block a user