2023-07-27 17:05:56 +02:00
|
|
|
import Logger from '@joplin/utils/Logger';
|
2023-01-11 16:00:36 +02:00
|
|
|
|
|
|
|
// Can't upgrade beyond 2.x because it doesn't work with Electron. If trying to
|
|
|
|
// upgrade again, check that adding a link from the CodeMirror editor works/
|
|
|
|
const smalltalk = require('smalltalk');
|
|
|
|
|
|
|
|
const logger = Logger.create('dialogs');
|
2017-12-24 10:36:31 +02:00
|
|
|
|
|
|
|
class Dialogs {
|
2023-03-06 16:22:01 +02:00
|
|
|
public async alert(message: string, title = '') {
|
2017-12-24 10:36:31 +02:00
|
|
|
await smalltalk.alert(title, message);
|
|
|
|
}
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2023-03-06 16:22:01 +02:00
|
|
|
public async confirm(message: string, title = '', options: any = {}) {
|
2017-12-24 10:36:31 +02:00
|
|
|
try {
|
2020-11-19 14:34:49 +02:00
|
|
|
await smalltalk.confirm(title, message, options);
|
2017-12-24 10:36:31 +02:00
|
|
|
return true;
|
|
|
|
} catch (error) {
|
2023-01-11 16:00:36 +02:00
|
|
|
logger.error(error);
|
2017-12-24 10:36:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-05 13:16:49 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2023-03-06 16:22:01 +02:00
|
|
|
public async prompt(message: string, title = '', defaultValue = '', options: any = null) {
|
2024-04-10 16:30:22 +02:00
|
|
|
options = { cancel: true, ...options };
|
2017-12-24 10:36:31 +02:00
|
|
|
|
|
|
|
try {
|
2024-04-10 16:30:22 +02:00
|
|
|
// https://github.com/laurent22/joplin/pull/10258#discussion_r1550306545
|
2017-12-24 10:36:31 +02:00
|
|
|
const answer = await smalltalk.prompt(title, message, defaultValue, options);
|
|
|
|
return answer;
|
|
|
|
} catch (error) {
|
2024-04-10 16:30:22 +02:00
|
|
|
logger.warn('Prompt appears to have been cancelled:', error);
|
2017-12-24 10:36:31 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const dialogs = new Dialogs();
|
|
|
|
|
2020-11-19 14:34:49 +02:00
|
|
|
export default dialogs;
|