Skip to content

Commit

Permalink
update flake
Browse files Browse the repository at this point in the history
  • Loading branch information
ominit committed Jan 23, 2025
1 parent d1f2f96 commit 6fd1a64
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 64 deletions.
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 92 additions & 21 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
};

outputs = {
self,
nixpkgs,
crane,
flake-utils,
Expand All @@ -24,30 +23,33 @@
inherit system;
overlays = [(import rust-overlay)];
};
rustToolchainFor = p:
p.rust-bin.stable.latest.default.override {
targets = ["wasm32-unknown-unknown"];
};

inherit (pkgs) lib;
craneLib = crane.mkLib pkgs;
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchainFor;

unfilteredRoot = ./.;
src = lib.fileset.toSource {
root = ./.;
root = unfilteredRoot;
fileset = lib.fileset.unions [
(craneLib.fileset.commonCargoSources ./.)
# ./public/.
(lib.fileset.fileFilter (file: lib.any file.hasExt ["html" "css"]) ./.)
(craneLib.fileset.commonCargoSources unfilteredRoot)
./Cargo.toml
./tailwind.config.js
(lib.fileset.maybeMissing ./src-tauri)
(lib.fileset.maybeMissing ./public)
(lib.fileset.fileFilter (file: lib.any file.hasExt ["html" "css"]) unfilteredRoot)
];
};

cargoArtifacts = craneLib.buildDepsOnly {
inherit src;
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
doCheck = false;
};

nativeBuildInputs = with pkgs; [
pkg-config
gobject-introspection
cargo-tauri
cargo-tauri.hook
(rust-bin.stable.latest.default.override {
targets = ["wasm32-unknown-unknown"];
targets = ["wasm32-unknown-unknown" "x86_64-unknown-linux-gnu"];
})
];

Expand All @@ -67,15 +69,84 @@
librsvg
];

