Skip to content

Commit

Permalink
chore: adjust for astal core lib split
Browse files Browse the repository at this point in the history
the astal core lib is now split into two parts
  • Loading branch information
Aylur committed Oct 15, 2024
1 parent 5838646 commit 89b8918
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 139 deletions.
6 changes: 3 additions & 3 deletions flake.lock

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

60 changes: 45 additions & 15 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
// {
default = self.packages.${system}.ags;
ags = pkgs.callPackage ./src {
astal = astal.packages.${system}.default;
astal3 = astal.packages.${system}.astal3;
astal-io = astal.packages.${system}.io;
astal-gjs = astal.packages.${system}.gjs;
};
agsFull = pkgs.callPackage ./src {
astal = astal.packages.${system}.default;
astal3 = astal.packages.${system}.astal3;
astal-io = astal.packages.${system}.io;
astal-gjs = astal.packages.${system}.gjs;
extraPackages = builtins.attrValues (
builtins.removeAttrs astal.packages.${system} ["docs"]
);
Expand All @@ -43,16 +47,20 @@
inherit (lib.modules) mkIf;
inherit (lib.options) mkOption mkEnableOption literalExpression;

defaultAgsPackage = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
defaultAstalPackage = self.packages.${pkgs.stdenv.hostPlatform.system}.astal;
cfg = config.programs.ags;
default = {
agsPackage = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
gtk3Package = self.packages.${pkgs.stdenv.hostPlatform.system}.astal3;
ioPackage = self.packages.${pkgs.stdenv.hostPlatform.system}.io;
gjsPackage = self.packages.${pkgs.stdenv.hostPlatform.system}.gjs;
};
in {
options.programs.ags = {
enable = mkEnableOption "ags";

package = mkOption {
type = types.package;
default = defaultAgsPackage;
default = default.agsPackage;
defaultText = literalExpression "inputs.ags.packages.${pkgs.stdenv.hostPlatform.system}.default";
description = ''
The Ags package to use.
Expand All @@ -61,14 +69,35 @@
'';
};

astalPackage = mkOption {
astal.gtk3Package = mkOption {
type = types.package;
default = default.gtk3Package;
defaultText = literalExpression "inputs.ags.packages.${pkgs.stdenv.hostPlatform.system}.astal3";
description = ''
The GTK3 Astal package to use.
By default, this option will use the `packages.astal3` as exposed by this flake.
'';
};

astal.ioPackage = mkOption {
type = types.package;
default = default.ioPackage;
defaultText = literalExpression "inputs.ags.packages.${pkgs.stdenv.hostPlatform.system}.io";
description = ''
The core Astal package to use.
By default, this option will use the `packages.io` as exposed by this flake.
'';
};

astal.gjsPackage = mkOption {
type = types.package;
default = defaultAstalPackage;
defaultText = literalExpression "inputs.ags.packages.${pkgs.stdenv.hostPlatform.system}.astal";
default = default.gjsPackage;
description = ''
The Astal package to use when transpiling.
The Astal Gjs package to use.
By default, this option will use the `packages.astal` as exposed by this flake.
By default, this option will use the `packages.gjs` as exposed by this flake.
'';
};

Expand Down Expand Up @@ -116,25 +145,26 @@
(let
pkg = cfg.package.override {
extraPackages = cfg.extraPackages;
astal = cfg.astalPackage;
astalGjs = "${config.home.homeDirectory}/.local/share/ags";
astal3 = cfg.astal.gtk3Package;
astal-io = cfg.astal.ioPackage;
astal-gjs = "${config.home.homeDirectory}/.local/share/ags";
};
in {
programs.ags.finalPackage = pkg;
home.packages = [pkg];
home.file.".local/share/ags".source = "${cfg.astalPackage}/share/astal/gjs";
home.file.".local/share/ags".source = "${cfg.astal.gjsPackage}/share/astal/gjs";
})
(mkIf cfg.systemd.enable {
systemd.user.services.ags = {
Unit = {
Description = "AGS - A library built for GJS to allow defining GTK widgets in a declarative way.";
Description = "AGS - Tool for scaffolding Astal+TypeScript+JSX projects.";
Documentation = "https://github.com/Aylur/ags";
PartOf = ["graphical-session.target"];
After = ["graphical-session-pre.target"];
};

Service = {
ExecStart = "${config.programs.ags.package}/bin/ags";
ExecStart = "${cfg.finalPackage}/bin/ags";
Restart = "on-failure";
KillMode = "mixed";
};
Expand Down
30 changes: 0 additions & 30 deletions src/data/config/Bar.jsx

This file was deleted.

5 changes: 3 additions & 2 deletions src/data/config/Bar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { App, Variable, Astal, Gtk } from "astal"
import { App, Astal, Gtk } from "astal/gtk3"
import { Variable } from "astal"

const time = Variable<string>("").poll(1000, "date")
const time = Variable("").poll(1000, "date")

export default function Bar(monitor: number) {
return <window
Expand Down
4 changes: 2 additions & 2 deletions src/data/config/app.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { App } from "astal"
import style from "inline:./style.css"
import { App } from "astal/gtk3"
import style from "./style.css"
import Bar from "./widget/Bar"

App.start({
Expand Down
32 changes: 0 additions & 32 deletions src/data/config/index.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/data/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ declare module "inline:*" {
export default content
}

declare module "*.sass" {
const content: string
export default content
}

declare module "*.scss" {
const content: string
export default content
Expand Down
4 changes: 2 additions & 2 deletions src/data/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
// "checkJs": true,
// "allowJs": true,
"jsx": "react-jsx",
"jsxImportSource": "@ASTAL_GJS@/src/jsx",
"jsxImportSource": "@ASTAL_GJS@/@GTK_VERSION@",
"paths": {
"astal": [
"@ASTAL_GJS@"
],
"astal/*": [
"@ASTAL_GJS@/src/*"
"@ASTAL_GJS@/*"
]
},
}
Expand Down
3 changes: 2 additions & 1 deletion src/data/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function ver(name = "", lib = "") {
print(`${name}: ${ver}`)
}

ver("astal")
ver("astal3")
ver("astal-io", "IO")
ver("apps", "Apps")
ver("auth", "Auth")
ver("battery", "Battery")
Expand Down
12 changes: 7 additions & 5 deletions src/default.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
astal3,
astal-io,
astal-gjs,
lib,
writers,
buildGoModule,
wrapGAppsHook,
gobject-introspection,
gtk3,
glib,
astal,
gjs,
nodejs,
dart-sass,
extraPackages ? [],
astalGjs ? "${astal}/share/astal/gjs"
}: let
inherit (builtins) replaceStrings readFile;

Expand All @@ -26,7 +27,7 @@
gjs
nodejs
dart-sass
astal # FIXME: should not be needed after the astal commends are properly implemented using dbus in astal.go
astal-io # FIXME: should not be needed after the astal commends are properly implemented using dbus in astal.go
];
in
buildGoModule {
Expand All @@ -44,7 +45,8 @@ in
buildInputs = extraPackages ++ [
glib
gtk3
astal
astal-io
astal3
];

preFixup = ''
Expand All @@ -55,6 +57,6 @@ in
'';

ldflags = [
"-X main.astalGjs=${astalGjs}"
"-X main.astalGjs=${astal-gjs}"
];
}
2 changes: 1 addition & 1 deletion src/gentypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"
)

var tsForGir = "@ts-for-gir/cli@4.0.0-beta.14"
var tsForGir = "@ts-for-gir/cli@4.0.0-beta.16"

func girDirectories() []string {
dataDirs := append([]string{
Expand Down
48 changes: 7 additions & 41 deletions src/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,32 @@ var (
//go:embed data/tsconfig.json
tsconfig string

//go:embed data/config/Bar.jsx
jsx string

//go:embed data/config/Bar.tsx
tsx string
bartsx string

//go:embed data/config/app.ts
app string
appts string

//go:embed data/config/style.css
style string
stylecss string
)

type File struct {
name string
content string
}

func ifelse(condition bool, yes string, no string) string {
if condition {
return yes
} else {
return no
}
}

func getConfig(typescript bool) (File, File) {
lang := ifelse(typescript, "ts", "js")

appfile := File{
name: "app." + lang,
content: app,
}

barfile := File{
name: "Bar." + lang + "x",
content: ifelse(typescript, tsx, jsx),
}

return appfile, barfile
}

// TODO: interactive init
func InitConfig() {
config := *Opts.config
if info, err := os.Stat(config); err == nil && info.IsDir() {
Err("could not initialize: " + Cyan(config) + " is not empty")
}

tsconf := strings.ReplaceAll(tsconfig, "@ASTAL_GJS@", astalGjs)
appfile, bar := getConfig(true)

tsconf = strings.ReplaceAll(tsconf, "@GTK_VERSION@", "gtk3") // TODO: gtk4 flag
Mkdir(config + "/widget")

WriteFile(config+"/.gitignore", "@girs/\nnode_modules/")
WriteFile(config+"/tsconfig.json", tsconf)
WriteFile(config+"/env.d.ts", envdts)
WriteFile(config+"/style.css", style)
WriteFile(config+"/widget/"+bar.name, bar.content)
WriteFile(config+"/"+appfile.name, appfile.content)
WriteFile(config+"/style.css", stylecss)
WriteFile(config+"/widget/Bar.tsx", bartsx)
WriteFile(config+"/app.ts", appts)

if err := GenTypes(); err != nil {
Err(err)
Expand Down

0 comments on commit 89b8918

Please sign in to comment.