Skip to content

Commit

Permalink
Odin (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
meisenzahl authored Aug 13, 2021
1 parent d9870a1 commit 5ae9547
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 144 deletions.
33 changes: 15 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,28 @@ name: CI
on: [push, pull_request]

jobs:
build:

flatpak:
runs-on: ubuntu-latest

container:
image: elementary/docker:stable
image: ghcr.io/elementary/flatpak-platform/runtime:6
options: --privileged

steps:
- uses: actions/checkout@v1
- name: Install Dependencies
run: |
apt update
apt install -y libgranite-dev libgtk-3-dev meson valac
- name: Build
env:
DESTDIR: out
run: |
meson build
ninja -C build
ninja -C build install
- uses: actions/checkout@v2
- uses: bilelmoussaoui/flatpak-github-actions/flatpak-builder@v3
with:
bundle: com.github.manexim.insomnia.flatpak
manifest-path: com.github.manexim.insomnia.yml

lint:
run-tests: true

runs-on: ubuntu-latest
repository-name: appcenter
repository-url: https://flatpak.elementary.io/repo.flatpakrepo
cache-key: "flatpak-builder-${{ github.sha }}"

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: elementary/actions/vala-lint@master
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*~
build
build-dir
.flatpak-builder
24 changes: 0 additions & 24 deletions .travis.yml

This file was deleted.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</p>

<p align="center">
<a href="https://travis-ci.org/manexim/insomnia">
<img src="https://img.shields.io/travis/manexim/insomnia.svg">
<a href="https://github.com/manexim/insomnia/actions/workflows/main.yml">
<img src="https://github.com/manexim/insomnia/workflows/CI/badge.svg">
</a>
<a href="https://github.com/manexim/insomnia/releases/">
<img src="https://img.shields.io/github/release/manexim/insomnia.svg">
Expand Down Expand Up @@ -45,6 +45,7 @@ These dependencies must be present before building:

- `libgranite-dev`
- `libgtk-3-dev`
- `libhandy-1-dev` >=1.0.0
- `meson`
- `valac`

Expand Down
21 changes: 21 additions & 0 deletions com.github.manexim.insomnia.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
app-id: com.github.manexim.insomnia
runtime: io.elementary.Platform
runtime-version: '6'
sdk: io.elementary.Sdk
command: com.github.manexim.insomnia
finish-args:
- '--share=ipc'
- '--socket=fallback-x11'
- '--socket=wayland'

# needed for perfers-color-scheme
- '--system-talk-name=org.freedesktop.Accounts'

# needed for inhibitor
- '--talk-name=org.freedesktop.ScreenSaver'
modules:
- name: insomnia
buildsystem: meson
sources:
- type: dir
path: .
1 change: 1 addition & 0 deletions data/com.github.manexim.insomnia.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<value key="x-appcenter-color-primary-text">#333</value>
<!-- Suggested price in USD; just a suggestion, NOT a minimum. -->
<value key="x-appcenter-suggested-price">5</value>
<value key="x-appcenter-stripe">pk_live_51EkDoMLYdJjuk3fQWqfwmLR9iSEtCiuaUOOJK61aay69r2W2gC6QoHEkOklKcIk2wMMebVKn5trxMYjCULqKKyZs00e78s0Kzo</value>
</custom>
<content_rating type="oars-1.1">
<content_attribute id="violence-cartoon">none</content_attribute>
Expand Down
5 changes: 0 additions & 5 deletions debian/changelog

This file was deleted.

1 change: 0 additions & 1 deletion debian/compat

This file was deleted.

16 changes: 0 additions & 16 deletions debian/control

This file was deleted.

7 changes: 0 additions & 7 deletions debian/copyright

This file was deleted.

29 changes: 0 additions & 29 deletions debian/rules

This file was deleted.

1 change: 0 additions & 1 deletion debian/source/format

This file was deleted.

2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ add_global_arguments('-DGETTEXT_PACKAGE="@0@"'.format (meson.project_name()), la

granite_dep = dependency('granite')
gtk_plus_3_dep = dependency('gtk+-3.0')
libhandy_dep = dependency('libhandy-1', version: '>=1.0.0')

dependencies = [
granite_dep,
gtk_plus_3_dep,
libhandy_dep,
]

subdir('data')
Expand Down
10 changes: 6 additions & 4 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ public class Insomnia.Application : Gtk.Application {
var granite_settings = Granite.Settings.get_default ();
var gtk_settings = Gtk.Settings.get_default ();

gtk_settings.gtk_application_prefer_dark_theme =
granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
gtk_settings.gtk_application_prefer_dark_theme = (
granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK
);

granite_settings.notify["prefers-color-scheme"].connect (() => {
gtk_settings.gtk_application_prefer_dark_theme =
granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK;
gtk_settings.gtk_application_prefer_dark_theme = (
granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK
);
});

window.show_all ();
Expand Down
27 changes: 0 additions & 27 deletions src/Inhibitor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
public interface Insomnia.ScreenSaverIface : Object {
public abstract uint32 inhibit (string app_name, string reason) throws Error;
public abstract void un_inhibit (uint32 cookie) throws Error;
public abstract void simulate_user_activity () throws Error;
}

public class Insomnia.Inhibitor : Object {
Expand All @@ -37,7 +36,6 @@ public class Insomnia.Inhibitor : Object {
private ScreenSaverIface? screensaver_iface = null;

private bool inhibited = false;
private bool simulator_started = false;

private Inhibitor () {
try {
Expand All @@ -60,7 +58,6 @@ public class Insomnia.Inhibitor : Object {
try {
inhibited = true;
inhibit_cookie = screensaver_iface.inhibit (Constants.APP_ID, Constants.INHIBIT_STRING);
simulate_activity ();
debug ("Inhibiting screen");
} catch (Error e) {
warning ("Could not inhibit screen: %s", e.message);
Expand All @@ -79,28 +76,4 @@ public class Insomnia.Inhibitor : Object {
}
}
}

/*
* Inhibit currently does not block a suspend from ocurring,
* so we simulate user activity every 2 mins to prevent it
*/
private void simulate_activity () {
if (simulator_started) return;

simulator_started = true;
Timeout.add_full (Priority.DEFAULT, 120000, ()=> {
if (inhibited) {
try {
debug ("Simulating activity");
screensaver_iface.simulate_user_activity ();
} catch (Error e) {
warning ("Could not simulate user activity: %s", e.message);
}
} else {
simulator_started = false;
}

return inhibited;
});
}
}
28 changes: 18 additions & 10 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* Authored by: Marius Meisenzahl <[email protected]>
*/

public class Insomnia.MainWindow : Gtk.ApplicationWindow {
private Gtk.HeaderBar headerbar;
public class Insomnia.MainWindow : Hdy.Window {
private Hdy.HeaderBar headerbar;
private Gtk.Label title_label;

private bool timer_started;
Expand All @@ -38,12 +38,13 @@ public class Insomnia.MainWindow : Gtk.ApplicationWindow {
}

construct {
get_style_context ().add_class ("rounded");
Hdy.init ();

headerbar = new Gtk.HeaderBar () {
show_close_button = true
headerbar = new Hdy.HeaderBar () {
decoration_layout = "close:",
show_close_button = true,
title = Constants.APP_NAME
};
headerbar.get_style_context ().add_class ("default-decoration");

var menu_widget = new Gtk.Grid () {
orientation = Gtk.Orientation.VERTICAL,
Expand Down Expand Up @@ -113,11 +114,11 @@ public class Insomnia.MainWindow : Gtk.ApplicationWindow {

headerbar.pack_end (app_menu);

set_titlebar (headerbar);

var grid = new Gtk.Grid () {
halign = Gtk.Align.CENTER,
valign = Gtk.Align.CENTER
valign = Gtk.Align.CENTER,
hexpand = true,
vexpand = true
};

title_label = new Gtk.Label ("") {
Expand All @@ -127,7 +128,14 @@ public class Insomnia.MainWindow : Gtk.ApplicationWindow {

grid.add (title_label);

add (grid);
var main_layout = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
main_layout.add (headerbar);
main_layout.add (grid);

var window_handle = new Hdy.WindowHandle ();
window_handle.add (main_layout);

add (window_handle);
}

private void update () {
Expand Down

0 comments on commit 5ae9547

Please sign in to comment.