1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-04-23 11:52:59 +02:00

Android: Fixes #7791: Fixed issue where app would close after sharing a file

This commit is contained in:
Laurent Cozic 2023-02-20 16:05:00 +00:00
parent f2995dd196
commit 25a31b0689
5 changed files with 53 additions and 28 deletions

View File

@ -78,10 +78,13 @@ public class SharePackage implements ReactPackage {
@ReactMethod
public void close() {
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
currentActivity.finish();
}
// We disable this, because otherwise it would close the whole application
// https://github.com/laurent22/joplin/issues/7791#issuecomment-1436078948
// Activity currentActivity = getCurrentActivity();
// if (currentActivity != null) {
// currentActivity.finish();
// }
}
@ReactMethod

View File

@ -729,7 +729,7 @@ class AppComponent extends React.Component {
};
this.handleOpenURL_ = (event: any) => {
logger.info('Sharing: handleOpenURL_: start');
// logger.info('Sharing: handleOpenURL_: start');
// If this is called while biometrics haven't been done yet, we can
// ignore the call, because handleShareData() will be called once
@ -741,7 +741,7 @@ class AppComponent extends React.Component {
};
this.handleNewShare_ = () => {
logger.info('Sharing: handleNewShare_: start');
// logger.info('Sharing: handleNewShare_: start');
// look at this.handleOpenURL_ comment
if (this.props.biometricsDone) {

View File

@ -81,7 +81,25 @@ class Logger {
}
public static get globalLogger(): Logger {
if (!this.globalLogger_) throw new Error('Global logger has not been initialized!!');
if (!this.globalLogger_) {
// The global logger normally is initialized early, so we shouldn't
// end up here. However due to early event handlers, it might happen
// and in this case we want to know about it. So we print this
// warning, and also flag the log statements using `[UNINITIALIZED
// GLOBAL LOGGER]` so that we know from where the incorrect log
// statement comes from.
console.warn('Logger: Trying to access globalLogger, but it has not been initialized. Make sure that initializeGlobalLogger() has been called before logging. Will use the console as fallback.');
const output: any = {
log: (level: LogLevel, prefix: string, ...object: any[]) => {
// eslint-disable-next-line no-console
console.info(`[UNINITIALIZED GLOBAL LOGGER] ${this.levelIdToString(level)}: ${prefix}:`, object);
},
};
return output;
// throw new Error('Global logger has not been initialized!!');
}
return this.globalLogger_;
}

View File

@ -120,27 +120,29 @@ shared.saveNoteButton_press = async function(comp: any, folderId: string = null,
comp.setState(newState);
if (isProvisionalNote) {
const geoNote: any = await Note.updateGeolocation(note.id);
const updateGeoloc = async () => {
const geoNote: NoteEntity = await Note.updateGeolocation(note.id);
// TODO: CHECK - this code has never worked??
const stateNote = comp.state.note;
if (!stateNote || !geoNote) return;
if (stateNote.id !== geoNote.id) return; // Another note has been loaded while geoloc was being retrieved
const stateNote = comp.state.note;
if (!stateNote || !geoNote) return;
if (stateNote.id !== geoNote.id) return; // Another note has been loaded while geoloc was being retrieved
// Geo-location for this note has been saved to the database however the properties
// are is not in the state so set them now.
// Geo-location for this note has been saved to the database however the properties
// are is not in the state so set them now.
const geoInfo = {
longitude: geoNote.longitude,
latitude: geoNote.latitude,
altitude: geoNote.altitude,
};
const geoInfo = {
longitude: geoNote.longitude,
latitude: geoNote.latitude,
altitude: geoNote.altitude,
const modNote = Object.assign({}, stateNote, geoInfo);
const modLastSavedNote = Object.assign({}, comp.state.lastSavedNote, geoInfo);
comp.setState({ note: modNote, lastSavedNote: modLastSavedNote });
};
const modNote = Object.assign({}, stateNote, geoInfo);
const modLastSavedNote = Object.assign({}, comp.state.lastSavedNote, geoInfo);
comp.setState({ note: modNote, lastSavedNote: modLastSavedNote });
await updateGeoloc();
}
releaseMutex();

View File

@ -468,9 +468,9 @@ export default class Note extends BaseItem {
return this.modelSelectAll('SELECT * FROM notes WHERE is_conflict = 0');
}
public static async updateGeolocation(noteId: string): Promise<void> {
if (!Setting.value('trackLocation')) return;
if (!Note.updateGeolocationEnabled_) return;
public static async updateGeolocation(noteId: string): Promise<NoteEntity | null> {
if (!Setting.value('trackLocation')) return null;
if (!Note.updateGeolocationEnabled_) return null;
const startWait = time.unixMs();
while (true) {
@ -479,7 +479,7 @@ export default class Note extends BaseItem {
await time.sleep(1);
if (startWait + 1000 * 20 < time.unixMs()) {
this.logger().warn(`Failed to update geolocation for: timeout: ${noteId}`);
return;
return null;
}
}
@ -499,7 +499,7 @@ export default class Note extends BaseItem {
this.geolocationUpdating_ = false;
if (!geoData) return;
if (!geoData) return null;
this.logger().info('Got lat/long');
this.geolocationCache_ = geoData;
@ -508,12 +508,14 @@ export default class Note extends BaseItem {
this.logger().info(`Updating lat/long of note ${noteId}`);
const note = await Note.load(noteId);
if (!note) return; // Race condition - note has been deleted in the meantime
if (!note) return null; // Race condition - note has been deleted in the meantime
note.longitude = geoData.coords.longitude;
note.latitude = geoData.coords.latitude;
note.altitude = geoData.coords.altitude;
await Note.save(note, { ignoreProvisionalFlag: true });
return note;
}
static filter(note: NoteEntity) {