Skip to content

Commit

Permalink
fix: Launcher import path fixed and some small onboarding frontend tw…
Browse files Browse the repository at this point in the history
…eaks
  • Loading branch information
LynithDev committed Oct 28, 2024
1 parent 709d2a0 commit ef4154c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
34 changes: 28 additions & 6 deletions apps/frontend/src/ui/pages/onboarding/Onboarding.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { ImportType } from '@onelauncher/client/bindings';
import { Route, useBeforeLeave, useLocation, useNavigate } from '@solidjs/router';
import { ChevronLeftIcon, ChevronRightIcon } from '@untitled-theme/icons-solid';
import { bridge } from '~imports';
import AnimatedRoutes from '~ui/components/AnimatedRoutes';
import Button from '~ui/components/base/Button';
import useSettings from '~ui/hooks/useSettings';
import { setAsyncTimeout } from '~utils';
import { pluralize, setAsyncTimeout } from '~utils';
import { type Accessor, type Context, createContext, createEffect, createSignal, type JSX, on, type ParentProps, useContext } from 'solid-js';
import OnboardingComplete from './OnboardingComplete';
import OnboardingImport from './OnboardingImport';
Expand Down Expand Up @@ -115,13 +116,26 @@ function Onboarding(props: ParentProps) {
const tasks = [

async () => {
setTasksMessage('Setting language');
setTasksMessage('Setting language'); // TODO: Actually do this
await setAsyncTimeout(500);
},

// eslint-disable-next-line solid/reactivity -- -
async () => {
setTasksMessage('Importing data');
await setAsyncTimeout(1000);
for (const [launcher, value] of importInstances()) {
if (value.instances.length === 0)
continue;

setTasksMessage(`Importing ${value.instances.length} ${pluralize(value.instances.length, 'instance')} ${launcher}`);
try {
await bridge.commands.importInstances(launcher, value.basePath, value.instances);
}
catch (e) {
console.error(e);
setTasksMessage(`Failed to import ${value.instances.length} ${pluralize(value.instances.length, 'instance')} ${launcher}...`);
await setAsyncTimeout(1500);
}
}
},

].map(task => task());
Expand All @@ -141,8 +155,16 @@ function Onboarding(props: ParentProps) {

tasks.push(`Set language to ${LanguagesList[language()][0]}`);

importInstances().forEach((type) => {
tasks.push(`Import profiles from ${type}`);
importInstances().forEach((value, launcher) => {
if (value.instances.length === 0)
return;

let builder = `Import ${value.instances.length} ${pluralize(value.instances.length, 'instance')} from ${launcher}\n`;
value.instances.forEach((instance, index) => {
builder += ` ${index + 1}. ${instance}\n`;
});

tasks.push(builder);
});

return tasks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function OnboardingSummary() {
<div class="my-8 max-h-36 w-full flex flex-1 flex-col gap-y-2 rounded-lg bg-page-elevated p-4 font-mono">
<For each={ctx.getTasks()}>
{task => (
<span class="text-lg text-fg-primary">
<span class="whitespace-pre text-lg text-fg-primary line-height-normal">
{task}
</span>
)}
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/api/package/import/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ impl ImportType {
}

pub async fn get_launcher_instances(import: ImportType, path: Option<PathBuf>) -> crate::Result<(PathBuf, Vec<String>)> {
let instances_dir = import.get_instances_subpath(
&path.unwrap_or(
default_launcher_path(import)
.ok_or(anyhow::anyhow!("could not get launcher base path for {import}")
)?
)).await?;
let base_path = &path.unwrap_or(
default_launcher_path(import)
.ok_or(anyhow::anyhow!("could not get launcher base path for {import}"))?
);

let instances_dir = import.get_instances_subpath(base_path).await?;

let mut instances = Vec::new();
let mut dir = io::read_dir(&instances_dir)
Expand All @@ -119,7 +119,7 @@ pub async fn get_launcher_instances(import: ImportType, path: Option<PathBuf>) -
}
}

Ok((instances_dir, instances))
Ok((base_path.to_owned(), instances))
}

#[tracing::instrument]
Expand Down

0 comments on commit ef4154c

Please sign in to comment.