2023-07-27 16:05:56 +01:00
|
|
|
import Logger from '@joplin/utils/Logger';
|
2023-01-11 14:00:36 +00: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 09:36:31 +01:00
|
|
|
|
|
|
|
class Dialogs {
|
2023-03-06 14:22:01 +00:00
|
|
|
public async alert(message: string, title = '') {
|
2017-12-24 09:36:31 +01:00
|
|
|
await smalltalk.alert(title, message);
|
|
|
|
}
|
|
|
|
|
2024-04-05 12:16:49 +01:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2023-03-06 14:22:01 +00:00
|
|
|
public async confirm(message: string, title = '', options: any = {}) {
|
2017-12-24 09:36:31 +01:00
|
|
|
try {
|
2020-11-19 12:34:49 +00:00
|
|
|
await smalltalk.confirm(title, message, options);
|
2017-12-24 09:36:31 +01:00
|
|
|
return true;
|
|
|
|
} catch (error) {
|
2023-01-11 14:00:36 +00:00
|
|
|
logger.error(error);
|
2017-12-24 09:36:31 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-05 12:16:49 +01:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
|
2023-03-06 14:22:01 +00:00
|
|
|
public async prompt(message: string, title = '', defaultValue = '', options: any = null) {
|
2024-04-10 15:30:22 +01:00
|
|
|
options = { cancel: true, ...options };
|
2017-12-24 09:36:31 +01:00
|
|
|
|
|
|
|
try {
|
2024-04-10 15:30:22 +01:00
|
|
|
// https://github.com/laurent22/joplin/pull/10258#discussion_r1550306545
|
2017-12-24 09:36:31 +01:00
|
|
|
const answer = await smalltalk.prompt(title, message, defaultValue, options);
|
|
|
|
return answer;
|
|
|
|
} catch (error) {
|
2024-04-10 15:30:22 +01:00
|
|
|
logger.warn('Prompt appears to have been cancelled:', error);
|
2017-12-24 09:36:31 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const dialogs = new Dialogs();
|
|
|
|
|
2020-11-19 12:34:49 +00:00
|
|
|
export default dialogs;
|