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

- fix: windows issues found by gil #514

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions apps/shinkai-desktop/src-tauri/src/tray.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use tauri::{
menu::{MenuBuilder, MenuItemBuilder, SubmenuBuilder},
tray::TrayIconBuilder,
Manager, Runtime,
tray::{MouseButton, TrayIconBuilder, TrayIconEvent},
Manager,
};

use crate::{
Expand Down Expand Up @@ -35,6 +35,16 @@ pub fn create_tray(app: &tauri::AppHandle) -> tauri::Result<()> {
let _ = TrayIconBuilder::with_id("tray")
.icon(icon)
.icon_as_template(is_template)
.on_tray_icon_event(|tray, event| {
if cfg!(target_os = "windows") {
if let TrayIconEvent::Click { button, .. } = event {
if button == MouseButton::Left {
recreate_window(tray.app_handle().clone(), Window::Main, true);
}
}
}
})
.menu_on_left_click(!cfg!(target_os = "windows"))
.menu(&menu)
.on_menu_event(move |tray, event| match event.id().as_ref() {
"show" => {
Expand Down
4 changes: 4 additions & 0 deletions apps/shinkai-desktop/src-tauri/src/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ pub fn recreate_window(app_handle: AppHandle, window_name: Window, focus: bool)
if let Some(window) = app_handle.get_webview_window(label) {
log::info!("window {} found, bringing to front", label);
if focus {
log::info!("focusing window {}", label);
if window.is_minimized().unwrap_or_default() {
let _ = window.unminimize();
}
window.show().unwrap();
window.center().unwrap();
let _ = window.set_focus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const ResetStorageBeforeConnectConfirmationPrompt = ({
{/*</Button>*/}
<Button
className="min-w-32 text-sm"
disabled={isResetLoading}
onClick={() => cancel()}
size="sm"
variant={'outline'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const useShinkaiNodeSpawnMutation = (options?: UseMutationOptions) => {
mutationFn: () => {
return invoke('shinkai_node_spawn');
},
...options,
onSuccess: (...onSuccessParameters) => {
queryClient.invalidateQueries({
queryKey: ['shinkai_node_is_running'],
Expand All @@ -89,7 +90,6 @@ export const useShinkaiNodeSpawnMutation = (options?: UseMutationOptions) => {
options.onSuccess(...onSuccessParameters);
}
},
...options,
});
return { ...response };
};
Expand All @@ -100,6 +100,7 @@ export const useShinkaiNodeKillMutation = (options?: UseMutationOptions) => {
mutationFn: async (): Promise<void> => {
return invoke('shinkai_node_kill');
},
...options,
onSuccess: (...onSuccessParameters) => {
queryClient.invalidateQueries({
queryKey: ['shinkai_node_is_running'],
Expand All @@ -108,7 +109,6 @@ export const useShinkaiNodeKillMutation = (options?: UseMutationOptions) => {
options.onSuccess(...onSuccessParameters);
}
},
...options,
});
return { ...response };
};
Expand Down Expand Up @@ -153,6 +153,7 @@ export const useShinkaiNodeSetOptionsMutation = (
options: shinkaiNodeOptions,
});
},
...options,
onSuccess: (...onSuccessParameters) => {
queryClient.invalidateQueries({
queryKey: ['shinkai_node_get_options'],
Expand All @@ -161,7 +162,6 @@ export const useShinkaiNodeSetOptionsMutation = (
options.onSuccess(...onSuccessParameters);
}
},
...options,
});
return { ...response };
};
Expand All @@ -174,6 +174,7 @@ export const useShinkaiNodeSetDefaultOptionsMutation = (
mutationFn: (): Promise<ShinkaiNodeOptions> => {
return invoke('shinkai_node_set_default_options', {});
},
...options,
onSuccess: (...onSuccessParameters) => {
queryClient.invalidateQueries({
queryKey: ['shinkai_node_set_default_options'],
Expand All @@ -182,7 +183,6 @@ export const useShinkaiNodeSetDefaultOptionsMutation = (
options.onSuccess(...onSuccessParameters);
}
},
...options,
});
return { ...response };
};
Expand All @@ -194,6 +194,7 @@ export const useShinkaiNodeRespawnMutation = (options?: UseMutationOptions) => {
await invoke('shinkai_node_kill');
await relaunch();
},
...options,
onSuccess: (...onSuccessParameters) => {
queryClient.invalidateQueries({
queryKey: ['shinkai_node_is_running'],
Expand All @@ -202,7 +203,6 @@ export const useShinkaiNodeRespawnMutation = (options?: UseMutationOptions) => {
options.onSuccess(...onSuccessParameters);
}
},
...options,
});
return { ...response };
};
76 changes: 43 additions & 33 deletions apps/shinkai-desktop/src/pages/get-started.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import { Link, useNavigate } from 'react-router-dom';

import { ResetStorageBeforeConnectConfirmationPrompt } from '../components/reset-storage-before-connect-confirmation-prompt';
import config from '../config';
import { useShinkaiNodeSpawnMutation } from '../lib/shinkai-node-manager/shinkai-node-manager-client';
import {
useShinkaiNodeKillMutation,
useShinkaiNodeRemoveStorageMutation,
useShinkaiNodeSpawnMutation,
} from '../lib/shinkai-node-manager/shinkai-node-manager-client';
import { ShinkaiNodeManagerEvent } from '../lib/shinkai-node-manager/shinkai-node-manager-client-types';
import { useShinkaiNodeEventsToast } from '../lib/shinkai-node-manager/shinkai-node-manager-hooks';
import { useAuth } from '../store/auth';
Expand Down Expand Up @@ -51,36 +55,36 @@ const GetStartedPage = () => {
},
});

const { mutateAsync: submitRegistrationNoCode } = useSubmitRegistrationNoCode(
{
onSuccess: (response, setupPayload) => {
if (response.status !== 'success') {
shinkaiNodeKill();
}
if (response.status === 'success' && encryptionKeys) {
const updatedSetupData = {
...encryptionKeys,
...setupPayload,
permission_type: '',
shinkai_identity:
setupDataForm.getValues().shinkai_identity ||
(response.data?.node_name ?? ''),
node_signature_pk: response.data?.identity_public_key ?? '',
node_encryption_pk: response.data?.encryption_public_key ?? '',
api_v2_key: response.data?.api_v2_key ?? '',
};
setAuth(updatedSetupData);
// Hide http subscription for now
// navigate('/connect-ai');
navigate('/ai-model-installation');
} else if (response.status === 'non-pristine') {
setResetStorageBeforeConnectConfirmationPrompt(true);
} else {
submitRegistrationNoCodeError();
}
},
const {
mutateAsync: submitRegistrationNoCode,
isPending: submitRegistrationNodeCodeIsPending,
} = useSubmitRegistrationNoCode({
onSuccess: (response, setupPayload) => {
if (response.status === 'success' && encryptionKeys) {
const updatedSetupData = {
...encryptionKeys,
...setupPayload,
permission_type: '',
shinkai_identity:
setupDataForm.getValues().shinkai_identity ||
(response.data?.node_name ?? ''),
node_signature_pk: response.data?.identity_public_key ?? '',
node_encryption_pk: response.data?.encryption_public_key ?? '',
api_v2_key: response.data?.api_v2_key ?? '',
};
setAuth(updatedSetupData);
// Hide http subscription for now
// navigate('/connect-ai');
navigate('/ai-model-installation');
} else if (response.status === 'non-pristine') {
setResetStorageBeforeConnectConfirmationPrompt(true);
} else {
submitRegistrationNoCodeError();
}
},
);
});
const { isPending: shinkaiNodeRemoveStorageIsPending } =
useShinkaiNodeRemoveStorageMutation();
const {
isPending: shinkaiNodeSpawnIsPending,
mutateAsync: shinkaiNodeSpawn,
Expand All @@ -89,7 +93,13 @@ const GetStartedPage = () => {
onSubmit(setupDataForm.getValues());
},
});
const { mutateAsync: shinkaiNodeKill } = useShinkaiNodeSpawnMutation();
const { isPending: shinkaiNodeKillIsPending } = useShinkaiNodeKillMutation();

const isStartLocalButtonLoading =
shinkaiNodeSpawnIsPending ||
shinkaiNodeKillIsPending ||
shinkaiNodeRemoveStorageIsPending ||
submitRegistrationNodeCodeIsPending;

async function onSubmit(currentValues: QuickConnectFormSchema) {
if (!encryptionKeys) return;
Expand Down Expand Up @@ -256,8 +266,8 @@ const GetStartedPage = () => {
<div className="space-y-4">
<Button
className="w-full"
disabled={shinkaiNodeSpawnIsPending}
isLoading={shinkaiNodeSpawnIsPending}
disabled={isStartLocalButtonLoading}
isLoading={isStartLocalButtonLoading}
onClick={() => shinkaiNodeSpawn()}
size="lg"
>
Expand Down