Compare commits
33 Commits
28ec64f8e6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a525c763e | |||
| a0dffdc715 | |||
| 4765d48021 | |||
| f888e28d15 | |||
| c934dbad84 | |||
| 4088db8ec0 | |||
| 255f171aa8 | |||
| 70870e1ec2 | |||
| f1a380d105 | |||
| 01ad237af3 | |||
| 7d49f7d5a4 | |||
| 87eb958869 | |||
| 4340fd3635 | |||
| ac2eac5fcd | |||
| a386802a55 | |||
| 1f94b9884c | |||
| 58a8d27315 | |||
| 7f4fc34dbf | |||
| 5af8038ec0 | |||
| 1ff250fa17 | |||
| 42e647c932 | |||
| 080c7f00ce | |||
| 545e023ffc | |||
| 10ba84e349 | |||
| adf13ae47c | |||
| 6c62d4bce4 | |||
| 000a56295f | |||
| bbd4f0e266 | |||
| 423132699e | |||
| 505777a40e | |||
| 3dccd16757 | |||
| e19dba594c | |||
| 73154aad08 |
@@ -0,0 +1,16 @@
|
|||||||
|
# 项目说明
|
||||||
|
|
||||||
|
## 构建与测试环境
|
||||||
|
|
||||||
|
- 开发设备:macOS
|
||||||
|
- Xcode 版本:26.3
|
||||||
|
- 主 App Deployment Target:iOS 26.0
|
||||||
|
- 可用的 iOS 模拟器:**iPhone 17 Pro**
|
||||||
|
|
||||||
|
## 常用命令
|
||||||
|
|
||||||
|
### 编译主 App(iPhone 17 Pro 模拟器)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
xcodebuild -scheme Note -destination 'platform=iOS Simulator,name=iPhone 17 Pro' build
|
||||||
|
```
|
||||||
@@ -6,8 +6,37 @@
|
|||||||
objectVersion = 77;
|
objectVersion = 77;
|
||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
|
/* Begin PBXBuildFile section */
|
||||||
|
CFD40B353003C283009C9F2A /* NoteShareExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = CFD40B283003C283009C9F2A /* NoteShareExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||||
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
|
/* Begin PBXContainerItemProxy section */
|
||||||
|
CFD40B313003C283009C9F2A /* PBXContainerItemProxy */ = {
|
||||||
|
isa = PBXContainerItemProxy;
|
||||||
|
containerPortal = CFD40B083003C283009C9F2A /* Project object */;
|
||||||
|
proxyType = 1;
|
||||||
|
remoteGlobalIDString = CFD40B293003C283009C9F2A;
|
||||||
|
remoteInfo = NoteShareExtension;
|
||||||
|
};
|
||||||
|
/* End PBXContainerItemProxy section */
|
||||||
|
|
||||||
|
/* Begin PBXCopyFilesBuildPhase section */
|
||||||
|
CFD40B2F3003C283009C9F2A /* Embed Foundation Extensions */ = {
|
||||||
|
isa = PBXCopyFilesBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
dstPath = "";
|
||||||
|
dstSubfolderSpec = 16;
|
||||||
|
files = (
|
||||||
|
CFD40B353003C283009C9F2A /* NoteShareExtension.appex in Embed Foundation Extensions */,
|
||||||
|
);
|
||||||
|
name = "Embed Foundation Extensions";
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXCopyFilesBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
CFD40B103003C283009C9F2A /* Note.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Note.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
CFD40B103003C283009C9F2A /* Note.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Note.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
|
CFD40B283003C283009C9F2A /* NoteShareExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = NoteShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
|
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
|
||||||
@@ -18,6 +47,13 @@
|
|||||||
);
|
);
|
||||||
target = CFD40B0F3003C283009C9F2A /* Note */;
|
target = CFD40B0F3003C283009C9F2A /* Note */;
|
||||||
};
|
};
|
||||||
|
CFD40B2E3003C283009C9F2A /* Exceptions for "NoteShareExtension" folder in "NoteShareExtension" target */ = {
|
||||||
|
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
|
||||||
|
membershipExceptions = (
|
||||||
|
Info.plist,
|
||||||
|
);
|
||||||
|
target = CFD40B293003C283009C9F2A /* NoteShareExtension */;
|
||||||
|
};
|
||||||
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
|
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
|
||||||
|
|
||||||
/* Begin PBXFileSystemSynchronizedRootGroup section */
|
/* Begin PBXFileSystemSynchronizedRootGroup section */
|
||||||
@@ -29,6 +65,14 @@
|
|||||||
path = Note;
|
path = Note;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
CFD40B2D3003C283009C9F2A /* NoteShareExtension */ = {
|
||||||
|
isa = PBXFileSystemSynchronizedRootGroup;
|
||||||
|
exceptions = (
|
||||||
|
CFD40B2E3003C283009C9F2A /* Exceptions for "NoteShareExtension" folder in "NoteShareExtension" target */,
|
||||||
|
);
|
||||||
|
path = NoteShareExtension;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
/* End PBXFileSystemSynchronizedRootGroup section */
|
/* End PBXFileSystemSynchronizedRootGroup section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@@ -39,6 +83,13 @@
|
|||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
CFD40B323003C283009C9F2A /* Frameworks */ = {
|
||||||
|
isa = PBXFrameworksBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
/* End PBXFrameworksBuildPhase section */
|
/* End PBXFrameworksBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXGroup section */
|
/* Begin PBXGroup section */
|
||||||
@@ -46,6 +97,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
CFD40B123003C283009C9F2A /* Note */,
|
CFD40B123003C283009C9F2A /* Note */,
|
||||||
|
CFD40B2D3003C283009C9F2A /* NoteShareExtension */,
|
||||||
CFD40B113003C283009C9F2A /* Products */,
|
CFD40B113003C283009C9F2A /* Products */,
|
||||||
);
|
);
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -54,6 +106,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
CFD40B103003C283009C9F2A /* Note.app */,
|
CFD40B103003C283009C9F2A /* Note.app */,
|
||||||
|
CFD40B283003C283009C9F2A /* NoteShareExtension.appex */,
|
||||||
);
|
);
|
||||||
name = Products;
|
name = Products;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -68,10 +121,12 @@
|
|||||||
CFD40B0C3003C283009C9F2A /* Sources */,
|
CFD40B0C3003C283009C9F2A /* Sources */,
|
||||||
CFD40B0D3003C283009C9F2A /* Frameworks */,
|
CFD40B0D3003C283009C9F2A /* Frameworks */,
|
||||||
CFD40B0E3003C283009C9F2A /* Resources */,
|
CFD40B0E3003C283009C9F2A /* Resources */,
|
||||||
|
CFD40B2F3003C283009C9F2A /* Embed Foundation Extensions */,
|
||||||
);
|
);
|
||||||
buildRules = (
|
buildRules = (
|
||||||
);
|
);
|
||||||
dependencies = (
|
dependencies = (
|
||||||
|
CFD40B303003C283009C9F2A /* PBXTargetDependency */,
|
||||||
);
|
);
|
||||||
fileSystemSynchronizedGroups = (
|
fileSystemSynchronizedGroups = (
|
||||||
CFD40B123003C283009C9F2A /* Note */,
|
CFD40B123003C283009C9F2A /* Note */,
|
||||||
@@ -83,6 +138,28 @@
|
|||||||
productReference = CFD40B103003C283009C9F2A /* Note.app */;
|
productReference = CFD40B103003C283009C9F2A /* Note.app */;
|
||||||
productType = "com.apple.product-type.application";
|
productType = "com.apple.product-type.application";
|
||||||
};
|
};
|
||||||
|
CFD40B293003C283009C9F2A /* NoteShareExtension */ = {
|
||||||
|
isa = PBXNativeTarget;
|
||||||
|
buildConfigurationList = CFD40B2A3003C283009C9F2A /* Build configuration list for PBXNativeTarget "NoteShareExtension" */;
|
||||||
|
buildPhases = (
|
||||||
|
CFD40B333003C283009C9F2A /* Sources */,
|
||||||
|
CFD40B343003C283009C9F2A /* Resources */,
|
||||||
|
CFD40B323003C283009C9F2A /* Frameworks */,
|
||||||
|
);
|
||||||
|
buildRules = (
|
||||||
|
);
|
||||||
|
dependencies = (
|
||||||
|
);
|
||||||
|
fileSystemSynchronizedGroups = (
|
||||||
|
CFD40B2D3003C283009C9F2A /* NoteShareExtension */,
|
||||||
|
);
|
||||||
|
name = NoteShareExtension;
|
||||||
|
packageProductDependencies = (
|
||||||
|
);
|
||||||
|
productName = NoteShareExtension;
|
||||||
|
productReference = CFD40B283003C283009C9F2A /* NoteShareExtension.appex */;
|
||||||
|
productType = "com.apple.product-type.app-extension";
|
||||||
|
};
|
||||||
/* End PBXNativeTarget section */
|
/* End PBXNativeTarget section */
|
||||||
|
|
||||||
/* Begin PBXProject section */
|
/* Begin PBXProject section */
|
||||||
@@ -96,6 +173,9 @@
|
|||||||
CFD40B0F3003C283009C9F2A = {
|
CFD40B0F3003C283009C9F2A = {
|
||||||
CreatedOnToolsVersion = 26.3;
|
CreatedOnToolsVersion = 26.3;
|
||||||
};
|
};
|
||||||
|
CFD40B293003C283009C9F2A = {
|
||||||
|
CreatedOnToolsVersion = 26.3;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
buildConfigurationList = CFD40B0B3003C283009C9F2A /* Build configuration list for PBXProject "Note" */;
|
buildConfigurationList = CFD40B0B3003C283009C9F2A /* Build configuration list for PBXProject "Note" */;
|
||||||
@@ -104,6 +184,7 @@
|
|||||||
knownRegions = (
|
knownRegions = (
|
||||||
en,
|
en,
|
||||||
Base,
|
Base,
|
||||||
|
"zh-Hans",
|
||||||
);
|
);
|
||||||
mainGroup = CFD40B073003C283009C9F2A;
|
mainGroup = CFD40B073003C283009C9F2A;
|
||||||
minimizedProjectReferenceProxies = 1;
|
minimizedProjectReferenceProxies = 1;
|
||||||
@@ -113,6 +194,7 @@
|
|||||||
projectRoot = "";
|
projectRoot = "";
|
||||||
targets = (
|
targets = (
|
||||||
CFD40B0F3003C283009C9F2A /* Note */,
|
CFD40B0F3003C283009C9F2A /* Note */,
|
||||||
|
CFD40B293003C283009C9F2A /* NoteShareExtension */,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
/* End PBXProject section */
|
/* End PBXProject section */
|
||||||
@@ -125,6 +207,13 @@
|
|||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
CFD40B343003C283009C9F2A /* Resources */ = {
|
||||||
|
isa = PBXResourcesBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
/* End PBXResourcesBuildPhase section */
|
/* End PBXResourcesBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXSourcesBuildPhase section */
|
/* Begin PBXSourcesBuildPhase section */
|
||||||
@@ -135,14 +224,30 @@
|
|||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
CFD40B333003C283009C9F2A /* Sources */ = {
|
||||||
|
isa = PBXSourcesBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
/* End PBXSourcesBuildPhase section */
|
/* End PBXSourcesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXTargetDependency section */
|
||||||
|
CFD40B303003C283009C9F2A /* PBXTargetDependency */ = {
|
||||||
|
isa = PBXTargetDependency;
|
||||||
|
target = CFD40B293003C283009C9F2A /* NoteShareExtension */;
|
||||||
|
targetProxy = CFD40B313003C283009C9F2A /* PBXContainerItemProxy */;
|
||||||
|
};
|
||||||
|
/* End PBXTargetDependency section */
|
||||||
|
|
||||||
/* Begin XCBuildConfiguration section */
|
/* Begin XCBuildConfiguration section */
|
||||||
CFD40B243003C284009C9F2A /* Debug */ = {
|
CFD40B243003C284009C9F2A /* Debug */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||||
|
CODE_SIGN_ENTITLEMENTS = Note/Note.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
DEVELOPMENT_TEAM = 37HGUEC495;
|
DEVELOPMENT_TEAM = 37HGUEC495;
|
||||||
@@ -176,6 +281,7 @@
|
|||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||||
|
CODE_SIGN_ENTITLEMENTS = Note/Note.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 1;
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
DEVELOPMENT_TEAM = 37HGUEC495;
|
DEVELOPMENT_TEAM = 37HGUEC495;
|
||||||
@@ -325,6 +431,68 @@
|
|||||||
};
|
};
|
||||||
name = Release;
|
name = Release;
|
||||||
};
|
};
|
||||||
|
CFD40B2B3003C283009C9F2A /* Debug */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
||||||
|
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||||
|
CODE_SIGN_ENTITLEMENTS = NoteShareExtension/NoteShareExtension.entitlements;
|
||||||
|
CODE_SIGN_STYLE = Automatic;
|
||||||
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
|
DEVELOPMENT_TEAM = 37HGUEC495;
|
||||||
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
|
INFOPLIST_FILE = NoteShareExtension/Info.plist;
|
||||||
|
INFOPLIST_KEY_CFBundleDisplayName = "备忘录格式化助手";
|
||||||
|
INFOPLIST_KEY_NSHumanReadableCopyright = "";
|
||||||
|
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
|
||||||
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
|
"$(inherited)",
|
||||||
|
"@executable_path/Frameworks",
|
||||||
|
"@executable_path/../../Frameworks",
|
||||||
|
);
|
||||||
|
MARKETING_VERSION = 1.0.0;
|
||||||
|
PRODUCT_BUNDLE_IDENTIFIER = com.fishestlife.note.share;
|
||||||
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
SKIP_INSTALL = YES;
|
||||||
|
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
|
||||||
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
|
SWIFT_VERSION = 5.0;
|
||||||
|
TARGETED_DEVICE_FAMILY = "1,2";
|
||||||
|
};
|
||||||
|
name = Debug;
|
||||||
|
};
|
||||||
|
CFD40B2C3003C283009C9F2A /* Release */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
||||||
|
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||||
|
CODE_SIGN_ENTITLEMENTS = NoteShareExtension/NoteShareExtension.entitlements;
|
||||||
|
CODE_SIGN_STYLE = Automatic;
|
||||||
|
CURRENT_PROJECT_VERSION = 1;
|
||||||
|
DEVELOPMENT_TEAM = 37HGUEC495;
|
||||||
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
|
INFOPLIST_FILE = NoteShareExtension/Info.plist;
|
||||||
|
INFOPLIST_KEY_CFBundleDisplayName = "备忘录格式化助手";
|
||||||
|
INFOPLIST_KEY_NSHumanReadableCopyright = "";
|
||||||
|
IPHONEOS_DEPLOYMENT_TARGET = 26.0;
|
||||||
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
|
"$(inherited)",
|
||||||
|
"@executable_path/Frameworks",
|
||||||
|
"@executable_path/../../Frameworks",
|
||||||
|
);
|
||||||
|
MARKETING_VERSION = 1.0.0;
|
||||||
|
PRODUCT_BUNDLE_IDENTIFIER = com.fishestlife.note.share;
|
||||||
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
SKIP_INSTALL = YES;
|
||||||
|
SWIFT_COMPILATION_MODE = wholemodule;
|
||||||
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
|
SWIFT_VERSION = 5.0;
|
||||||
|
TARGETED_DEVICE_FAMILY = "1,2";
|
||||||
|
VALIDATE_PRODUCT = YES;
|
||||||
|
};
|
||||||
|
name = Release;
|
||||||
|
};
|
||||||
/* End XCBuildConfiguration section */
|
/* End XCBuildConfiguration section */
|
||||||
|
|
||||||
/* Begin XCConfigurationList section */
|
/* Begin XCConfigurationList section */
|
||||||
@@ -346,6 +514,15 @@
|
|||||||
defaultConfigurationIsVisible = 0;
|
defaultConfigurationIsVisible = 0;
|
||||||
defaultConfigurationName = Release;
|
defaultConfigurationName = Release;
|
||||||
};
|
};
|
||||||
|
CFD40B2A3003C283009C9F2A /* Build configuration list for PBXNativeTarget "NoteShareExtension" */ = {
|
||||||
|
isa = XCConfigurationList;
|
||||||
|
buildConfigurations = (
|
||||||
|
CFD40B2B3003C283009C9F2A /* Debug */,
|
||||||
|
CFD40B2C3003C283009C9F2A /* Release */,
|
||||||
|
);
|
||||||
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
|
};
|
||||||
/* End XCConfigurationList section */
|
/* End XCConfigurationList section */
|
||||||
};
|
};
|
||||||
rootObject = CFD40B083003C283009C9F2A /* Project object */;
|
rootObject = CFD40B083003C283009C9F2A /* Project object */;
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "2630"
|
||||||
|
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 = "CFD40B0F3003C283009C9F2A"
|
||||||
|
BuildableName = "Note.app"
|
||||||
|
BlueprintName = "Note"
|
||||||
|
ReferencedContainer = "container:Note.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 = "CFD40B0F3003C283009C9F2A"
|
||||||
|
BuildableName = "Note.app"
|
||||||
|
BlueprintName = "Note"
|
||||||
|
ReferencedContainer = "container:Note.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildableProductRunnable>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
<BuildableProductRunnable
|
||||||
|
runnableDebuggingMode = "0">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "CFD40B0F3003C283009C9F2A"
|
||||||
|
BuildableName = "Note.app"
|
||||||
|
BlueprintName = "Note"
|
||||||
|
ReferencedContainer = "container:Note.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildableProductRunnable>
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "2630"
|
||||||
|
wasCreatedForAppExtension = "YES"
|
||||||
|
version = "2.0">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES"
|
||||||
|
buildArchitectures = "Automatic">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "CFD40B293003C283009C9F2A"
|
||||||
|
BuildableName = "NoteShareExtension.appex"
|
||||||
|
BlueprintName = "NoteShareExtension"
|
||||||
|
ReferencedContainer = "container:Note.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "CFD40B0F3003C283009C9F2A"
|
||||||
|
BuildableName = "Note.app"
|
||||||
|
BlueprintName = "Note"
|
||||||
|
ReferencedContainer = "container:Note.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 = ""
|
||||||
|
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
|
||||||
|
launchStyle = "0"
|
||||||
|
askForAppToLaunch = "Yes"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES"
|
||||||
|
launchAutomaticallySubstyle = "2">
|
||||||
|
<BuildableProductRunnable
|
||||||
|
runnableDebuggingMode = "0">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "CFD40B0F3003C283009C9F2A"
|
||||||
|
BuildableName = "Note.app"
|
||||||
|
BlueprintName = "Note"
|
||||||
|
ReferencedContainer = "container:Note.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildableProductRunnable>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
askForAppToLaunch = "Yes"
|
||||||
|
launchAutomaticallySubstyle = "2">
|
||||||
|
<BuildableProductRunnable
|
||||||
|
runnableDebuggingMode = "0">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "CFD40B0F3003C283009C9F2A"
|
||||||
|
BuildableName = "Note.app"
|
||||||
|
BlueprintName = "Note"
|
||||||
|
ReferencedContainer = "container:Note.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildableProductRunnable>
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
//
|
||||||
|
// ClipEditViewController.swift
|
||||||
|
// Note
|
||||||
|
//
|
||||||
|
// Created by Kimi Code CLI on 2026/7/15.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
class ClipEditViewController: UIViewController {
|
||||||
|
|
||||||
|
private var textView: UITextView!
|
||||||
|
private var floatingDoneButton: UIButton!
|
||||||
|
private var floatingDoneButtonBottomConstraint: NSLayoutConstraint!
|
||||||
|
private var clip: Clip
|
||||||
|
|
||||||
|
init(clip: Clip) {
|
||||||
|
self.clip = clip
|
||||||
|
super.init(nibName: nil, bundle: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewDidLoad() {
|
||||||
|
super.viewDidLoad()
|
||||||
|
title = "编辑文案"
|
||||||
|
navigationItem.largeTitleDisplayMode = .never
|
||||||
|
view.backgroundColor = .systemGroupedBackground
|
||||||
|
|
||||||
|
setupNavigationBar()
|
||||||
|
setupTextView()
|
||||||
|
setupKeyboardObservers()
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
NotificationCenter.default.removeObserver(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setupKeyboardObservers() {
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
|
||||||
|
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func keyboardWillShow(_ notification: Notification) {
|
||||||
|
guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
|
||||||
|
let keyboardFrameInView = view.convert(keyboardFrame, from: nil)
|
||||||
|
let intersection = keyboardFrameInView.intersection(view.bounds)
|
||||||
|
let keyboardHeight = intersection.height
|
||||||
|
|
||||||
|
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0.25
|
||||||
|
|
||||||
|
UIView.animate(withDuration: duration, delay: 0, options: .beginFromCurrentState) {
|
||||||
|
self.textView.contentInset.bottom = keyboardHeight
|
||||||
|
self.textView.verticalScrollIndicatorInsets.bottom = keyboardHeight
|
||||||
|
self.floatingDoneButtonBottomConstraint.constant = -(keyboardHeight + 8)
|
||||||
|
self.floatingDoneButton.alpha = 1
|
||||||
|
self.view.layoutIfNeeded()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func keyboardWillHide(_ notification: Notification) {
|
||||||
|
let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval ?? 0.25
|
||||||
|
|
||||||
|
UIView.animate(withDuration: duration, delay: 0, options: .beginFromCurrentState) {
|
||||||
|
self.textView.contentInset.bottom = 0
|
||||||
|
self.textView.verticalScrollIndicatorInsets.bottom = 0
|
||||||
|
self.floatingDoneButtonBottomConstraint.constant = -16
|
||||||
|
self.floatingDoneButton.alpha = 0
|
||||||
|
self.view.layoutIfNeeded()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewDidAppear(_ animated: Bool) {
|
||||||
|
super.viewDidAppear(animated)
|
||||||
|
textView.becomeFirstResponder()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setupNavigationBar() {
|
||||||
|
let saveButton = UIBarButtonItem(
|
||||||
|
title: "保存",
|
||||||
|
style: .prominent,
|
||||||
|
target: self,
|
||||||
|
action: #selector(didTapSaveButton)
|
||||||
|
)
|
||||||
|
navigationItem.rightBarButtonItem = saveButton
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setupTextView() {
|
||||||
|
textView = UITextView()
|
||||||
|
textView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
textView.backgroundColor = UIColor { traitCollection in
|
||||||
|
traitCollection.userInterfaceStyle == .dark ? .secondarySystemBackground : .white
|
||||||
|
}
|
||||||
|
textView.layer.cornerRadius = 12
|
||||||
|
textView.layer.borderWidth = 0.5
|
||||||
|
textView.layer.borderColor = UIColor.separator.cgColor
|
||||||
|
textView.layer.masksToBounds = true
|
||||||
|
textView.font = UIFont.preferredFont(forTextStyle: .body)
|
||||||
|
textView.textContainerInset = UIEdgeInsets(top: 12, left: 12, bottom: 12, right: 12)
|
||||||
|
textView.text = clip.text
|
||||||
|
view.addSubview(textView)
|
||||||
|
|
||||||
|
var doneConfig = UIButton.Configuration.glass()
|
||||||
|
doneConfig.title = "完成"
|
||||||
|
doneConfig.titleTextAttributesTransformer = UIConfigurationTextAttributesTransformer { incoming in
|
||||||
|
var outgoing = incoming
|
||||||
|
outgoing.font = UIFont.systemFont(ofSize: 17, weight: .semibold)
|
||||||
|
return outgoing
|
||||||
|
}
|
||||||
|
doneConfig.baseForegroundColor = .label
|
||||||
|
doneConfig.cornerStyle = .capsule
|
||||||
|
doneConfig.contentInsets = NSDirectionalEdgeInsets(top: 15, leading: 22, bottom: 15, trailing: 22)
|
||||||
|
floatingDoneButton = UIButton(configuration: doneConfig)
|
||||||
|
floatingDoneButton.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
floatingDoneButton.alpha = 0
|
||||||
|
floatingDoneButton.addTarget(self, action: #selector(didTapFloatingDoneButton), for: .touchUpInside)
|
||||||
|
view.addSubview(floatingDoneButton)
|
||||||
|
|
||||||
|
let safeArea = view.safeAreaLayoutGuide
|
||||||
|
floatingDoneButtonBottomConstraint = floatingDoneButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -16)
|
||||||
|
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
textView.topAnchor.constraint(equalTo: safeArea.topAnchor, constant: 16),
|
||||||
|
textView.leadingAnchor.constraint(equalTo: safeArea.leadingAnchor, constant: 16),
|
||||||
|
textView.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -16),
|
||||||
|
textView.bottomAnchor.constraint(equalTo: safeArea.bottomAnchor, constant: -16),
|
||||||
|
|
||||||
|
floatingDoneButton.trailingAnchor.constraint(equalTo: safeArea.trailingAnchor, constant: -16),
|
||||||
|
floatingDoneButtonBottomConstraint
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func didTapFloatingDoneButton() {
|
||||||
|
textView.resignFirstResponder()
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func didTapSaveButton() {
|
||||||
|
let updatedText = textView.text ?? ""
|
||||||
|
guard !updatedText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else {
|
||||||
|
let alert = UIAlertController(title: "提示", message: "文案不能为空。", preferredStyle: .alert)
|
||||||
|
alert.addAction(UIAlertAction(title: "确定", style: .default))
|
||||||
|
present(alert, animated: true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var updatedClip = clip
|
||||||
|
updatedClip.text = updatedText
|
||||||
|
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
try await ClipStore.shared.update(updatedClip)
|
||||||
|
_ = await MainActor.run {
|
||||||
|
self.navigationController?.popViewController(animated: true)
|
||||||
|
return ()
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
await MainActor.run {
|
||||||
|
let alert = UIAlertController(title: "提示", message: "保存失败: \(error.localizedDescription)", preferredStyle: .alert)
|
||||||
|
alert.addAction(UIAlertAction(title: "确定", style: .default))
|
||||||
|
self.present(alert, animated: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,290 @@
|
|||||||
|
//
|
||||||
|
// ClipInboxViewController.swift
|
||||||
|
// Note
|
||||||
|
//
|
||||||
|
// Created by Kimi Code CLI on 2026/7/15.
|
||||||
|
//
|
||||||
|
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
class ClipInboxViewController: UIViewController {
|
||||||
|
|
||||||
|
private var tableView: UITableView!
|
||||||
|
private var emptyLabel: UILabel!
|
||||||
|
private var archiveButton: UIButton!
|
||||||
|
private var clips: [Clip] = []
|
||||||
|
|
||||||
|
override func viewDidLoad() {
|
||||||
|
super.viewDidLoad()
|
||||||
|
title = "收集箱"
|
||||||
|
navigationItem.largeTitleDisplayMode = .never
|
||||||
|
view.backgroundColor = .systemGroupedBackground
|
||||||
|
|
||||||
|
setupNavigationBar()
|
||||||
|
setupArchiveButton()
|
||||||
|
setupTableView()
|
||||||
|
setupEmptyLabel()
|
||||||
|
setupAppStateObserver()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
super.viewWillAppear(animated)
|
||||||
|
loadClips()
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
NotificationCenter.default.removeObserver(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setupAppStateObserver() {
|
||||||
|
NotificationCenter.default.addObserver(
|
||||||
|
self,
|
||||||
|
selector: #selector(appDidBecomeActive),
|
||||||
|
name: UIApplication.didBecomeActiveNotification,
|
||||||
|
object: nil
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func appDidBecomeActive() {
|
||||||
|
loadClips()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setupNavigationBar() {
|
||||||
|
let clearButton = UIBarButtonItem(
|
||||||
|
title: "清空",
|
||||||
|
style: .plain,
|
||||||
|
target: self,
|
||||||
|
action: #selector(didTapClearButton)
|
||||||
|
)
|
||||||
|
clearButton.tintColor = .systemRed
|
||||||
|
navigationItem.rightBarButtonItem = clearButton
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setupTableView() {
|
||||||
|
tableView = UITableView(frame: .zero, style: .insetGrouped)
|
||||||
|
tableView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
tableView.delegate = self
|
||||||
|
tableView.dataSource = self
|
||||||
|
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "clipCell")
|
||||||
|
tableView.backgroundColor = .systemGroupedBackground
|
||||||
|
view.addSubview(tableView)
|
||||||
|
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
tableView.topAnchor.constraint(equalTo: view.topAnchor),
|
||||||
|
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||||
|
tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||||
|
tableView.bottomAnchor.constraint(equalTo: archiveButton.topAnchor, constant: -16)
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setupArchiveButton() {
|
||||||
|
var config = UIButton.Configuration.filled()
|
||||||
|
config.title = "归档"
|
||||||
|
config.baseBackgroundColor = .systemBlue
|
||||||
|
config.baseForegroundColor = .white
|
||||||
|
config.cornerStyle = .medium
|
||||||
|
config.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16)
|
||||||
|
|
||||||
|
archiveButton = UIButton(configuration: config)
|
||||||
|
archiveButton.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
archiveButton.addTarget(self, action: #selector(didTapArchiveButton), for: .touchUpInside)
|
||||||
|
view.addSubview(archiveButton)
|
||||||
|
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
archiveButton.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 16),
|
||||||
|
archiveButton.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -16),
|
||||||
|
archiveButton.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -16),
|
||||||
|
archiveButton.heightAnchor.constraint(equalToConstant: 52)
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func didTapArchiveButton() {
|
||||||
|
guard clips.count >= 2 else {
|
||||||
|
let alert = UIAlertController(title: "提示", message: "至少需要两条文案才能归档。", preferredStyle: .alert)
|
||||||
|
alert.addAction(UIAlertAction(title: "确定", style: .default))
|
||||||
|
present(alert, animated: true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let title = self.archiveTitle()
|
||||||
|
let itemsText = clips.map { "\($0.text)\n\n---" }.joined(separator: "\n\n")
|
||||||
|
let archivedText = "\(title)\n\n\(itemsText)"
|
||||||
|
let viewController = FormatNoteViewController()
|
||||||
|
viewController.initialText = archivedText
|
||||||
|
navigationController?.pushViewController(viewController, animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func archiveTitle() -> String {
|
||||||
|
let dateFormatter = DateFormatter()
|
||||||
|
dateFormatter.locale = Locale(identifier: "zh_CN")
|
||||||
|
dateFormatter.dateFormat = "yyyy年MM月dd日"
|
||||||
|
let dateString = dateFormatter.string(from: Date())
|
||||||
|
let weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"]
|
||||||
|
let weekdayIndex = Calendar.current.component(.weekday, from: Date()) - 1
|
||||||
|
let weekday = (weekdayIndex >= 0 && weekdayIndex < weekdays.count) ? weekdays[weekdayIndex] : ""
|
||||||
|
return "【读书摘抄】\(dateString) \(weekday)"
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setupEmptyLabel() {
|
||||||
|
emptyLabel = UILabel()
|
||||||
|
emptyLabel.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
emptyLabel.text = "还没有保存的文案\n复制内容后运行快捷指令即可收藏"
|
||||||
|
emptyLabel.numberOfLines = 0
|
||||||
|
emptyLabel.textAlignment = .center
|
||||||
|
emptyLabel.textColor = .secondaryLabel
|
||||||
|
emptyLabel.font = UIFont.preferredFont(forTextStyle: .body)
|
||||||
|
emptyLabel.isHidden = true
|
||||||
|
view.addSubview(emptyLabel)
|
||||||
|
|
||||||
|
NSLayoutConstraint.activate([
|
||||||
|
emptyLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
||||||
|
emptyLabel.centerYAnchor.constraint(equalTo: view.centerYAnchor),
|
||||||
|
emptyLabel.leadingAnchor.constraint(equalTo: view.readableContentGuide.leadingAnchor),
|
||||||
|
emptyLabel.trailingAnchor.constraint(equalTo: view.readableContentGuide.trailingAnchor)
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
private func loadClips() {
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
clips = try await ClipStore.shared.loadAll()
|
||||||
|
await MainActor.run {
|
||||||
|
tableView.reloadData()
|
||||||
|
updateEmptyState()
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
await MainActor.run {
|
||||||
|
showError(message: "加载失败: \(error.localizedDescription)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateEmptyState() {
|
||||||
|
let isEmpty = clips.isEmpty
|
||||||
|
emptyLabel.isHidden = !isEmpty
|
||||||
|
tableView.isHidden = isEmpty
|
||||||
|
archiveButton.isHidden = isEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func didTapClearButton() {
|
||||||
|
guard !clips.isEmpty else {
|
||||||
|
let alert = UIAlertController(title: "提示", message: "收集箱为空,没有可清空的内容。", preferredStyle: .alert)
|
||||||
|
alert.addAction(UIAlertAction(title: "确定", style: .default))
|
||||||
|
present(alert, animated: true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let alert = UIAlertController(
|
||||||
|
title: "清空收集箱",
|
||||||
|
message: "确定要删除所有保存的文案吗?此操作不可撤销。",
|
||||||
|
preferredStyle: .alert
|
||||||
|
)
|
||||||
|
alert.addAction(UIAlertAction(title: "取消", style: .cancel))
|
||||||
|
alert.addAction(UIAlertAction(title: "清空", style: .destructive) { [weak self] _ in
|
||||||
|
self?.clearAllClips()
|
||||||
|
})
|
||||||
|
present(alert, animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func clearAllClips() {
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
try await ClipStore.shared.clearAll()
|
||||||
|
clips = []
|
||||||
|
await MainActor.run {
|
||||||
|
tableView.reloadData()
|
||||||
|
updateEmptyState()
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
await MainActor.run {
|
||||||
|
showError(message: "清空失败: \(error.localizedDescription)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func deleteClip(at indexPath: IndexPath) {
|
||||||
|
let clip = clips[indexPath.row]
|
||||||
|
Task {
|
||||||
|
do {
|
||||||
|
try await ClipStore.shared.delete(id: clip.id)
|
||||||
|
clips.remove(at: indexPath.row)
|
||||||
|
await MainActor.run {
|
||||||
|
tableView.deleteRows(at: [indexPath], with: .automatic)
|
||||||
|
updateEmptyState()
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
await MainActor.run {
|
||||||
|
showError(message: "删除失败: \(error.localizedDescription)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func openClip(_ clip: Clip) {
|
||||||
|
let viewController = ClipEditViewController(clip: clip)
|
||||||
|
navigationController?.pushViewController(viewController, animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func showError(message: String) {
|
||||||
|
let alert = UIAlertController(title: "提示", message: message, preferredStyle: .alert)
|
||||||
|
alert.addAction(UIAlertAction(title: "确定", style: .default))
|
||||||
|
present(alert, animated: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ClipInboxViewController: UITableViewDataSource {
|
||||||
|
|
||||||
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||||
|
return clips.count
|
||||||
|
}
|
||||||
|
|
||||||
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
let cell = tableView.dequeueReusableCell(withIdentifier: "clipCell", for: indexPath)
|
||||||
|
let clip = clips[indexPath.row]
|
||||||
|
|
||||||
|
var config = cell.defaultContentConfiguration()
|
||||||
|
config.text = previewText(for: clip.text)
|
||||||
|
config.textProperties.numberOfLines = 0
|
||||||
|
config.secondaryText = formattedDate(clip.createdAt)
|
||||||
|
config.secondaryTextProperties.color = .secondaryLabel
|
||||||
|
config.textToSecondaryTextVerticalPadding = 12
|
||||||
|
cell.contentConfiguration = config
|
||||||
|
cell.accessoryType = .disclosureIndicator
|
||||||
|
|
||||||
|
return cell
|
||||||
|
}
|
||||||
|
|
||||||
|
private func previewText(for text: String) -> String {
|
||||||
|
let preview = text.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
if preview.isEmpty {
|
||||||
|
return "(无内容)"
|
||||||
|
}
|
||||||
|
return preview
|
||||||
|
}
|
||||||
|
|
||||||
|
private func formattedDate(_ date: Date) -> String {
|
||||||
|
let formatter = RelativeDateTimeFormatter()
|
||||||
|
formatter.unitsStyle = .short
|
||||||
|
return formatter.localizedString(for: date, relativeTo: Date())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ClipInboxViewController: UITableViewDelegate {
|
||||||
|
|
||||||
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
|
tableView.deselectRow(at: indexPath, animated: true)
|
||||||
|
let clip = clips[indexPath.row]
|
||||||
|
openClip(clip)
|
||||||
|
}
|
||||||
|
|
||||||
|
func tableView(_ tableView: UITableView,
|
||||||
|
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
||||||
|
let deleteAction = UIContextualAction(style: .destructive, title: "删除") { [weak self] _, _, completion in
|
||||||
|
self?.deleteClip(at: indexPath)
|
||||||
|
completion(true)
|
||||||
|
}
|
||||||
|
return UISwipeActionsConfiguration(actions: [deleteAction])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
//
|
||||||
|
// ClipStore.swift
|
||||||
|
// Note
|
||||||
|
//
|
||||||
|
// Created by Kimi Code CLI on 2026/7/15.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
struct Clip: Codable, Identifiable, Equatable, Sendable {
|
||||||
|
let id: UUID
|
||||||
|
var text: String
|
||||||
|
let createdAt: Date
|
||||||
|
var source: String?
|
||||||
|
|
||||||
|
nonisolated init(id: UUID = UUID(), text: String, createdAt: Date = Date(), source: String? = nil) {
|
||||||
|
self.id = id
|
||||||
|
self.text = text
|
||||||
|
self.createdAt = createdAt
|
||||||
|
self.source = source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ClipStoreError: Error, LocalizedError {
|
||||||
|
case appGroupUnavailable
|
||||||
|
|
||||||
|
var errorDescription: String? {
|
||||||
|
switch self {
|
||||||
|
case .appGroupUnavailable:
|
||||||
|
return "无法访问 App Group 容器,请检查签名和 entitlements 配置。"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
actor ClipStore {
|
||||||
|
|
||||||
|
static let shared = ClipStore()
|
||||||
|
|
||||||
|
private let appGroupIdentifier = "group.com.fishestlife.note"
|
||||||
|
private let fileName = "clips.json"
|
||||||
|
private let subdirectory = "SharedFiles/Clips"
|
||||||
|
|
||||||
|
private var cachedClips: [Clip]?
|
||||||
|
|
||||||
|
private func fileURL() throws -> URL {
|
||||||
|
let fileManager = FileManager.default
|
||||||
|
guard let containerURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier) else {
|
||||||
|
throw ClipStoreError.appGroupUnavailable
|
||||||
|
}
|
||||||
|
let directoryURL = containerURL.appendingPathComponent(subdirectory, isDirectory: true)
|
||||||
|
try fileManager.createDirectory(at: directoryURL, withIntermediateDirectories: true)
|
||||||
|
return directoryURL.appendingPathComponent(fileName)
|
||||||
|
}
|
||||||
|
|
||||||
|
private init() {}
|
||||||
|
|
||||||
|
func save(text: String, source: String? = nil) async throws {
|
||||||
|
var clips = try await loadAll()
|
||||||
|
let clip = Clip(text: text, source: source)
|
||||||
|
clips.insert(clip, at: 0)
|
||||||
|
try await persist(clips)
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadAll() async throws -> [Clip] {
|
||||||
|
if let cached = cachedClips {
|
||||||
|
return cached
|
||||||
|
}
|
||||||
|
|
||||||
|
let url = try fileURL()
|
||||||
|
let fileManager = FileManager.default
|
||||||
|
guard fileManager.fileExists(atPath: url.path) else {
|
||||||
|
cachedClips = []
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = try Data(contentsOf: url)
|
||||||
|
let clips = try JSONDecoder().decode([Clip].self, from: data)
|
||||||
|
cachedClips = clips
|
||||||
|
return clips
|
||||||
|
}
|
||||||
|
|
||||||
|
func update(_ clip: Clip) async throws {
|
||||||
|
var clips = try await loadAll()
|
||||||
|
guard let index = clips.firstIndex(where: { $0.id == clip.id }) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clips[index] = clip
|
||||||
|
try await persist(clips)
|
||||||
|
}
|
||||||
|
|
||||||
|
func delete(id: UUID) async throws {
|
||||||
|
var clips = try await loadAll()
|
||||||
|
clips.removeAll { $0.id == id }
|
||||||
|
try await persist(clips)
|
||||||
|
}
|
||||||
|
|
||||||
|
func clearAll() async throws {
|
||||||
|
try await persist([])
|
||||||
|
}
|
||||||
|
|
||||||
|
func count() async throws -> Int {
|
||||||
|
let clips = try await loadAll()
|
||||||
|
return clips.count
|
||||||
|
}
|
||||||
|
|
||||||
|
private func persist(_ clips: [Clip]) async throws {
|
||||||
|
let url = try fileURL()
|
||||||
|
let data = try JSONEncoder().encode(clips)
|
||||||
|
try data.write(to: url, options: .atomic)
|
||||||
|
cachedClips = clips
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -184,6 +184,19 @@ class FormatLogViewController: UIViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc private func didTapResetButton() {
|
@objc private func didTapResetButton() {
|
||||||
|
let alert = UIAlertController(
|
||||||
|
title: "确认重置",
|
||||||
|
message: "确定要清空当前内容吗?",
|
||||||
|
preferredStyle: .alert
|
||||||
|
)
|
||||||
|
alert.addAction(UIAlertAction(title: "取消", style: .cancel))
|
||||||
|
alert.addAction(UIAlertAction(title: "重置", style: .destructive) { [weak self] _ in
|
||||||
|
self?.performReset()
|
||||||
|
})
|
||||||
|
present(alert, animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func performReset() {
|
||||||
textView.text = ""
|
textView.text = ""
|
||||||
isFormatted = false
|
isFormatted = false
|
||||||
formatButton.setTitle("格式化", for: .normal)
|
formatButton.setTitle("格式化", for: .normal)
|
||||||
|
|||||||
@@ -35,10 +35,6 @@ class FormatNoteViewController: UIViewController {
|
|||||||
setupUI()
|
setupUI()
|
||||||
if let initialText = initialText {
|
if let initialText = initialText {
|
||||||
textView.text = initialText
|
textView.text = initialText
|
||||||
isNoteFormatted = true
|
|
||||||
noteButton.setTitle("复制并打开备忘录", for: .normal)
|
|
||||||
rightBarButtonMode = .reset
|
|
||||||
updateRightBarButtonItem()
|
|
||||||
}
|
}
|
||||||
setupKeyboardObservers()
|
setupKeyboardObservers()
|
||||||
}
|
}
|
||||||
@@ -192,6 +188,19 @@ class FormatNoteViewController: UIViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc private func didTapResetButton() {
|
@objc private func didTapResetButton() {
|
||||||
|
let alert = UIAlertController(
|
||||||
|
title: "确认重置",
|
||||||
|
message: "确定要清空当前内容吗?",
|
||||||
|
preferredStyle: .alert
|
||||||
|
)
|
||||||
|
alert.addAction(UIAlertAction(title: "取消", style: .cancel))
|
||||||
|
alert.addAction(UIAlertAction(title: "重置", style: .destructive) { [weak self] _ in
|
||||||
|
self?.performReset()
|
||||||
|
})
|
||||||
|
present(alert, animated: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func performReset() {
|
||||||
textView.text = ""
|
textView.text = ""
|
||||||
rightBarButtonMode = .paste
|
rightBarButtonMode = .paste
|
||||||
isCloudFormatted = false
|
isCloudFormatted = false
|
||||||
|
|||||||
+125
-4
@@ -8,6 +8,18 @@
|
|||||||
<array>
|
<array>
|
||||||
<string>mobilenotes</string>
|
<string>mobilenotes</string>
|
||||||
<string>shareddocuments</string>
|
<string>shareddocuments</string>
|
||||||
|
<string>noteapp</string>
|
||||||
|
</array>
|
||||||
|
<key>CFBundleURLTypes</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleURLName</key>
|
||||||
|
<string>com.fishestlife.note</string>
|
||||||
|
<key>CFBundleURLSchemes</key>
|
||||||
|
<array>
|
||||||
|
<string>noteapp</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleDocumentTypes</key>
|
<key>CFBundleDocumentTypes</key>
|
||||||
<array>
|
<array>
|
||||||
@@ -15,25 +27,135 @@
|
|||||||
<key>CFBundleTypeName</key>
|
<key>CFBundleTypeName</key>
|
||||||
<string>Markdown File</string>
|
<string>Markdown File</string>
|
||||||
<key>CFBundleTypeRole</key>
|
<key>CFBundleTypeRole</key>
|
||||||
|
<string>Editor</string>
|
||||||
|
<key>LSHandlerRank</key>
|
||||||
|
<string>Owner</string>
|
||||||
|
<key>LSItemContentTypes</key>
|
||||||
|
<array>
|
||||||
|
<string>net.daringfireball.markdown</string>
|
||||||
|
<string>public.markdown</string>
|
||||||
|
<string>public.text</string>
|
||||||
|
<string>public.plain-text</string>
|
||||||
|
<string>public.utf8-plain-text</string>
|
||||||
|
</array>
|
||||||
|
<key>CFBundleTypeExtensions</key>
|
||||||
|
<array>
|
||||||
|
<string>md</string>
|
||||||
|
<string>markdown</string>
|
||||||
|
<string>mdown</string>
|
||||||
|
<string>mkd</string>
|
||||||
|
<string>mkdn</string>
|
||||||
|
</array>
|
||||||
|
<key>CFBundleTypeMIMETypes</key>
|
||||||
|
<array>
|
||||||
|
<string>text/markdown</string>
|
||||||
|
<string>text/x-markdown</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleTypeName</key>
|
||||||
|
<string>Plain Text File</string>
|
||||||
|
<key>CFBundleTypeRole</key>
|
||||||
|
<string>Editor</string>
|
||||||
|
<key>LSHandlerRank</key>
|
||||||
|
<string>Alternate</string>
|
||||||
|
<key>LSItemContentTypes</key>
|
||||||
|
<array>
|
||||||
|
<string>public.plain-text</string>
|
||||||
|
<string>public.utf8-plain-text</string>
|
||||||
|
<string>public.text</string>
|
||||||
|
</array>
|
||||||
|
<key>CFBundleTypeExtensions</key>
|
||||||
|
<array>
|
||||||
|
<string>txt</string>
|
||||||
|
<string>text</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleTypeName</key>
|
||||||
|
<string>Any Text or Data File</string>
|
||||||
|
<key>CFBundleTypeRole</key>
|
||||||
<string>Viewer</string>
|
<string>Viewer</string>
|
||||||
<key>LSHandlerRank</key>
|
<key>LSHandlerRank</key>
|
||||||
<string>Alternate</string>
|
<string>Alternate</string>
|
||||||
<key>LSItemContentTypes</key>
|
<key>LSItemContentTypes</key>
|
||||||
<array>
|
<array>
|
||||||
<string>net.daringfireball.markdown</string>
|
|
||||||
<string>public.plain-text</string>
|
|
||||||
<string>public.data</string>
|
<string>public.data</string>
|
||||||
|
<string>public.content</string>
|
||||||
|
<string>public.item</string>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleTypeExtensions</key>
|
<key>CFBundleTypeExtensions</key>
|
||||||
<array>
|
<array>
|
||||||
<string>md</string>
|
<string>md</string>
|
||||||
<string>markdown</string>
|
<string>markdown</string>
|
||||||
<string>txt</string>
|
<string>txt</string>
|
||||||
|
<string>*</string>
|
||||||
</array>
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>LSSupportsOpeningDocumentsInPlace</key>
|
<key>LSSupportsOpeningDocumentsInPlace</key>
|
||||||
<false/>
|
<true/>
|
||||||
|
<key>UTExportedTypeDeclarations</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>UTTypeConformsTo</key>
|
||||||
|
<array>
|
||||||
|
<string>public.text</string>
|
||||||
|
<string>public.plain-text</string>
|
||||||
|
</array>
|
||||||
|
<key>UTTypeDescription</key>
|
||||||
|
<string>Markdown File</string>
|
||||||
|
<key>UTTypeIdentifier</key>
|
||||||
|
<string>net.daringfireball.markdown</string>
|
||||||
|
<key>UTTypeTagSpecification</key>
|
||||||
|
<dict>
|
||||||
|
<key>public.filename-extension</key>
|
||||||
|
<array>
|
||||||
|
<string>md</string>
|
||||||
|
<string>markdown</string>
|
||||||
|
<string>mdown</string>
|
||||||
|
<string>mkd</string>
|
||||||
|
<string>mkdn</string>
|
||||||
|
</array>
|
||||||
|
<key>public.mime-type</key>
|
||||||
|
<array>
|
||||||
|
<string>text/markdown</string>
|
||||||
|
<string>text/x-markdown</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
|
<key>UTImportedTypeDeclarations</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>UTTypeConformsTo</key>
|
||||||
|
<array>
|
||||||
|
<string>public.text</string>
|
||||||
|
<string>public.plain-text</string>
|
||||||
|
<string>public.data</string>
|
||||||
|
</array>
|
||||||
|
<key>UTTypeDescription</key>
|
||||||
|
<string>Markdown File</string>
|
||||||
|
<key>UTTypeIdentifier</key>
|
||||||
|
<string>net.daringfireball.markdown</string>
|
||||||
|
<key>UTTypeTagSpecification</key>
|
||||||
|
<dict>
|
||||||
|
<key>public.filename-extension</key>
|
||||||
|
<array>
|
||||||
|
<string>md</string>
|
||||||
|
<string>markdown</string>
|
||||||
|
<string>mdown</string>
|
||||||
|
<string>mkd</string>
|
||||||
|
<string>mkdn</string>
|
||||||
|
</array>
|
||||||
|
<key>public.mime-type</key>
|
||||||
|
<array>
|
||||||
|
<string>text/markdown</string>
|
||||||
|
<string>text/x-markdown</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
<key>UIApplicationSceneManifest</key>
|
<key>UIApplicationSceneManifest</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>UIApplicationSupportsMultipleScenes</key>
|
<key>UIApplicationSupportsMultipleScenes</key>
|
||||||
@@ -47,7 +169,6 @@
|
|||||||
<string>Default Configuration</string>
|
<string>Default Configuration</string>
|
||||||
<key>UISceneDelegateClassName</key>
|
<key>UISceneDelegateClassName</key>
|
||||||
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
|
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
|
||||||
|
|
||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>com.apple.security.application-groups</key>
|
||||||
|
<array>
|
||||||
|
<string>group.com.fishestlife.note</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
//
|
||||||
|
// NoteAppShortcuts.swift
|
||||||
|
// Note
|
||||||
|
//
|
||||||
|
// Created by Kimi Code CLI on 2026/7/15.
|
||||||
|
//
|
||||||
|
|
||||||
|
import AppIntents
|
||||||
|
|
||||||
|
struct NoteAppShortcuts: AppShortcutsProvider {
|
||||||
|
|
||||||
|
static var appShortcuts: [AppShortcut] {
|
||||||
|
AppShortcut(
|
||||||
|
intent: SaveClipIntent(),
|
||||||
|
phrases: ["保存剪贴板到 ${applicationName}"],
|
||||||
|
shortTitle: "保存剪贴板",
|
||||||
|
systemImageName: "doc.text"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
//
|
||||||
|
// SaveClipIntent.swift
|
||||||
|
// Note
|
||||||
|
//
|
||||||
|
// Created by Kimi Code CLI on 2026/7/15.
|
||||||
|
//
|
||||||
|
|
||||||
|
import AppIntents
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
struct SaveClipIntent: AppIntent {
|
||||||
|
|
||||||
|
static var title: LocalizedStringResource = "保存剪贴板到 Note"
|
||||||
|
static var description: IntentDescription? = "将一段文本保存到 Note App 的收集箱,稍后统一处理。"
|
||||||
|
|
||||||
|
@Parameter(title: "文案", description: "要保存的文本内容", default: "")
|
||||||
|
var text: String
|
||||||
|
|
||||||
|
@Parameter(title: "来源", description: "文案来源,例如应用名称", default: "快捷指令")
|
||||||
|
var source: String?
|
||||||
|
|
||||||
|
init() {}
|
||||||
|
|
||||||
|
init(text: String, source: String? = nil) {
|
||||||
|
self.text = text
|
||||||
|
self.source = source
|
||||||
|
}
|
||||||
|
|
||||||
|
func perform() async throws -> some IntentResult & ReturnsValue<String> {
|
||||||
|
var inputText = text
|
||||||
|
if inputText.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
||||||
|
inputText = await MainActor.run {
|
||||||
|
UIPasteboard.general.string ?? ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let trimmed = inputText.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
|
guard !trimmed.isEmpty else {
|
||||||
|
return .result(value: "文案为空,未保存。")
|
||||||
|
}
|
||||||
|
|
||||||
|
guard !isSystemClipboardPlaceholder(trimmed) else {
|
||||||
|
return .result(value: "剪贴板没有有效文本,未保存。")
|
||||||
|
}
|
||||||
|
|
||||||
|
let formattedText = TextFormatter.formatForShortcut(trimmed)
|
||||||
|
try await ClipStore.shared.save(text: formattedText, source: source)
|
||||||
|
return .result(value: "已保存到收集箱。")
|
||||||
|
}
|
||||||
|
|
||||||
|
private func isSystemClipboardPlaceholder(_ text: String) -> Bool {
|
||||||
|
let lowercased = text.lowercased()
|
||||||
|
if lowercased.hasPrefix("clipboard ") && lowercased.contains(" at ") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if text == "获取剪贴板" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,11 +60,17 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func handleSharedFile(_ url: URL) {
|
private func handleSharedFile(_ url: URL) {
|
||||||
guard url.isFileURL,
|
guard let navigationController = window?.rootViewController as? UINavigationController else {
|
||||||
let navigationController = window?.rootViewController as? UINavigationController else {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if url.scheme == "noteapp", url.host == "share" {
|
||||||
|
handleShareURL(url, navigationController: navigationController)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
guard url.isFileURL else { return }
|
||||||
|
|
||||||
let shouldStopAccessing = url.startAccessingSecurityScopedResource()
|
let shouldStopAccessing = url.startAccessingSecurityScopedResource()
|
||||||
defer {
|
defer {
|
||||||
if shouldStopAccessing {
|
if shouldStopAccessing {
|
||||||
@@ -86,6 +92,40 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func handleShareURL(_ url: URL, navigationController: UINavigationController) {
|
||||||
|
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
|
||||||
|
let queryItems = components.queryItems else { return }
|
||||||
|
|
||||||
|
let fileManager = FileManager.default
|
||||||
|
let containerURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "group.com.fishestlife.note")
|
||||||
|
let sharedDir = containerURL?.appendingPathComponent("SharedFiles", isDirectory: true)
|
||||||
|
|
||||||
|
var contents: [(text: String, fileName: String)] = []
|
||||||
|
|
||||||
|
for item in queryItems {
|
||||||
|
if item.name.hasPrefix("text"), let text = item.value, !text.isEmpty {
|
||||||
|
contents.append((text: text, fileName: "shared.md"))
|
||||||
|
} else if item.name.hasPrefix("file"), let fileName = item.value, !fileName.isEmpty {
|
||||||
|
if let sharedDir = sharedDir {
|
||||||
|
let fileURL = sharedDir.appendingPathComponent(fileName)
|
||||||
|
if let text = try? String(contentsOf: fileURL, encoding: .utf8) {
|
||||||
|
contents.append((text: text, fileName: fileName))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
guard let first = contents.first else { return }
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
let viewController = PreviewViewController()
|
||||||
|
viewController.initialText = first.text
|
||||||
|
viewController.fileName = first.fileName
|
||||||
|
viewController.title = first.fileName
|
||||||
|
navigationController.pushViewController(viewController, animated: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import Foundation
|
|||||||
|
|
||||||
enum TextFormatter {
|
enum TextFormatter {
|
||||||
|
|
||||||
static func formatLog(_ text: String) -> String {
|
static nonisolated func formatLog(_ text: String) -> String {
|
||||||
var content = text
|
var content = text
|
||||||
|
|
||||||
content = content.replacingOccurrences(of: "# ", with: "")
|
content = content.replacingOccurrences(of: "# ", with: "")
|
||||||
@@ -31,7 +31,14 @@ enum TextFormatter {
|
|||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
static func formatForCloud(_ text: String) -> String {
|
static nonisolated func formatForCloud(_ text: String) -> String {
|
||||||
|
var content = formatForShortcut(text)
|
||||||
|
content = "# " + content
|
||||||
|
content = insertEmptyLineAfterFirstLine(content)
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
|
static nonisolated func formatForShortcut(_ text: String) -> String {
|
||||||
var content = text
|
var content = text
|
||||||
content = content.replacingOccurrences(of: " ", with: "")
|
content = content.replacingOccurrences(of: " ", with: "")
|
||||||
content = content.replacingOccurrences(of: " ", with: "")
|
content = content.replacingOccurrences(of: " ", with: "")
|
||||||
@@ -71,12 +78,10 @@ enum TextFormatter {
|
|||||||
content = content.replacingOccurrences(of: " ", with: "")
|
content = content.replacingOccurrences(of: " ", with: "")
|
||||||
content = content.replacingOccurrences(of: "---", with: "---\n")
|
content = content.replacingOccurrences(of: "---", with: "---\n")
|
||||||
content = content.replacingOccurrences(of: "日星期", with: "日 星期")
|
content = content.replacingOccurrences(of: "日星期", with: "日 星期")
|
||||||
content = "# " + content
|
|
||||||
content = insertEmptyLineAfterFirstLine(content)
|
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
static func formatForNote(_ text: String) -> String {
|
static nonisolated func formatForNote(_ text: String) -> String {
|
||||||
var content = text
|
var content = text
|
||||||
content = content.replacingOccurrences(of: "# ", with: "")
|
content = content.replacingOccurrences(of: "# ", with: "")
|
||||||
content = content.replacingOccurrences(of: "#", with: "")
|
content = content.replacingOccurrences(of: "#", with: "")
|
||||||
@@ -111,13 +116,13 @@ enum TextFormatter {
|
|||||||
return result.trimmingCharacters(in: .whitespacesAndNewlines)
|
return result.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func removeEmptyLines(_ text: String) -> String {
|
static nonisolated func removeEmptyLines(_ text: String) -> String {
|
||||||
let lines = text.components(separatedBy: .newlines)
|
let lines = text.components(separatedBy: .newlines)
|
||||||
let nonEmptyLines = lines.filter { !$0.trimmingCharacters(in: .whitespaces).isEmpty }
|
let nonEmptyLines = lines.filter { !$0.trimmingCharacters(in: .whitespaces).isEmpty }
|
||||||
return nonEmptyLines.joined(separator: "\n")
|
return nonEmptyLines.joined(separator: "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
static func insertEmptyLineAfterFirstLine(_ text: String) -> String {
|
static nonisolated func insertEmptyLineAfterFirstLine(_ text: String) -> String {
|
||||||
var lines = text.components(separatedBy: .newlines)
|
var lines = text.components(separatedBy: .newlines)
|
||||||
if !lines.isEmpty {
|
if !lines.isEmpty {
|
||||||
lines.insert("", at: 1)
|
lines.insert("", at: 1)
|
||||||
|
|||||||
+130
-13
@@ -10,25 +10,54 @@ import UIKit
|
|||||||
class ViewController: UIViewController {
|
class ViewController: UIViewController {
|
||||||
|
|
||||||
private var tableView: UITableView!
|
private var tableView: UITableView!
|
||||||
|
private var editButton: UIBarButtonItem!
|
||||||
|
|
||||||
|
private let menuOrderKey = "homeMenuOrder"
|
||||||
|
|
||||||
private struct MenuItem {
|
private struct MenuItem {
|
||||||
let icon: String
|
let icon: String
|
||||||
let iconColor: UIColor
|
let iconColor: UIColor
|
||||||
let title: String
|
let title: String
|
||||||
|
let identifier: String
|
||||||
}
|
}
|
||||||
|
|
||||||
private let menuItems: [[MenuItem]] = [
|
private let defaultMenuItems: [MenuItem] = [
|
||||||
[
|
MenuItem(icon: "tray.full", iconColor: .systemIndigo, title: "收集箱", identifier: "inbox"),
|
||||||
MenuItem(icon: "note.text", iconColor: .systemYellow, title: "打开备忘录"),
|
MenuItem(icon: "note.text", iconColor: .systemYellow, title: "打开备忘录", identifier: "notes"),
|
||||||
MenuItem(icon: "doc.text", iconColor: .systemBlue, title: "格式化日志"),
|
MenuItem(icon: "doc.text", iconColor: .systemBlue, title: "格式化日志", identifier: "formatLog"),
|
||||||
MenuItem(icon: "text.alignleft", iconColor: .systemGreen, title: "格式化笔记"),
|
MenuItem(icon: "text.alignleft", iconColor: .systemGreen, title: "格式化笔记", identifier: "formatNote"),
|
||||||
MenuItem(icon: "folder", iconColor: .systemOrange, title: "打开文件")
|
MenuItem(icon: "folder", iconColor: .systemOrange, title: "打开文件", identifier: "files")
|
||||||
]
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
private var menuItems: [[MenuItem]] = []
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
menuItems = [loadMenuOrder()]
|
||||||
setupUI()
|
setupUI()
|
||||||
|
setupAppStateObserver()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
super.viewWillAppear(animated)
|
||||||
|
updateInboxBadge()
|
||||||
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
NotificationCenter.default.removeObserver(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setupAppStateObserver() {
|
||||||
|
NotificationCenter.default.addObserver(
|
||||||
|
self,
|
||||||
|
selector: #selector(appDidBecomeActive),
|
||||||
|
name: UIApplication.didBecomeActiveNotification,
|
||||||
|
object: nil
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func appDidBecomeActive() {
|
||||||
|
updateInboxBadge()
|
||||||
}
|
}
|
||||||
|
|
||||||
private func setupUI() {
|
private func setupUI() {
|
||||||
@@ -37,6 +66,9 @@ class ViewController: UIViewController {
|
|||||||
navigationItem.largeTitleDisplayMode = .always
|
navigationItem.largeTitleDisplayMode = .always
|
||||||
view.backgroundColor = .systemGroupedBackground
|
view.backgroundColor = .systemGroupedBackground
|
||||||
|
|
||||||
|
editButton = UIBarButtonItem(title: "编辑", style: .plain, target: self, action: #selector(didTapEditButton))
|
||||||
|
navigationItem.rightBarButtonItem = editButton
|
||||||
|
|
||||||
tableView = UITableView(frame: .zero, style: .insetGrouped)
|
tableView = UITableView(frame: .zero, style: .insetGrouped)
|
||||||
tableView.translatesAutoresizingMaskIntoConstraints = false
|
tableView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
tableView.delegate = self
|
tableView.delegate = self
|
||||||
@@ -52,6 +84,34 @@ class ViewController: UIViewController {
|
|||||||
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc private func didTapEditButton() {
|
||||||
|
tableView.setEditing(!tableView.isEditing, animated: true)
|
||||||
|
editButton.title = tableView.isEditing ? "完成" : "编辑"
|
||||||
|
}
|
||||||
|
|
||||||
|
private func loadMenuOrder() -> [MenuItem] {
|
||||||
|
guard let savedOrder = UserDefaults.standard.array(forKey: menuOrderKey) as? [String] else {
|
||||||
|
return defaultMenuItems
|
||||||
|
}
|
||||||
|
|
||||||
|
var orderedItems: [MenuItem] = []
|
||||||
|
for identifier in savedOrder {
|
||||||
|
if let item = defaultMenuItems.first(where: { $0.identifier == identifier }) {
|
||||||
|
orderedItems.append(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let remaining = defaultMenuItems.filter { item in
|
||||||
|
!orderedItems.contains { $0.identifier == item.identifier }
|
||||||
|
}
|
||||||
|
return orderedItems + remaining
|
||||||
|
}
|
||||||
|
|
||||||
|
private func saveMenuOrder() {
|
||||||
|
let identifiers = menuItems.flatMap { $0.map(\.identifier) }
|
||||||
|
UserDefaults.standard.set(identifiers, forKey: menuOrderKey)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ViewController: UITableViewDataSource {
|
extension ViewController: UITableViewDataSource {
|
||||||
@@ -74,34 +134,91 @@ extension ViewController: UITableViewDataSource {
|
|||||||
config.imageProperties.tintColor = item.iconColor
|
config.imageProperties.tintColor = item.iconColor
|
||||||
config.imageToTextPadding = 12
|
config.imageToTextPadding = 12
|
||||||
cell.contentConfiguration = config
|
cell.contentConfiguration = config
|
||||||
cell.accessoryType = .disclosureIndicator
|
cell.accessoryType = tableView.isEditing ? .none : .disclosureIndicator
|
||||||
|
cell.selectionStyle = tableView.isEditing ? .none : .default
|
||||||
|
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
|
||||||
|
guard sourceIndexPath != destinationIndexPath else { return }
|
||||||
|
|
||||||
|
let item = menuItems[sourceIndexPath.section].remove(at: sourceIndexPath.row)
|
||||||
|
menuItems[destinationIndexPath.section].insert(item, at: destinationIndexPath.row)
|
||||||
|
saveMenuOrder()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ViewController: UITableViewDelegate {
|
extension ViewController: UITableViewDelegate {
|
||||||
|
|
||||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
tableView.deselectRow(at: indexPath, animated: true)
|
tableView.deselectRow(at: indexPath, animated: true)
|
||||||
|
guard !tableView.isEditing else { return }
|
||||||
|
|
||||||
let item = menuItems[indexPath.section][indexPath.row]
|
let item = menuItems[indexPath.section][indexPath.row]
|
||||||
switch item.title {
|
switch item.identifier {
|
||||||
case "打开备忘录":
|
case "inbox":
|
||||||
|
let viewController = ClipInboxViewController()
|
||||||
|
navigationController?.pushViewController(viewController, animated: true)
|
||||||
|
case "notes":
|
||||||
openSystemNotesApp()
|
openSystemNotesApp()
|
||||||
case "格式化日志":
|
case "formatLog":
|
||||||
let viewController = FormatLogViewController()
|
let viewController = FormatLogViewController()
|
||||||
navigationController?.pushViewController(viewController, animated: true)
|
navigationController?.pushViewController(viewController, animated: true)
|
||||||
case "格式化笔记":
|
case "formatNote":
|
||||||
let viewController = FormatNoteViewController()
|
let viewController = FormatNoteViewController()
|
||||||
navigationController?.pushViewController(viewController, animated: true)
|
navigationController?.pushViewController(viewController, animated: true)
|
||||||
case "打开文件":
|
case "files":
|
||||||
openFilesApp()
|
openFilesApp()
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
|
||||||
|
return .none
|
||||||
|
}
|
||||||
|
|
||||||
|
func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateInboxBadge() {
|
||||||
|
Task {
|
||||||
|
guard let count = try? await ClipStore.shared.count(), count > 0 else {
|
||||||
|
await MainActor.run {
|
||||||
|
self.updateInboxTitle("收集箱")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await MainActor.run {
|
||||||
|
self.updateInboxTitle("收集箱(\(count))")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateInboxTitle(_ title: String) {
|
||||||
|
for (sectionIndex, section) in menuItems.enumerated() {
|
||||||
|
for (rowIndex, item) in section.enumerated() {
|
||||||
|
if item.identifier == "inbox" {
|
||||||
|
menuItems[sectionIndex][rowIndex] = MenuItem(
|
||||||
|
icon: item.icon,
|
||||||
|
iconColor: item.iconColor,
|
||||||
|
title: title,
|
||||||
|
identifier: item.identifier
|
||||||
|
)
|
||||||
|
let indexPath = IndexPath(row: rowIndex, section: sectionIndex)
|
||||||
|
tableView.reloadRows(at: [indexPath], with: .none)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func openSystemNotesApp() {
|
private func openSystemNotesApp() {
|
||||||
openURLIfPossible("mobilenotes://")
|
openURLIfPossible("mobilenotes://")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
/* Simplified Chinese localization */
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>NSExtension</key>
|
||||||
|
<dict>
|
||||||
|
<key>NSExtensionAttributes</key>
|
||||||
|
<dict>
|
||||||
|
<key>NSExtensionActivationRule</key>
|
||||||
|
<dict>
|
||||||
|
<key>NSExtensionActivationSupportsFileWithMaxCount</key>
|
||||||
|
<integer>10</integer>
|
||||||
|
<key>NSExtensionActivationSupportsText</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
<key>NSExtensionPointIdentifier</key>
|
||||||
|
<string>com.apple.share-services</string>
|
||||||
|
<key>NSExtensionPrincipalClass</key>
|
||||||
|
<string>$(PRODUCT_MODULE_NAME).ShareViewController</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>com.apple.security.application-groups</key>
|
||||||
|
<array>
|
||||||
|
<string>group.com.fishestlife.note</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import UIKit
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
|
class ShareViewController: UIViewController {
|
||||||
|
override func viewDidLoad() {
|
||||||
|
super.viewDidLoad()
|
||||||
|
handleSharedItems()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func handleSharedItems() {
|
||||||
|
guard let items = extensionContext?.inputItems as? [NSExtensionItem] else {
|
||||||
|
closeExtension()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let fileManager = FileManager.default
|
||||||
|
guard let containerURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "group.com.fishestlife.note") else {
|
||||||
|
closeExtension()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let sharedDir = containerURL.appendingPathComponent("SharedFiles", isDirectory: true)
|
||||||
|
try? fileManager.createDirectory(at: sharedDir, withIntermediateDirectories: true)
|
||||||
|
|
||||||
|
var sharedTexts: [String] = []
|
||||||
|
var sharedFileNames: [String] = []
|
||||||
|
let group = DispatchGroup()
|
||||||
|
|
||||||
|
for item in items {
|
||||||
|
guard let attachments = item.attachments else { continue }
|
||||||
|
|
||||||
|
for attachment in attachments {
|
||||||
|
group.enter()
|
||||||
|
|
||||||
|
if attachment.hasItemConformingToTypeIdentifier(UTType.plainText.identifier) {
|
||||||
|
attachment.loadItem(forTypeIdentifier: UTType.plainText.identifier, options: nil) { data, _ in
|
||||||
|
defer { group.leave() }
|
||||||
|
if let text = data as? String {
|
||||||
|
sharedTexts.append(text)
|
||||||
|
} else if let url = data as? URL, let text = try? String(contentsOf: url, encoding: .utf8) {
|
||||||
|
sharedTexts.append(text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if attachment.hasItemConformingToTypeIdentifier(UTType.url.identifier) {
|
||||||
|
attachment.loadItem(forTypeIdentifier: UTType.url.identifier, options: nil) { data, _ in
|
||||||
|
defer { group.leave() }
|
||||||
|
if let url = data as? URL, let text = try? String(contentsOf: url, encoding: .utf8) {
|
||||||
|
sharedTexts.append(text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
attachment.loadItem(forTypeIdentifier: UTType.data.identifier, options: nil) { data, _ in
|
||||||
|
defer { group.leave() }
|
||||||
|
if let url = data as? URL {
|
||||||
|
let destURL = sharedDir.appendingPathComponent(url.lastPathComponent)
|
||||||
|
try? fileManager.removeItem(at: destURL)
|
||||||
|
if (try? fileManager.copyItem(at: url, to: destURL)) != nil {
|
||||||
|
sharedFileNames.append(url.lastPathComponent)
|
||||||
|
}
|
||||||
|
} else if let fileData = data as? Data {
|
||||||
|
let fileName = "shared-\(UUID().uuidString).md"
|
||||||
|
let destURL = sharedDir.appendingPathComponent(fileName)
|
||||||
|
if (try? fileData.write(to: destURL)) != nil {
|
||||||
|
sharedFileNames.append(fileName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
group.notify(queue: .main) { [weak self] in
|
||||||
|
self?.openMainApp(texts: sharedTexts, fileNames: sharedFileNames)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func openMainApp(texts: [String], fileNames: [String]) {
|
||||||
|
var components = URLComponents(string: "noteapp://share")!
|
||||||
|
var queryItems: [URLQueryItem] = []
|
||||||
|
|
||||||
|
for (index, text) in texts.prefix(5).enumerated() {
|
||||||
|
queryItems.append(URLQueryItem(name: "text\(index)", value: text))
|
||||||
|
}
|
||||||
|
for (index, fileName) in fileNames.prefix(5).enumerated() {
|
||||||
|
queryItems.append(URLQueryItem(name: "file\(index)", value: fileName))
|
||||||
|
}
|
||||||
|
|
||||||
|
components.queryItems = queryItems.isEmpty ? nil : queryItems
|
||||||
|
|
||||||
|
guard let url = components.url else {
|
||||||
|
closeExtension()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
extensionContext?.open(url) { [weak self] _ in
|
||||||
|
self?.closeExtension()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func closeExtension() {
|
||||||
|
extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user