From dcf441586ce95aa2e3ed569f41459b2ac9b3faef Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Mon, 15 May 2023 16:53:42 -0700 Subject: [PATCH] app: land Tom's Cody-in-system-tray experiment (#51755) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I've revamped Tom's PR https://github.com/sourcegraph/sourcegraph/pull/51266 and updated the branch since there were quite a few conflicts that were a bit tedious to solve. I also fixed a good number of bugs. I think it would be worth merging this as-is, once CI passes, to avoid more merge conflicts and then we can continue to iterate on it. ## Test plan `sg start app` -> manually test the behavior from system tray --------- Signed-off-by: Stephen Gutekanst Co-authored-by: Tom Ross Co-authored-by: Juliana Peña --- client/web/BUILD.bazel | 1 + client/web/src/LegacyLayout.tsx | 16 +- client/web/src/cody/CodyStandalonePage.tsx | 61 ++++ client/web/src/cody/stores/chat.ts | 4 +- client/web/src/routes.constants.ts | 1 + client/web/src/routes.tsx | 9 + src-tauri/Cargo.lock | 310 +++++++++------------ src-tauri/Cargo.toml | 1 + src-tauri/src/cody.rs | 15 + src-tauri/src/common.rs | 10 +- src-tauri/src/main.rs | 34 ++- src-tauri/src/tray.rs | 15 +- 12 files changed, 281 insertions(+), 196 deletions(-) create mode 100644 client/web/src/cody/CodyStandalonePage.tsx create mode 100644 src-tauri/src/cody.rs diff --git a/client/web/BUILD.bazel b/client/web/BUILD.bazel index 339206cc8ea..cbbdfc1d113 100644 --- a/client/web/BUILD.bazel +++ b/client/web/BUILD.bazel @@ -184,6 +184,7 @@ ts_project( "src/codeintel/useCodeIntel.ts", "src/codeintel/useRepoAndBlob.ts", "src/codeintel/util/helpers.ts", + "src/cody/CodyStandalonePage.tsx", "src/cody/chat/CodyChatPage.tsx", "src/cody/chat/CodyPageIcon.tsx", "src/cody/chat/index.tsx", diff --git a/client/web/src/LegacyLayout.tsx b/client/web/src/LegacyLayout.tsx index 59af88f5e96..3e105a4bbd4 100644 --- a/client/web/src/LegacyLayout.tsx +++ b/client/web/src/LegacyLayout.tsx @@ -62,6 +62,7 @@ export const LegacyLayout: FC = props => { const isSearchNotebookListPage = location.pathname === EnterprisePageRoutes.Notebooks const isCodySearchPage = routeMatch === EnterprisePageRoutes.CodySearch const isRepositoryRelatedPage = routeMatch === PageRoutes.RepoContainer ?? false + const isCodyStandalonePage = location.pathname === PageRoutes.CodyStandalone // eslint-disable-next-line no-restricted-syntax const [wasSetupWizardSkipped] = useLocalStorage('setup.skipped', false) @@ -186,12 +187,19 @@ export const LegacyLayout: FC = props => { /> )} - - {!isSiteInit && !isSignInOrUp && !props.isSourcegraphDotCom && !disableFeedbackSurvey && ( - + {!isCodyStandalonePage && ( + )} + {!isSiteInit && + !isSignInOrUp && + !props.isSourcegraphDotCom && + !disableFeedbackSurvey && + !isCodyStandalonePage && } {props.isSourcegraphDotCom && props.authenticatedUser && } - {!isSiteInit && !isSignInOrUp && ( + {!isSiteInit && !isSignInOrUp && !isCodyStandalonePage && ( {} + +const REPOS_QUERY = gql` + query GetReposForCody { + repositories(first: 1000) { + nodes { + name + embeddingExists + } + } + } +` + +export const CodyStandalonePage: React.FunctionComponent = () => { + const { data } = useQuery(REPOS_QUERY, {}) + + const [selectedRepo, setSelectedRepo] = useState('github.com/sourcegraph/sourcegraph') + useChatStore({ codebase: selectedRepo, setIsCodySidebarOpen: noop }) + + const repos = data?.repositories.nodes ?? [] + + return ( +
+ + + invoke('hide_window')} /> +
+ ) +} diff --git a/client/web/src/cody/stores/chat.ts b/client/web/src/cody/stores/chat.ts index 3495e2119dc..6b0b2a24e05 100644 --- a/client/web/src/cody/stores/chat.ts +++ b/client/web/src/cody/stores/chat.ts @@ -239,7 +239,7 @@ export const useChatStoreState = create((set, get): CodyChatStore try { const client = await createClient({ - config, + config: { ...config, customHeaders: window.context.xhrHeaders }, editor, setMessageInProgress, initialTranscript, @@ -287,7 +287,7 @@ export const useChatStoreState = create((set, get): CodyChatStore try { const client = await createClient({ - config, + config: { ...config, customHeaders: window.context.xhrHeaders }, editor, setMessageInProgress, initialTranscript: transcript, diff --git a/client/web/src/routes.constants.ts b/client/web/src/routes.constants.ts index a533e084236..fa0c74257aa 100644 --- a/client/web/src/routes.constants.ts +++ b/client/web/src/routes.constants.ts @@ -23,6 +23,7 @@ export enum PageRoutes { InstallGitHubAppSuccess = '/install-github-app-success', Teams = '/teams/*', RequestAccess = '/request-access/*', + CodyStandalone = '/cody-standalone', } export enum EnterprisePageRoutes { diff --git a/client/web/src/routes.tsx b/client/web/src/routes.tsx index 657060bc47b..1aa56384ef4 100644 --- a/client/web/src/routes.tsx +++ b/client/web/src/routes.tsx @@ -33,6 +33,7 @@ const UserArea = lazyComponent(() => import('./user/area/UserArea'), 'UserArea') const SurveyPage = lazyComponent(() => import('./marketing/page/SurveyPage'), 'SurveyPage') const RepoContainer = lazyComponent(() => import('./repo/RepoContainer'), 'RepoContainer') const TeamsArea = lazyComponent(() => import('./team/TeamsArea'), 'TeamsArea') +const CodyStandalonePage = lazyComponent(() => import('./cody/CodyStandalonePage'), 'CodyStandalonePage') // Force a hard reload so that we delegate to the serverside HTTP handler for a route. const PassThroughToServer: React.FC = () => { @@ -155,6 +156,14 @@ export const routes: RouteObject[] = [ // expose this information in the handle object instead. handle: { isRepoContainer: true }, }, + ...(window.context.sourcegraphAppMode + ? [ + { + path: PageRoutes.CodyStandalone, + element: , + }, + ] + : []), ] function SearchConsolePageOrRedirect(props: LegacyLayoutRouteContext): JSX.Element { diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 5ce917a892a..f16f385fa5d 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -68,7 +68,8 @@ dependencies = [ "tauri-build", "tauri-plugin-deep-link", "tauri-plugin-log", - "tauri-utils 1.2.1 (git+https://github.com/tauri-apps/tauri?branch=dev)", + "tauri-plugin-positioner", + "tauri-utils 1.3.0 (git+https://github.com/tauri-apps/tauri?branch=dev)", ] [[package]] @@ -231,12 +232,12 @@ dependencies = [ [[package]] name = "cargo_toml" -version = "0.13.3" +version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497049e9477329f8f6a559972ee42e117487d01d1e8c2cc9f836ea6fa23a9e1a" +checksum = "7f83bc2e401ed041b7057345ebc488c005efa0341d5541ce7004d30458d0090b" dependencies = [ "serde", - "toml 0.5.11", + "toml 0.7.3", ] [[package]] @@ -251,16 +252,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" -[[package]] -name = "cfb" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74f89d248799e3f15f91b70917f65381062a01bb8e222700ea0e5a7ff9785f9c" -dependencies = [ - "byteorder", - "uuid 0.8.2", -] - [[package]] name = "cfb" version = "0.7.3" @@ -269,7 +260,7 @@ checksum = "d38f2da7a0a2c4ccf0065be06397cc26a81f4e528be095826eee9d4adbb8c60f" dependencies = [ "byteorder", "fnv", - "uuid 1.3.2", + "uuid", ] [[package]] @@ -550,43 +541,19 @@ dependencies = [ [[package]] name = "darling" -version = "0.13.4" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +checksum = "0558d22a7b463ed0241e993f76f09f30b126687447751a8638587b864e4b3944" dependencies = [ - "darling_core 0.13.4", - "darling_macro 0.13.4", -] - -[[package]] -name = "darling" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c99d16b88c92aef47e58dadd53e87b4bd234c29934947a6cec8b466300f99b" -dependencies = [ - "darling_core 0.20.0", - "darling_macro 0.20.0", + "darling_core", + "darling_macro", ] [[package]] name = "darling_core" -version = "0.13.4" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn 1.0.109", -] - -[[package]] -name = "darling_core" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ea05d2fcb27b53f7a98faddaf5f2914760330ab7703adfc9df13332b42189f9" +checksum = "ab8bfa2e259f8ee1ce5e97824a3c55ec4404a0d772ca7fa96bf19f0752a046eb" dependencies = [ "fnv", "ident_case", @@ -598,22 +565,11 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.13.4" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +checksum = "29a358ff9f12ec09c3e61fef9b5a9902623a695a46a917b07f269bff1445611a" dependencies = [ - "darling_core 0.13.4", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "darling_macro" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bfb82b62b1b8a2a9808fb4caf844ede819a76cfc23b2827d7f94eefb49551eb" -dependencies = [ - "darling_core 0.20.0", + "darling_core", "quote", "syn 2.0.15", ] @@ -710,6 +666,19 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" +[[package]] +name = "embed-resource" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80663502655af01a2902dff3f06869330782267924bf1788410b74edcd93770a" +dependencies = [ + "cc", + "rustc_version", + "toml 0.7.3", + "vswhom", + "winreg 0.11.0", +] + [[package]] name = "embed_plist" version = "1.2.2" @@ -1368,22 +1337,13 @@ dependencies = [ "serde", ] -[[package]] -name = "infer" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20b2b533137b9cad970793453d4f921c2e91312a6d88b1085c07bc15fc51bb3b" -dependencies = [ - "cfb 0.6.1", -] - [[package]] name = "infer" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a898e4b7951673fce96614ce5751d13c40fc5674bc2d759288e46c3ab62598b3" dependencies = [ - "cfb 0.7.3", + "cfb", ] [[package]] @@ -1483,17 +1443,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "json-patch" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3fa5a61630976fc4c353c70297f2e93f1930e3ccee574d59d618ccbd5154ce" -dependencies = [ - "serde", - "serde_json", - "treediff 3.0.2", -] - [[package]] name = "json-patch" version = "1.0.0" @@ -1503,7 +1452,7 @@ dependencies = [ "serde", "serde_json", "thiserror", - "treediff 4.0.2", + "treediff", ] [[package]] @@ -1584,9 +1533,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b64f40e5e03e0d54f03845c8197d0291253cdbedfb1cb46b13c2c117554a9f4c" +checksum = "ece97ea872ece730aed82664c424eb4c8291e1ff2480247ccf7409044bc6479f" [[package]] name = "lock_api" @@ -2083,9 +2032,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "plist" @@ -2379,9 +2328,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.18" +version = "0.37.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bbfc1d1c7c40c01715f47d71444744a81669ca84e8b63e25a55e169b1f86433" +checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" dependencies = [ "bitflags", "errno", @@ -2516,16 +2465,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde_with" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff" -dependencies = [ - "serde", - "serde_with_macros 1.5.2", -] - [[package]] name = "serde_with" version = "2.3.3" @@ -2538,29 +2477,17 @@ dependencies = [ "indexmap", "serde", "serde_json", - "serde_with_macros 2.3.3", + "serde_with_macros", "time", ] -[[package]] -name = "serde_with_macros" -version = "1.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082" -dependencies = [ - "darling 0.13.4", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "serde_with_macros" version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "881b6f881b17d13214e5d494c939ebab463d01264ce1811e9d4ac3a882e7695f" dependencies = [ - "darling 0.20.0", + "darling", "proc-macro2", "quote", "syn 2.0.15", @@ -2829,7 +2756,7 @@ dependencies = [ "serde", "tao-macros", "unicode-segmentation", - "uuid 1.3.2", + "uuid", "windows 0.39.0", "windows-implement", "x11-dl", @@ -2865,8 +2792,8 @@ checksum = "fd1ba337640d60c3e96bc6f0638a939b9c9a7f2c316a1598c279828b3d1dc8c5" [[package]] name = "tauri" -version = "1.2.4" -source = "git+https://github.com/tauri-apps/tauri?branch=dev#e8e214b72ede33ca2cc09fa41a8baf56fa7e8b8e" +version = "1.3.0" +source = "git+https://github.com/tauri-apps/tauri?branch=dev#6a6b1388ea5787aea4c0e0b0701a4772087bbc0f" dependencies = [ "anyhow", "cocoa", @@ -2901,12 +2828,12 @@ dependencies = [ "tauri-macros", "tauri-runtime", "tauri-runtime-wry", - "tauri-utils 1.2.1 (git+https://github.com/tauri-apps/tauri?branch=dev)", + "tauri-utils 1.3.0 (git+https://github.com/tauri-apps/tauri?branch=dev)", "tempfile", "thiserror", "tokio", "url", - "uuid 1.3.2", + "uuid", "webkit2gtk", "webview2-com", "windows 0.39.0", @@ -2914,29 +2841,31 @@ dependencies = [ [[package]] name = "tauri-build" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8807c85d656b2b93927c19fe5a5f1f1f348f96c2de8b90763b3c2d561511f9b4" +checksum = "929b3bd1248afc07b63e33a6a53c3f82c32d0b0a5e216e4530e94c467e019389" dependencies = [ "anyhow", "cargo_toml", "heck 0.4.1", - "json-patch 0.2.7", + "json-patch", "semver", + "serde", "serde_json", - "tauri-utils 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winres", + "tauri-utils 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tauri-winres", + "winnow", ] [[package]] name = "tauri-codegen" -version = "1.2.1" -source = "git+https://github.com/tauri-apps/tauri?branch=dev#e8e214b72ede33ca2cc09fa41a8baf56fa7e8b8e" +version = "1.3.0" +source = "git+https://github.com/tauri-apps/tauri?branch=dev#6a6b1388ea5787aea4c0e0b0701a4772087bbc0f" dependencies = [ "base64 0.21.0", "brotli", "ico", - "json-patch 1.0.0", + "json-patch", "plist", "png", "proc-macro2", @@ -2946,24 +2875,24 @@ dependencies = [ "serde", "serde_json", "sha2", - "tauri-utils 1.2.1 (git+https://github.com/tauri-apps/tauri?branch=dev)", + "tauri-utils 1.3.0 (git+https://github.com/tauri-apps/tauri?branch=dev)", "thiserror", "time", - "uuid 1.3.2", + "uuid", "walkdir", ] [[package]] name = "tauri-macros" -version = "1.2.1" -source = "git+https://github.com/tauri-apps/tauri?branch=dev#e8e214b72ede33ca2cc09fa41a8baf56fa7e8b8e" +version = "1.3.0" +source = "git+https://github.com/tauri-apps/tauri?branch=dev#6a6b1388ea5787aea4c0e0b0701a4772087bbc0f" dependencies = [ "heck 0.4.1", "proc-macro2", "quote", "syn 1.0.109", "tauri-codegen", - "tauri-utils 1.2.1 (git+https://github.com/tauri-apps/tauri?branch=dev)", + "tauri-utils 1.3.0 (git+https://github.com/tauri-apps/tauri?branch=dev)", ] [[package]] @@ -2976,15 +2905,15 @@ dependencies = [ "log", "objc2", "once_cell", - "tauri-utils 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tauri-utils 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "windows-sys 0.48.0", - "winreg", + "winreg 0.50.0", ] [[package]] name = "tauri-plugin-log" version = "0.0.0" -source = "git+https://github.com/tauri-apps/plugins-workspace?branch=dev#d02432df065eaf9510d08f67bcff90cf618b6098" +source = "git+https://github.com/tauri-apps/plugins-workspace?branch=dev#dce0f02bc571128308c30278cde3233f341e6a50" dependencies = [ "byte-unit", "fern", @@ -2996,10 +2925,23 @@ dependencies = [ "time", ] +[[package]] +name = "tauri-plugin-positioner" +version = "1.0.4" +source = "git+https://github.com/tauri-apps/plugins-workspace?branch=dev#dce0f02bc571128308c30278cde3233f341e6a50" +dependencies = [ + "log", + "serde", + "serde_json", + "serde_repr", + "tauri", + "thiserror", +] + [[package]] name = "tauri-runtime" -version = "0.12.1" -source = "git+https://github.com/tauri-apps/tauri?branch=dev#e8e214b72ede33ca2cc09fa41a8baf56fa7e8b8e" +version = "0.13.0" +source = "git+https://github.com/tauri-apps/tauri?branch=dev#6a6b1388ea5787aea4c0e0b0701a4772087bbc0f" dependencies = [ "gtk", "http", @@ -3008,18 +2950,18 @@ dependencies = [ "raw-window-handle", "serde", "serde_json", - "tauri-utils 1.2.1 (git+https://github.com/tauri-apps/tauri?branch=dev)", + "tauri-utils 1.3.0 (git+https://github.com/tauri-apps/tauri?branch=dev)", "thiserror", "url", - "uuid 1.3.2", + "uuid", "webview2-com", "windows 0.39.0", ] [[package]] name = "tauri-runtime-wry" -version = "0.12.2" -source = "git+https://github.com/tauri-apps/tauri?branch=dev#e8e214b72ede33ca2cc09fa41a8baf56fa7e8b8e" +version = "0.13.0" +source = "git+https://github.com/tauri-apps/tauri?branch=dev#6a6b1388ea5787aea4c0e0b0701a4772087bbc0f" dependencies = [ "cocoa", "gtk", @@ -3027,8 +2969,8 @@ dependencies = [ "rand 0.8.5", "raw-window-handle", "tauri-runtime", - "tauri-utils 1.2.1 (git+https://github.com/tauri-apps/tauri?branch=dev)", - "uuid 1.3.2", + "tauri-utils 1.3.0 (git+https://github.com/tauri-apps/tauri?branch=dev)", + "uuid", "webkit2gtk", "webview2-com", "windows 0.39.0", @@ -3037,16 +2979,16 @@ dependencies = [ [[package]] name = "tauri-utils" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5abbc109a6eb45127956ffcc26ef0e875d160150ac16cfa45d26a6b2871686f1" +checksum = "5a6f9c2dafef5cbcf52926af57ce9561bd33bb41d7394f8bb849c0330260d864" dependencies = [ "ctor", "glob", "heck 0.4.1", "html5ever", - "infer 0.7.0", - "json-patch 0.2.7", + "infer", + "json-patch", "kuchiki", "memchr", "phf 0.10.1", @@ -3055,7 +2997,7 @@ dependencies = [ "semver", "serde", "serde_json", - "serde_with 1.14.0", + "serde_with", "thiserror", "url", "walkdir", @@ -3064,16 +3006,16 @@ dependencies = [ [[package]] name = "tauri-utils" -version = "1.2.1" -source = "git+https://github.com/tauri-apps/tauri?branch=dev#e8e214b72ede33ca2cc09fa41a8baf56fa7e8b8e" +version = "1.3.0" +source = "git+https://github.com/tauri-apps/tauri?branch=dev#6a6b1388ea5787aea4c0e0b0701a4772087bbc0f" dependencies = [ "brotli", "ctor", "glob", "heck 0.4.1", "html5ever", - "infer 0.12.0", - "json-patch 1.0.0", + "infer", + "json-patch", "kuchiki", "memchr", "phf 0.10.1", @@ -3082,13 +3024,23 @@ dependencies = [ "semver", "serde", "serde_json", - "serde_with 2.3.3", + "serde_with", "thiserror", "url", "walkdir", "windows 0.39.0", ] +[[package]] +name = "tauri-winres" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5993dc129e544393574288923d1ec447c857f3f644187f4fbf7d9a875fbfc4fb" +dependencies = [ + "embed-resource", + "toml 0.7.3", +] + [[package]] name = "tempfile" version = "3.5.0" @@ -3309,15 +3261,6 @@ dependencies = [ "tracing-log", ] -[[package]] -name = "treediff" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "761e8d5ad7ce14bb82b7e61ccc0ca961005a275a060b9644a2431aa11553c2ff" -dependencies = [ - "serde_json", -] - [[package]] name = "treediff" version = "4.0.2" @@ -3396,12 +3339,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" -[[package]] -name = "uuid" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" - [[package]] name = "uuid" version = "1.3.2" @@ -3445,6 +3382,26 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "vswhom" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be979b7f07507105799e854203b470ff7c78a1639e330a58f183b5fea574608b" +dependencies = [ + "libc", + "vswhom-sys", +] + +[[package]] +name = "vswhom-sys" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3b17ae1f6c8a2b28506cd96d412eebf83b4a0ff2cbefeeb952f2f9dfa44ba18" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "vte" version = "0.10.1" @@ -3957,13 +3914,23 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "winnow" -version = "0.4.5" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69af645a61644c6dd379ade8b77cc87efb5393c988707bad12d3c8e00c50f669" +checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28" dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76a1a57ff50e9b408431e8f97d5456f2807f8eb2a2cd79b06068fc87f8ecf189" +dependencies = [ + "cfg-if", + "winapi", +] + [[package]] name = "winreg" version = "0.50.0" @@ -3974,15 +3941,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "winres" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b68db261ef59e9e52806f688020631e987592bd83619edccda9c47d42cde4f6c" -dependencies = [ - "toml 0.5.11", -] - [[package]] name = "wry" version = "0.24.1" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 85aa2c30a8b..b572b9897f3 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -27,6 +27,7 @@ log = "0.4.17" serde = { version = "1.0", features = ["derive"] } tauri-plugin-log = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" } tauri-plugin-deep-link = { git = "https://github.com/FabianLars/tauri-plugin-deep-link", branch = "main" } +tauri-plugin-positioner = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev", features = ["system-tray"] } tauri-utils = { git = "https://github.com/tauri-apps/tauri", branch = "dev" } [dependencies.tauri] diff --git a/src-tauri/src/cody.rs b/src-tauri/src/cody.rs new file mode 100644 index 00000000000..9b587d1884c --- /dev/null +++ b/src-tauri/src/cody.rs @@ -0,0 +1,15 @@ +use tauri::{WindowBuilder, WindowUrl}; +use tauri_plugin_positioner::{Position, WindowExt}; + +pub fn init_cody_window(handle: &tauri::AppHandle) { + let app = handle.clone(); + tauri::async_runtime::spawn(async move { + let cody_win = WindowBuilder::new(&app, "cody", WindowUrl::App("/cody-standalone".into())) + .title("Cody") + .fullscreen(false) + .inner_size(480.0, 720.0) + .always_on_top(false); + + cody_win.build().unwrap().move_window(Position::TopRight); + }); +} diff --git a/src-tauri/src/common.rs b/src-tauri/src/common.rs index b09dec26848..549146d73d4 100644 --- a/src-tauri/src/common.rs +++ b/src-tauri/src/common.rs @@ -1,10 +1,12 @@ use tauri::AppHandle; use tauri::Manager; -pub fn show_window(app: &AppHandle) { - let window = app.get_window("main").unwrap(); - window.show().unwrap(); - window.set_focus().unwrap(); +pub fn show_window(app: &AppHandle, label: &str) { + let window = app.get_window(label).unwrap(); + if !window.is_visible().unwrap() { + window.show().unwrap() + } + window.set_focus().unwrap() } /// Extracts the path from a URL that starts with the scheme followed by `://`. diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index e65ef4e4cc2..0e56e740b75 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -7,6 +7,7 @@ use {tauri::api::process::Command, tauri::api::process::CommandEvent}; mod common; +mod cody; mod tray; use common::{extract_path_from_scheme_url, show_window}; use std::sync::RwLock; @@ -20,10 +21,18 @@ use common::is_scheme_url; static LAUNCH_PATH: RwLock = RwLock::new(String::new()); #[tauri::command] -fn get_launch_path() -> String { +fn get_launch_path(window: tauri::Window) -> String { + if window.label() == "cody" { + return "/cody-standalone".to_string(); + } LAUNCH_PATH.read().unwrap().clone() } +#[tauri::command] +fn hide_window(app: tauri::AppHandle, window: tauri::Window) { + window.hide().unwrap(); +} + fn set_launch_path(url: String) { *LAUNCH_PATH.write().unwrap() = url; } @@ -48,7 +57,7 @@ fn main() { let scope = RemoteDomainAccessScope { scheme: Some("http".to_string()), domain: "localhost".to_string(), - windows: vec!["main".to_string()], + windows: vec!["main".to_string(), "cody".to_string()], plugins: vec![], enable_tauri_api: true, }; @@ -62,11 +71,16 @@ fn main() { tauri::Builder::default() .system_tray(tray) .on_system_tray_event(tray::on_system_tray_event) + .on_system_tray_event(|app, event| { + tauri_plugin_positioner::on_tray_event(app, &event); + }) .on_window_event(|event| match event.event() { tauri::WindowEvent::CloseRequested { api, .. } => { // Ensure the app stays open after the last window is closed. - event.window().hide().unwrap(); - api.prevent_close(); + if event.window().label() == "main" { + event.window().hide().unwrap(); + api.prevent_close(); + } } _ => {} }) @@ -79,11 +93,13 @@ fn main() { .level(log::LevelFilter::Info) .build(), ) + .plugin(tauri_plugin_positioner::init()) .setup(|app| { start_embedded_services(); - // Register handler for sourcegraph:// scheme urls. let handle = app.handle(); + + // Register handler for sourcegraph:// scheme urls. tauri_plugin_deep_link::register(SCHEME, move |request| { let path: &str = extract_path_from_scheme_url(&request, SCHEME); @@ -102,7 +118,7 @@ fn main() { .unwrap() .eval(&format!("window.location.href = '{}'", path)) .unwrap(); - show_window(&handle); + show_window(&handle, "main"); }) .unwrap(); @@ -116,7 +132,6 @@ fn main() { set_launch_path(url) } } - Ok(()) }) // Define a handler so that invoke("get_launch_scheme_url") can be @@ -124,7 +139,10 @@ fn main() { // its name which may suggest that it invokes something, actually only // *defines* an invoke() handler and does not invoke anything during // setup here.) - .invoke_handler(tauri::generate_handler![get_launch_path]) + .invoke_handler(tauri::generate_handler![ + get_launch_path, + hide_window, + ]) .run(context) .expect("error while running tauri application"); } diff --git a/src-tauri/src/tray.rs b/src-tauri/src/tray.rs index 0b014131289..0bb1c78ed70 100644 --- a/src-tauri/src/tray.rs +++ b/src-tauri/src/tray.rs @@ -1,9 +1,11 @@ +use crate::cody::init_cody_window; use crate::common::show_window; use tauri::api::shell; use tauri::{ AppHandle, CustomMenuItem, Manager, SystemTray, SystemTrayEvent, SystemTrayMenu, SystemTrayMenuItem, }; +use tauri_plugin_positioner::{Position, WindowExt}; pub fn create_system_tray() -> SystemTray { SystemTray::new().with_menu(create_system_tray_menu()) @@ -15,6 +17,7 @@ fn create_system_tray_menu() -> SystemTrayMenu { "open".to_string(), "Open Sourcegraph App", )) + .add_item(CustomMenuItem::new("cody".to_string(), "Show Cody")) .add_native_item(SystemTrayMenuItem::Separator) .add_item( CustomMenuItem::new("settings".to_string(), "Settings").accelerator("CmdOrCtrl+,"), @@ -36,11 +39,19 @@ fn create_system_tray_menu() -> SystemTrayMenu { pub fn on_system_tray_event(app: &AppHandle, event: SystemTrayEvent) { if let SystemTrayEvent::MenuItemClick { id, .. } = event { match id.as_str() { - "open" => show_window(app), + "open" => show_window(app, "main"), + "cody" => { + let win = app.get_window("cody"); + if win.is_none() { + init_cody_window(app); + } else { + show_window(app, "cody") + } + } "settings" => { let window = app.get_window("main").unwrap(); window.eval("window.location.href = '/settings'").unwrap(); - show_window(app); + show_window(app, "main"); } "troubleshoot" => { let log_dir_path = app.path_resolver().app_log_dir().unwrap();