mirror of
https://github.com/haorendashu/nowser.git
synced 2026-01-31 15:14:27 +01:00
add quick action and desktop, bookmark add edit dialog
This commit is contained in:
@@ -5,6 +5,7 @@ class Bookmark {
|
||||
String? favicon;
|
||||
int? weight;
|
||||
int? addedToIndex;
|
||||
int? addedToQa;
|
||||
int? createdAt;
|
||||
|
||||
Bookmark(
|
||||
@@ -14,6 +15,7 @@ class Bookmark {
|
||||
this.favicon,
|
||||
this.weight,
|
||||
this.addedToIndex,
|
||||
this.addedToQa,
|
||||
this.createdAt});
|
||||
|
||||
Bookmark.fromJson(Map<String, dynamic> json) {
|
||||
@@ -23,6 +25,7 @@ class Bookmark {
|
||||
favicon = json['favicon'];
|
||||
weight = json['weight'];
|
||||
addedToIndex = json['added_to_index'];
|
||||
addedToQa = json['added_to_qa'];
|
||||
createdAt = json['created_at'];
|
||||
}
|
||||
|
||||
@@ -34,6 +37,7 @@ class Bookmark {
|
||||
data['favicon'] = this.favicon;
|
||||
data['weight'] = this.weight;
|
||||
data['added_to_index'] = this.addedToIndex;
|
||||
data['added_to_qa'] = this.addedToQa;
|
||||
data['created_at'] = this.createdAt;
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,20 @@ class BookmarkDB {
|
||||
return objs;
|
||||
}
|
||||
|
||||
static Future<List<Bookmark>> allQas({DatabaseExecutor? db}) async {
|
||||
List<Bookmark> objs = [];
|
||||
List<Object?>? arguments = [];
|
||||
db = await DB.getDB(db);
|
||||
var sql =
|
||||
"select * from bookmark where added_to_qa = 1 order by created_at desc";
|
||||
List<Map<String, dynamic>> list = await db.rawQuery(sql, arguments);
|
||||
for (var i = 0; i < list.length; i++) {
|
||||
var json = list[i];
|
||||
objs.add(Bookmark.fromJson(json));
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
static Future<void> deleteByIds(List<int> ids, {DatabaseExecutor? db}) async {
|
||||
var sql = "delete from bookmark where id in(";
|
||||
for (var id in ids) {
|
||||
@@ -39,4 +53,9 @@ class BookmarkDB {
|
||||
db = await DB.getDB(db);
|
||||
await db.execute(sql, ids);
|
||||
}
|
||||
|
||||
static Future update(Bookmark o, {DatabaseExecutor? db}) async {
|
||||
db = await DB.getDB(db);
|
||||
await db.update("bookmark", o.toJson(), where: "id = ?", whereArgs: [o.id]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import 'package:path/path.dart';
|
||||
import 'package:process_run/shell_run.dart';
|
||||
|
||||
class DB {
|
||||
static const _VERSION = 1;
|
||||
static const _VERSION = 2;
|
||||
|
||||
static const _dbName = "nowser.db";
|
||||
|
||||
@@ -21,14 +21,14 @@ class DB {
|
||||
}
|
||||
|
||||
try {
|
||||
_database =
|
||||
await openDatabase(path, version: _VERSION, onCreate: _onCreate);
|
||||
_database = await openDatabase(path,
|
||||
version: _VERSION, onCreate: _onCreate, onUpgrade: _onUpgrade);
|
||||
} catch (e) {
|
||||
if (Platform.isLinux) {
|
||||
// maybe it need install sqlite first, but this command need run by root.
|
||||
await run('sudo apt-get -y install libsqlite3-0 libsqlite3-dev');
|
||||
_database =
|
||||
await openDatabase(path, version: _VERSION, onCreate: _onCreate);
|
||||
_database = await openDatabase(path,
|
||||
version: _VERSION, onCreate: _onCreate, onUpgrade: _onUpgrade);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,11 +50,19 @@ class DB {
|
||||
db.execute("create index zap_log_index on zap_log (app_id);");
|
||||
|
||||
db.execute(
|
||||
"create table bookmark(id integer not null constraint bookmark_pk primary key autoincrement,title text,url text not null,favicon text,weight integer,added_to_index integer,created_at integer);");
|
||||
"create table bookmark(id integer not null constraint bookmark_pk primary key autoincrement,title text,url text not null,favicon text,weight integer,added_to_index integer, added_to_qa integer,created_at integer);");
|
||||
db.execute(
|
||||
"create table browser_history(id integer not null constraint browser_history_pk primary key autoincrement,title text,url text not null,favicon text,created_at integer);");
|
||||
}
|
||||
|
||||
static Future<void> _onUpgrade(
|
||||
Database db, int oldVersion, int newVersion) async {
|
||||
if (oldVersion == 1 && newVersion == 2) {
|
||||
db.execute(
|
||||
"alter table bookmark add added_to_qa integer after added_to_index");
|
||||
}
|
||||
}
|
||||
|
||||
static Future<Database> getCurrentDatabase() async {
|
||||
if (_database == null) {
|
||||
await init();
|
||||
|
||||
Reference in New Issue
Block a user