Skip to content

Commit

Permalink
Fixes macOS Sonoma crashing when inserting Rich Text. Addresses #36
Browse files Browse the repository at this point in the history
Sonoma beta 2 changed the temp location for sandboxed apps from the global
temp folder to a folder in the sandbox (/Users/adomas/Library/Containers) so we
create our temp rtf files in
/Users/adomas/Library/Group Containers/UBF8T346G9.Office/org.zotero.zotero
now
  • Loading branch information
adomasven committed Jul 5, 2023
1 parent 46c59e8 commit 3edf992
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
3 changes: 3 additions & 0 deletions build/src/document.m
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,9 @@ statusCode insertText(document_t *doc, const char htmlString[]) {
CHECK_STATUS_LOCKED(doc)

FILE* temporaryFile = getTemporaryFile(doc);
if (temporaryFile == NULL) {
DIE(([NSString stringWithFormat:@"Could not create a temporary file at %@", getTemporaryFilePath()]));
}

// Write HTML to a file
fprintf(temporaryFile, "%s", htmlString);
Expand Down
3 changes: 3 additions & 0 deletions build/src/field.m
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ statusCode setTextRaw(field_t* field, const char string[], bool isRich,
WordTextRange* insertRange;

FILE* temporaryFile = getTemporaryFile(field->doc);
if (temporaryFile == NULL) {
DIE(([NSString stringWithFormat:@"Could not create a temporary file at %@", getTemporaryFilePath()]));
}

// Word 16.9 and higher has changed the way [application insertFile]
// works. Instead of inserting text into specified range it inserts
Expand Down
27 changes: 15 additions & 12 deletions build/src/utilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@
// Gets a FILE for the temporary file, truncating it to zero length
FILE* getTemporaryFile(document_t *doc) {
if(tempFile == NULL) {
const char *tempFileTemplate;
if(doc->wordVersion == 2016 || doc->wordVersion >= 16 && doc->wordVersion < 2000) {
tempFileTemplate = [[NSTemporaryDirectory()
stringByAppendingPathComponent:
@"com.microsoft.Word/zotero.XXXXXX.rtf"]
fileSystemRepresentation];
} else {
tempFileTemplate = [[NSTemporaryDirectory()
stringByAppendingPathComponent:
@"zotero.XXXXXX.rtf"]
fileSystemRepresentation];
}
NSString *tempFileFolder = [NSHomeDirectory()
stringByAppendingPathComponent:
@"Library/Group Containers/UBF8T346G9.Office/org.zotero.zotero"];
const char *tempFileTemplate;
tempFileTemplate = [[NSHomeDirectory()
stringByAppendingPathComponent:
@"Library/Group Containers/UBF8T346G9.Office/org.zotero.zotero/zotero.XXXXXX.rtf"]
fileSystemRepresentation];
if (![[NSFileManager defaultManager] fileExistsAtPath:tempFileFolder]) {
[[NSFileManager defaultManager] createDirectoryAtPath:tempFileFolder
withIntermediateDirectories:TRUE attributes:NULL error:NULL];
}
size_t tempFileLength = strlen(tempFileTemplate)+1;
tempFileString = (char *)malloc(tempFileLength);
strlcpy(tempFileString, tempFileTemplate, tempFileLength);
Expand All @@ -54,6 +54,9 @@
stringWithFileSystemRepresentation:tempFileString
length:strlen(tempFileString)];
[tempFileStringNS retain];
if (tempFileDescriptor == -1) {
return tempFile;
}
tempFile = fdopen(tempFileDescriptor, "w");
}
rewind(tempFile);
Expand Down
Binary file modified resource/libZoteroWordIntegration.dylib
Binary file not shown.

0 comments on commit 3edf992

Please sign in to comment.