Browse Source

fix widget attribute names

master
yggverse 2 months ago
parent
commit
5b88c67084
  1. 8
      src/app/browser.rs
  2. 42
      src/app/browser/database.rs

8
src/app/browser.rs

@ -15,6 +15,7 @@ use std::{path::PathBuf, sync::Arc};
const DEFAULT_HEIGHT: i32 = 480; const DEFAULT_HEIGHT: i32 = 480;
const DEFAULT_WIDTH: i32 = 640; const DEFAULT_WIDTH: i32 = 640;
const MAXIMIZED: bool = false;
pub struct Browser { pub struct Browser {
// Extras // Extras
@ -81,6 +82,7 @@ impl Browser {
.child(main.widget()) .child(main.widget())
.default_height(DEFAULT_HEIGHT) .default_height(DEFAULT_HEIGHT)
.default_width(DEFAULT_WIDTH) .default_width(DEFAULT_WIDTH)
.maximized(MAXIMIZED)
.build(); .build();
// Assign actions // Assign actions
@ -222,9 +224,9 @@ impl Browser {
pub fn save(&self, app_id: i64) { pub fn save(&self, app_id: i64) {
match self.database.add( match self.database.add(
app_id, app_id,
self.widget.width(), self.widget.default_width(),
self.widget.height(), self.widget.default_height(),
self.widget.is_fullscreen(), self.widget.is_maximized(),
) { ) {
Ok(_) => { Ok(_) => {
// Delegate save action to childs // Delegate save action to childs

42
src/app/browser/database.rs

@ -5,9 +5,9 @@ pub struct Table {
pub id: i64, pub id: i64,
pub app_id: i64, pub app_id: i64,
// pub time: i64, // pub time: i64,
pub width: i32, pub default_width: i32,
pub height: i32, pub default_height: i32,
pub is_fullscreen: bool, pub is_maximized: bool,
} }
pub struct Database { pub struct Database {
@ -22,9 +22,9 @@ impl Database {
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
`time` INTEGER NOT NULL DEFAULT (UNIXEPOCH('NOW')), `time` INTEGER NOT NULL DEFAULT (UNIXEPOCH('NOW')),
`app_id` INTEGER NOT NULL, `app_id` INTEGER NOT NULL,
`width` INTEGER NOT NULL, `default_width` INTEGER NOT NULL,
`height` INTEGER NOT NULL, `default_height` INTEGER NOT NULL,
`is_fullscreen` INTEGER NOT NULL `is_maximized` INTEGER NOT NULL
)", )",
[], [],
)?; )?;
@ -35,22 +35,22 @@ impl Database {
pub fn add( pub fn add(
&self, &self,
app_id: i64, app_id: i64,
width: i32, default_width: i32,
height: i32, default_height: i32,
is_fullscreen: bool, is_maximized: bool,
) -> Result<usize, Error> { ) -> Result<usize, Error> {
self.connection.execute( self.connection.execute(
"INSERT INTO `app_browser` ( "INSERT INTO `app_browser` (
`app_id`, `app_id`,
`width`, `default_width`,
`height`, `default_height`,
`is_fullscreen` `is_maximized`
) VALUES (?, ?, ?, ?)", ) VALUES (?, ?, ?, ?)",
[ [
app_id, app_id,
width as i64, default_width as i64,
height as i64, default_height as i64,
match is_fullscreen { match is_maximized {
true => 1, true => 1,
false => 0, false => 0,
}, },
@ -62,18 +62,18 @@ impl Database {
let mut statement = self.connection.prepare( let mut statement = self.connection.prepare(
"SELECT `id`, "SELECT `id`,
`app_id`, `app_id`,
`width`, `default_width`,
`height`, `default_height`,
`is_fullscreen` FROM `app_browser` WHERE `app_id` = ?", `is_maximized` FROM `app_browser` WHERE `app_id` = ?",
)?; )?;
let result = statement.query_map([app_id], |row| { let result = statement.query_map([app_id], |row| {
Ok(Table { Ok(Table {
id: row.get(0)?, id: row.get(0)?,
app_id: row.get(1)?, app_id: row.get(1)?,
width: row.get(2)?, default_width: row.get(2)?,
height: row.get(3)?, default_height: row.get(3)?,
is_fullscreen: row.get(4)?, is_maximized: row.get(4)?,
}) })
})?; })?;

Loading…
Cancel
Save