Skip to content

Commit

Permalink
Update to latest mach zig + misc improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Beyley committed Jun 9, 2024
1 parent da7c2e3 commit e7208ce
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 106 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install Zig
uses: goto-bus-stop/setup-zig@v2
with:
version: 0.12.0-dev.3180+83e578a18
version: 0.13.0-dev.351+64ef45eb0

- name: Build
run: zig build -Doptimize=${{ matrix.mode }} -Dtarget=${{ matrix.target }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
zig-out/
zig-cache/
.zig-cache/
fresh_presence_config.ini
22 changes: 12 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

This document details the steps and other important information on how to contribute to FreshPresence. Feel free to skip sections if you believe you're already set.

## Requirements:
## Requirements

- Basic knowledge of [Zig](https://ziglang.org/)
- Basic knowledge of the Discord RPC API

## Software prerequisites

- [Zig](https://ziglang.org) (We target the latest [Mach Nominated Zig Version](https://machengine.org/about/nominated-zig))
- [Git](https://git-scm.com)
- Any text editor

# Preparing your system
In order to use Git you must set up your configuration, this should ideally match your GitHub account's name and email.
## Preparing your system

In order to use Git you must set up your configuration, this should ideally match your GitHub account's name and email.

You can use [GitHub Desktop](https://desktop.github.com) or the IDE of your choice to help you with this! **Or if you're more technically inclined**, follow the CLI instructions below.

Expand All @@ -22,23 +25,22 @@ This will modify the **global** config, which will allow you to contribute to mu

`$ git config --global user.email [email protected]`

# Preparing your new development environment
## Preparing your new development environment

It's almost time to clone FreshPresence! Create a fork by pressing the "Fork" button at the base of this repository.

Afterwards, open a terminal to your working directory and clone the new fork using Git.

This is usually done with the following command:
`$ git@github.com:<YOUR_USERNAME>/FreshPresence.git`
This is usually done with the following command:
`$ git clone https://github.com/<YOUR_USERNAME>/FreshPresence`

Now, open the folder/workspace/solution with the IDE you chose. Explore the codebase, experiment, and have fun!

To run the software in **DEBUG** mode, simply write:
To run the software in **Debug** mode, simply write:
`$ zig build run`

To compile for a specific platform, you can append `-Dtarget=TARGET` to the build invocation, eg. `zig build -Dtarget=x86_64-linux`
To compile for a specific platform, you can append `-Dtarget=TARGET` to the build invocation, eg. `zig build -Dtarget=x86_64-linux-gnu`

To compile a release build, you can append `-Doptimize=ReleaseSmall`. the possible options are `Debug`, `ReleaseSmall`, `ReleaseFast`, `ReleaseSafe`. Our builds are compiled with ReleaseSmall, but for test builds Debug or ReleaseSafe are preferred!

Make sure to add [the upstream FreshPresence repository](https://github.com/LittleBigRefresh/FreshPresence) as the "**upstream**" remote using your IDE or GitHub Desktop. Happy hunting!

### Follow up in the patching documentation for connecting using your choice of device, TBW
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ A tiny background app providing Discord Rich Presence for the LittleBigPlanet ga
[![Discord](https://img.shields.io/discord/1049223665243389953?label=Discord)](https://discord.gg/xN5yKdxmWG)

## Compatibility

FreshPresence is only designed for the [Refresh v3 API](https://github.com/LittleBigRefresh/Refresh), so FreshPresence will not work with alternative servers.

Additionally, LBP1 will only have limited rich presence.

## Running

### Legalties

> [!WARNING]
> FreshPresence is still early in development, as such we cannot make any guarantees about anything. You use FreshPresence at YOUR OWN RISK.
> FreshPresence is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Expand All @@ -25,6 +27,7 @@ Anyway, with the legal disclaimers out of the way...
### Instructions

#### From Github Actions

1. [Find the latest run](https://github.com/LittleBigRefresh/FreshPresence/actions)
1. Download the artifact for your OS, extract it somewhere most convenient to you, and run it.
1. Once it closes, update the `fresh_presence_config.ini` file to your preferred settings, set your username, then save and close the file.
Expand All @@ -33,12 +36,14 @@ Anyway, with the legal disclaimers out of the way...
To update, you can simply repeat this process, overwriting the previous file.

## It's on fire! What do I do?

FreshPresence isn't perfect, so it's not exactly uncommon to run into bugs. If you'd like, you can [create an issue](https://github.com/LittleBigRefresh/FreshPresence/issues/new) here on GitHub or join our [Discord](https://discord.gg/xN5yKdxmWG) for support.

Wherever you choose to post, be sure to include details about how to trigger the bug, text logs (not screenshots!), your environment, the bug's symptoms, and anything else you might find relevant to the bug.

## Building & Contributing
To contribute to FreshPresence, it may be helpful to refer to our [contributing guide](CONTRIBUTING.md) to get a basic development environment set up. If you're a pro, feel free to skip this as it's just your bog-standard setting up Zig guide.

To contribute to FreshPresence, it may be helpful to refer to our [contributing guide](CONTRIBUTING.md) to get a basic development environment set up. If you're a pro, feel free to skip this as it's just your bog-standard Zig set-up guide.

However, something important for all those involved: we also serve additional documentation relating to FreshPresence, Refresh, Bunkum, and LittleBigPlanet in general in our [Docs repo](https://littlebigrefresh.github.io/Docs/).

Expand Down
5 changes: 3 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn build(b: *std.Build) !void {

const exe = b.addExecutable(.{
.name = "FreshPresence",
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
Expand All @@ -26,7 +26,8 @@ pub fn build(b: *std.Build) !void {
exe.root_module.addImport("api", module);
//If we are on MacOS, we need to import the xcode frameworks
if (target.result.isDarwin()) {
@import("xcode_frameworks").addPaths(exe);
try exe.root_module.include_dirs.appendSlice(b.allocator, zboxer_lib.root_module.include_dirs.items);
try exe.root_module.lib_paths.appendSlice(b.allocator, zboxer_lib.root_module.lib_paths.items);
}
if (optimize == .ReleaseSmall) {
exe.root_module.strip = true;
Expand Down
24 changes: 10 additions & 14 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,24 @@
.version = "0.0.0",
.dependencies = .{
.@"zig-discord" = .{
.url = "https://github.com/Beyley/zig-discord/archive/94fd186363261afb0d85c34d39d8a6578469852a.tar.gz",
.hash = "12204b05e2b92642296d1a5918da6df7c8880d2a04ee5b9fbf7e8a8c0b1367ac2ad8",
.url = "git+https://github.com/Beyley/zig-discord#34807ac5259a1fcbf6006c33c584a2d5f2c7c658",
.hash = "1220ef5998bfbd39924e63cb87db71406b690bbddb000bf5f70a1597829f4b67e324",
},
.zBoxer = .{
.url = "https://github.com/Beyley/zBoxer/archive/ef0d24342a389c1eb5e9f5a01a23b1fb4fa6665f.tar.gz",
.hash = "122042d462b2600f3bd7bfb00292dde1d07dd26ae742655db7de6239aff58a56b394",
.url = "git+https://github.com/Beyley/zBoxer#b81c8b4de8eba47f2e0d27e56ebfaa10727c1dcc",
.hash = "1220b7b6ecd4554d46c6c4a047dc32fb024cb12c1806809eb66128cfbe1ffdf249b5",
},
.zini = .{
.url = "https://github.com/Beyley/zini/archive/aaeba1ad81742d52d3af086cb3c89c515ce5e728.tar.gz",
.hash = "1220b322b8ec9b10bc79e9da8def6cc3a49c9ffccf87d2e7577fc6e522bd0893173b",
.url = "git+https://github.com/Beyley/zini#58d413ea3a33c1ed5a88c2ec6a1ef5581e7bee15",
.hash = "12209bb5da9e8a7f39594bcb8e14282d4d2fb9f667005d33c1025369e4c2d41ba53d",
},
.known_folders = .{
.url = "https://github.com/ziglibs/known-folders/archive/055c95a717c5b54a0fc52ff5f370439c28eb2e73.tar.gz",
.hash = "12204a8a7e9184a77f70795b1fc8a9f94dff5cce208c20c5c6452967dddc498e0b64",
},
.xcode_frameworks = .{
.url = "https://github.com/hexops/xcode-frameworks/archive/ff1f5c15120b65504d8feccca8015a7e96ed580c.tar.gz",
.hash = "12207bc2707695102c636c26b60343e634127ee4d6e23210b1ae1664b2b2fea6076f",
.url = "git+https://github.com/ziglibs/known-folders#21a04eae9e0dca52e274ff848596941d5d68649f",
.hash = "12204536e3fef16cd9000b9f023a7c8c53399c4ebd70a9f7e310d1464484d410731d",
},
.refresh_api = .{
.url = "https://github.com/LittleBigRefresh/refresh-api-zig/archive/91c8c143742ce29f728698d73252fb7d15b0bb5b.tar.gz",
.hash = "1220b379d09524a31c0399a60756deaf61389a7acb69684211b9a722ab9b33a55e91",
.url = "git+https://github.com/LittleBigRefresh/refresh-api-zig#d98003c71161521b68358cfc2fcd0edf189d033d",
.hash = "1220ef4701713dd8589870c9b1d64ba298da8ff84676d5c28b75f8c354b353e87f88",
},
},
.paths = .{
Expand Down
7 changes: 3 additions & 4 deletions src/config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,19 @@ pub fn getConfig(allocator: std.mem.Allocator) !Self {

_ = win32.ShellExecuteW(null, std.unicode.utf8ToUtf16LeStringLiteral("edit"), windows_path, null, null, 0);
} else {
var child_process = std.ChildProcess.init(
var child_process = std.process.Child.init(
switch (builtin.os.tag) {
.linux => &.{ "xdg-open", full_path },
.macos => &.{ "open", full_path },
else => @compileError("Unknown platform!"),
},
allocator,
);
try child_process.spawn();
_ = try child_process.wait();
_ = try child_process.spawnAndWait();
}
}

std.os.exit(0);
std.posix.exit(0);
} else {
return err;
}
Expand Down
12 changes: 4 additions & 8 deletions src/lbp.zig
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
const std = @import("std");

pub fn qualifyAsset(allocator: std.mem.Allocator, uri: std.Uri, asset: []const u8, use_application_asset: bool) ![]const u8 {
var qualified_asset = std.ArrayList(u8).init(allocator);

pub fn qualifyAsset(writer: anytype, uri: std.Uri, asset: []const u8, use_application_asset: bool) !void {
//If the asset length matches a SHA1 hex string,
if (!use_application_asset) {
//Assume it is a server asset
try uri.format(":+", .{}, qualified_asset.writer());
try std.fmt.format(qualified_asset.writer(), "/api/v3/assets/{s}/image", .{asset});
try uri.format(";+", .{}, writer);
try std.fmt.format(writer, "/api/v3/assets/{s}/image", .{asset});
} else {
//Assume it is a discord asset
try qualified_asset.appendSlice(asset);
try writer.writeAll(asset);
}

return try qualified_asset.toOwnedSlice();
}
Loading

0 comments on commit e7208ce

Please sign in to comment.