Skip to content

Commit

Permalink
Init hooks in quarks supercollider#5753
Browse files Browse the repository at this point in the history
  • Loading branch information
capital-G committed May 20, 2022
1 parent b38fbc1 commit aae6c60
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions SCClassLibrary/Common/Quarks/Quark.sc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ Quark {
});
^isCompatible
}
runHook { |hook|
hook = hook.asSymbol;
if(this.data[hook].notNil, {
"Run % hook".format(hook).postln;
this.data[hook].();
});
}

install {
var success = Quarks.installQuark(this);
Expand All @@ -89,16 +96,20 @@ Quark {
if(Git.isGit(localPath), {
data = git = refspec = nil;
changed = true;
this.runHook(\preUpdate);
git = Git(localPath);
git.pull();
git.checkout("master");
this.runHook(\postUpdate);
("Quark '%' updated to version: % tag: % refspec: %".format(name, this.version, this.git.tag, this.refspec)).postln;
}, {
("Quark" + name + "was not installed using git, cannot update.").warn;
});
}
uninstall {
this.runHook(\preUninstall);
Quarks.uninstallQuark(this);
this.runHook(\postUninstall);
changed = true;
}

Expand Down
7 changes: 6 additions & 1 deletion SCClassLibrary/Common/Quarks/Quarks.sc
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ Quarks {
// by quark name or local path
this.installed.do { |q|
if(q.name == name, {
this.unlink(q.localPath)
this.uninstallQuark(q);
});
};
}
*uninstallQuark { |quark|
quark.runHook(\preUninstall);
this.unlink(quark.localPath);
quark.runHook(\postUninstall);
this.clearCache;
}
*clear {
Expand Down Expand Up @@ -151,6 +153,7 @@ Quarks {
});
localPath = this.quarkNameAsLocalPath(name);
if(Git.isGit(localPath), {
// Quark.update will run preUpdate and postUpdate hooks
Quark.fromLocalPath(localPath).update();
}, {
("Quark" + name + "was not installed using git, cannot update.").warn;
Expand Down Expand Up @@ -212,7 +215,9 @@ Quarks {
^false
});
};
quark.runHook(\preInstall);
this.link(quark.localPath);
quark.runHook(\postInstall);
(quark.name + "installed").postln;
this.clearCache();
^true
Expand Down

0 comments on commit aae6c60

Please sign in to comment.