discidium = craneLib.buildPackage {
name = "discidium";
inherit buildInputs nativeBuildInputs cargoArtifacts src;
discidium-trunk = craneLib.buildPackage {
inherit src;
strictDeps = true;
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
cargoArtifacts = craneLib.buildDepsOnly {
inherit src;
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
doCheck = false;
};
doCheck = false;
pnameSuffix = "-trunk";

preConfigure = ''
echo configuring trunk tools
TRUNK_TOOLS_SASS=$(sass --version | head -n1)
TRUNK_TOOLS_WASM_BINDGEN=$(wasm-bindgen --version | cut -d' ' -f2)
TRUNK_TOOLS_WASM_OPT="version_$(wasm-opt --version | cut -d' ' -f3)"
export TRUNK_TOOLS_SASS
export TRUNK_TOOLS_WASM_BINDGEN
export TRUNK_TOOLS_WASM_OPT
postInstall = ''
# cargo tauri build
# wrapProgram $out/bin/discidium \
# --prefix LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath buildInputs}"
echo "TRUNK_TOOLS_SASS=''${TRUNK_TOOLS_SASS}"
echo "TRUNK_TOOLS_WASM_BINDGEN=''${TRUNK_TOOLS_WASM_BINDGEN}"
echo "TRUNK_TOOLS_WASM_OPT=''${TRUNK_TOOLS_WASM_OPT}"
'';

buildPhaseCargoCommand = ''
trunk build --release=true --offline
'';

installPhaseCommand = ''
cp -r ./dist $out
'';

doNotPostBuildInstallCargoBinaries = true;
doInstallCargoArtifacs = false;

wasm-bindgen-cli = pkgs.wasm-bindgen-cli.override {
version = "0.2.100";
hash = "sha256-3RJzK7mkYFrs7C/WkhW9Rr4LdP5ofb2FdYGz1P7Uxog=";
cargoHash = "sha256-tD0OY2PounRqsRiFh8Js5nyknQ809ZcHMvCOLrvYHRE=";
# When updating to a new version comment out the above two lines and
# uncomment the bottom two lines. Then try to do a build, which will fail
# but will print out the correct value for `hash`. Replace the value and then
# repeat the process but this time the printed value will be for `cargoHash`
# hash = lib.fakeHash;
# cargoHash = lib.fakeHash;
};

nativeBuildInputs = with pkgs; [binaryen dart-sass trunk wasm-bindgen-cli tailwindcss];
};

discidium = craneLib.buildPackage {
pname = "discidium";
inherit buildInputs nativeBuildInputs src;
cargoArtifacts = craneLib.buildDepsOnly {
postUnpack = ''
cd $sourceRoot/src-tauri
sourceRoot="."
'';
inherit buildInputs nativeBuildInputs src;
postInstall = ''
cd ../
'';
doCheck = false;
};
doCheck = false;
preConfigure = ''
cp -r ${discidium-trunk} ./dist
'';
buildPhaseCargoCommand = ''
cargo tauri build
'';
installPhaseCommand = ''
cp -r ./target/release/bundle/deb/*/data/usr $out
mv $out/bin/discidium-tauri $out/bin/discidium
'';
doNotPostBuildInstallCargoBinaries = true;
};
in {
packages.default = discidium;
Expand Down
7 changes: 4 additions & 3 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"build": {
"beforeDevCommand": "trunk serve",
"devUrl": "http://localhost:1420",
"beforeBuildCommand": "trunk build",
"frontendDist": "../dist"
},
"app": {
Expand All @@ -24,7 +23,9 @@
},
"bundle": {
"active": true,
"targets": "all",
"targets": [
"deb"
],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
Expand All @@ -33,4 +34,4 @@
"icons/icon.ico"
]
}
}
}
30 changes: 16 additions & 14 deletions src/api/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,21 @@ impl Client {
}

async fn get_gateway_url(&self) -> Result<String> {
let response = self
.client
.request(Method::GET, format!("{}{}", ENDPOINT_URL, "/gateway"))
.header("Content-Type", "application/json")
.send()
.await?;
Ok(response
.json::<Value>()
.await?
.get("url")
.expect("no url in response to get_gateway_url")
.as_str()
.expect("could not parse str")
.replace("\"", ""))
// let response = self
// .client
// .request(Method::GET, format!("{}{}", ENDPOINT_URL, "/gateway"))
// .header("Content-Type", "application/json")
// .send()
// .await?;
// Ok(response
// .json::<Value>()
// .await?
// .get("url")
// .expect("no url in response to get_gateway_url")
// .as_str()
// .expect("could not parse str")
// .replace("\"", ""))
// TODO it currents receives a cors cross origin refferer error
Ok("wss://gateway.discord.gg".to_string())
}
}
35 changes: 18 additions & 17 deletions src/api/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,18 @@ impl Connection {

let sequence;
let ready;
loop {
match ws_receiver.next().await.unwrap() {
GatewayEvent::Dispatch(seq, Event::Ready(event)) => {
sequence = seq;
ready = event;
break;
}
GatewayEvent::InvalidateSession => {
web_sys::console::log_1(&format!("invalidate session").into());
todo!("invalidate session")
}
other => {
web_sys::console::log_1(&format!("unknown response: {:?}", other).into());
// panic!("unknown response: {:?}", other)
}
match ws_receiver.next().await.unwrap() {
GatewayEvent::Dispatch(seq, Event::Ready(event)) => {
sequence = seq;
ready = event;
}
GatewayEvent::InvalidateSession => {
web_sys::console::log_1(&format!("invalidate session").into());
todo!("invalidate session")
}
other => {
web_sys::console::log_1(&format!("unknown response: {:?}", other).into());
panic!("unknown response: {:?}", other)
}
}
web_sys::console::log_1(&format!("a").into());
Expand Down Expand Up @@ -143,7 +140,9 @@ async fn keepalive(
.await
.unwrap()
{
GatewayEvent::Hello(heartbeat_interval) => interval = heartbeat_interval,
GatewayEvent::Hello(heartbeat_interval) => {
interval = heartbeat_interval;
}
_ => panic!("expected hello during handshake"),
}

Expand All @@ -153,7 +152,9 @@ async fn keepalive(
spawn_local(async move {
loop {
match receive_json(&mut ws_receiver, GatewayEvent::decode).await {
Ok(event) => sender.unbounded_send(event).unwrap(),
Ok(event) => {
sender.unbounded_send(event).unwrap();
}
Err(_) => {}
}
sleep(std::time::Duration::from_millis(100)).await;
Expand Down

0 comments on commit 6fd1a64

Please sign in to comment.