Switch to Electron confirmation dialogs
This commit is contained in:
		
							parent
							
								
									585bb5e095
								
							
						
					
					
						commit
						b42a1417b0
					
				@ -129,6 +129,7 @@
 | 
				
			|||||||
    import PrivateConversation = Conversation.PrivateConversation;
 | 
					    import PrivateConversation = Conversation.PrivateConversation;
 | 
				
			||||||
    import * as _ from 'lodash';
 | 
					    import * as _ from 'lodash';
 | 
				
			||||||
    import NoteStatus from '../site/NoteStatus.vue';
 | 
					    import NoteStatus from '../site/NoteStatus.vue';
 | 
				
			||||||
 | 
					    import { Dialog } from '../helpers/dialog';
 | 
				
			||||||
    // import { EventBus } from './preview/event-bus';
 | 
					    // import { EventBus } from './preview/event-bus';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const unreadClasses = {
 | 
					    const unreadClasses = {
 | 
				
			||||||
@ -317,7 +318,7 @@
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        logOut(): void {
 | 
					        logOut(): void {
 | 
				
			||||||
            if(confirm(l('chat.confirmLeave'))) core.connection.close();
 | 
					            if(Dialog.confirmDialog(l('chat.confirmLeave'))) core.connection.close();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        showSettings(): void {
 | 
					        showSettings(): void {
 | 
				
			||||||
 | 
				
			|||||||
@ -73,6 +73,7 @@
 | 
				
			|||||||
    import l from './localize';
 | 
					    import l from './localize';
 | 
				
			||||||
    import MessageView from './message_view';
 | 
					    import MessageView from './message_view';
 | 
				
			||||||
    import Zip from './zip';
 | 
					    import Zip from './zip';
 | 
				
			||||||
 | 
					    import { Dialog } from '../helpers/dialog';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function formatDate(this: void, date: Date): string {
 | 
					    function formatDate(this: void, date: Date): string {
 | 
				
			||||||
        return format(date, 'yyyy-MM-dd');
 | 
					        return format(date, 'yyyy-MM-dd');
 | 
				
			||||||
@ -195,7 +196,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        downloadDay(): void {
 | 
					        downloadDay(): void {
 | 
				
			||||||
            if(this.selectedConversation === undefined || this.selectedDate === undefined || this.messages.length === 0) return;
 | 
					            if(this.selectedConversation === undefined || this.selectedDate === undefined || this.messages.length === 0) return;
 | 
				
			||||||
            const html = confirm(l('logs.html'));
 | 
					            const html = Dialog.confirmDialog(l('logs.html'));
 | 
				
			||||||
            const name = `${this.selectedConversation.name}-${formatDate(new Date(this.selectedDate))}.${html ? 'html' : 'txt'}`;
 | 
					            const name = `${this.selectedConversation.name}-${formatDate(new Date(this.selectedDate))}.${html ? 'html' : 'txt'}`;
 | 
				
			||||||
            this.download(name, `data:${encodeURIComponent(name)},${encodeURIComponent(getLogs(this.messages, html))}`);
 | 
					            this.download(name, `data:${encodeURIComponent(name)},${encodeURIComponent(getLogs(this.messages, html))}`);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -203,7 +204,7 @@
 | 
				
			|||||||
        async downloadConversation(): Promise<void> {
 | 
					        async downloadConversation(): Promise<void> {
 | 
				
			||||||
            if(this.selectedConversation === undefined) return;
 | 
					            if(this.selectedConversation === undefined) return;
 | 
				
			||||||
            const zip = new Zip();
 | 
					            const zip = new Zip();
 | 
				
			||||||
            const html = confirm(l('logs.html'));
 | 
					            const html = Dialog.confirmDialog(l('logs.html'));
 | 
				
			||||||
            for(const date of this.dates) {
 | 
					            for(const date of this.dates) {
 | 
				
			||||||
                const messages = await core.logs.getLogs(this.selectedCharacter, this.selectedConversation.key, date);
 | 
					                const messages = await core.logs.getLogs(this.selectedCharacter, this.selectedConversation.key, date);
 | 
				
			||||||
                zip.addFile(`${formatDate(date)}.${html ? 'html' : 'txt'}`, getLogs(messages, html));
 | 
					                zip.addFile(`${formatDate(date)}.${html ? 'html' : 'txt'}`, getLogs(messages, html));
 | 
				
			||||||
@ -212,9 +213,9 @@
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        async downloadCharacter(): Promise<void> {
 | 
					        async downloadCharacter(): Promise<void> {
 | 
				
			||||||
            if(this.selectedCharacter === '' || !confirm(l('logs.confirmExport', this.selectedCharacter))) return;
 | 
					            if(this.selectedCharacter === '' || !Dialog.confirmDialog(l('logs.confirmExport', this.selectedCharacter))) return;
 | 
				
			||||||
            const zip = new Zip();
 | 
					            const zip = new Zip();
 | 
				
			||||||
            const html = confirm(l('logs.html'));
 | 
					            const html = Dialog.confirmDialog(l('logs.html'));
 | 
				
			||||||
            for(const conv of this.conversations) {
 | 
					            for(const conv of this.conversations) {
 | 
				
			||||||
                zip.addFile(`${conv.name}/`, '');
 | 
					                zip.addFile(`${conv.name}/`, '');
 | 
				
			||||||
                const dates = await core.logs.getLogDates(this.selectedCharacter, conv.key);
 | 
					                const dates = await core.logs.getLogDates(this.selectedCharacter, conv.key);
 | 
				
			||||||
 | 
				
			|||||||
@ -27,6 +27,7 @@
 | 
				
			|||||||
    import core from './core';
 | 
					    import core from './core';
 | 
				
			||||||
    import { BBCodeView } from '../bbcode/view';
 | 
					    import { BBCodeView } from '../bbcode/view';
 | 
				
			||||||
    import * as _ from 'lodash';
 | 
					    import * as _ from 'lodash';
 | 
				
			||||||
 | 
					    import { Dialog } from '../helpers/dialog';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Component({
 | 
					    @Component({
 | 
				
			||||||
        components: {modal: Modal, bbcode: BBCodeView(core.bbCodeParser)}
 | 
					        components: {modal: Modal, bbcode: BBCodeView(core.bbCodeParser)}
 | 
				
			||||||
@ -75,7 +76,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        async removeStatusHistoryEntry(index: number): Promise<void> {
 | 
					        async removeStatusHistoryEntry(index: number): Promise<void> {
 | 
				
			||||||
          if(confirm('Are you sure you want to remove this status message?')) {
 | 
					          if(Dialog.confirmDialog('Are you sure you want to remove this status message?')) {
 | 
				
			||||||
              this.history.splice(index, 1);
 | 
					              this.history.splice(index, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
              await core.settingsStore.set('statusHistory', this.history);
 | 
					              await core.settingsStore.set('statusHistory', this.history);
 | 
				
			||||||
 | 
				
			|||||||
@ -32,6 +32,7 @@
 | 
				
			|||||||
    import l from '../localize';
 | 
					    import l from '../localize';
 | 
				
			||||||
    import {Editor} from '../bbcode';
 | 
					    import {Editor} from '../bbcode';
 | 
				
			||||||
    import core from '../core';
 | 
					    import core from '../core';
 | 
				
			||||||
 | 
					    import { Dialog } from '../../helpers/dialog';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Component({
 | 
					    @Component({
 | 
				
			||||||
        components: {modal: Modal, editor: Editor}
 | 
					        components: {modal: Modal, editor: Editor}
 | 
				
			||||||
@ -72,14 +73,13 @@
 | 
				
			|||||||
            this.ads.push('');
 | 
					            this.ads.push('');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        removeAd(index: number): void {
 | 
					        removeAd(index: number): void {
 | 
				
			||||||
            if (confirm('Are you sure you wish to remove this ad?')) {
 | 
					            // if (confirm('Are you sure you wish to remove this ad?')) {
 | 
				
			||||||
 | 
					            if (Dialog.confirmDialog('Are you sure you wish to remove this ad?')) {
 | 
				
			||||||
                this.ads.splice(index, 1);
 | 
					                this.ads.splice(index, 1);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
        moveAdUp(index: number): void {
 | 
					        moveAdUp(index: number): void {
 | 
				
			||||||
            const ad = this.ads.splice(index, 1);
 | 
					            const ad = this.ads.splice(index, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -194,8 +194,6 @@ function createWindow(): electron.BrowserWindow | undefined {
 | 
				
			|||||||
    if(tabCount >= 3) return;
 | 
					    if(tabCount >= 3) return;
 | 
				
			||||||
    const lastState = windowState.getSavedWindowState();
 | 
					    const lastState = windowState.getSavedWindowState();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    console.log('ICon is', process.platform === 'win32' ? winIcon : pngIcon);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    const windowProperties: electron.BrowserWindowConstructorOptions & {maximized: boolean} = {
 | 
					    const windowProperties: electron.BrowserWindowConstructorOptions & {maximized: boolean} = {
 | 
				
			||||||
        ...lastState,
 | 
					        ...lastState,
 | 
				
			||||||
        center: lastState.x === undefined,
 | 
					        center: lastState.x === undefined,
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										15
									
								
								helpers/dialog.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								helpers/dialog.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					import * as remote from '@electron/remote';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export class Dialog {
 | 
				
			||||||
 | 
					  static confirmDialog(message: string): boolean {
 | 
				
			||||||
 | 
					    const result = remote.dialog.showMessageBoxSync({
 | 
				
			||||||
 | 
					      message,
 | 
				
			||||||
 | 
					      type: 'question',
 | 
				
			||||||
 | 
					      buttons: ['Yes', 'No'],
 | 
				
			||||||
 | 
					      defaultId: 1,
 | 
				
			||||||
 | 
					      cancelId: 1
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return result === 0;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user