mirror of
https://github.com/amitwh/markdown-converter.git
synced 2026-08-02 10:00:17 +05:30
fix(updater): dispatch setFeedURL by provider instead of raw url
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
const { ipcMain } = require('electron');
|
||||
const { resolveFeedUrl } = require('../updater/feed-config');
|
||||
const { feedConfigFor } = require('../updater/feed-config');
|
||||
|
||||
function register({ updater, getMainWindow, getChannel }) {
|
||||
ipcMain.handle('updater:check', async () => {
|
||||
const channel = getChannel();
|
||||
const version = require('electron').app.getVersion();
|
||||
const platform = process.platform;
|
||||
const feed = resolveFeedUrl(channel, version, platform);
|
||||
updater.autoUpdater.setFeedURL({ url: feed.replace(/\/latest-[^/]+\.yml$/, '') });
|
||||
updater.autoUpdater.setFeedURL(feedConfigFor(channel));
|
||||
await updater.check();
|
||||
return { state: updater.state };
|
||||
});
|
||||
|
||||
@@ -28,4 +28,11 @@ function resolveFeedUrl(channel, version, platform) {
|
||||
return feedForChannel(channel, version, platform);
|
||||
}
|
||||
|
||||
module.exports = { resolveFeedUrl, FEEDS };
|
||||
function feedConfigFor(channel) {
|
||||
if (channel === 'github') {
|
||||
return { provider: 'github', owner: 'amitwh', repo: 'markdown-converter' };
|
||||
}
|
||||
return { provider: 'generic', url: 'https://updates.concreteinfo.co.in/v5' };
|
||||
}
|
||||
|
||||
module.exports = { resolveFeedUrl, feedConfigFor, FEEDS };
|
||||
@@ -27,9 +27,14 @@ export const useSettingsStore = create<SettingsState>()(
|
||||
},
|
||||
onRehydrateStorage: () => (state) => {
|
||||
if (!state) return;
|
||||
const result = settingsSchema.safeParse(state);
|
||||
if (!result.success) {
|
||||
console.warn('[settings-store] invalid persisted state, resetting to defaults', result.error);
|
||||
try {
|
||||
const result = settingsSchema.safeParse(state);
|
||||
if (!result.success) {
|
||||
console.warn('[settings-store] invalid persisted state, resetting to defaults', result.error);
|
||||
useSettingsStore.setState({ ...DEFAULTS } as any);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[settings-store] rehydration failed, resetting to defaults', err);
|
||||
useSettingsStore.setState({ ...DEFAULTS } as any);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { resolveFeedUrl, FEEDS } = require('../../../../src/main/updater/feed-config');
|
||||
const { resolveFeedUrl, feedConfigFor, FEEDS } = require('../../../../src/main/updater/feed-config');
|
||||
|
||||
describe('feed-config', () => {
|
||||
test('resolves github channel to GitHub Releases feed', () => {
|
||||
@@ -31,3 +31,19 @@ describe('feed-config', () => {
|
||||
expect(FEEDS.concreteinfo).toBeDefined();
|
||||
});
|
||||
});
|
||||
describe('feedConfigFor', () => {
|
||||
test('returns github provider config for github channel', () => {
|
||||
const config = feedConfigFor('github');
|
||||
expect(config).toEqual({ provider: 'github', owner: 'amitwh', repo: 'markdown-converter' });
|
||||
});
|
||||
|
||||
test('returns generic provider config for concreteinfo channel', () => {
|
||||
const config = feedConfigFor('concreteinfo');
|
||||
expect(config).toEqual({ provider: 'generic', url: 'https://updates.concreteinfo.co.in/v5' });
|
||||
});
|
||||
|
||||
test('falls back to generic provider on unknown channel', () => {
|
||||
const config = feedConfigFor('something-weird');
|
||||
expect(config).toEqual({ provider: 'generic', url: 'https://updates.concreteinfo.co.in/v5' });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user