Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nit: fix autostart not working #2942

Merged
merged 3 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/renderer/src/lib/dashboard/DashboardPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ProviderStopped from './ProviderStopped.svelte';
import ProviderStarting from './ProviderStarting.svelte';
import NavPage from '../ui/NavPage.svelte';
import type { InitializationContext } from './ProviderInitUtils';
import { InitializeAndStartMode } from './ProviderInitUtils';
import { DoNothingMode } from './ProviderInitUtils';
import FeaturedExtensions from '/@/lib/featured/FeaturedExtensions.svelte';
import ProviderConfiguring from '/@/lib/dashboard/ProviderConfiguring.svelte';

Expand All @@ -28,7 +28,7 @@ function getInitializationContext(id: string) {
if (providerInitContexts.has(id)) {
context = providerInitContexts.get(id);
} else {
context = { mode: InitializeAndStartMode };
context = { mode: DoNothingMode };
providerInitContexts.set(id, context);
}
return context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ import { beforeAll, test, vi } from 'vitest';
import { verifyStatus } from './ProviderStatusTestHelper.spec';
import ProviderConfigured from '/@/lib/dashboard/ProviderConfigured.svelte';

// fake the window.events object
beforeAll(() => {
(window as any).startProvider = vi.fn();

// mock that autostart is configured as true
cdrage marked this conversation as resolved.
Show resolved Hide resolved
(window.getConfigurationValue as unknown) = (_key: string) => {
return true;
};

// fake the window.events object
(window.events as unknown) = {
receive: (_channel: string, func: any) => {
func();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ async function runProvider() {
runInProgress = false;
}

onMount(() => {
onMount(async () => {
// Get the autostart configuration setting. If it's disabled, we do *not* want to start the current container provider.
cdrage marked this conversation as resolved.
Show resolved Hide resolved
const autostart = await window.getConfigurationValue<boolean>('preferences.engine.autostart');
runAtStart = autostart || initializationContext.mode === InitializeAndStartMode;

if (runAtStart) {
runProvider();
}
Expand Down
3 changes: 2 additions & 1 deletion packages/renderer/src/lib/dashboard/ProviderInitUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import { faPlay, faWrench } from '@fortawesome/free-solid-svg-icons';
import Fa from 'svelte-fa/src/fa.svelte';
import type { ProviderDetectionCheck } from '@podman-desktop/api';

export const DoNothingMode = 'Do nothing';
export const InitializeOnlyMode = 'Initialize';
export const InitializeAndStartMode = 'Initialize and start';

export type InitializationMode = typeof InitializeOnlyMode | typeof InitializeAndStartMode;
export type InitializationMode = typeof DoNothingMode | typeof InitializeOnlyMode | typeof InitializeAndStartMode;

export interface InitializationContext {
mode: InitializationMode;
Expand Down