Skip to content

Commit bc4bbb6

Browse files
committed
Portin stuff
1 parent 98513c9 commit bc4bbb6

File tree

23 files changed

+412
-347
lines changed

23 files changed

+412
-347
lines changed

apps/buzz/dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ async function main() {
188188
log('\n⚡ Starting Electron app...', colors.green);
189189

190190
// Start the electron app
191-
electronProcess = spawnProcess('web', ['.'], buzzDir);
191+
electronProcess = spawnProcess('electron', ['.'], buzzDir);
192192

193193
electronProcess.on('close', (code) => {
194194
log(`Electron app exited with code ${code}`, colors.yellow);

apps/buzz/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { app, BrowserWindow, dialog, ipcMain } from 'web';
1+
import { app, BrowserWindow, dialog, ipcMain } from 'electron';
22
import path from 'path';
33

44
function createWindow() {

apps/buzz/src/preload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { contextBridge, ipcRenderer } from 'web';
1+
import { contextBridge, ipcRenderer } from 'electron';
22

33
contextBridge.exposeInMainWorld('electronAPI', {
44
openDirectory: async () => await ipcRenderer.invoke('dialog:openDirectory')

crates/but-interface/src/commands/cli.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
//! In place of commands.rs
22
use std::path::Path;
33

4-
use anyhow::{anyhow, bail, Context};
5-
use serde::Deserialize;
4+
use anyhow::{Context, anyhow, bail};
65

7-
use crate::{IpcContext, error::Error};
6+
use crate::{IpcContext, NoParams, error::Error};
87

98
fn get_cli_path() -> anyhow::Result<std::path::PathBuf> {
109
let cli_path = std::env::current_exe()?;
@@ -15,7 +14,8 @@ fn do_install_cli() -> anyhow::Result<()> {
1514
let cli_path = get_cli_path()?;
1615
if cfg!(windows) {
1716
bail!(
18-
"CLI installation is not supported on Windows. Please install manually by placing '{}' in PATH.", cli_path.display()
17+
"CLI installation is not supported on Windows. Please install manually by placing '{}' in PATH.",
18+
cli_path.display()
1919
);
2020
}
2121

@@ -84,17 +84,11 @@ fn do_install_cli() -> anyhow::Result<()> {
8484
}
8585
}
8686

87-
pub fn install_cli(
88-
_ipc_ctx: &IpcContext,
89-
_params: (),
90-
) -> Result<(), Error> {
87+
pub fn install_cli(_ipc_ctx: &IpcContext, _params: NoParams) -> Result<(), Error> {
9188
do_install_cli().map_err(Error::from)
9289
}
9390

94-
pub fn cli_path(
95-
_ipc_ctx: &IpcContext,
96-
_params: (),
97-
) -> Result<String, Error> {
91+
pub fn cli_path(_ipc_ctx: &IpcContext, _params: NoParams) -> Result<String, Error> {
9892
let cli_path = get_cli_path()?;
9993
if !cli_path.exists() {
10094
return Err(anyhow::anyhow!(

crates/but-interface/src/commands/git.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use gitbutler_repo::RepositoryExt as _;
88
use gitbutler_repo_actions::RepoActionsExt as _;
99
use serde::Deserialize;
1010

11+
use crate::NoParams;
1112
use crate::error::ToError as _;
1213
use crate::{IpcContext, error::Error};
1314

@@ -89,7 +90,7 @@ pub fn git_head(ipc_ctx: &IpcContext, params: GitHeadParams) -> Result<String, E
8990
Ok(head.name().unwrap().to_string())
9091
}
9192

92-
pub fn delete_all_data(_ipc_ctx: &IpcContext, _params: ()) -> Result<(), Error> {
93+
pub fn delete_all_data(_ipc_ctx: &IpcContext, _params: NoParams) -> Result<(), Error> {
9394
for project in gitbutler_project::list().context("failed to list projects")? {
9495
gitbutler_project::delete(project.id)
9596
.map_err(|err| err.context("failed to delete project"))?;

crates/but-interface/src/commands/github.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use anyhow::{Context, Result};
33
use serde::{Deserialize, Serialize};
44
use std::collections::HashMap;
55

6-
use crate::{IpcContext, error::Error};
6+
use crate::{IpcContext, NoParams, error::Error};
77

88
#[derive(Debug, Deserialize, Serialize, Clone, Default)]
99
pub struct Verification {
@@ -13,10 +13,15 @@ pub struct Verification {
1313

1414
pub async fn init_device_oauth(
1515
ipc_ctx: &IpcContext,
16-
_params: (),
16+
_params: NoParams,
1717
) -> Result<Verification, Error> {
1818
let mut req_body = HashMap::new();
19-
let client_id = ipc_ctx.app_settings.get()?.github_oauth_app.oauth_client_id.clone();
19+
let client_id = ipc_ctx
20+
.app_settings
21+
.get()?
22+
.github_oauth_app
23+
.oauth_client_id
24+
.clone();
2025
req_body.insert("client_id", client_id.as_str());
2126
req_body.insert("scope", "repo");
2227

@@ -58,7 +63,12 @@ pub async fn check_auth_status(
5863
}
5964

6065
let mut req_body = HashMap::new();
61-
let client_id = ipc_ctx.app_settings.get()?.github_oauth_app.oauth_client_id.clone();
66+
let client_id = ipc_ctx
67+
.app_settings
68+
.get()?
69+
.github_oauth_app
70+
.oauth_client_id
71+
.clone();
6272
req_body.insert("client_id", client_id.as_str());
6373
req_body.insert("device_code", params.device_code.as_str());
6474
req_body.insert("grant_type", "urn:ietf:params:oauth:grant-type:device_code");

crates/but-interface/src/commands/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod git;
77
pub mod github;
88
pub mod modes;
99
pub mod open;
10+
pub mod projects;
1011
pub mod remotes;
1112
pub mod repo;
1213
pub mod rules;
@@ -17,3 +18,4 @@ pub mod undo;
1718
pub mod users;
1819
pub mod virtual_branches;
1920
pub mod workspace;
21+
pub mod zip;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use crate::{IpcContext, error::Error};
2+
use gitbutler_project::{self as projects, ProjectId};
3+
use std::path::PathBuf;
4+
use serde::Deserialize;
5+
6+
#[derive(Deserialize)]
7+
#[serde(rename_all = "camelCase")]
8+
pub struct UpdateProjectParams {
9+
pub project: projects::UpdateRequest,
10+
}
11+
12+
pub fn update_project(
13+
_ipc_ctx: &IpcContext,
14+
params: UpdateProjectParams,
15+
) -> Result<projects::Project, Error> {
16+
Ok(gitbutler_project::update(&params.project)?)
17+
}
18+
19+
#[derive(Deserialize)]
20+
#[serde(rename_all = "camelCase")]
21+
pub struct AddProjectParams {
22+
pub path: PathBuf,
23+
}
24+
25+
pub fn add_project(
26+
ipc_ctx: &IpcContext,
27+
params: AddProjectParams,
28+
) -> Result<projects::Project, Error> {
29+
let user = ipc_ctx.user_controller.get_user()?;
30+
let name = user.as_ref().and_then(|u| u.name.clone());
31+
let email = user.as_ref().and_then(|u| u.email.clone());
32+
Ok(gitbutler_project::add(&params.path, name, email)?)
33+
}
34+
35+
#[derive(Deserialize)]
36+
#[serde(rename_all = "camelCase")]
37+
pub struct GetProjectParams {
38+
pub project_id: ProjectId,
39+
pub no_validation: Option<bool>,
40+
}
41+
42+
pub fn get_project(
43+
_ipc_ctx: &IpcContext,
44+
params: GetProjectParams,
45+
) -> Result<projects::Project, Error> {
46+
if params.no_validation.unwrap_or(false) {
47+
Ok(gitbutler_project::get_raw(params.project_id)?)
48+
} else {
49+
Ok(gitbutler_project::get_validated(params.project_id)?)
50+
}
51+
}
52+
53+
#[derive(Deserialize)]
54+
#[serde(rename_all = "camelCase")]
55+
pub struct DeleteProjectParams {
56+
pub project_id: ProjectId,
57+
}
58+
59+
pub fn delete_project(
60+
_ipc_ctx: &IpcContext,
61+
params: DeleteProjectParams,
62+
) -> Result<(), Error> {
63+
gitbutler_project::delete(params.project_id).map_err(Into::into)
64+
}

crates/but-interface/src/commands/settings.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
//! In place of commands.rs
2-
use but_settings::api::{FeatureFlagsUpdate, TelemetryUpdate};
32
use but_settings::AppSettings;
3+
use but_settings::api::{FeatureFlagsUpdate, TelemetryUpdate};
44
use serde::Deserialize;
55

6+
use crate::NoParams;
67
use crate::{IpcContext, error::Error};
78

8-
pub fn get_app_settings(
9-
ipc_ctx: &IpcContext,
10-
_params: (),
11-
) -> Result<AppSettings, Error> {
9+
pub fn get_app_settings(ipc_ctx: &IpcContext, _params: NoParams) -> Result<AppSettings, Error> {
1210
Ok(ipc_ctx.app_settings.get()?.clone())
1311
}
1412

@@ -34,11 +32,11 @@ pub struct UpdateTelemetryParams {
3432
pub update: TelemetryUpdate,
3533
}
3634

37-
pub fn update_telemetry(
38-
ipc_ctx: &IpcContext,
39-
params: UpdateTelemetryParams,
40-
) -> Result<(), Error> {
41-
ipc_ctx.app_settings.update_telemetry(params.update).map_err(|e| e.into())
35+
pub fn update_telemetry(ipc_ctx: &IpcContext, params: UpdateTelemetryParams) -> Result<(), Error> {
36+
ipc_ctx
37+
.app_settings
38+
.update_telemetry(params.update)
39+
.map_err(|e| e.into())
4240
}
4341

4442
#[derive(Deserialize)]
@@ -67,5 +65,8 @@ pub fn update_feature_flags(
6765
ipc_ctx: &IpcContext,
6866
params: UpdateFeatureFlagsParams,
6967
) -> Result<(), Error> {
70-
ipc_ctx.app_settings.update_feature_flags(params.update).map_err(|e| e.into())
71-
}
68+
ipc_ctx
69+
.app_settings
70+
.update_feature_flags(params.update)
71+
.map_err(|e| e.into())
72+
}

crates/but-interface/src/commands/users.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use anyhow::Result;
22
use gitbutler_user::User;
33
use serde::{Deserialize, Serialize};
44

5-
use crate::{IpcContext, error::Error};
5+
use crate::{IpcContext, NoParams, error::Error};
66

77
#[derive(Deserialize)]
88
#[serde(rename_all = "camelCase")]
@@ -62,7 +62,7 @@ impl TryFrom<User> for UserWithSecrets {
6262
}
6363
}
6464

65-
pub fn get_user(ipc_ctx: &IpcContext, _params: ()) -> Result<Option<UserWithSecrets>, Error> {
65+
pub fn get_user(ipc_ctx: &IpcContext, _params: NoParams) -> Result<Option<UserWithSecrets>, Error> {
6666
match ipc_ctx.user_controller.get_user()? {
6767
Some(user) => {
6868
if let Err(err) = user.access_token() {
@@ -80,7 +80,7 @@ pub fn set_user(ipc_ctx: &IpcContext, params: SetUserParams) -> Result<User, Err
8080
Ok(params.user)
8181
}
8282

83-
pub fn delete_user(ipc_ctx: &IpcContext, _params: ()) -> Result<(), Error> {
83+
pub fn delete_user(ipc_ctx: &IpcContext, _params: NoParams) -> Result<(), Error> {
8484
ipc_ctx.user_controller.delete_user()?;
8585
Ok(())
8686
}

0 commit comments

Comments
 (0)