Skip to content

Commit

Permalink
Show tauri notification when repositories are first synced (BloopAI#252)
Browse files Browse the repository at this point in the history
* show tauri notification when repositories are first synced

* roll back manual check for updates
  • Loading branch information
anastasiya1155 authored Mar 17, 2023
1 parent 5b450df commit 8e97e00
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tauri-build = { version = "1.2.1", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.2.4", features = ["dialog-open", "fs-all", "http-all", "native-tls-vendored", "os-all", "path-all", "shell-all", "updater", "window-all", "process-all"] }
tauri = { version = "1.2.4", features = ["dialog-all", "fs-all", "http-all", "native-tls-vendored", "os-all", "path-all", "shell-all", "updater", "window-all", "process-all"] }
bleep = { path = "../../../server/bleep", package = "bleep" }
anyhow = "1.0.68"
tokio = { version = "1.24.2", features = ["rt-multi-thread"] }
Expand Down
4 changes: 2 additions & 2 deletions apps/desktop/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"all": true
},
"dialog": {
"open": true
"all": true
},
"http": {
"all": true
Expand Down Expand Up @@ -84,7 +84,7 @@
"endpoints": [
"https://api.bloop.ai/releases/{{target}}/{{current_version}}"
],
"dialog": false,
"dialog": true,
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDNGQkQ2RjRBNEM3OURFQ0IKUldUTDNubE1TbSs5UDVIMms5dTU2cVk4cGt4Zzl3bkRXU2UvSzliZktUQTQ5TXFWcmpwb1RvYXMK"
},
"windows": [
Expand Down
11 changes: 6 additions & 5 deletions apps/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ function App() {
]).then(([arch, type, platform, version, appVersion]) => {
setOs({ arch, type, platform, version });
setRelease(appVersion);
checkUpdateAndInstall(appVersion);
intervalId = window.setInterval(
() => checkUpdateAndInstall(appVersion),
1000 * 60 * 60,
);
// checkUpdateAndInstall(appVersion);
// intervalId = window.setInterval(
// () => checkUpdateAndInstall(appVersion),
// 1000 * 60 * 60,
// );
});
if (import.meta.env.SENTRY_DSN_BE) {
invoke('initialize_sentry', {
Expand Down Expand Up @@ -138,6 +138,7 @@ function App() {
isRepoManagementAllowed: true,
forceAnalytics: false,
isSelfServe: false,
showNativeMessage: message,
}),
[homeDirectory, indexFolder, deviceId, os, release],
);
Expand Down
2 changes: 2 additions & 0 deletions client/src/context/deviceContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type DeviceContextType = {
isRepoManagementAllowed: boolean;
forceAnalytics: boolean;
isSelfServe: boolean;
showNativeMessage: (m: string, options?: any) => Promise<void> | void;
};

export const DeviceContext = createContext<DeviceContextType>({
Expand All @@ -47,4 +48,5 @@ export const DeviceContext = createContext<DeviceContextType>({
isRepoManagementAllowed: true,
forceAnalytics: false,
isSelfServe: false,
showNativeMessage: () => Promise.resolve(),
});
1 change: 1 addition & 0 deletions client/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
isRepoManagementAllowed: true,
isSelfServe: true,
forceAnalytics: true,
showNativeMessage: alert,
}}
/>
</React.StrictMode>,
Expand Down
4 changes: 4 additions & 0 deletions client/src/pages/Home/Onboarding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React, {
} from 'react';
import { UIContext } from '../../../context/uiContext';
import { DeviceContext } from '../../../context/deviceContext';
import { repositoriesSyncCache } from '../../../services/cache';
import DataFormStep from './DataFormStep';
import FolderSelectStep from './FolderSelectStep';
import LocalReposStep from './LocalReposStep';
Expand Down Expand Up @@ -39,6 +40,9 @@ const Onboarding = ({ onFinish }: Props) => {
useEffect(() => {
if (isSelfServe ? step === 1 : step === Steps.FINISHED) {
onFinish();
if (!isSelfServe) {
repositoriesSyncCache.shouldNotifyWhenDone = true;
}
}
}, [step, isSelfServe]);

Expand Down
23 changes: 22 additions & 1 deletion client/src/pages/Home/ReposSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { RepositoriesContext } from '../../../context/repositoriesContext';
import { DeviceContext } from '../../../context/deviceContext';
import { SettingSections } from '../../../components/Settings';
import RepoCardSkeleton from '../../../components/RepoCard/RepoCardSkeleton';
import { repositoriesSyncCache } from '../../../services/cache';

type Props = {
filter: ReposFilter;
Expand Down Expand Up @@ -102,7 +103,8 @@ const filterRepositories = (filter: ReposFilter, repos?: RepoType[]) => {

const ReposSection = ({ filter, emptyRepos }: Props) => {
const { setSettingsSection, setSettingsOpen } = useContext(UIContext);
const { isRepoManagementAllowed, isSelfServe } = useContext(DeviceContext);
const { isRepoManagementAllowed, isSelfServe, showNativeMessage } =
useContext(DeviceContext);
const { setRepositories, repositories } = useContext(RepositoriesContext);
const [reposToShow, setReposToShow] = useState<RepoType[]>(
filterRepositories(filter, repositories),
Expand Down Expand Up @@ -130,6 +132,25 @@ const ReposSection = ({ filter, emptyRepos }: Props) => {
setReposToShow(filterRepositories(filter, repositories));
}, [filter, repositories]);

useEffect(() => {
if (repositoriesSyncCache.shouldNotifyWhenDone) {
if (
repositories?.find((r) => r.sync_status === SyncStatus.Done) &&
repositories?.every(
(r) =>
r.sync_status === SyncStatus.Done ||
r.sync_status === SyncStatus.Uninitialized,
)
) {
showNativeMessage(
'All repositories are now indexed and ready for search!',
{ title: 'Ready to search!' },
);
repositoriesSyncCache.shouldNotifyWhenDone = false;
}
}
}, [repositories]);

return (
<div className="p-8 flex-1 overflow-x-auto mx-auto max-w-6.5xl box-content relative">
<div className="flex items-center justify-between">
Expand Down
3 changes: 3 additions & 0 deletions client/src/services/cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const repositoriesSyncCache = {
shouldNotifyWhenDone: false,
};

0 comments on commit 8e97e00

Please sign in to comment.