Add app auto-update toggle option (#87)
This commit is contained in:
		
							parent
							
								
									d161102bc0
								
							
						
					
					
						commit
						ee28516a4e
					
				@ -6,7 +6,8 @@ const LATEST_SCHEMA = {
 | 
			
		||||
            { name: 'email', type: 'TEXT NOT NULL' },
 | 
			
		||||
            { name: 'created_at', type: 'INTEGER' },
 | 
			
		||||
            { name: 'api_key', type: 'TEXT' },
 | 
			
		||||
            { name: 'provider', type: 'TEXT DEFAULT \'openai\'' }
 | 
			
		||||
            { name: 'provider', type: 'TEXT DEFAULT \'openai\'' },
 | 
			
		||||
            { name: 'auto_update_enabled', type: 'INTEGER DEFAULT 1' }
 | 
			
		||||
        ]
 | 
			
		||||
    },
 | 
			
		||||
    sessions: {
 | 
			
		||||
 | 
			
		||||
@ -157,6 +157,53 @@ class SQLiteClient {
 | 
			
		||||
        return result.length > 0 && result[0].value === 'true';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    getAutoUpdate(uid = this.defaultUserId) {
 | 
			
		||||
        try {
 | 
			
		||||
            const row = this.query(
 | 
			
		||||
                'SELECT auto_update_enabled FROM users WHERE uid = ?',
 | 
			
		||||
                [uid]
 | 
			
		||||
            );
 | 
			
		||||
            
 | 
			
		||||
            if (row.length > 0) {
 | 
			
		||||
                return row[0].auto_update_enabled !== 0;
 | 
			
		||||
            } else {
 | 
			
		||||
                // User doesn't exist, create them with default settings
 | 
			
		||||
                const now = Math.floor(Date.now() / 1000);
 | 
			
		||||
                this.query(
 | 
			
		||||
                    'INSERT OR REPLACE INTO users (uid, display_name, email, created_at, auto_update_enabled) VALUES (?, ?, ?, ?, ?)',
 | 
			
		||||
                    [uid, 'User', 'user@example.com', now, 1]
 | 
			
		||||
                );
 | 
			
		||||
                return true; // default to enabled
 | 
			
		||||
            }
 | 
			
		||||
        } catch (error) {
 | 
			
		||||
            console.error('Error getting auto_update_enabled setting:', error);
 | 
			
		||||
            return true; // fallback to enabled
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    setAutoUpdate(isEnabled, uid = this.defaultUserId) {
 | 
			
		||||
        try {
 | 
			
		||||
            const result = this.query(
 | 
			
		||||
                'UPDATE users SET auto_update_enabled = ? WHERE uid = ?',
 | 
			
		||||
                [isEnabled ? 1 : 0, uid]
 | 
			
		||||
            );
 | 
			
		||||
            
 | 
			
		||||
            // If no rows were updated, the user might not exist, so create them
 | 
			
		||||
            if (result.changes === 0) {
 | 
			
		||||
                const now = Math.floor(Date.now() / 1000);
 | 
			
		||||
                this.query(
 | 
			
		||||
                    'INSERT OR REPLACE INTO users (uid, display_name, email, created_at, auto_update_enabled) VALUES (?, ?, ?, ?, ?)',
 | 
			
		||||
                    [uid, 'User', 'user@example.com', now, isEnabled ? 1 : 0]
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            return result;
 | 
			
		||||
        } catch (error) {
 | 
			
		||||
            console.error('Error setting auto-update:', error);
 | 
			
		||||
            throw error;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    close() {
 | 
			
		||||
        if (this.db) {
 | 
			
		||||
            try {
 | 
			
		||||
 | 
			
		||||
@ -456,6 +456,8 @@ export class SettingsView extends LitElement {
 | 
			
		||||
        presets: { type: Array, state: true },
 | 
			
		||||
        selectedPreset: { type: Object, state: true },
 | 
			
		||||
        showPresets: { type: Boolean, state: true },
 | 
			
		||||
        autoUpdateEnabled: { type: Boolean, state: true },
 | 
			
		||||
        autoUpdateLoading: { type: Boolean, state: true },
 | 
			
		||||
    };
 | 
			
		||||
    //////// after_modelStateService ////////
 | 
			
		||||
 | 
			
		||||
@ -479,10 +481,46 @@ export class SettingsView extends LitElement {
 | 
			
		||||
        this.selectedPreset = null;
 | 
			
		||||
        this.showPresets = false;
 | 
			
		||||
        this.handleUsePicklesKey = this.handleUsePicklesKey.bind(this)
 | 
			
		||||
        this.autoUpdateEnabled = true;
 | 
			
		||||
        this.autoUpdateLoading = true;
 | 
			
		||||
        this.loadInitialData();
 | 
			
		||||
        //////// after_modelStateService ////////
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async loadAutoUpdateSetting() {
 | 
			
		||||
        if (!window.require) return;
 | 
			
		||||
        const { ipcRenderer } = window.require('electron');
 | 
			
		||||
        this.autoUpdateLoading = true;
 | 
			
		||||
        try {
 | 
			
		||||
            const enabled = await ipcRenderer.invoke('get-auto-update');
 | 
			
		||||
            this.autoUpdateEnabled = enabled;
 | 
			
		||||
        } catch (e) {
 | 
			
		||||
            this.autoUpdateEnabled = true; // fallback
 | 
			
		||||
        }
 | 
			
		||||
        this.autoUpdateLoading = false;
 | 
			
		||||
        this.requestUpdate();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    async handleToggleAutoUpdate() {
 | 
			
		||||
        if (!window.require || this.autoUpdateLoading) return;
 | 
			
		||||
        const { ipcRenderer } = window.require('electron');
 | 
			
		||||
        this.autoUpdateLoading = true;
 | 
			
		||||
        this.requestUpdate();
 | 
			
		||||
        try {
 | 
			
		||||
            const newValue = !this.autoUpdateEnabled;
 | 
			
		||||
            const success = await ipcRenderer.invoke('set-auto-update', newValue);
 | 
			
		||||
            if (success) {
 | 
			
		||||
                this.autoUpdateEnabled = newValue;
 | 
			
		||||
            } else {
 | 
			
		||||
                console.error('Failed to update auto-update setting');
 | 
			
		||||
            }
 | 
			
		||||
        } catch (e) {
 | 
			
		||||
            console.error('Error toggling auto-update:', e);
 | 
			
		||||
        }
 | 
			
		||||
        this.autoUpdateLoading = false;
 | 
			
		||||
        this.requestUpdate();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //////// after_modelStateService ////////
 | 
			
		||||
    async loadInitialData() {
 | 
			
		||||
        if (!window.require) return;
 | 
			
		||||
@ -617,6 +655,7 @@ export class SettingsView extends LitElement {
 | 
			
		||||
        this.setupEventListeners();
 | 
			
		||||
        this.setupIpcListeners();
 | 
			
		||||
        this.setupWindowResize();
 | 
			
		||||
        this.loadAutoUpdateSetting();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    disconnectedCallback() {
 | 
			
		||||
@ -1161,6 +1200,9 @@ export class SettingsView extends LitElement {
 | 
			
		||||
                    <button class="settings-button full-width" @click=${this.handlePersonalize}>
 | 
			
		||||
                        <span>Personalize / Meeting Notes</span>
 | 
			
		||||
                    </button>
 | 
			
		||||
                    <button class="settings-button full-width" @click=${this.handleToggleAutoUpdate} ?disabled=${this.autoUpdateLoading}>
 | 
			
		||||
                        <span>Automatic Updates: ${this.autoUpdateEnabled ? 'On' : 'Off'}</span>
 | 
			
		||||
                    </button>
 | 
			
		||||
                    
 | 
			
		||||
                    <div class="move-buttons">
 | 
			
		||||
                        <button class="settings-button half-width" @click=${this.handleMoveLeft}>
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										27
									
								
								src/index.js
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								src/index.js
									
									
									
									
									
								
							@ -26,6 +26,7 @@ const askService = require('./features/ask/askService');
 | 
			
		||||
const settingsService = require('./features/settings/settingsService');
 | 
			
		||||
const sessionRepository = require('./common/repositories/session');
 | 
			
		||||
const ModelStateService = require('./common/services/modelStateService');
 | 
			
		||||
const sqliteClient = require('./common/services/sqliteClient');
 | 
			
		||||
 | 
			
		||||
const eventBridge = new EventEmitter();
 | 
			
		||||
let WEB_PORT = 3000;
 | 
			
		||||
@ -290,6 +291,27 @@ function setupGeneralIpcHandlers() {
 | 
			
		||||
        return authService.getCurrentUser();
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    ipcMain.handle('get-auto-update', () => {
 | 
			
		||||
        const uid = authService.getCurrentUserId();
 | 
			
		||||
        try {
 | 
			
		||||
            return sqliteClient.getAutoUpdate(uid);
 | 
			
		||||
        } catch (error) {
 | 
			
		||||
            console.error('Error getting auto-update setting:', error);
 | 
			
		||||
            return true; // fallback to enabled
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    ipcMain.handle('set-auto-update', (event, isEnabled) => {
 | 
			
		||||
        const uid = authService.getCurrentUserId();
 | 
			
		||||
        try {
 | 
			
		||||
            sqliteClient.setAutoUpdate(isEnabled, uid);
 | 
			
		||||
            return true;
 | 
			
		||||
        } catch (error) {
 | 
			
		||||
            console.error('Error setting auto-update:', error);
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    // --- Web UI Data Handlers (New) ---
 | 
			
		||||
    setupWebDataHandlers();
 | 
			
		||||
}
 | 
			
		||||
@ -653,6 +675,11 @@ async function startWebStack() {
 | 
			
		||||
// Auto-update initialization
 | 
			
		||||
function initAutoUpdater() {
 | 
			
		||||
    try {
 | 
			
		||||
        const autoUpdateEnabled = sqliteClient.getAutoUpdate();
 | 
			
		||||
        if (!autoUpdateEnabled) {
 | 
			
		||||
            console.log('[AutoUpdater] Skipped because auto-updates are disabled in settings');
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        // Skip auto-updater in development mode
 | 
			
		||||
        if (!app.isPackaged) {
 | 
			
		||||
            console.log('[AutoUpdater] Skipped in development (app is not packaged)');
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user